blob: f96592fbf026134d4e8f6a42e9781a1f8b835f18 [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
975static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
976{
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) {}
985static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
986#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
2319 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302320 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302321
2322 if (QDF_TIMER_STATE_RUNNING ==
2323 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2324
2325 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002326 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2328 }
2329
2330 switch (hdd_ctx->driver_status) {
2331 case DRIVER_MODULES_UNINITIALIZED:
2332 unint = true;
2333 /* Fall through dont add break here */
2334 case DRIVER_MODULES_CLOSED:
2335 if (!reinit && !unint) {
2336 ret = pld_power_on(qdf_dev->dev);
2337 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002338 hdd_err("Failed to Powerup the device; errno: %d",
2339 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302340 goto release_lock;
2341 }
2342 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002343
2344 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2345 hdd_ctx->config->enable_fw_log);
2346
Arun Khandavallifae92942016-08-01 13:31:08 +05302347 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2348 qdf_dev->bus_type,
2349 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2350 HIF_ENABLE_TYPE_PROBE);
2351 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002352 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302353 goto power_down;
2354 }
2355
2356 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302357 if (!hif_ctx) {
2358 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002359 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302360 goto power_down;
2361 }
2362
Arun Khandavallifae92942016-08-01 13:31:08 +05302363 status = ol_cds_init(qdf_dev, hif_ctx);
2364 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002365 hdd_err("No Memory to Create BMI Context; status: %d",
2366 status);
2367 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302368 goto hif_close;
2369 }
2370
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002371 ret = hdd_update_config(hdd_ctx);
2372 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002373 hdd_err("Failed to update configuration; errno: %d",
2374 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002375 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002376 }
2377
gbian62edd7e2017-03-07 13:12:13 +08002378 hdd_update_cds_ac_specs_params(hdd_ctx);
2379
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302380 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002381 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002382 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002383 ret = qdf_status_to_os_return(status);
2384 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302385 }
2386
Mukul Sharma9d797a02017-01-05 20:26:03 +05302387 /* initalize components configurations after psoc open */
2388 ret = hdd_update_components_config(hdd_ctx);
2389 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002390 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302391 ret);
2392 goto close;
2393 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002394 status = cds_dp_open(hdd_ctx->hdd_psoc);
2395 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002396 hdd_err("Failed to Open cds post open; status: %d",
2397 status);
2398 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002399 goto close;
2400 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302401
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002402 /*
2403 * NAN compoenet requires certian operations like, open adapter,
2404 * close adapter, etc. to be initiated by HDD, for those
2405 * register HDD callbacks with UMAC's NAN componenet.
2406 */
2407 hdd_nan_register_callbacks(hdd_ctx);
2408
Arun Khandavallifae92942016-08-01 13:31:08 +05302409 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2410
Jeff Johnson3a280122017-09-13 07:42:00 -07002411 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302412 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002413 hdd_err("Failed to pre-enable CDS; status: %d", status);
2414 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002415 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302416 }
2417
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002418 hdd_register_policy_manager_callback(
2419 hdd_ctx->hdd_psoc);
2420
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302421 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302422 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302423
Arun Khandavallifae92942016-08-01 13:31:08 +05302424 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2425 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2426 hdd_ftm_mc_process_msg);
2427 break;
2428 }
2429 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002430 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302431 break;
2432 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302433
2434 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002435 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2436 if (ret) {
2437 hdd_err("HDD IPA UC reinit failed; errno: %d",
2438 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002439 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002440 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302441 }
2442
Arun Khandavallifae92942016-08-01 13:31:08 +05302443 /* Fall through dont add break here */
2444 case DRIVER_MODULES_OPENED:
2445 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002446 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002447 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002448 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302449 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302450 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2451 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002452 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302453 break;
2454 }
Dustin Browndca39692017-11-09 15:30:25 -08002455
2456 ret = hdd_configure_cds(hdd_ctx, adapter);
2457 if (ret) {
2458 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002459 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302460 }
Dustin Browndca39692017-11-09 15:30:25 -08002461
Komal Seelamf2136bb2016-09-28 18:30:44 +05302462 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302463 hdd_info("Driver Modules Successfully Enabled");
2464 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2465 break;
2466 case DRIVER_MODULES_ENABLED:
2467 hdd_info("Driver modules already Enabled");
2468 break;
2469 default:
2470 hdd_err("WLAN start invoked in wrong state! :%d\n",
2471 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002472 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302473 goto release_lock;
2474 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302475 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302476 mutex_unlock(&hdd_ctx->iface_change_lock);
2477 EXIT();
2478 return 0;
2479
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002480post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002481 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002482
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002483cds_txrx_free:
2484 cds_dp_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302485close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002486 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002487 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302488
Dustin Brown28b17892017-10-10 13:29:38 -07002489deinit_config:
2490 cds_deinit_ini_config();
2491
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002492cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302493 ol_cds_free();
2494
2495hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002496 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2497 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302498power_down:
2499 if (!reinit && !unint)
2500 pld_power_off(qdf_dev->dev);
2501release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302502 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302503 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302504 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002505
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002506 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302507}
2508
Naveen Rawat910726a2017-03-06 11:42:51 -08002509#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002510static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002511{
2512 int ret = os_if_wifi_pos_register_nl();
2513
2514 if (ret)
2515 hdd_err("os_if_wifi_pos_register_nl failed");
2516
2517 return ret;
2518}
2519
2520static int hdd_deactivate_wifi_pos(void)
2521{
2522 int ret = os_if_wifi_pos_deregister_nl();
2523
2524 if (ret)
2525 hdd_err("os_if_wifi_pos_deregister_nl failed");
2526
2527 return ret;
2528}
2529
2530/**
2531 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2532 * @hdd_ctx: hdd context
2533 *
2534 * Return: status of operation
2535 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002536static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002537{
2538 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2539 struct hdd_config *cfg = hdd_ctx->config;
2540
2541 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2542 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2543 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2544 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2545 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2546 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2547 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2548 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2549}
2550#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002551static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002552{
2553 return oem_activate_service(hdd_ctx);
2554}
2555
2556static int hdd_deactivate_wifi_pos(void)
2557{
2558 return 0;
2559}
2560
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002561static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002562{
2563}
2564#endif
2565
Arun Khandavallifae92942016-08-01 13:31:08 +05302566/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 * __hdd_open() - HDD Open function
2568 * @dev: Pointer to net_device structure
2569 *
2570 * This is called in response to ifconfig up
2571 *
2572 * Return: 0 for success; non-zero for failure
2573 */
2574static int __hdd_open(struct net_device *dev)
2575{
Jeff Johnson9d295242017-08-29 14:39:48 -07002576 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002577 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578 int ret;
2579
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002580 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302581 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002582 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302584 /* Nothing to be done if device is unloading */
2585 if (cds_is_driver_unloading()) {
2586 hdd_err("Driver is unloading can not open the hdd");
2587 return -EBUSY;
2588 }
2589
Dustin Brown01847752017-10-25 13:56:27 -07002590 if (cds_is_driver_recovering()) {
2591 hdd_err("WLAN is currently recovering; Please try again.");
2592 return -EBUSY;
2593 }
2594
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302595 mutex_lock(&hdd_init_deinit_lock);
2596
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302597 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2598
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302599 /*
2600 * This scenario can be hit in cases where in the wlan driver after
2601 * registering the netdevices and there is a failure in driver
2602 * initialization. So return error gracefully because the netdevices
2603 * will be de-registered as part of the load failure.
2604 */
2605
2606 if (!cds_is_driver_loaded()) {
2607 hdd_err("Failed to start the wlan driver!!");
2608 ret = -EIO;
2609 goto err_hdd_hdd_init_deinit_lock;
2610 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612
Arun Khandavallifae92942016-08-01 13:31:08 +05302613 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2614 if (ret) {
2615 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302616 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302617 }
2618
2619
2620 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2621 ret = hdd_start_adapter(adapter);
2622 if (ret) {
2623 hdd_err("Failed to start adapter :%d",
2624 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302625 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302626 }
2627 }
2628
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002629 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2630 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002631 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002632 /* Enable TX queues only when we are connected */
2633 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302634 WLAN_START_ALL_NETIF_QUEUE,
2635 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002636 }
2637
Naveen Rawat286def52016-09-23 15:38:02 -07002638 /* Enable carrier and transmit queues for NDI */
2639 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002640 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002641 wlan_hdd_netif_queue_control(adapter,
2642 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2643 WLAN_CONTROL_PATH);
2644 }
2645
Naveen Rawat910726a2017-03-06 11:42:51 -08002646 hdd_populate_wifi_pos_cfg(hdd_ctx);
2647
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302648err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302649 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302650 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651 return ret;
2652}
2653
Arun Khandavallifae92942016-08-01 13:31:08 +05302654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655/**
2656 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2657 * @dev: Pointer to net_device structure
2658 *
2659 * This is called in response to ifconfig up
2660 *
2661 * Return: 0 for success; non-zero for failure
2662 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002663static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664{
2665 int ret;
2666
2667 cds_ssr_protect(__func__);
2668 ret = __hdd_open(dev);
2669 cds_ssr_unprotect(__func__);
2670
2671 return ret;
2672}
2673
2674/**
2675 * __hdd_stop() - HDD stop function
2676 * @dev: Pointer to net_device structure
2677 *
2678 * This is called in response to ifconfig down
2679 *
2680 * Return: 0 for success; non-zero for failure
2681 */
2682static int __hdd_stop(struct net_device *dev)
2683{
Jeff Johnson9d295242017-08-29 14:39:48 -07002684 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002685 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686 int ret;
2687
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002688 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002689
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302690 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002691 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002692
2693 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302694 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002696
2697 /* Nothing to be done if the interface is not opened */
2698 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002699 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 return -ENODEV;
2701 }
2702
2703 /* Make sure the interface is marked as closed */
2704 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302705
2706 hdd_debug("Disabling Auto Power save timer");
2707 sme_ps_disable_auto_ps_timer(
2708 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002709 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302710
2711 /*
2712 * Disable TX on the interface, after this hard_start_xmit() will not
2713 * be called on that interface
2714 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002715 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2716 hdd_device_mode_to_string(adapter->device_mode),
2717 adapter->device_mode);
2718
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302719 wlan_hdd_netif_queue_control(adapter,
2720 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2721 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722
2723 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002724 * NAN data interface is different in some sense. The traffic on NDI is
2725 * bursty in nature and depends on the need to transfer. The service
2726 * layer may down the interface after the usage and up again when
2727 * required. In some sense, the NDI is expected to be available
2728 * (like SAP) iface until NDI delete request is issued by the service
2729 * layer. Skip BSS termination and adapter deletion for NAN Data
2730 * interface (NDI).
2731 */
2732 if (WLAN_HDD_IS_NDI(adapter))
2733 return 0;
2734
Tushnim Bhattacharyya86294892017-10-25 16:29:11 -07002735 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->hdd_psoc);
2736
Naveen Rawat286def52016-09-23 15:38:02 -07002737 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 * The interface is marked as down for outside world (aka kernel)
2739 * But the driver is pretty much alive inside. The driver needs to
2740 * tear down the existing connection on the netdev (session)
2741 * cleanup the data pipes and wait until the control plane is stabilized
2742 * for this interface. The call also needs to wait until the above
2743 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002744 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002745 * That is intentional to be able to scan if it is a STA/P2P interface
2746 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302747 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002748
2749 /* DeInit the adapter. This ensures datapath cleanup as well */
2750 hdd_deinit_adapter(hdd_ctx, adapter, true);
2751
Arun Khandavallifae92942016-08-01 13:31:08 +05302752
2753 /*
2754 * Find if any iface is up. If any iface is up then can't put device to
2755 * sleep/power save mode
2756 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302757 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002758 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302759 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302760 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302761 hdd_prevent_suspend_timeout(
2762 hdd_ctx->config->iface_change_wait_time,
2763 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302764 }
2765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766 EXIT();
2767 return 0;
2768}
2769
2770/**
2771 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2772 * @dev: pointer to net_device structure
2773 *
2774 * This is called in response to ifconfig down
2775 *
2776 * Return: 0 for success and error number for failure
2777 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002778static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779{
2780 int ret;
2781
2782 cds_ssr_protect(__func__);
2783 ret = __hdd_stop(dev);
2784 cds_ssr_unprotect(__func__);
2785
2786 return ret;
2787}
2788
2789/**
2790 * __hdd_uninit() - HDD uninit function
2791 * @dev: Pointer to net_device structure
2792 *
2793 * This is called during the netdev unregister to uninitialize all data
2794 * associated with the device
2795 *
2796 * Return: None
2797 */
2798static void __hdd_uninit(struct net_device *dev)
2799{
Jeff Johnson9d295242017-08-29 14:39:48 -07002800 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002801 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002803 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804
2805 do {
2806 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002807 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002808 break;
2809 }
2810
Jeff Johnson399c6272017-08-30 10:51:00 -07002811 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2812 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002813 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 break;
2815 }
2816
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002817 if (dev != adapter->dev)
2818 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002819
Jeff Johnson399c6272017-08-30 10:51:00 -07002820 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821
2822 /* after uninit our adapter structure will no longer be valid */
2823 adapter->dev = NULL;
2824 adapter->magic = 0;
2825 } while (0);
2826
2827 EXIT();
2828}
2829
2830/**
2831 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2832 * @dev: pointer to net_device structure
2833 *
2834 * This is called during the netdev unregister to uninitialize all data
2835 * associated with the device
2836 *
2837 * Return: none
2838 */
2839static void hdd_uninit(struct net_device *dev)
2840{
2841 cds_ssr_protect(__func__);
2842 __hdd_uninit(dev);
2843 cds_ssr_unprotect(__func__);
2844}
2845
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002846static int hdd_open_cesium_nl_sock(void)
2847{
2848#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2849 struct netlink_kernel_cfg cfg = {
2850 .groups = WLAN_NLINK_MCAST_GRP_ID,
2851 .input = NULL
2852 };
2853#endif
2854 int ret = 0;
2855
2856#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2857 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2858#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2859 THIS_MODULE,
2860#endif
2861 &cfg);
2862#else
2863 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2864 WLAN_NLINK_MCAST_GRP_ID,
2865 NULL, NULL, THIS_MODULE);
2866#endif
2867
2868 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002869 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002870 ret = -ECONNREFUSED;
2871 }
2872
2873 return ret;
2874}
2875
2876static void hdd_close_cesium_nl_sock(void)
2877{
2878 if (NULL != cesium_nl_srv_sock) {
2879 netlink_kernel_release(cesium_nl_srv_sock);
2880 cesium_nl_srv_sock = NULL;
2881 }
2882}
2883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884/**
2885 * __hdd_set_mac_address() - set the user specified mac address
2886 * @dev: Pointer to the net device.
2887 * @addr: Pointer to the sockaddr.
2888 *
2889 * This function sets the user specified mac address using
2890 * the command ifconfig wlanX hw ether <mac adress>.
2891 *
2892 * Return: 0 for success, non zero for failure
2893 */
2894static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2895{
Jeff Johnson9d295242017-08-29 14:39:48 -07002896 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002897 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002898 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302899 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 int ret;
2901
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002902 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903
2904 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2905 ret = wlan_hdd_validate_context(hdd_ctx);
2906 if (0 != ret)
2907 return ret;
2908
Jeff Johnson1e851a12017-10-28 14:36:12 -07002909 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2911
2912 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302913 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002914}
2915
2916/**
2917 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2918 * function from SSR
2919 * @dev: pointer to net_device structure
2920 * @addr: Pointer to the sockaddr
2921 *
2922 * This function sets the user specified mac address using
2923 * the command ifconfig wlanX hw ether <mac adress>.
2924 *
2925 * Return: 0 for success.
2926 */
2927static int hdd_set_mac_address(struct net_device *dev, void *addr)
2928{
2929 int ret;
2930
2931 cds_ssr_protect(__func__);
2932 ret = __hdd_set_mac_address(dev, addr);
2933 cds_ssr_unprotect(__func__);
2934
2935 return ret;
2936}
2937
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002938uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002939{
2940 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002941
Anurag Chouhan6d760662016-02-20 16:05:43 +05302942 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002943 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2944 break;
2945 }
2946
Anurag Chouhan6d760662016-02-20 16:05:43 +05302947 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948 return NULL;
2949
2950 hdd_ctx->config->intfAddrMask |= (1 << i);
2951 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2952}
2953
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07002954void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
2955 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002956{
2957 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002958
Anurag Chouhan6d760662016-02-20 16:05:43 +05302959 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960 if (!memcmp(releaseAddr,
2961 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2962 6)) {
2963 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2964 break;
2965 }
2966 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967}
2968
2969#ifdef WLAN_FEATURE_PACKET_FILTERING
2970/**
2971 * __hdd_set_multicast_list() - set the multicast address list
2972 * @dev: Pointer to the WLAN device.
2973 * @skb: Pointer to OS packet (sk_buff).
2974 *
2975 * This funciton sets the multicast address list.
2976 *
2977 * Return: None
2978 */
2979static void __hdd_set_multicast_list(struct net_device *dev)
2980{
Jeff Johnson9d295242017-08-29 14:39:48 -07002981 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 int i = 0, status;
2983 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002984 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302985 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2986 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2987 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002989 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302990 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302991 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302994 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302995 goto out;
2996
Dustin Brownc788acb2017-08-01 17:43:51 -07002997 status = hdd_validate_adapter(adapter);
2998 if (status)
2999 goto out;
3000
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303001 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3002 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003003 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303004 goto out;
3005 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303007 /* Delete already configured multicast address list */
3008 if (adapter->mc_addr_list.mc_cnt > 0) {
3009 hdd_info("clear previously configured MC address list");
3010 hdd_disable_and_flush_mc_addr_list(adapter,
3011 pmo_mc_list_change_notify);
3012 }
3013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003015 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303016 hdd_disable_and_flush_mc_addr_list(adapter,
3017 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 } else {
3019 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303020 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003021 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303022 pmo_ucfg_max_mc_addr_supported(psoc));
3023 hdd_disable_and_flush_mc_addr_list(adapter,
3024 pmo_mc_list_change_notify);
3025 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003026 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003028 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303029 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030 if (i == mc_count)
3031 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303032 memset(&(mc_list_request->mc_addr[i].bytes),
3033 0, ETH_ALEN);
3034 memcpy(&(mc_list_request->mc_addr[i].bytes),
3035 ha->addr, ETH_ALEN);
3036 hdd_info("mlist[%d] = %pM", i,
3037 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003038 i++;
3039 }
3040 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303041
3042 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003043 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303044 mc_list_request->count = mc_count;
3045 status = hdd_cache_mc_addr_list(mc_list_request);
3046 if (status == 0) {
3047 hdd_enable_mc_addr_filtering(adapter,
3048 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303050 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303052out:
3053 if (mc_list_request)
3054 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303055 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056}
3057
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059/**
3060 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3061 * @dev: pointer to net_device
3062 *
3063 * Return: none
3064 */
3065static void hdd_set_multicast_list(struct net_device *dev)
3066{
3067 cds_ssr_protect(__func__);
3068 __hdd_set_multicast_list(dev);
3069 cds_ssr_unprotect(__func__);
3070}
3071#endif
3072
3073/**
3074 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3075 * @dev: Pointer to the WLAN device.
3076 * @skb: Pointer to OS packet (sk_buff).
3077 *
3078 * This function is registered with the Linux OS for network
3079 * core to decide which queue to use first.
3080 *
3081 * Return: ac, Queue Index/access category corresponding to UP in IP header
3082 */
3083static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3084#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3085 , void *accel_priv
3086#endif
3087#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3088 , select_queue_fallback_t fallback
3089#endif
3090)
3091{
3092 return hdd_wmm_select_queue(dev, skb);
3093}
3094
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003095static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096 .ndo_open = hdd_open,
3097 .ndo_stop = hdd_stop,
3098 .ndo_uninit = hdd_uninit,
3099 .ndo_start_xmit = hdd_hard_start_xmit,
3100 .ndo_tx_timeout = hdd_tx_timeout,
3101 .ndo_get_stats = hdd_get_stats,
3102 .ndo_do_ioctl = hdd_ioctl,
3103 .ndo_set_mac_address = hdd_set_mac_address,
3104 .ndo_select_queue = hdd_select_queue,
3105#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003107#endif
3108};
3109
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003110/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003111static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003112 .ndo_open = hdd_mon_open,
3113 .ndo_stop = hdd_stop,
3114 .ndo_get_stats = hdd_get_stats,
3115};
3116
3117/**
3118 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003119 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003120 * Return: None
3121 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003122void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003124 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003125 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003126 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003127 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003128}
3129
3130/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003131 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3132 * @hdd_ctx: global hdd context
3133 * @macAddr: mac address to assign to the interface
3134 * @name: User-visible name of the interface
3135 *
3136 * hdd adapter pointer would point to the netdev->priv space, this function
3137 * would retrive the pointer, and setup the hdd adapter configuration.
3138 *
3139 * Return: the pointer to hdd adapter, otherwise NULL
3140 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003141static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003143 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 const char *name)
3145{
Jeff Johnson5505db82017-11-02 21:19:23 -07003146 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003147 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003148 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 /*
3150 * cfg80211 initialization and registration....
3151 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003152 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003153#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3154 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003156 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3157 hdd_mon_mode_ether_setup : ether_setup),
3158 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159
Jeff Johnson5505db82017-11-02 21:19:23 -07003160 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161
3162 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003163 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164
Jeff Johnson9d295242017-08-29 14:39:48 -07003165 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003166 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303167 qdf_mem_set(sta_ctx->conn_info.staId,
3168 sizeof(sta_ctx->conn_info.staId),
3169 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003170 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003171 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003173 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174
3175 init_completion(&adapter->session_open_comp_var);
3176 init_completion(&adapter->session_close_comp_var);
3177 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303178 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 init_completion(&adapter->linkup_event_var);
3180 init_completion(&adapter->cancel_rem_on_chan_var);
3181 init_completion(&adapter->rem_on_chan_ready_event);
3182 init_completion(&adapter->sta_authorized_event);
3183 init_completion(&adapter->offchannel_tx_event);
3184 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003185 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303187 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188
3189 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003190 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003191 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003192 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193
Jeff Johnson5505db82017-11-02 21:19:23 -07003194 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003196 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003198 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
3200 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003201 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003203 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204
Jeff Johnson5505db82017-11-02 21:19:23 -07003205 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207 hdd_set_station_ops(adapter->dev);
3208
Jeff Johnson5505db82017-11-02 21:19:23 -07003209 hdd_dev_setup_destructor(dev);
3210 dev->ieee80211_ptr = &adapter->wdev;
3211 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003213 adapter->wdev.netdev = dev;
3214 /* set dev's parent to underlying device */
3215 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003216 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303217 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003218 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303219 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 }
3221
3222 return adapter;
3223}
3224
Jeff Johnson9d295242017-08-29 14:39:48 -07003225static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003227 struct net_device *dev = adapter->dev;
3228 int ret;
3229
3230 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003232 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003233 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3234
3235 ret = dev_alloc_name(dev, dev->name);
3236 if (ret < 0) {
3237 hdd_err(
3238 "unable to get dev name: %s, err = 0x%x",
3239 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303240 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 }
3242 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003243
3244 ret = register_netdevice(dev);
3245 if (ret) {
3246 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3247 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303248 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249 }
3250 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003251 ret = register_netdev(dev);
3252 if (ret) {
3253 hdd_err("register_netdev(%s) failed, err = 0x%x",
3254 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303255 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256 }
3257 }
3258 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3259
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003260 EXIT();
3261
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303262 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263}
3264
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003265QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003266{
Jeff Johnson9d295242017-08-29 14:39:48 -07003267 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268
3269 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003270 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303271 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 }
3273
3274 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003275 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303276 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 }
3278
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003279 /*
3280 * For NAN Data interface, the close session results in the final
3281 * indication to the userspace
3282 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003283 if (adapter->device_mode == QDF_NDI_MODE)
3284 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003285
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 /*
3289 * We can be blocked while waiting for scheduled work to be
3290 * flushed, and the adapter structure can potentially be freed, in
3291 * which case the magic will have been reset. So make sure the
3292 * magic is still good, and hence the adapter structure is still
3293 * valid, before signaling completion
3294 */
3295 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3296 complete(&adapter->session_close_comp_var);
3297
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303298 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299}
3300
Jeff Johnson9d295242017-08-29 14:39:48 -07003301int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302{
Dustin Brownd28772b2017-03-17 14:16:07 -07003303 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304
Dustin Brownd28772b2017-03-17 14:16:07 -07003305 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003306 if (QDF_IS_STATUS_ERROR(status))
3307 return qdf_status_to_os_return(status);
3308
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003309 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003310 if (QDF_IS_STATUS_ERROR(status))
3311 return qdf_status_to_os_return(status);
3312
3313 if (wma_capability_enhanced_mcast_filter())
3314 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3315 else
3316 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003317
3318 return qdf_status_to_os_return(status);
3319}
3320
Jeff Johnson9d295242017-08-29 14:39:48 -07003321int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003322{
3323 QDF_STATUS status;
3324 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003325 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003326 unsigned long rc;
3327
Jeff Johnson1b780e42017-10-31 14:11:45 -07003328 hdd_info("destroying vdev %d", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003329
3330 /* vdev created sanity check */
3331 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003332 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003333 return -EINVAL;
3334 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003335 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003336 /*
3337 * In SSR case, there is no need to destroy vdev in firmware since
3338 * it has already asserted. vdev can be released directly.
3339 */
3340 if (cds_is_driver_recovering())
3341 goto release_vdev;
3342
Dustin Brownd28772b2017-03-17 14:16:07 -07003343 /* close sme session (destroy vdev in firmware via legacy API) */
3344 INIT_COMPLETION(adapter->session_close_comp_var);
3345 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003346 status = sme_close_session(hdd_ctx->hHal, adapter->session_id,
Dustin Brownd28772b2017-03-17 14:16:07 -07003347 hdd_sme_close_session_callback, adapter);
3348 if (QDF_IS_STATUS_ERROR(status)) {
3349 hdd_err("failed to close sme session: %d", status);
3350 return qdf_status_to_os_return(status);
3351 }
3352
3353 /* block on a completion variable until sme session is closed */
3354 rc = wait_for_completion_timeout(
3355 &adapter->session_close_comp_var,
3356 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3357 if (!rc) {
3358 hdd_err("timed out waiting for close sme session: %ld", rc);
3359 if (adapter->device_mode == QDF_NDI_MODE)
3360 hdd_ndp_session_end_handler(adapter);
3361 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3362 return -ETIMEDOUT;
3363 }
Yue Maf9782842017-05-08 12:49:49 -07003364release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003365 /* do vdev logical destroy via objmgr */
3366 errno = hdd_objmgr_destroy_vdev(adapter);
3367 if (errno) {
3368 hdd_err("failed to destroy objmgr vdev: %d", errno);
3369 return errno;
3370 }
3371
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003372 /* now that sme session is closed, allow physical vdev destroy */
3373 errno = hdd_objmgr_release_vdev(adapter);
3374 if (errno) {
3375 hdd_err("failed to release objmgr vdev: %d", errno);
3376 return errno;
3377 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003378 hdd_info("vdev destroyed successfully");
3379
3380 return 0;
3381}
3382
Jeff Johnson9d295242017-08-29 14:39:48 -07003383int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003384{
3385 QDF_STATUS status;
3386 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003387 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003388 uint32_t type;
3389 uint32_t sub_type;
3390 unsigned long rc;
3391
3392 hdd_info("creating new vdev");
3393
3394 /* determine vdev (sub)type */
3395 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303396 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003397 hdd_err("failed to get vdev type: %d", status);
3398 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003400
3401 /* do vdev create via objmgr */
3402 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003403 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003404 if (errno) {
3405 hdd_err("failed to create objmgr vdev: %d", errno);
3406 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003408
3409 /* Open a SME session (prepare vdev in firmware via legacy API) */
3410 INIT_COMPLETION(adapter->session_open_comp_var);
3411 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
Jeff Johnson1e851a12017-10-28 14:36:12 -07003412 (uint8_t *)&adapter->mac_addr,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003413 adapter->session_id, type, sub_type);
Dustin Brownd28772b2017-03-17 14:16:07 -07003414 if (QDF_IS_STATUS_ERROR(status)) {
3415 hdd_err("failed to open sme session: %d", status);
3416 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003417 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003418 }
3419
3420 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 rc = wait_for_completion_timeout(
3422 &adapter->session_open_comp_var,
3423 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3424 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003425 hdd_err("timed out waiting for open sme session: %ld", rc);
3426 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303427 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Krunal Soni4a020c72017-10-30 20:58:40 -07003428 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003429 }
3430
3431 /* firmware ready for component communication, raise vdev_ready event */
3432 errno = hdd_vdev_ready(adapter);
3433 if (errno) {
3434 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003435 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003436 }
3437
Jeff Johnson1b780e42017-10-31 14:11:45 -07003438 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003439
3440 return 0;
3441
3442 /*
3443 * Due to legacy constraints, we need to destroy in the same order as
3444 * create. So, split error handling into 2 cases to accommodate.
3445 */
3446
Krunal Soni4a020c72017-10-30 20:58:40 -07003447objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003448 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003449
3450 return errno;
3451
Krunal Soni4a020c72017-10-30 20:58:40 -07003452hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003453 QDF_BUG(!hdd_vdev_destroy(adapter));
3454
3455 return errno;
3456}
3457
Jeff Johnson9d295242017-08-29 14:39:48 -07003458QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003459{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003460 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003461 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003462 QDF_STATUS status;
3463 int ret_val;
3464
3465 ret_val = hdd_vdev_create(adapter);
3466 if (ret_val) {
3467 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303468 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 }
3470
Dustin Brownd28772b2017-03-17 14:16:07 -07003471 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3472 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3473 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003474 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003477 status = hdd_register_wext(adapter->dev);
3478 if (QDF_IS_STATUS_ERROR(status)) {
3479 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480 goto error_register_wext;
3481 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003482 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483
Jeff Johnsond377dce2017-10-04 10:32:42 -07003484 qdf_mem_set(sta_ctx->conn_info.staId,
3485 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303486
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003487 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003488 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003489 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003491 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 hdd_ctx->config->OperatingChannel;
3493
3494 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003495 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496
3497 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303498 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003499 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500 status, status);
3501 goto error_init_txrx;
3502 }
3503
3504 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3505
3506 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303507 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003508 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509 status, status);
3510 goto error_wmm_init;
3511 }
3512
3513 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3514
Jeff Johnson1b780e42017-10-31 14:11:45 -07003515 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 WMI_PDEV_PARAM_BURST_ENABLE,
3517 hdd_ctx->config->enableSifsBurst,
3518 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003519 if (ret_val)
3520 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003521
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303522 /*
3523 * In case of USB tethering, LRO is disabled. If SSR happened
3524 * during that time, then as part of SSR init, do not enable
3525 * the LRO again. Keep the LRO state same as before SSR.
3526 */
3527 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003528 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303529
3530 /* rcpi info initialization */
3531 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3532
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303533 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535error_wmm_init:
3536 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3537 hdd_deinit_tx_rx(adapter);
3538error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003539 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003541 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543 return status;
3544}
3545
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303546/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003547 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303548 * @hdd_ctx: global hdd context
3549 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003550 * @rtnl_held: Used to indicate whether or not the caller is holding
3551 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303552 *
3553 * This function De-initializes the STA/P2P/OCB adapter.
3554 *
3555 * Return: None.
3556 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003557static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003558 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003559 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303560{
3561 ENTER_DEV(adapter->dev);
3562
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303563 if (adapter->dev) {
3564 if (rtnl_held)
3565 adapter->dev->wireless_handlers = NULL;
3566 else {
3567 rtnl_lock();
3568 adapter->dev->wireless_handlers = NULL;
3569 rtnl_unlock();
3570 }
3571 }
3572
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303573 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3574 hdd_deinit_tx_rx(adapter);
3575 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3576 }
3577
3578 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3579 hdd_wmm_adapter_close(adapter);
3580 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3581 }
3582
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303583 EXIT();
3584}
3585
Jeff Johnson9d295242017-08-29 14:39:48 -07003586void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 bool rtnl_held)
3588{
3589 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003592 case QDF_STA_MODE:
3593 case QDF_P2P_CLIENT_MODE:
3594 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003596 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597 break;
3598 }
3599
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003600 case QDF_SAP_MODE:
3601 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003603 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 break;
3605 }
3606
3607 default:
3608 break;
3609 }
3610
3611 EXIT();
3612}
3613
Jeff Johnson9d295242017-08-29 14:39:48 -07003614static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003615 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616{
Jeff Johnson5505db82017-11-02 21:19:23 -07003617 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618
3619 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003620 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003622 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623 return;
3624 }
3625
Rajeev Kumardca5f812016-02-04 17:28:06 -08003626 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303627
3628 if (adapter->scan_info.default_scan_ies) {
3629 qdf_mem_free(adapter->scan_info.default_scan_ies);
3630 adapter->scan_info.default_scan_ies = NULL;
3631 }
3632
Komal Seelama89be8d2016-09-29 11:09:26 +05303633 hdd_adapter_runtime_suspend_denit(adapter);
3634
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 /*
3636 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3637 * the driver is almost closed and cannot handle either control
3638 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003639 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3640 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 * is not right. Setting this flag helps hdd_stop() to recognize that
3642 * the interface is closed and restricts any operations on that
3643 */
3644 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3645
3646 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003647 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003648 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003649 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003650 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 /*
3652 * Note that the adapter is no longer valid at this point
3653 * since the memory has been reclaimed
3654 */
3655 }
3656}
3657
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003658static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003659 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660{
3661 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003662 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303663 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303666 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003667 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07003669 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303671 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672 }
3673 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3674 adapterNode = pNext;
3675 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303676 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003678
Arun Khandavalli2358d522016-05-16 18:05:37 +05303679#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3680/**
3681 * hdd_set_fw_log_params() - Set log parameters to FW
3682 * @hdd_ctx: HDD Context
3683 * @adapter: HDD Adapter
3684 *
3685 * This function set the FW Debug log level based on the INI.
3686 *
3687 * Return: None
3688 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003689static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003690 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303691{
3692 uint8_t count = 0, numentries = 0,
3693 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3694 uint32_t value = 0;
3695 int ret;
3696
Arun Khandavallifae92942016-08-01 13:31:08 +05303697 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3698 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003699 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303700 return;
3701 }
3702
Arun Khandavallifae92942016-08-01 13:31:08 +05303703 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303704 hdd_ctx->fw_log_settings.dl_type =
3705 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003706 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303707 WMI_DBGLOG_TYPE,
3708 hdd_ctx->config->enableFwLogType,
3709 DBG_CMD);
3710 if (ret != 0)
3711 hdd_err("Failed to enable FW log type ret %d",
3712 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303713
3714 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303715 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003716 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303717 WMI_DBGLOG_LOG_LEVEL,
3718 hdd_ctx->config->enableFwLogLevel,
3719 DBG_CMD);
3720 if (ret != 0)
3721 hdd_err("Failed to enable FW log level ret %d",
3722 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303723
3724 hdd_string_to_u8_array(
3725 hdd_ctx->config->enableFwModuleLogLevel,
3726 moduleloglevel,
3727 &numentries,
3728 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3729
3730 while (count < numentries) {
3731 /*
3732 * FW module log level input string looks like
3733 * below:
3734 * gFwDebugModuleLoglevel=<FW Module ID>,
3735 * <Log Level>,...
3736 * For example:
3737 * gFwDebugModuleLoglevel=
3738 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3739 * Above input string means :
3740 * For FW module ID 1 enable log level 0
3741 * For FW module ID 2 enable log level 1
3742 * For FW module ID 3 enable log level 2
3743 * For FW module ID 4 enable log level 3
3744 * For FW module ID 5 enable log level 4
3745 * For FW module ID 6 enable log level 5
3746 * For FW module ID 7 enable log level 6
3747 */
3748
Nishank Aggarwale239d962017-03-03 12:26:02 +05303749 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3750 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3751 hdd_err("Module id %d and dbglog level %d input length is more than max",
3752 moduleloglevel[count],
3753 moduleloglevel[count + 1]);
3754 return;
3755 }
3756
3757 value = moduleloglevel[count] << 16;
3758 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07003759 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303760 WMI_DBGLOG_MOD_LOG_LEVEL,
3761 value, DBG_CMD);
3762 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303763 hdd_err("Failed to enable FW module log level %d ret %d",
3764 value, ret);
3765
3766 count += 2;
3767 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303768
Arun Khandavalli2358d522016-05-16 18:05:37 +05303769}
3770#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003771static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003772 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303773{
3774}
3775
3776#endif
3777
3778/**
3779 * hdd_set_fw_params() - Set parameters to firmware
3780 * @adapter: HDD adapter
3781 *
3782 * This function Sets various parameters to fw once the
3783 * adapter is started.
3784 *
3785 * Return: 0 on success or errno on failure
3786 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003787int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303788{
3789 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003790 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303791
3792 ENTER_DEV(adapter->dev);
3793
3794 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3795 if (!hdd_ctx)
3796 return -EINVAL;
3797
Dustin Brown732ab9c2017-06-15 13:24:09 -07003798 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3799 hdd_debug("FTM Mode is active; nothing to do");
3800 return 0;
3801 }
3802
Jeff Johnson1b780e42017-10-31 14:11:45 -07003803 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303804 WMI_PDEV_PARAM_DTIM_SYNTH,
3805 hdd_ctx->config->enable_lprx, PDEV_CMD);
3806 if (ret) {
3807 hdd_err("Failed to set LPRx");
3808 goto error;
3809 }
3810
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303811 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003812 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303813 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3814 hdd_ctx->config->upper_brssi_thresh);
3815
Jeff Johnson1b780e42017-10-31 14:11:45 -07003816 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303817 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3818 hdd_ctx->config->lower_brssi_thresh);
3819
Jeff Johnson1b780e42017-10-31 14:11:45 -07003820 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303821 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3822 hdd_ctx->config->enable_dtim_1chrx);
3823 }
3824
Dustin Brown732ab9c2017-06-15 13:24:09 -07003825 if (hdd_ctx->config->enable2x2) {
3826 hdd_debug("configuring 2x2 mode fw params");
3827
Jeff Johnson1b780e42017-10-31 14:11:45 -07003828 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003829 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3830 hdd_ctx->config->enable_cck_tx_fir_override,
3831 PDEV_CMD);
3832 if (ret) {
3833 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3834 ret);
3835 goto error;
3836 }
3837 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303838#define HDD_DTIM_1CHAIN_RX_ID 0x5
3839#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003840 hdd_debug("configuring 1x1 mode fw params");
3841
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003842 /*
3843 * Disable DTIM 1 chain Rx when in 1x1,
3844 * we are passing two value
3845 * as param_id << 29 | param_value.
3846 * Below param_value = 0(disable)
3847 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003848 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003849 WMI_STA_SMPS_PARAM_CMDID,
3850 HDD_DTIM_1CHAIN_RX_ID <<
3851 HDD_SMPS_PARAM_VALUE_S,
3852 VDEV_CMD);
3853 if (ret) {
3854 hdd_err("DTIM 1 chain set failed %d", ret);
3855 goto error;
3856 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303857
Jeff Johnson1b780e42017-10-31 14:11:45 -07003858 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003859 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3860 hdd_ctx->config->txchainmask1x1,
3861 PDEV_CMD);
3862 if (ret) {
3863 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3864 ret);
3865 goto error;
3866 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303867
Jeff Johnson1b780e42017-10-31 14:11:45 -07003868 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003869 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3870 hdd_ctx->config->rxchainmask1x1,
3871 PDEV_CMD);
3872 if (ret) {
3873 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3874 ret);
3875 goto error;
3876 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303877#undef HDD_DTIM_1CHAIN_RX_ID
3878#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003879 }
3880
Jeff Johnson1b780e42017-10-31 14:11:45 -07003881 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003882 WMI_PDEV_PARAM_HYST_EN,
3883 hdd_ctx->config->enableMemDeepSleep,
3884 PDEV_CMD);
3885 if (ret) {
3886 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3887 goto error;
3888 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303889
Jeff Johnson1b780e42017-10-31 14:11:45 -07003890 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003891 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3892 hdd_ctx->config->rts_profile,
3893 VDEV_CMD);
3894 if (ret) {
3895 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3896 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303897 }
3898
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003899 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3900
Jeff Johnson1b780e42017-10-31 14:11:45 -07003901 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003902 GEN_VDEV_PARAM_AMSDU,
3903 hdd_ctx->config->max_amsdu_num,
3904 GEN_CMD);
3905 if (ret != 0) {
3906 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3907 goto error;
3908 }
3909
Arun Khandavalli2358d522016-05-16 18:05:37 +05303910 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303911 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003912
Arun Khandavalli2358d522016-05-16 18:05:37 +05303913 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303914
Arun Khandavalli2358d522016-05-16 18:05:37 +05303915error:
3916 return -EINVAL;
3917}
3918
Ryan Hsu07495ea2016-01-21 15:25:39 -08003919/**
3920 * hdd_open_adapter() - open and setup the hdd adatper
3921 * @hdd_ctx: global hdd context
3922 * @session_type: type of the interface to be created
3923 * @iface_name: User-visible name of the interface
3924 * @macAddr: MAC address to assign to the interface
3925 * @name_assign_type: the name of assign type of the netdev
3926 * @rtnl_held: the rtnl lock hold flag
3927 *
3928 * This function open and setup the hdd adpater according to the device
3929 * type request, assign the name, the mac address assigned, and then prepared
3930 * the hdd related parameters, queue, lock and ready to start.
3931 *
3932 * Return: the pointer of hdd adapter, otherwise NULL.
3933 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003934struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003936 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003937 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938{
Jeff Johnson9d295242017-08-29 14:39:48 -07003939 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303941 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942
3943 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3944 /*
3945 * Max limit reached on the number of vdevs configured by the
3946 * host. Return error
3947 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303948 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3949 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 return NULL;
3951 }
3952
3953 if (macAddr == NULL) {
3954 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303955 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 return NULL;
3957 }
3958 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303959 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303960 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3961 " already exists",
3962 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963 return NULL;
3964 }
3965
3966 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003967 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 /* Reset locally administered bit if the device mode is STA */
3969 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303970 hdd_info("locally administered bit reset in sta mode: "
3971 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003973 case QDF_P2P_CLIENT_MODE:
3974 case QDF_P2P_DEVICE_MODE:
3975 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003976 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303977 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003978 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3979 name_assign_type,
3980 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981
3982 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303983 hdd_err("failed to allocate adapter for session %d",
3984 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 return NULL;
3986 }
3987
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003988 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003990 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303992 else if (QDF_MONITOR_MODE == session_type)
3993 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 else
3995 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3996
3997 adapter->device_mode = session_type;
3998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 /*
4001 * Workqueue which gets scheduled in IPv4 notification
4002 * callback
4003 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004004 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006
4007#ifdef WLAN_NS_OFFLOAD
4008 /*
4009 * Workqueue which gets scheduled in IPv6
4010 * notification callback.
4011 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004012 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 hdd_ipv6_notifier_work_queue);
4014#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304016 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304018 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 }
4020
4021 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004022 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304024 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4025 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304026
Ravi Joshi1a292562017-05-18 16:28:54 -07004027 /* Initialize NAN Data Interface */
4028 if (QDF_NDI_MODE == session_type) {
4029 status = hdd_init_nan_data_mode(adapter);
4030 if (QDF_STATUS_SUCCESS != status)
4031 goto err_free_netdev;
4032 }
4033
4034 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004036 case QDF_P2P_GO_MODE:
4037 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004038 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4039 name_assign_type,
4040 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004042 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304043 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 return NULL;
4045 }
4046
4047 adapter->wdev.iftype =
4048 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004049 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 NL80211_IFTYPE_P2P_GO;
4051 adapter->device_mode = session_type;
4052
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004053 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304054 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4056 goto err_free_netdev;
4057 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004058 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304060 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4061 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304062
4063 /*
4064 * Workqueue which gets scheduled in IPv4 notification
4065 * callback
4066 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004067 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304068 hdd_ipv4_notifier_work_queue);
4069
4070#ifdef WLAN_NS_OFFLOAD
4071 /*
4072 * Workqueue which gets scheduled in IPv6
4073 * notification callback.
4074 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004075 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304076 hdd_ipv6_notifier_work_queue);
4077#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304079 case QDF_FTM_MODE:
4080 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4081 name_assign_type,
4082 "wlan0");
4083 if (NULL == adapter) {
4084 hdd_err("Failed to allocate adapter for FTM mode");
4085 return NULL;
4086 }
4087 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4088 adapter->device_mode = session_type;
4089 status = hdd_register_interface(adapter, rtnl_held);
4090 if (QDF_STATUS_SUCCESS != status) {
4091 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4092 goto err_free_netdev;
4093 }
4094 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004095 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304096 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304097 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4098 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304099 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004101 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304102 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103 return NULL;
4104 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105
hqueaa33ee2017-05-04 17:56:35 +08004106 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4107
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304108 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 /* Add it to the hdd's session list. */
4110 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304111 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304113 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004115 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4117 }
4118 }
4119
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304120 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 if (NULL != adapter) {
4122 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4123 adapter = NULL;
4124 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004125 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304126 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 return NULL;
4129 }
4130
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304131 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004132 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4133 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135 /* Adapter successfully added. Increment the vdev count */
4136 hdd_ctx->current_intf_count++;
4137
Jeff Johnson5880d792016-08-15 13:32:30 -07004138 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139 hdd_ctx->current_intf_count);
4140
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004141 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 }
4143
Rajeev Kumardca5f812016-02-04 17:28:06 -08004144 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004145 hdd_err("Interface %s wow debug_fs init failed",
4146 netdev_name(adapter->dev));
4147
4148 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4149 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150
4151 return adapter;
4152
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004154 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304155 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004156
4157 return NULL;
4158}
4159
Jeff Johnson9d295242017-08-29 14:39:48 -07004160QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004161 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162{
4163 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304164 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165
4166 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304167 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004168 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 status);
4170 return status;
4171 }
4172
Jeff Johnson57eb2732017-10-02 11:40:20 -07004173 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304175 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 break;
4177
4178 pCurrent = pNext;
4179 }
4180 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304181 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004182 /*
4183 * Here we are stopping global bus_bw timer & work per adapter.
4184 *
4185 * The reason is to fix one race condition between
4186 * bus bandwidth work and cleaning up an adapter.
4187 * Under some conditions, it is possible for the bus bandwidth
4188 * work to access a particularly destroyed adapter, leading to
4189 * use-after-free.
4190 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004191 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004192 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004193 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004194
4195 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004196 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4197 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004198 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304200 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 adapterNode = NULL;
4202
Dustin Brown5ec6b552017-03-31 12:11:40 -07004203 /* conditionally restart the bw timer */
4204 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 /* Adapter removed. Decrement vdev count */
4207 if (hdd_ctx->current_intf_count != 0)
4208 hdd_ctx->current_intf_count--;
4209
4210 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304211 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304213
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304214 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215}
4216
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004217/**
4218 * hdd_close_all_adapters - Close all open adapters
4219 * @hdd_ctx: Hdd context
4220 * rtnl_held: True if RTNL lock held
4221 *
4222 * Close all open adapters.
4223 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304224 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004225 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004226QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227{
4228 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304229 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230
4231 ENTER();
4232
4233 do {
4234 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304235 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304236 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004237 pHddAdapterNode->adapter->mac_addr.bytes);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004238 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004239 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304240 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304241 /* Adapter removed. Decrement vdev count */
4242 if (hdd_ctx->current_intf_count != 0)
4243 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304245 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246
4247 EXIT();
4248
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304249 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004250}
4251
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004252void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304254 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004256
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004257 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004258 case QDF_STA_MODE:
4259 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004261 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004262 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004263 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 break;
4265 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004266 case QDF_SAP_MODE:
4267 case QDF_P2P_GO_MODE:
4268 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004270 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 break;
4272 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004273 case QDF_FTM_MODE:
4274 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 default:
4276 /*
4277 * wlan_hdd_reset_prob_rspies should not have been called
4278 * for these kind of devices
4279 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004280 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004281 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282 return;
4283 }
4284
Anurag Chouhanc5548422016-02-24 18:33:27 +05304285 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004286 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004287 updateIE.ieBufferlength = 0;
4288 updateIE.pAdditionIEBuffer = NULL;
4289 updateIE.append = true;
4290 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004291 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304293 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004294 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 }
4296}
4297
Jeff Johnson9d295242017-08-29 14:39:48 -07004298QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299 const bool bCloseSession)
4300{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304301 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004302 struct hdd_wext_state *pWextState =
4303 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 union iwreq_data wrqu;
4305 tSirUpdateIE updateIE;
4306 unsigned long rc;
4307
4308 ENTER();
4309
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004310 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304311 wlan_hdd_netif_queue_control(adapter,
4312 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4313 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004315 case QDF_STA_MODE:
4316 case QDF_P2P_CLIENT_MODE:
4317 case QDF_IBSS_MODE:
4318 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004319 case QDF_NDI_MODE:
4320 if ((QDF_NDI_MODE == adapter->device_mode) ||
4321 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4323 hdd_is_connecting(
4324 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004325 INIT_COMPLETION(adapter->disconnect_comp_var);
4326 /*
4327 * For NDI do not use pWextState from sta_ctx, if needed
4328 * extract from ndi_ctx.
4329 */
4330 if (QDF_NDI_MODE == adapter->device_mode)
4331 qdf_ret_status = sme_roam_disconnect(
4332 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004333 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004334 eCSR_DISCONNECT_REASON_NDI_DELETE);
4335 else if (pWextState->roamProfile.BSSType ==
4336 eCSR_BSS_TYPE_START_IBSS)
4337 qdf_ret_status = sme_roam_disconnect(
4338 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004339 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004340 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004341 else if (QDF_STA_MODE == adapter->device_mode)
4342 qdf_ret_status =
4343 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004344 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004345 qdf_ret_status = sme_roam_disconnect(
4346 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004347 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004348 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004349 /* success implies disconnect command got
4350 * queued up successfully
4351 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004352 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4353 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 rc = wait_for_completion_timeout(
4355 &adapter->disconnect_comp_var,
4356 msecs_to_jiffies
4357 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004358 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004359 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004361 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4362 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 memset(&wrqu, '\0', sizeof(wrqu));
4364 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4365 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4366 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4367 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304368 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004369 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004370
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304371 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304372 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373
4374#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004375 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376#endif
4377
4378 hdd_deregister_tx_flow_control(adapter);
4379
4380#ifdef WLAN_NS_OFFLOAD
4381#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004382 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383#endif
4384#endif
4385
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304386 if (adapter->device_mode == QDF_STA_MODE)
4387 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4388 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 /*
4390 * It is possible that the caller of this function does not
4391 * wish to close the session
4392 */
Krunal Soni985b8132017-02-10 18:49:08 -08004393 if (true == bCloseSession) {
4394 if (0 != wlan_hdd_try_disconnect(adapter)) {
4395 hdd_err("Error: Can't disconnect adapter");
4396 return QDF_STATUS_E_FAILURE;
4397 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004398 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004399 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 break;
4401
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004402 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304403 /* Flush IPA exception path packets */
4404 hdd_ipa_flush(hdd_ctx);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004405
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004406 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004407 if (QDF_SAP_MODE == adapter->device_mode) {
4408 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4409 cds_flush_delayed_work(
4410 &adapter->acs_pending_work);
4411 clear_bit(ACS_PENDING, &adapter->event_flags);
4412 }
4413 }
Krunal Soni22208392017-09-29 18:10:34 -07004414 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004417 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004418 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4420
4421 hdd_deregister_tx_flow_control(adapter);
4422
Kapil Guptac1224bf2017-06-22 21:22:40 +05304423 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 mutex_lock(&hdd_ctx->sap_lock);
4425 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304426 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304427 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428
4429 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430 status = wlansap_stop_bss(
4431 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304433 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004434 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304436 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304437 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304438 qdf_status =
4439 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004440 qdf_stop_bss_event,
4441 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442
Anurag Chouhance0dc992016-02-16 18:18:03 +05304443 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004444 hdd_err("failure waiting for wlansap_stop_bss %d",
4445 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 }
4447 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004448 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 }
4450 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004451 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4452 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004453 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004454
Anurag Chouhanc5548422016-02-24 18:33:27 +05304455 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004456 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004457 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458 updateIE.ieBufferlength = 0;
4459 updateIE.pAdditionIEBuffer = NULL;
4460 updateIE.append = false;
4461 updateIE.notify = false;
4462 /* Probe bcn reset */
4463 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4464 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304465 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004466 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467 }
4468 /* Assoc resp reset */
4469 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4470 &updateIE,
4471 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304472 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004473 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 }
4475 /* Reset WNI_CFG_PROBE_RSP Flags */
4476 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004477 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004478 qdf_mem_free(adapter->session.ap.beacon);
4479 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304480 /*
4481 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4482 */
4483 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4484 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4485
Peng Xu66162de2016-02-11 17:01:20 -08004486 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004487 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004488 mutex_unlock(&hdd_ctx->sap_lock);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304489
4490#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004491 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304492#endif
4493
4494#ifdef WLAN_NS_OFFLOAD
4495#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004496 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304497#endif
4498#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004499 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004500 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004501 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004502 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004503 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 break;
4505 default:
4506 break;
4507 }
4508
4509 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304510 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511}
4512
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304513/**
4514 * hdd_deinit_all_adapters - deinit all adapters
4515 * @hdd_ctx: HDD context
4516 * @rtnl_held: True if RTNL lock held
4517 *
4518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004519void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304520{
4521 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4522 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004523 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304524
4525 ENTER();
4526
4527 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4528
4529 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004530 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304531 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4532 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4533 adapter_node = next;
4534 }
4535
4536 EXIT();
4537}
4538
Dustin Brown27cd9942017-09-27 16:11:44 -07004539QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4540 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541{
4542 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304543 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004544 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545
4546 ENTER();
4547
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304548 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4549
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004553 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004554 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4556 adapterNode = pNext;
4557 }
4558
4559 EXIT();
4560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304561 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004562}
4563
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004564QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565{
4566 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304567 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004568 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004569 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004570 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571
4572 ENTER();
4573
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304574 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004576 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4577
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304578 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004579 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004580 hdd_notice("Disabling queues for adapter type: %d",
4581 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304582
4583 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004584 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304585 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004586 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304587
Arun Khandavallicc544b32017-01-30 19:52:16 +05304588 if (hdd_ctx->config->sap_internal_restart &&
4589 adapter->device_mode == QDF_SAP_MODE) {
4590 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304591 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304592 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004593 if (test_bit(SOFTAP_BSS_STARTED,
4594 &adapter->event_flags)) {
4595 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004596 hdd_sap_destroy_events(adapter);
4597 }
4598 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4599 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304600 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304601 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004603 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604
Jeff Johnsonb9424862017-10-30 08:49:35 -07004605 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004606
4607 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004608 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004609 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4611 hdd_wmm_adapter_close(adapter);
4612 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4613 }
4614
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304615 if (adapter->device_mode == QDF_STA_MODE)
4616 hdd_clear_fils_connection_info(adapter);
4617
Wu Gao3545e642017-07-14 19:24:41 +08004618 if (adapter->device_mode == QDF_SAP_MODE) {
4619 /*
4620 * If adapter is SAP, set session ID to invalid
4621 * since SAP session will be cleanup during SSR.
4622 */
Wu Gao36717432016-11-21 15:09:48 +08004623 wlansap_set_invalid_session(
4624 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4625
Wu Gao3545e642017-07-14 19:24:41 +08004626 wlansap_cleanup_cac_timer(
4627 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4628 }
4629
Yue Mad5b4b9f2017-05-26 16:23:40 -07004630 /* Delete peers if any for STA and P2P client modes */
4631 if (adapter->device_mode == QDF_STA_MODE ||
4632 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004633 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004634 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004635 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004636
4637 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4638 peerMacAddr.bytes);
4639 }
4640
Yue Maf9782842017-05-08 12:49:49 -07004641 /* Destroy vdev which will be recreated during reinit. */
4642 hdd_vdev_destroy(adapter);
4643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4645 adapterNode = pNext;
4646 }
4647
4648 EXIT();
4649
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304650 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651}
4652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004653bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304654{
4655 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4656 QDF_STATUS status;
4657 bool close_modules = true;
4658
Arun Khandavalliba479c42017-07-26 21:29:40 +05304659 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4660 hdd_info("FTM mode, don't close the module");
4661 return false;
4662 }
4663
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304664 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4665 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4666 if (test_bit(DEVICE_IFACE_OPENED,
Yeshwanth Sriram Guntuka4ce0a1b2017-10-17 17:55:45 +05304667 &adapter_node->adapter->event_flags) ||
4668 test_bit(SME_SESSION_OPENED,
4669 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004670 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304671 close_modules = false;
4672 break;
4673 }
4674 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4675 adapter_node = next;
4676 }
4677
4678 return close_modules;
4679}
4680
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304681bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304682{
4683 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4684 return true;
4685 else
4686 return false;
4687}
4688
Anurag Chouhanc4092922016-09-08 15:56:11 +05304689#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004690 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304691struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4692 struct ieee80211_channel *channel,
4693 const u8 *bssid, const u8 *ssid,
4694 size_t ssid_len)
4695{
4696 return cfg80211_get_bss(wiphy, channel, bssid,
4697 ssid, ssid_len,
4698 WLAN_CAPABILITY_ESS,
4699 WLAN_CAPABILITY_ESS);
4700}
4701#else
4702struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4703 struct ieee80211_channel *channel,
4704 const u8 *bssid, const u8 *ssid,
4705 size_t ssid_len)
4706{
4707 return cfg80211_get_bss(wiphy, channel, bssid,
4708 ssid, ssid_len,
4709 IEEE80211_BSS_TYPE_ESS,
4710 IEEE80211_PRIVACY_ANY);
4711}
4712#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304713
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304714#if defined CFG80211_CONNECT_BSS || \
4715 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304716#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304717 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304718/**
4719 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4720 * @timeout_reason: reason for connect timeout
4721 *
4722 * This function is used to convert host timeout
4723 * reason enum to kernel specific enum.
4724 *
4725 * Return: nl timeout enum
4726 */
4727static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4728 tSirResultCodes timeout_reason)
4729{
4730 switch (timeout_reason) {
4731 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4732 return NL80211_TIMEOUT_SCAN;
4733 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4734 return NL80211_TIMEOUT_AUTH;
4735 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4736 return NL80211_TIMEOUT_ASSOC;
4737 default:
4738 return NL80211_TIMEOUT_UNSPECIFIED;
4739 }
4740}
4741
4742/**
4743 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4744 * @dev: network device
4745 * @bssid: bssid to which we want to associate
4746 * @timeout_reason: reason for connect timeout
4747 *
4748 * This API is used to send connection timeout reason to supplicant
4749 *
4750 * Return: void
4751 */
4752static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4753 const u8 *bssid,
4754 tSirResultCodes timeout_reason)
4755{
4756 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004757
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304758 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4759
4760 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4761 nl_timeout_reason);
4762}
4763
4764/**
4765 * __hdd_connect_bss() - API to send connection status to supplicant
4766 * @dev: network device
4767 * @bssid: bssid to which we want to associate
4768 * @req_ie: Request Information Element
4769 * @req_ie_len: len of the req IE
4770 * @resp_ie: Response IE
4771 * @resp_ie_len: len of ht response IE
4772 * @status: status
4773 * @gfp: Kernel Flag
4774 * @timeout_reason: reason for connect timeout
4775 *
4776 * Return: void
4777 */
4778static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4779 struct cfg80211_bss *bss, const u8 *req_ie,
4780 size_t req_ie_len, const u8 *resp_ie,
4781 size_t resp_ie_len, int status, gfp_t gfp,
4782 tSirResultCodes timeout_reason)
4783{
4784 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004785
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304786 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4787
4788 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4789 resp_ie, resp_ie_len, status, gfp,
4790 nl_timeout_reason);
4791}
4792#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304793#if defined CFG80211_CONNECT_TIMEOUT || \
4794 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304795static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4796 const u8 *bssid,
4797 tSirResultCodes timeout_reason)
4798{
4799 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4800}
4801#endif
4802
4803static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4804 struct cfg80211_bss *bss, const u8 *req_ie,
4805 size_t req_ie_len, const u8 *resp_ie,
4806 size_t resp_ie_len, int status, gfp_t gfp,
4807 tSirResultCodes timeout_reason)
4808{
4809 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4810 resp_ie, resp_ie_len, status, gfp);
4811}
4812#endif
4813
Abhishek Singha84d3952016-09-13 13:45:05 +05304814/**
4815 * hdd_connect_bss() - API to send connection status to supplicant
4816 * @dev: network device
4817 * @bssid: bssid to which we want to associate
4818 * @req_ie: Request Information Element
4819 * @req_ie_len: len of the req IE
4820 * @resp_ie: Response IE
4821 * @resp_ie_len: len of ht response IE
4822 * @status: status
4823 * @gfp: Kernel Flag
4824 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304825 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304826 *
4827 * The API is a wrapper to send connection status to supplicant
4828 *
4829 * Return: Void
4830 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304831#if defined CFG80211_CONNECT_TIMEOUT || \
4832 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05304833static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4834 struct cfg80211_bss *bss, const u8 *req_ie,
4835 size_t req_ie_len, const u8 *resp_ie,
4836 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304837 bool connect_timeout,
4838 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304839{
4840 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304841 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304842 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304843 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4844 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304845}
4846#else
4847static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4848 struct cfg80211_bss *bss, const u8 *req_ie,
4849 size_t req_ie_len, const u8 *resp_ie,
4850 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304851 bool connect_timeout,
4852 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304853{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304854 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4855 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304856}
4857#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304858
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304859#if defined(WLAN_FEATURE_FILS_SK)
4860#if defined(CFG80211_CONNECT_DONE) || \
4861 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
4862#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
4863 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304864/**
4865 * hdd_populate_fils_params() - Populate FILS keys to connect response
4866 * @fils_params: connect response to supplicant
4867 * @fils_kek: FILS kek
4868 * @fils_kek_len: FILS kek length
4869 * @pmk: FILS PMK
4870 * @pmk_len: FILS PMK length
4871 * @pmkid: PMKID
4872 * @fils_seq_num: FILS Seq number
4873 *
4874 * Return: None
4875 */
4876static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4877 *fils_params, const uint8_t *fils_kek,
4878 size_t fils_kek_len, const uint8_t *pmk,
4879 size_t pmk_len, const uint8_t *pmkid,
4880 uint16_t fils_seq_num)
4881{
4882 /* Increament seq number to be used for next FILS */
4883 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4884 fils_params->update_erp_next_seq_num = true;
4885 fils_params->fils_kek = fils_kek;
4886 fils_params->fils_kek_len = fils_kek_len;
4887 fils_params->pmk = pmk;
4888 fils_params->pmk_len = pmk_len;
4889 fils_params->pmkid = pmkid;
4890}
4891#else
4892static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4893 *fils_params, const uint8_t
4894 *fils_kek, size_t fils_kek_len,
4895 const uint8_t *pmk, size_t pmk_len,
4896 const uint8_t *pmkid,
4897 uint16_t fils_seq_num)
4898{ }
4899#endif
4900
Jeff Johnson172237b2017-11-07 15:32:59 -08004901void hdd_update_hlp_info(struct net_device *dev,
4902 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304903{
4904 struct sk_buff *skb;
4905 uint16_t skb_len;
4906 struct llc_snap_hdr_t *llc_hdr;
4907 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304908 uint8_t *hlp_data;
4909 uint16_t hlp_data_len;
4910 struct fils_join_rsp_params *roam_fils_params
4911 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304912 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
4913
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304914 if (!roam_fils_params) {
4915 hdd_err("FILS Roam Param NULL");
4916 return;
4917 }
4918
4919 if (!roam_fils_params->hlp_data_len || !roam_fils_params->hlp_data) {
4920 hdd_err("FILS HLP Data NULL, len %d",
4921 roam_fils_params->hlp_data_len);
4922 return;
4923 }
4924
4925 hlp_data = roam_fils_params->hlp_data;
4926 hlp_data_len = roam_fils_params->hlp_data_len;
4927
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05304928 /* Calculate skb length */
4929 skb_len = (2 * ETH_ALEN) + hlp_data_len;
4930 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
4931 if (skb == NULL) {
4932 hdd_err("HLP packet nbuf alloc fails");
4933 return;
4934 }
4935
4936 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
4937 QDF_MAC_ADDR_SIZE);
4938 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
4939 QDF_MAC_ADDR_SIZE);
4940
4941 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
4942 if (IS_SNAP(llc_hdr)) {
4943 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4944 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
4945 }
4946
4947 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
4948
4949 /*
4950 * This HLP packet is formed from HLP info encapsulated
4951 * in assoc response frame which is AEAD encrypted.
4952 * Hence, this checksum validation can be set unnecessary.
4953 * i.e. network layer need not worry about checksum.
4954 */
4955 skb->ip_summed = CHECKSUM_UNNECESSARY;
4956
4957 status = hdd_rx_packet_cbk(padapter, skb);
4958 if (QDF_IS_STATUS_ERROR(status)) {
4959 hdd_err("Sending HLP packet fails");
4960 return;
4961 }
4962 hdd_debug("send HLP packet to netif successfully");
4963}
4964
4965/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304966 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4967 * @dev: network device
4968 * @bssid: bssid to which we want to associate
4969 * @bss: cfg80211 bss info
4970 * @roam_info: information about connected bss
4971 * @req_ie: Request Information Element
4972 * @req_ie_len: len of the req IE
4973 * @resp_ie: Response IE
4974 * @resp_ie_len: len of ht response IE
4975 * @status: status
4976 * @gfp: allocation flags
4977 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4978 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304979 *
4980 * This API is used as wrapper to send FILS key/sequence number
4981 * params etc. to supplicant in case of FILS connection
4982 *
4983 * Return: None
4984 */
4985static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08004986 struct cfg80211_bss *bss,
4987 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304988 const u8 *req_ie, size_t req_ie_len,
4989 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004990 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304991 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304992{
4993 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05304994 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
4995 struct fils_join_rsp_params *roam_fils_params =
4996 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07004997
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304998 qdf_mem_zero(&fils_params, sizeof(fils_params));
4999
5000 if (!roam_fils_params) {
5001 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5002 } else {
5003 fils_params.status = status;
5004 fils_params.bssid = bssid;
5005 fils_params.timeout_reason = timeout_reason;
5006 fils_params.req_ie = req_ie;
5007 fils_params.req_ie_len = req_ie_len;
5008 fils_params.resp_ie = resp_ie;
5009 fils_params.resp_ie_len = resp_ie_len;
5010 fils_params.bss = bss;
5011 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5012 roam_fils_params->kek_len,
5013 roam_fils_params->fils_pmk,
5014 roam_fils_params->fils_pmk_len,
5015 roam_fils_params->fils_pmkid,
5016 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305017 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305018 }
5019 hdd_debug("FILS indicate connect status %d seq no %d",
5020 fils_params.status,
5021 fils_params.fils_erp_next_seq_num);
5022
5023 cfg80211_connect_done(dev, &fils_params, gfp);
5024
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305025 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305026 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305027
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305028 /* Clear all the FILS key info */
5029 if (roam_fils_params && roam_fils_params->fils_pmk)
5030 qdf_mem_free(roam_fils_params->fils_pmk);
5031 if (roam_fils_params)
5032 qdf_mem_free(roam_fils_params);
5033 roam_info->fils_join_rsp = NULL;
5034}
5035#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005036static inline void
5037hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005038 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005039 const u8 *req_ie, size_t req_ie_len,
5040 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5041 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305042 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305043{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305044#endif
5045#endif
5046
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305047#if defined(WLAN_FEATURE_FILS_SK) && \
5048 (defined(CFG80211_CONNECT_DONE) || \
5049 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305050/**
5051 * hdd_fils_update_connect_results() - API to send fils connection status to
5052 * supplicant.
5053 * @dev: network device
5054 * @bssid: bssid to which we want to associate
5055 * @bss: cfg80211 bss info
5056 * @roam_info: information about connected bss
5057 * @req_ie: Request Information Element
5058 * @req_ie_len: len of the req IE
5059 * @resp_ie: Response IE
5060 * @resp_ie_len: len of ht response IE
5061 * @status: status
5062 * @gfp: allocation flags
5063 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5064 * @timeout_reason: reason for connect timeout
5065 *
5066 * The API is a wrapper to send connection status to supplicant
5067 *
5068 * Return: 0 if success else failure
5069 */
5070static int hdd_fils_update_connect_results(struct net_device *dev,
5071 const u8 *bssid,
5072 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005073 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305074 size_t req_ie_len, const u8 *resp_ie,
5075 size_t resp_ie_len, u16 status, gfp_t gfp,
5076 bool connect_timeout,
5077 tSirResultCodes timeout_reason)
5078{
5079 ENTER();
5080 if (!roam_info || !roam_info->is_fils_connection)
5081 return -EINVAL;
5082
5083 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5084 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305085 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305086 return 0;
5087}
5088#else
5089static inline int hdd_fils_update_connect_results(struct net_device *dev,
5090 const u8 *bssid,
5091 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005092 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305093 size_t req_ie_len, const u8 *resp_ie,
5094 size_t resp_ie_len, u16 status, gfp_t gfp,
5095 bool connect_timeout,
5096 tSirResultCodes timeout_reason)
5097{
5098 return -EINVAL;
5099}
5100#endif
5101
Anurag Chouhanc4092922016-09-08 15:56:11 +05305102/**
5103 * hdd_connect_result() - API to send connection status to supplicant
5104 * @dev: network device
5105 * @bssid: bssid to which we want to associate
5106 * @roam_info: information about connected bss
5107 * @req_ie: Request Information Element
5108 * @req_ie_len: len of the req IE
5109 * @resp_ie: Response IE
5110 * @resp_ie_len: len of ht response IE
5111 * @status: status
5112 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305113 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305114 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305115 *
5116 * The API is a wrapper to send connection status to supplicant
5117 * and allow runtime suspend
5118 *
5119 * Return: Void
5120 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305121void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005122 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305123 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305124 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305125 bool connect_timeout,
5126 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305127{
Jeff Johnson9d295242017-08-29 14:39:48 -07005128 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305129 struct cfg80211_bss *bss = NULL;
5130
5131 if (WLAN_STATUS_SUCCESS == status) {
5132 struct ieee80211_channel *chan;
5133 int freq;
5134 int chan_no = roam_info->pBssDesc->channelId;
5135
5136 if (chan_no <= 14)
5137 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005138 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305139 else
5140 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005141 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305142
5143 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5144 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5145 roam_info->u.pConnectedProfile->SSID.ssId,
5146 roam_info->u.pConnectedProfile->SSID.length);
5147 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305148
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305149 if (hdd_fils_update_connect_results(dev, bssid, bss,
5150 roam_info, req_ie, req_ie_len, resp_ie,
5151 resp_ie_len, status, gfp, connect_timeout,
5152 timeout_reason) != 0) {
5153 hdd_connect_bss(dev, bssid, bss, req_ie,
5154 req_ie_len, resp_ie, resp_ie_len,
5155 status, gfp, connect_timeout, timeout_reason);
5156 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305157
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005158 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005159 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305160}
5161#else
5162void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005163 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305164 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305165 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305166 bool connect_timeout,
5167 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305168{
Jeff Johnson9d295242017-08-29 14:39:48 -07005169 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305170
Anurag Chouhanc4092922016-09-08 15:56:11 +05305171 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5172 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005173
5174 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005175 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305176}
5177#endif
5178
5179
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005180QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181{
5182 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305183 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005184 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305186 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187#endif
5188 eConnectionState connState;
5189
5190 ENTER();
5191
5192 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305193 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005194 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005195
Arun Khandavallifae92942016-08-01 13:31:08 +05305196 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305197 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 hdd_wmm_init(adapter);
5200
5201 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005202 case QDF_STA_MODE:
5203 case QDF_P2P_CLIENT_MODE:
5204 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
5206 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5207 ->conn_info.connState;
5208
5209 hdd_init_station_mode(adapter);
5210 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005211 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005213 /* Indicate disconnect event to supplicant
5214 * if associated previously
5215 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005217 eConnectionState_IbssConnected == connState ||
5218 eConnectionState_NotConnected == connState ||
5219 eConnectionState_IbssDisconnected == connState ||
5220 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 memset(&wrqu, '\0', sizeof(wrqu));
5224 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5225 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5226 wireless_send_event(adapter->dev, SIOCGIWAP,
5227 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005228 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005229 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230
5231 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305232 wlan_hdd_cfg80211_indicate_disconnect(
5233 adapter->dev, false,
5234 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235 } else if (eConnectionState_Connecting == connState) {
5236 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005237 * Indicate connect failure to supplicant if we
5238 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305240 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305241 NULL, 0, NULL, 0,
5242 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005243 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 }
5245
5246 hdd_register_tx_flow_control(adapter,
5247 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005248 hdd_tx_resume_cb,
5249 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250
5251 break;
5252
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005253 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005254 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305255 hdd_init_ap_mode(adapter, true);
5256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257 break;
5258
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005259 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005261 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5263#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005264 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 /* event supplicant to restart */
5266 cfg80211_del_sta(adapter->dev,
5267 (const u8 *)&bcastMac.bytes[0],
5268 GFP_KERNEL);
5269#endif
5270 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305271 case QDF_MONITOR_MODE:
5272 hdd_init_station_mode(adapter);
5273 hdd_set_mon_rx_cb(adapter->dev);
5274 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5275 adapter->mon_bandwidth);
5276 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 default:
5278 break;
5279 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005280 /*
5281 * Action frame registered in one adapter which will
5282 * applicable to all interfaces
5283 */
5284 wlan_hdd_cfg80211_register_frames(adapter);
5285
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305286get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5288 adapterNode = pNext;
5289 }
5290
5291 EXIT();
5292
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305293 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294}
5295
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005296QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 hdd_adapter_list_node_t **padapterNode)
5298{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305299 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005300
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005301 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005302 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305303 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005304 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 return status;
5306}
5307
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005308QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309 hdd_adapter_list_node_t *adapterNode,
5310 hdd_adapter_list_node_t **pNextAdapterNode)
5311{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305312 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005313
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005314 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005315 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305316 (qdf_list_node_t *) adapterNode,
5317 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005319 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320 return status;
5321}
5322
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005323QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005324 hdd_adapter_list_node_t *adapterNode)
5325{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305326 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005327
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005328 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005329 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005330 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005331 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 return status;
5333}
5334
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005335QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 hdd_adapter_list_node_t **padapterNode)
5337{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305338 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005339
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005340 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005341 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305342 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005343 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344 return status;
5345}
5346
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005347QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 hdd_adapter_list_node_t *adapterNode)
5349{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305350 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005351
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005352 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005353 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305354 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005355 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356 return status;
5357}
5358
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005359QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 hdd_adapter_list_node_t *adapterNode)
5361{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305362 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005363
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005364 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005365 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters,
Anurag Chouhanffb21542016-02-17 14:33:03 +05305366 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005367 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005368 return status;
5369}
5370
Jeff Johnson9d295242017-08-29 14:39:48 -07005371struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372 tSirMacAddr macAddr)
5373{
5374 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005375 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305376 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005377
5378 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5379
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305380 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005381 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005382
5383 if (adapter
Jeff Johnson1e851a12017-10-28 14:36:12 -07005384 && !qdf_mem_cmp(adapter->mac_addr.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005385 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005386 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5389 adapterNode = pNext;
5390 }
5391
5392 return NULL;
5393
5394}
5395
Jeff Johnson9d295242017-08-29 14:39:48 -07005396struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005397 uint32_t vdev_id)
5398{
5399 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005400 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305401 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305403 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005404
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305405 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005406 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407
Jeff Johnson1b780e42017-10-31 14:11:45 -07005408 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005409 return adapter;
5410
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305411 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5413 adapterNode = pNext;
5414 }
5415
Jeff Johnson5880d792016-08-15 13:32:30 -07005416 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417
5418 return NULL;
5419}
5420
Abhishek Singh7996eb72015-12-30 17:24:02 +05305421/**
5422 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5423 * the sessionid
5424 * @hdd_ctx: hdd context.
5425 * @sme_session_id: sme session is for the adapter to get.
5426 *
5427 * This function is used to get the adapter with provided session id
5428 *
5429 * Return: adapter pointer if found
5430 *
5431 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005432struct hdd_adapter *
5433hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5434 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305435{
5436 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005437 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305438 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305439
5440
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305441 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305442
5443 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305444 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005445 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305446
5447 if (adapter &&
Jeff Johnson1b780e42017-10-31 14:11:45 -07005448 adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305449 return adapter;
5450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305451 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305452 hdd_get_next_adapter(hdd_ctx,
5453 adapter_node, &next);
5454 adapter_node = next;
5455 }
5456 return NULL;
5457}
5458
Jeff Johnson9d295242017-08-29 14:39:48 -07005459struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005460 const char *iface_name)
5461{
5462 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005463 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005464 QDF_STATUS qdf_status;
5465
5466 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5467
5468 while ((NULL != adapter_node) &&
5469 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005470 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005471
5472 if (adapter &&
5473 !qdf_str_cmp(adapter->dev->name, iface_name))
5474 return adapter;
5475
5476 qdf_status =
5477 hdd_get_next_adapter(hdd_ctx,
5478 adapter_node, &next);
5479 adapter_node = next;
5480 }
5481 return NULL;
5482}
5483
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005484/**
5485 * hdd_get_adapter() - to get adapter matching the mode
5486 * @hdd_ctx: hdd context
5487 * @mode: adapter mode
5488 *
5489 * This routine will return the pointer to adapter matching
5490 * with the passed mode.
5491 *
5492 * Return: pointer to adapter or null
5493 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005494struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005495 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496{
5497 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005498 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305499 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500
5501 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5502
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305503 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005504 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505
5506 if (adapter && (mode == adapter->device_mode))
5507 return adapter;
5508
5509 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5510 adapterNode = pNext;
5511 }
5512
5513 return NULL;
5514
5515}
5516
5517/**
5518 * hdd_get_operating_channel() - return operating channel of the device mode
5519 * @hdd_ctx: Pointer to the HDD context.
5520 * @mode: Device mode for which operating channel is required.
5521 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005522 * QDF_STA_MODE,
5523 * QDF_P2P_CLIENT_MODE,
5524 * QDF_SAP_MODE,
5525 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005526 *
5527 * This API returns the operating channel of the requested device mode
5528 *
5529 * Return: channel number. "0" id the requested device is not found OR it is
5530 * not connected.
5531 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005532uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005533 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005534{
5535 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305536 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005537 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005538 uint8_t operatingChannel = 0;
5539
5540 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5541
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305542 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005543 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544
5545 if (mode == adapter->device_mode) {
5546 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005547 case QDF_STA_MODE:
5548 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549 if (hdd_conn_is_connected
5550 (WLAN_HDD_GET_STATION_CTX_PTR
5551 (adapter))) {
5552 operatingChannel =
5553 (WLAN_HDD_GET_STATION_CTX_PTR
5554 (adapter))->conn_info.
5555 operationChannel;
5556 }
5557 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005558 case QDF_SAP_MODE:
5559 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005560 /* softap connection info */
5561 if (test_bit
5562 (SOFTAP_BSS_STARTED,
5563 &adapter->event_flags))
5564 operatingChannel =
5565 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005566 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005567 break;
5568 default:
5569 break;
5570 }
5571
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005572 /* Found the device of interest. break the loop */
5573 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574 }
5575
5576 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5577 adapterNode = pNext;
5578 }
5579 return operatingChannel;
5580}
5581
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005582static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005583 hdd_ctx)
5584{
5585 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305586 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005587 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588
5589 ENTER();
5590
5591 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5592
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305593 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005594 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005595 if ((adapter->device_mode == QDF_STA_MODE) ||
5596 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5597 (adapter->device_mode == QDF_IBSS_MODE) ||
5598 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5599 (adapter->device_mode == QDF_SAP_MODE) ||
5600 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005601 wlan_hdd_cfg80211_deregister_frames(adapter);
5602 hdd_unregister_wext(adapter->dev);
5603 }
5604 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5605 adapterNode = pNext;
5606 }
5607
5608 EXIT();
5609
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305610 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611}
5612
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005613QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614{
5615 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305616 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005617 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005618
5619 ENTER();
5620
5621 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305623 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005624 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005625 if ((adapter->device_mode == QDF_STA_MODE) ||
5626 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5627 (adapter->device_mode == QDF_IBSS_MODE) ||
5628 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5629 (adapter->device_mode == QDF_SAP_MODE) ||
5630 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005631 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005632 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005633 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005634 }
5635 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5636 adapterNode = pNext;
5637 }
5638
5639 EXIT();
5640
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305641 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642}
5643
Dustin Brownf27bce82016-11-03 12:52:27 -07005644/**
5645 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5646 * adapters
5647 * @hdd_ctx: The HDD context containing the adapters to operate on
5648 *
5649 * return: QDF_STATUS_SUCCESS
5650 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005651static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005652{
5653 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5654 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005655 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005656 int err;
5657
5658 ENTER();
5659
5660 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5661
5662 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005663 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005664 if ((adapter->device_mode == QDF_STA_MODE) ||
5665 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5666 (adapter->device_mode == QDF_IBSS_MODE) ||
5667 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5668 (adapter->device_mode == QDF_SAP_MODE) ||
5669 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5670 err = wlan_hdd_sched_scan_stop(adapter->dev);
5671 if (err)
5672 hdd_err("Unable to stop scheduled scan");
5673 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005674 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5675 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005676 adapter_node = next_node;
5677 }
5678
5679 EXIT();
5680
5681 return QDF_STATUS_SUCCESS;
5682}
5683
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684#ifdef WLAN_NS_OFFLOAD
5685/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005686 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687 * @hdd_ctx: Pointer to hdd context
5688 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005689 * Unregister for IPv6 address change notifications.
5690 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 * Return: None
5692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005693static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694{
5695 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696}
5697
5698/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005699 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700 * @hdd_ctx: Pointer to hdd context
5701 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005702 * Register for IPv6 address change notifications.
5703 *
5704 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005706static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707{
5708 int ret;
5709
5710 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5711 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005712 if (ret) {
5713 hdd_err("Failed to register IPv6 notifier: %d", ret);
5714 goto out;
5715 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005717 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005718out:
5719 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720}
5721#else
5722/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005723 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724 * @hdd_ctx: Pointer to hdd context
5725 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005726 * Unregister for IPv6 address change notifications.
5727 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 * Return: None
5729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005730static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005731{
5732}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005733
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005735 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736 * @hdd_ctx: Pointer to hdd context
5737 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005738 * Register for IPv6 address change notifications.
5739 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005740 * Return: None
5741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005742static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005744 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745}
5746#endif
5747
5748/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005749 * hdd_register_notifiers - Register netdev notifiers.
5750 * @hdd_ctx: HDD context
5751 *
5752 * Register netdev notifiers like IPv4 and IPv6.
5753 *
5754 * Return: 0 on success and errno on failure
5755 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005756static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005757{
5758 int ret;
5759
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005760 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5761 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305762 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005763
5764 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5765 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5766 if (ret) {
5767 hdd_err("Failed to register IPv4 notifier: %d", ret);
5768 goto unregister_ip6_notifier;
5769 }
5770
5771 return 0;
5772
5773unregister_ip6_notifier:
5774 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005775out:
5776 return ret;
5777
5778}
5779
5780/**
5781 * hdd_unregister_notifiers - Unregister netdev notifiers.
5782 * @hdd_ctx: HDD context
5783 *
5784 * Unregister netdev notifiers like IPv4 and IPv6.
5785 *
5786 * Return: None.
5787 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005788void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005789{
5790 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5791
5792 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005793}
5794
5795/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005796 * hdd_exit_netlink_services - Exit netlink services
5797 * @hdd_ctx: HDD context
5798 *
5799 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5800 * nl service.
5801 *
5802 * Return: None.
5803 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005804static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005805{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005806 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005807 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005808 ptt_sock_deactivate_svc();
5809
5810 nl_srv_exit();
5811}
5812
5813/**
5814 * hdd_init_netlink_services- Init netlink services
5815 * @hdd_ctx: HDD context
5816 *
5817 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5818 * nl service.
5819 *
5820 * Return: 0 on success and errno on failure.
5821 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005822static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005823{
5824 int ret;
5825
Ryan Hsuceddceb2016-04-28 10:20:14 -07005826 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005827 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005828 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005829 goto out;
5830 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005831 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005832
Naveen Rawat910726a2017-03-06 11:42:51 -08005833 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005834 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005835 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005836 goto err_nl_srv;
5837 }
5838
5839 ret = ptt_sock_activate_svc();
5840 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005841 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005842 goto err_nl_srv;
5843 }
5844
5845 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005846 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005847 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005848
5849 ret = cnss_diag_activate_service();
5850 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005851 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005852 goto err_close_cesium;
5853 }
5854
5855 return 0;
5856
5857err_close_cesium:
5858 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005859 ptt_sock_deactivate_svc();
5860err_nl_srv:
5861 nl_srv_exit();
5862out:
5863 return ret;
5864}
5865
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005866/**
5867 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5868 * @hdd_ctx: HDD context.
5869 *
5870 * Destroy RX wakelock.
5871 *
5872 * Return: None.
5873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005874static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005875{
5876 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5877}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005878
5879/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005880 * hdd_rx_wake_lock_create() - Create RX wakelock
5881 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005882 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005883 * Create RX wakelock.
5884 *
5885 * Return: None.
5886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005887static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005888{
5889 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5890}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005891
5892/**
Houston Hoffman160db392016-10-10 17:37:51 -07005893 * hdd_context_deinit() - Deinitialize HDD context
5894 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005895 *
Houston Hoffman160db392016-10-10 17:37:51 -07005896 * Deinitialize HDD context along with all the feature specific contexts but
5897 * do not free hdd context itself. Caller of this API is supposed to free
5898 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005899 *
Houston Hoffman160db392016-10-10 17:37:51 -07005900 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005902static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005903{
Houston Hoffman160db392016-10-10 17:37:51 -07005904 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005905
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005906 hdd_sap_context_destroy(hdd_ctx);
5907
5908 hdd_rx_wake_lock_destroy(hdd_ctx);
5909
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005910 hdd_scan_context_destroy(hdd_ctx);
5911
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005912 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005913
Houston Hoffman160db392016-10-10 17:37:51 -07005914 return 0;
5915}
5916
5917/**
5918 * hdd_context_destroy() - Destroy HDD context
5919 * @hdd_ctx: HDD context to be destroyed.
5920 *
5921 * Free config and HDD context as well as destroy all the resources.
5922 *
5923 * Return: None
5924 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005925static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005926{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005927 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305928
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305929 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5930
Houston Hoffman160db392016-10-10 17:37:51 -07005931 hdd_context_deinit(hdd_ctx);
5932
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305933 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005934 hdd_ctx->config = NULL;
5935
5936 wiphy_free(hdd_ctx->wiphy);
5937}
5938
5939/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305940 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5941 *
5942 * This function is used to destroy bug report lock
5943 *
5944 * Return: None
5945 */
5946static void wlan_destroy_bug_report_lock(void)
5947{
5948 p_cds_contextType p_cds_context;
5949
5950 p_cds_context = cds_get_global_context();
5951 if (!p_cds_context) {
5952 hdd_err("cds context is NULL");
5953 return;
5954 }
5955
5956 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5957}
5958
5959/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005960 * hdd_wlan_exit() - HDD WLAN exit function
5961 * @hdd_ctx: Pointer to the HDD Context
5962 *
5963 * This is the driver exit point (invoked during rmmod)
5964 *
5965 * Return: None
5966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005967static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305969 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305971 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972
5973 ENTER();
5974
Arun Khandavallifae92942016-08-01 13:31:08 +05305975 if (QDF_TIMER_STATE_RUNNING ==
5976 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005977 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305978 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 }
5980
Arun Khandavallifae92942016-08-01 13:31:08 +05305981 if (!QDF_IS_STATUS_SUCCESS
5982 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5983 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005984
Arun Khandavallifae92942016-08-01 13:31:08 +05305985
5986 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005987
Prashanth Bhattaab004382016-10-11 16:08:11 -07005988 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989
5990#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305991 if (QDF_TIMER_STATE_RUNNING ==
5992 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5993 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994 }
5995
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305996 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305997 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005998 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006000 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6001 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6002 hdd_ctx->last_acs_channel_list = NULL;
6003 hdd_ctx->num_of_channels = 0;
6004 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006005#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006006
Arun Khandavallifae92942016-08-01 13:31:08 +05306007 mutex_lock(&hdd_ctx->iface_change_lock);
6008 driver_status = hdd_ctx->driver_status;
6009 mutex_unlock(&hdd_ctx->iface_change_lock);
6010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006011 /*
6012 * Powersave Offload Case
6013 * Disable Idle Power Save Mode
6014 */
6015 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006016 /* clear the scan queue in all the scenarios */
6017 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018
Arun Khandavallifae92942016-08-01 13:31:08 +05306019 if (driver_status != DRIVER_MODULES_CLOSED) {
6020 hdd_unregister_wext_all_adapters(hdd_ctx);
6021 /*
6022 * Cancel any outstanding scan requests. We are about to close
6023 * all of our adapters, but an adapter structure is what SME
6024 * passes back to our callback function. Hence if there
6025 * are any outstanding scan requests then there is a
6026 * race condition between when the adapter is closed and
6027 * when the callback is invoked. We try to resolve that
6028 * race condition here by canceling any outstanding scans
6029 * before we close the adapters.
6030 * Note that the scans may be cancelled in an asynchronous
6031 * manner, so ideally there needs to be some kind of
6032 * synchronization. Rather than introduce a new
6033 * synchronization here, we will utilize the fact that we are
6034 * about to Request Full Power, and since that is synchronized,
6035 * the expectation is that by the time Request Full Power has
6036 * completed, all scans will be cancelled
6037 */
6038 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006039 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006040 hdd_stop_all_adapters(hdd_ctx, true);
bings29c99862017-11-01 13:54:13 +08006041 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006042 }
6043
6044 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306045 * Close the scheduler before calling cds_close to make sure
6046 * no thread is scheduled after the each module close is
6047 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006049 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306050 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306051 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306052 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006054
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306055 unregister_netdevice_notifier(&hdd_netdev_notifier);
6056
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006057 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306058
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306059 qdf_nbuf_deinit_replenish_timer();
6060
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306061 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6062 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6063 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065 /*
6066 * Close CDS
6067 * This frees pMac(HAL) context. There should not be any call
6068 * that requires pMac access after this.
6069 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006071 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006072 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006074 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075
6076 hdd_ipa_cleanup(hdd_ctx);
6077
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306078 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306079 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306080 /*
6081 * If there is re_init failure wiphy would have already de-registered
6082 * check the wiphy status before un-registering again
6083 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306084 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306085 wiphy_unregister(wiphy);
6086 wlan_hdd_cfg80211_deinit(wiphy);
6087 hdd_lpass_notify_stop(hdd_ctx);
6088 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006089
Arun Khandavallifae92942016-08-01 13:31:08 +05306090 hdd_exit_netlink_services(hdd_ctx);
6091 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306092#ifdef FEATURE_WLAN_CH_AVOID
6093 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6094#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306095
6096 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6097 if (driver_status)
6098 hdd_err("Pdev delete failed");
6099
6100 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6101 if (driver_status)
6102 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006103
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006104 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105}
6106
6107void __hdd_wlan_exit(void)
6108{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006109 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006110
6111 ENTER();
6112
Anurag Chouhan6d760662016-02-20 16:05:43 +05306113 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006115 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006116 EXIT();
6117 return;
6118 }
6119
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006120 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306121 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006123 /* Do all the cleanup before deregistering the driver */
6124 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006126 EXIT();
6127}
6128
6129#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006130/**
6131 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006132 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006133 *
6134 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6135 * Then new ACS request will do a fresh scan without reusing the cached
6136 * scan information.
6137 *
6138 * Return: void
6139 */
Tang Yingying523322d2017-01-17 23:28:43 +08006140static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006142 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006143
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006144 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006146 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6147 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6148 hdd_ctx->last_acs_channel_list = NULL;
6149 hdd_ctx->num_of_channels = 0;
6150 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151
6152 if (!hdd_ctx->hHal)
6153 return;
6154 sme_scan_flush_result(hdd_ctx->hHal);
6155}
6156#endif
6157
6158#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006159int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6160 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161{
6162 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306163 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006164 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165
6166 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6167
6168 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306169 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006170 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006172 if (!hdd_ctx->hHal)
6173 return -EINVAL;
6174
Jeff Johnsone7672e72017-10-21 15:10:04 -07006175 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006176 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306177 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006178 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179 return -EINVAL;
6180 }
6181
6182 return 0;
6183}
6184#endif
6185
6186/**
6187 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6188 * @state: state
6189 *
6190 * This function notifies FW with modem power status
6191 *
6192 * Return: 0 if successful, error number otherwise
6193 */
6194int hdd_wlan_notify_modem_power_state(int state)
6195{
6196 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306197 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006198 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199
Anurag Chouhan6d760662016-02-20 16:05:43 +05306200 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306202 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006203 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006205 if (!hdd_ctx->hHal)
6206 return -EINVAL;
6207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306208 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6209 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006210 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 state);
6212 return -EINVAL;
6213 }
6214 return 0;
6215}
6216
6217/**
6218 *
6219 * hdd_post_cds_enable_config() - HDD post cds start config helper
6220 * @adapter - Pointer to the HDD
6221 *
6222 * Return: None
6223 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006224QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306226 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227
6228 /*
6229 * Send ready indication to the HDD. This will kick off the MAC
6230 * into a 'running' state and should kick off an initial scan.
6231 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306232 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6233 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006234 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6235 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306236 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237 }
6238
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306239 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240}
6241
6242/* wake lock APIs for HDD */
6243void hdd_prevent_suspend(uint32_t reason)
6244{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306245 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246}
6247
6248void hdd_allow_suspend(uint32_t reason)
6249{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306250 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251}
6252
6253void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6254{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306255 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6256 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257}
6258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006260QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006262
Amar Singhal6f8592b2017-04-26 14:31:58 -07006263 return sme_init_chan_list(hdd_ctx->hHal,
6264 hdd_ctx->reg.alpha2,
6265 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266}
6267
6268/**
6269 * hdd_is_5g_supported() - check if hardware supports 5GHz
6270 * @hdd_ctx: Pointer to the hdd context
6271 *
6272 * HDD function to know if hardware supports 5GHz
6273 *
6274 * Return: true if hardware supports 5GHz
6275 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006276bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006278 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006279 return true;
6280
Amar Singhal58b45ef2017-08-01 13:43:54 -07006281 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006282 return true;
6283 else
6284 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285}
6286
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006287static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288{
6289 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006290 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291
6292 wiphy = hdd_ctx->wiphy;
6293
6294 /*
6295 * The channel information in
6296 * wiphy needs to be initialized before wiphy registration
6297 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006298 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6299 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006300 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006301 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006302 }
6303
6304#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6305 wiphy->wowlan = &wowlan_support_reg_init;
6306#else
6307 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6308 WIPHY_WOWLAN_MAGIC_PKT |
6309 WIPHY_WOWLAN_DISCONNECT |
6310 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6311 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6312 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6313 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6314 WIPHY_WOWLAN_RFKILL_RELEASE;
6315
6316 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6317 WOW_MAX_FILTERS_PER_LIST);
6318 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6319 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6320#endif
6321
6322 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006323 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306324 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006325 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306326 return ret_val;
6327 }
6328
Amar Singhal5cccafe2017-02-15 12:42:58 -08006329 if (!hdd_ctx->reg_offload)
6330 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331
Amar Singhale4f28ee2015-10-21 14:36:56 -07006332 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333}
6334
Ravi Joshie2331e82015-07-01 18:18:54 -07006335/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006336 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006337 * @hdd_ctx - handle to hdd context
6338 * @tx_packets - transmit packet count
6339 * @rx_packets - receive packet count
6340 *
6341 * The function controls the bus bandwidth and dynamic control of
6342 * tcp delayed ack configuration
6343 *
6344 * Returns: None
6345 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006347static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006348 const uint64_t tx_packets,
6349 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006351 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006352 uint64_t temp_rx = 0;
6353 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006354 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006355 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006356 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006357 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006358 uint16_t index = 0;
6359 bool vote_level_change = false;
6360 bool rx_level_change = false;
6361 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006364 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006365 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006366 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006367 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006368 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006369 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006370 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006373 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6374 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006375 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006376 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006377 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306378 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306379 if (hdd_ctx->hbw_requested) {
6380 pld_remove_pm_qos(hdd_ctx->parent_dev);
6381 hdd_ctx->hbw_requested = false;
6382 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306383 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006384 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006385 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306386 if (!hdd_ctx->hbw_requested) {
6387 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6388 hdd_ctx->hbw_requested = true;
6389 }
6390
Nirav Shah3bbfa512016-05-12 16:43:49 +05306391 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006392 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006393 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006394 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006396
Mohit Khannaf8f96822017-05-17 17:11:59 -07006397 qdf_dp_trace_throttle_live_mode(
6398 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6399
Mohit Khannae71e2262015-11-10 09:37:24 -08006400 /* fine-tuning parameters for RX Flows */
6401 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006404
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306405 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6406 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6407 else
6408 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6409
Ravi Joshifed83572016-10-07 16:20:37 -07006410 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6411 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6412 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6413 next_rx_level = WLAN_SVC_TP_HIGH;
6414 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006415 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006416 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006417 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006418 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006421 struct wlan_rx_tp_data rx_tp_data = {0};
6422
Ravi Joshie2331e82015-07-01 18:18:54 -07006423 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 next_rx_level, temp_rx);
6425 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006426 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006427 /* Send throughput indication only if it is enabled.
6428 * Disabling tcp_del_ack will revert the tcp stack behavior
6429 * to default delayed ack. Note that this will disable the
6430 * dynamic delayed ack mechanism across the system
6431 */
6432 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006433 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6434
6435 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6436 rx_tp_data.level = next_rx_level;
6437 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6438 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6439 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440 }
6441
Mohit Khannae71e2262015-11-10 09:37:24 -08006442 /* fine-tuning parameters for TX Flows */
6443 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6444 hdd_ctx->prev_tx = tx_packets;
6445 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6446 next_tx_level = WLAN_SVC_TP_HIGH;
6447 else
6448 next_tx_level = WLAN_SVC_TP_LOW;
6449
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006450 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006451 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6452 next_tx_level, temp_tx);
6453 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006454 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306455 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6456 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006457 &next_tx_level,
6458 sizeof(next_tx_level));
6459 }
6460
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006461 index = hdd_ctx->hdd_txrx_hist_idx;
6462
6463 if (vote_level_change || tx_level_change || rx_level_change) {
6464 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6465 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6466 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6467 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6468 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6469 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6470 hdd_ctx->hdd_txrx_hist_idx++;
6471 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6472 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006473}
6474
6475#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306476static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006477{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006478 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306479 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006480 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306481 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306482 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6483 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 uint64_t total_tx = 0, total_rx = 0;
6485 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306486 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306487 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006488 bool connected = false;
6489 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6490
Prashanth Bhattaab004382016-10-11 16:08:11 -07006491 if (wlan_hdd_validate_context(hdd_ctx))
6492 return;
6493
Jeff Johnson214671b2017-10-30 19:45:23 -07006494 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006495 goto restart_timer;
6496
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006497 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306498 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499 status =
6500 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6501
Jeff Johnson57eb2732017-10-02 11:40:20 -07006502 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006504 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306505 /*
6506 * Validate magic so we don't end up accessing
6507 * an invalid adapter.
6508 */
6509 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6510 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006511
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006512 if ((adapter->device_mode == QDF_STA_MODE ||
6513 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6515 != eConnectionState_Associated) {
6516
6517 continue;
6518 }
6519
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006520 if ((adapter->device_mode == QDF_SAP_MODE ||
6521 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006522 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523
6524 continue;
6525 }
6526
6527 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6528 adapter->prev_tx_packets);
6529 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6530 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306531
6532 if (adapter->device_mode == QDF_SAP_MODE ||
6533 adapter->device_mode == QDF_P2P_GO_MODE ||
6534 adapter->device_mode == QDF_IBSS_MODE) {
6535
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006536 ret = cdp_get_intra_bss_fwd_pkts_count(
6537 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006538 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306539 &fwd_tx_packets, &fwd_rx_packets);
6540 if (ret == A_OK) {
6541 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6542 fwd_tx_packets,
6543 adapter->prev_fwd_tx_packets);
6544 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6545 fwd_tx_packets,
6546 adapter->prev_fwd_rx_packets);
6547 }
6548 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549
6550 total_rx += adapter->stats.rx_packets;
6551 total_tx += adapter->stats.tx_packets;
6552
6553 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6554 adapter->prev_tx_packets = adapter->stats.tx_packets;
6555 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306556 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6557 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006558 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6559 connected = true;
6560 }
6561
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306562 /* add intra bss forwarded tx and rx packets */
6563 tx_packets += fwd_tx_packets_diff;
6564 rx_packets += fwd_rx_packets_diff;
6565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6567 tx_packets += (uint64_t)ipa_tx_packets;
6568 rx_packets += (uint64_t)ipa_rx_packets;
6569
Yun Park2aa880c2017-08-22 10:58:10 -07006570 if (adapter) {
6571 adapter->stats.tx_packets += ipa_tx_packets;
6572 adapter->stats.rx_packets += ipa_rx_packets;
6573 }
6574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006576 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006577 return;
6578 }
6579
Yuanyuan Liu13738502016-04-06 17:41:37 -07006580 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006581
6582 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6583 hdd_ipa_uc_stat_request(adapter, 2);
6584
Jingxiang Gec64e1932017-08-22 14:38:59 +08006585restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006586 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006587 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006588 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306589 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006590 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006591 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006593
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306594/**
6595 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6596 * @arg: Argument of timer function
6597 *
6598 * Schedule a workqueue in this function where all the processing is done.
6599 *
6600 * Return: None.
6601 */
6602static void __hdd_bus_bw_cbk(void *arg)
6603{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006604 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306605
6606 if (wlan_hdd_validate_context(hdd_ctx))
6607 return;
6608
6609 schedule_work(&hdd_ctx->bus_bw_work);
6610}
6611
6612/**
6613 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6614 * @arg: Argument of timer function
6615 *
6616 * Return: None.
6617 */
6618static void hdd_bus_bw_cbk(void *arg)
6619{
6620 cds_ssr_protect(__func__);
6621 __hdd_bus_bw_cbk(arg);
6622 cds_ssr_unprotect(__func__);
6623}
6624
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006625int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006626{
6627 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306628 INIT_WORK(&hdd_ctx->bus_bw_work,
6629 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006630 hdd_ctx->bus_bw_timer_running = false;
6631 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306632 qdf_timer_init(NULL,
6633 &hdd_ctx->bus_bw_timer,
6634 hdd_bus_bw_cbk, (void *)hdd_ctx,
6635 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006636
6637 return 0;
6638}
6639
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006640void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006641{
Dustin Brownfce08d12017-01-17 16:29:38 -08006642 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006643 hdd_reset_tcp_delack(hdd_ctx);
6644
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006645 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306646 cancel_work_sync(&hdd_ctx->bus_bw_work);
6647 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006648 hdd_ctx->bus_bw_timer_running = false;
6649 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006650}
Lin Baic5c06882017-09-21 13:58:43 +08006651
6652void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6653{
6654 if (hdd_ctx)
6655 cancel_work_sync(&hdd_ctx->bus_bw_work);
6656}
jiadcdaf9bd2017-10-26 12:20:21 +08006657
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658#endif
6659
6660/**
Nirav Shahed34b212016-04-25 10:59:16 +05306661 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6662 * @hdd_ctx: hdd context
6663 *
6664 * Return: 0 for success or error code
6665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006666static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306667{
6668 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6669 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6670 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006671 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306672 return -ENOMEM;
6673 }
6674 return 0;
6675}
6676
6677/**
6678 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6679 * @hdd_ctx: hdd context
6680 *
6681 * Return: none
6682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006683void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306684{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306685 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6686 return;
6687
6688 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6689 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306690}
6691
Nirav Shahda008342016-05-17 18:50:40 +05306692static uint8_t *convert_level_to_string(uint32_t level)
6693{
6694 switch (level) {
6695 /* initialize the wlan sub system */
6696 case WLAN_SVC_TP_NONE:
6697 return "NONE";
6698 case WLAN_SVC_TP_LOW:
6699 return "LOW";
6700 case WLAN_SVC_TP_MEDIUM:
6701 return "MED";
6702 case WLAN_SVC_TP_HIGH:
6703 return "HIGH";
6704 default:
6705 return "INVAL";
6706 }
6707}
6708
Nirav Shahed34b212016-04-25 10:59:16 +05306709
6710/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006711 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6712 * @hdd_ctx: hdd context
6713 *
6714 * Return: none
6715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006716void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717{
6718 int i;
6719
6720#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006721 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306722 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006723 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006724 hdd_ctx->config->busBandwidthHighThreshold,
6725 hdd_ctx->config->busBandwidthMediumThreshold,
6726 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006727 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306728 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006729 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730 hdd_ctx->config->tcpDelackThresholdHigh,
6731 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006732 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306733 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734#endif
6735
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006736 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306737 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6738
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006739 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006740
6741 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006742 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006743 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006744 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006745 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6746 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006747 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006748 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6749 convert_level_to_string(
6750 hdd_ctx->hdd_txrx_hist[i].
6751 next_vote_level),
6752 convert_level_to_string(
6753 hdd_ctx->hdd_txrx_hist[i].
6754 next_rx_level),
6755 convert_level_to_string(
6756 hdd_ctx->hdd_txrx_hist[i].
6757 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006758 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759}
6760
6761/**
6762 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6763 * @hdd_ctx: hdd context
6764 *
6765 * Return: none
6766 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006767void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768{
6769 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306770 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6771 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772}
6773
6774/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006775 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006776 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777 *
6778 * Return: none
6779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006780void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781{
6782
Jeff Johnson9d295242017-08-29 14:39:48 -07006783 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306785 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006786 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306787 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788
6789 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306790 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006791 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006792
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006793 hdd_debug("Netif queue operation statistics:");
6794 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07006795 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006796 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306797 curr_time = qdf_system_ticks();
6798 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306799 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306800 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306801 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306802 unpause = adapter->total_unpause_time;
6803 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306804 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306805 pause = adapter->total_pause_time;
6806 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006807 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306808 qdf_system_ticks_to_msecs(total),
6809 qdf_system_ticks_to_msecs(pause),
6810 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006811 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006812
Nirav Shahda008342016-05-17 18:50:40 +05306813 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6814 qdf_time_t pause_delta = 0;
6815
6816 if (adapter->pause_map & (1 << i))
6817 pause_delta = delta;
6818
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006819 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006820 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006821 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822 hdd_reason_type_to_string(i),
6823 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306824 adapter->queue_oper_stats[i].unpause_count,
6825 qdf_system_ticks_to_msecs(
6826 adapter->queue_oper_stats[i].total_pause_time +
6827 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006828 }
6829
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006830 hdd_debug("Netif queue operation history:");
6831 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306832 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6833
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006834 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006835
6836 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006837 /* using hdd_log to avoid printing function name */
6838 if (adapter->queue_oper_history[i].time == 0)
6839 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006840 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006841 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306842 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006843 adapter->queue_oper_history[i].time),
6844 hdd_action_type_to_string(
6845 adapter->queue_oper_history[i].netif_action),
6846 hdd_reason_type_to_string(
6847 adapter->queue_oper_history[i].netif_reason),
6848 adapter->queue_oper_history[i].pause_map);
6849 }
6850
6851 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6852 adapter_node = next;
6853 }
6854
6855
6856}
6857
6858/**
6859 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6860 * @hdd_ctx: hdd context
6861 *
6862 * Return: none
6863 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006864void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006865{
Jeff Johnson9d295242017-08-29 14:39:48 -07006866 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006867 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306868 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869
6870 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306871 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006872 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306874 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306876 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006877 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306878 adapter->history_index = 0;
6879 adapter->start_time = adapter->last_time = qdf_system_ticks();
6880 adapter->total_pause_time = 0;
6881 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6883 adapter_node = next;
6884 }
6885}
6886
6887/**
6888 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6889 * @halHandle: Hal handle
6890 * @pContext: Pointer to the context
6891 * @sessionId: Session ID
6892 * @scanId: Scan ID
6893 * @status: Status
6894 *
6895 * This is the callback to be executed when 11d scan is completed to flush out
6896 * the scan results
6897 *
6898 * 11d scan is done during driver load and is a passive scan on all
6899 * channels supported by the device, 11d scans may find some APs on
6900 * frequencies which are forbidden to be used in the regulatory domain
6901 * the device is operating in. If these APs are notified to the supplicant
6902 * it may try to connect to these APs, thus flush out all the scan results
6903 * which are present in SME after 11d scan is done.
6904 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306905 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306907static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908 uint8_t sessionId, uint32_t scanId,
6909 eCsrScanStatus status)
6910{
6911 ENTER();
6912
6913 sme_scan_flush_result(halHandle);
6914
6915 EXIT();
6916
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306917 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006918}
6919
6920#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6921/**
6922 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6923 * @hdd_ctx: hdd global context
6924 *
6925 * Return: none
6926 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006927static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006928{
6929 uint8_t i;
6930
6931 mutex_init(&hdd_ctx->op_ctx.op_lock);
6932 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6933 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6934 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6935 }
6936}
6937#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006938static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006939{
6940}
6941#endif
6942
Yingying Tang95409972016-10-20 15:16:15 +08006943#ifdef WLAN_FEATURE_WOW_PULSE
6944/**
6945 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006947 * @enable: enable or disable this behaviour
6948 *
6949 * Return: int
6950 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006951static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006952{
6953 struct hdd_config *pcfg_ini = phddctx->config;
6954 struct wow_pulse_mode wow_pulse_set_info;
6955 QDF_STATUS status;
6956
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006957 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006958
6959 if (false == phddctx->config->wow_pulse_support)
6960 return 0;
6961
6962 /* prepare the request to send to SME */
6963 if (enable == true) {
6964 wow_pulse_set_info.wow_pulse_enable = true;
6965 wow_pulse_set_info.wow_pulse_pin =
6966 pcfg_ini->wow_pulse_pin;
6967 wow_pulse_set_info.wow_pulse_interval_low =
6968 pcfg_ini->wow_pulse_interval_low;
6969 wow_pulse_set_info.wow_pulse_interval_high =
6970 pcfg_ini->wow_pulse_interval_high;
6971 } else {
6972 wow_pulse_set_info.wow_pulse_enable = false;
6973 wow_pulse_set_info.wow_pulse_pin = 0;
6974 wow_pulse_set_info.wow_pulse_interval_low = 0;
6975 wow_pulse_set_info.wow_pulse_interval_high = 0;
6976 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006977 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006978 wow_pulse_set_info.wow_pulse_enable,
6979 wow_pulse_set_info.wow_pulse_pin,
6980 wow_pulse_set_info.wow_pulse_interval_low,
6981 wow_pulse_set_info.wow_pulse_interval_high);
6982
6983 status = sme_set_wow_pulse(&wow_pulse_set_info);
6984 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006985 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006986 return -EIO;
6987 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006988 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006989 return 0;
6990}
6991#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006992static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006993{
6994 return 0;
6995}
6996#endif
6997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998#ifdef WLAN_FEATURE_FASTPATH
6999/**
7000 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7001 * @hdd_cfg: hdd config
7002 * @context: lower layer context
7003 *
7004 * Return: none
7005 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307006void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007 void *context)
7008{
7009 if (hdd_cfg->fastpath_enable)
7010 hif_enable_fastpath(context);
7011}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012#endif
7013
Yuanyuan Liu13738502016-04-06 17:41:37 -07007014#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007015/**
7016 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007017 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018 * @level: thermal level
7019 *
7020 * Change IPA data path to SW path when the thermal throttle level greater
7021 * than 0, and restore the original data path when throttle level is 0
7022 *
7023 * Return: none
7024 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007025static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007027 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007029 /* Change IPA to SW path when throttle level greater than 0 */
7030 if (level > THROTTLE_LEVEL_0)
7031 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7032 else
7033 /* restore original concurrency mode */
7034 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7035}
7036
7037/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307038 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7039 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307040 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007041 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307042 * Get a safe channel to restart SAP. PCL already takes into account the
7043 * unsafe channels. So, the PCL is validated with the ACS range to provide
7044 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007045 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307046 * Return: Channel number to restart SAP in case of success. In case of any
7047 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007048 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007050 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307052 struct sir_pcl_list pcl;
7053 QDF_STATUS status;
7054 uint32_t i, j;
7055 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007056 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307057 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007058
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307059 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7060 if (!hdd_ctx) {
7061 hdd_err("invalid HDD context");
7062 return INVALID_CHANNEL_ID;
7063 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307065 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7066 if (!hal_handle) {
7067 hdd_err("invalid HAL handle");
7068 return INVALID_CHANNEL_ID;
7069 }
7070
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007071 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7072 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007073 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7074 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307075 if (QDF_IS_STATUS_ERROR(status)) {
7076 hdd_err("Get PCL failed");
7077 return INVALID_CHANNEL_ID;
7078 }
7079
Frank Liudc2cefb2017-06-21 15:38:18 +08007080 /*
7081 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7082 * channel is unsafe channel, the pcl may be empty, instead of return,
7083 * try to choose a safe channel from acs range.
7084 */
7085 if (!pcl.pcl_len)
7086 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307087
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007088 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007089 adapter->session.ap.sap_config.acs_cfg.start_ch,
7090 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091
7092 /* PCL already takes unsafe channel into account */
7093 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007094 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307095 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007096 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307097 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007098 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007099 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307100 return pcl.pcl_list[i];
7101 }
7102 }
7103
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007104 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307105
7106 /* Try for safe channel from all valid channel */
7107 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007108 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307109 &pcl.pcl_len);
7110 if (QDF_IS_STATUS_ERROR(status)) {
7111 hdd_err("error in getting valid channel list");
7112 return INVALID_CHANNEL_ID;
7113 }
7114
7115 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007116 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307117 found = false;
7118 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007119 if (pcl.pcl_list[i] ==
7120 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007121 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307122 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007123 break;
7124 }
7125 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307126
7127 if (found)
7128 continue;
7129
7130 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007131 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307132 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007133 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007134 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307135 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007136 }
7137 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307138
7139 return INVALID_CHANNEL_ID;
7140}
7141
7142/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007143 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307144 * @adapter: AP adapter
7145 * @channel: Channel
7146 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007147 * Moves the SAP interface by invoking the function which
7148 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307149 *
7150 * Return: None
7151 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007152void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307153{
Jeff Johnson87251032017-08-29 13:31:11 -07007154 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307155 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007156 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307157
7158 if (!adapter) {
7159 hdd_err("invalid adapter");
7160 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307162
7163 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7164
7165 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7166 if (!hal_handle) {
7167 hdd_err("invalid HAL handle");
7168 return;
7169 }
7170
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007171 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7172
Jeff Johnson91df29d2017-10-27 19:29:50 -07007173 hdd_ap_ctx->sap_config.channel = channel;
7174 hdd_ap_ctx->sap_config.ch_params.ch_width =
7175 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307176
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007177 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007178 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307179
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007180 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007181 hdd_ap_ctx->sap_config.channel,
7182 hdd_ap_ctx->sap_config.sec_ch,
7183 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307184
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007185 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007186 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007187 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007188}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307189
Jeff Johnson9d295242017-08-29 14:39:48 -07007190int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307191{
7192 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307193 int status;
7194 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307195
7196 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7197
7198 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007199 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307200 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007201 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307202 }
7203 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007204 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307205 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307206 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007207 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307208 WLAN_VENDOR_ACS_WAIT_TIME);
7209 if (qdf_status != QDF_STATUS_SUCCESS) {
7210 hdd_err("failed to start external acs timer");
7211 return -ENOSPC;
7212 }
7213 /* Update config to application */
7214 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307215 hdd_notice("Updated ACS config to nl with reason %d", reason);
7216
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307217 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307218}
7219
Agrawal Ashish467dde42016-09-08 18:44:22 +05307220/**
7221 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7222 * @hdd_ctx: hdd context pointer
7223 *
7224 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7225 * and if ACS is enabled, driver will ask userspace to restart the
7226 * sap. User space on LTE coex indication restart driver.
7227 *
7228 * Return - none
7229 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007230void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307231{
7232 QDF_STATUS status;
7233 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007234 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307235 uint32_t i;
7236 bool found = false;
7237 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007238
Agrawal Ashish467dde42016-09-08 18:44:22 +05307239 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7240 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007241 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307242
7243 if (!adapter_temp) {
7244 hdd_err("adapter is NULL, moving to next one");
7245 goto next_adapater;
7246 }
7247
7248 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
Jeff Johnsonb9424862017-10-30 08:49:35 -07007249 (adapter_temp->session.ap.sap_config.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007250 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307251 adapter_temp->device_mode,
Jeff Johnsonb9424862017-10-30 08:49:35 -07007252 adapter_temp->session.ap.sap_config.
Agrawal Ashish467dde42016-09-08 18:44:22 +05307253 acs_cfg.acs_mode);
7254 goto next_adapater;
7255 }
7256
7257 found = false;
7258 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007259 if (adapter_temp->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307260 hdd_ctxt->unsafe_channel_list[i]) {
7261 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007262 hdd_debug("operating ch:%d is unsafe",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007263 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307264 break;
7265 }
7266 }
7267
7268 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007269 hdd_debug("ch:%d is safe. no need to change channel",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007270 adapter_temp->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307271 goto next_adapater;
7272 }
7273
Kapil Gupta8878ad92017-02-13 11:56:04 +05307274 if (hdd_ctxt->config->vendor_acs_support &&
7275 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7276 hdd_update_acs_timer_reason(adapter_temp,
7277 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7278 goto next_adapater;
7279 } else
7280 restart_chan =
7281 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307282 adapter_temp);
7283 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007284 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307285 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007286 /*
7287 * SAP restart due to unsafe channel. While
7288 * restarting the SAP, make sure to clear
7289 * acs_channel, channel to reset to
7290 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307291 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007292 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307293 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007294 adapter_temp->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307295 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007296 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307297 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7298 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007299 hdd_debug("driver to start sap: %d",
7300 hdd_ctxt->config->sap_internal_restart);
7301 if (hdd_ctxt->config->sap_internal_restart)
7302 hdd_switch_sap_channel(adapter_temp, restart_chan);
7303 else
7304 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307305 }
7306
7307next_adapater:
7308 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7309 adapter_node = next;
7310 }
7311}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307312
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007313/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007314 * hdd_init_channel_avoidance() - Initialize channel avoidance
7315 * @hdd_ctx: HDD global context
7316 *
7317 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007318 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007319 * down to the lower layers. Then subscribe to subsequent channel
7320 * avoidance events.
7321 *
7322 * Return: None
7323 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007324static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325{
7326 uint16_t unsafe_channel_count;
7327 int index;
7328
Yuanyuan Liu13738502016-04-06 17:41:37 -07007329 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7330 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007332 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007333
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007334 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007335 hdd_ctx->unsafe_channel_count);
7336
Anurag Chouhan6d760662016-02-20 16:05:43 +05307337 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007338 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339
7340 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007341 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342 hdd_ctx->unsafe_channel_list[index]);
7343
7344 }
7345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346}
Dustin Brown676a2322017-08-15 13:16:13 -07007347
Jeff Johnson9d295242017-08-29 14:39:48 -07007348static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007349 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007350{
7351 uint8_t restart_chan;
7352
7353 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7354 if (!restart_chan) {
7355 hdd_alert("fail to restart SAP");
7356 return;
7357 }
7358
7359 /* SAP restart due to unsafe channel. While restarting
7360 * the SAP, make sure to clear acs_channel, channel to
7361 * reset to 0. Otherwise these settings will override
7362 * the ACS while restart.
7363 */
7364 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007365 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007366
7367 hdd_debug("sending coex indication");
7368
7369 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7370 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7371 hdd_switch_sap_channel(adapter, restart_chan);
7372}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007373
7374int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7375 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7376{
7377 uint32_t size;
7378 uint16_t *unsafe_list;
7379 uint16_t chan_count;
7380
7381 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7382 return -EINVAL;
7383
7384 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7385 NUM_CHANNELS);
7386 if (chan_count) {
7387 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7388 unsafe_list = qdf_mem_malloc(size);
7389 if (!unsafe_list) {
7390 hdd_err("No memory for unsafe chan list size%d",
7391 size);
7392 return -ENOMEM;
7393 }
7394 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7395 } else {
7396 unsafe_list = NULL;
7397 }
7398
7399 *local_unsafe_list = unsafe_list;
7400 *local_unsafe_list_count = chan_count;
7401
7402 return 0;
7403}
7404
7405bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7406 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7407{
7408 int i, j;
7409
7410 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7411 return true;
7412 if (local_unsafe_list_count == 0)
7413 return false;
7414 for (i = 0; i < local_unsafe_list_count; i++) {
7415 for (j = 0; j < local_unsafe_list_count; j++)
7416 if (local_unsafe_list[i] ==
7417 hdd_ctx->unsafe_channel_list[j])
7418 break;
7419 if (j >= local_unsafe_list_count)
7420 break;
7421 }
7422 if (i >= local_unsafe_list_count) {
7423 hdd_info("unsafe chan list same");
7424 return false;
7425 }
7426
7427 return true;
7428}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007430static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431{
7432}
Dustin Brown676a2322017-08-15 13:16:13 -07007433
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007434static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435{
7436}
Dustin Brown676a2322017-08-15 13:16:13 -07007437
Jeff Johnson9d295242017-08-29 14:39:48 -07007438static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007439 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007440{
7441 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7442}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007443#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444
7445/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007446 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7447 * user space
7448 * @frame_ind: Management frame data to be informed.
7449 *
7450 * This function is used to indicate management frame to
7451 * user space
7452 *
7453 * Return: None
7454 *
7455 */
7456void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7457{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007458 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007459 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007460 int i;
7461
Rajeev Kumard004abc2016-02-17 12:09:56 -08007462 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007463 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007464
7465 if (0 != wlan_hdd_validate_context(hdd_ctx))
7466 return;
7467
7468 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7469 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7470 adapter =
7471 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7472 if (adapter)
7473 break;
7474 }
7475 } else {
7476 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7477 frame_ind->sessionId);
7478 }
7479
7480 if ((NULL != adapter) &&
7481 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7482 __hdd_indicate_mgmt_frame(adapter,
7483 frame_ind->frame_len,
7484 frame_ind->frameBuf,
7485 frame_ind->frameType,
7486 frame_ind->rxChan,
7487 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007488}
7489
Kapil Gupta8878ad92017-02-13 11:56:04 +05307490void hdd_acs_response_timeout_handler(void *context)
7491{
7492 struct hdd_external_acs_timer_context *timer_context =
7493 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007494 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007495 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307496 uint8_t reason;
7497
7498 ENTER();
7499 if (!timer_context) {
7500 hdd_err("invlaid timer context");
7501 return;
7502 }
7503 adapter = timer_context->adapter;
7504 reason = timer_context->reason;
7505
7506
7507 if ((!adapter) ||
7508 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7509 hdd_err("invalid adapter or adapter has invalid magic");
7510 return;
7511 }
7512 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7513 if (wlan_hdd_validate_context(hdd_ctx))
7514 return;
7515
7516 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7517 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7518 else
7519 return;
7520
7521 hdd_err("ACS timeout happened for %s reason %d",
7522 adapter->dev->name, reason);
7523 switch (reason) {
7524 /* SAP init case */
7525 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7526 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7527 false);
7528 wlan_hdd_cfg80211_start_acs(adapter);
7529 break;
7530 /* DFS detected on current channel */
7531 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7532 wlan_sap_update_next_channel(
7533 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7534 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007535 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307536 break;
7537 /* LTE coex event on current channel */
7538 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7539 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7540 break;
7541 default:
7542 hdd_info("invalid reason for timer invoke");
7543
7544 }
7545}
7546
Rajeev Kumard004abc2016-02-17 12:09:56 -08007547/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007548 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7549 * @hdd_ctx: HDD context
7550 *
7551 * Disables all the dual mac features like DBS, Agile DFS etc.
7552 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307553 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007555static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007556{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007557 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307558 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007559
7560 if (!hdd_ctx) {
7561 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307562 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563 }
7564
7565 cfg.scan_config = 0;
7566 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007567 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568
7569 hdd_debug("Disabling all dual mac features...");
7570
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007571 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307572 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7574 return status;
7575 }
7576
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307577 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007578}
7579
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007580static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007581wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007582{
7583 struct policy_mgr_dual_mac_config cfg = {0};
7584 QDF_STATUS status;
7585
7586 if (!hdd_ctx) {
7587 hdd_err("HDD context is NULL");
7588 return QDF_STATUS_E_FAILURE;
7589 }
7590
7591 cfg.scan_config = 0;
7592 cfg.fw_mode_config = 0;
7593 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7594 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7595 hdd_ctx->hdd_psoc, &cfg.scan_config,
7596 &cfg.fw_mode_config,
7597 hdd_ctx->config->dual_mac_feature_disable);
7598
7599 if (status != QDF_STATUS_SUCCESS) {
7600 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7601 status);
7602 return status;
7603 }
7604
7605 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7606 cfg.scan_config, cfg.fw_mode_config);
7607
7608 status = sme_soc_set_dual_mac_config(cfg);
7609 if (status != QDF_STATUS_SUCCESS) {
7610 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7611 return status;
7612 }
7613
7614 return QDF_STATUS_SUCCESS;
7615}
7616
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007617/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007618 * hdd_override_ini_config - Override INI config
7619 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007620 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007621 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007622 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007623 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007625static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007628 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7629 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007630 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007631 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007632 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007633 if (0 == enable_11d || 1 == enable_11d) {
7634 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007635 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 }
Leo Chang11545d62016-10-17 14:53:50 -07007637
7638 if (!hdd_ipa_is_present(hdd_ctx))
7639 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05307640
7641 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
7642 !hdd_ctx->config->enable_bcast_probe_rsp) {
7643 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
7644 hdd_ctx->config->rssi_assoc_reject_enabled,
7645 hdd_ctx->config->enable_bcast_probe_rsp);
7646 hdd_ctx->config->oce_sta_enabled = 0;
7647 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007648}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007650/**
7651 * hdd_set_trace_level_for_each - Set trace level for each INI config
7652 * @hdd_ctx - HDD context
7653 *
7654 * Set trace level for each module based on INI config.
7655 *
7656 * Return: None
7657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007658static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007659{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307660 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7661 hdd_ctx->config->qdf_trace_enable_wdi);
7662 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7663 hdd_ctx->config->qdf_trace_enable_hdd);
7664 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7665 hdd_ctx->config->qdf_trace_enable_sme);
7666 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7667 hdd_ctx->config->qdf_trace_enable_pe);
7668 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7669 hdd_ctx->config->qdf_trace_enable_wma);
7670 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7671 hdd_ctx->config->qdf_trace_enable_sys);
7672 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7673 hdd_ctx->config->qdf_trace_enable_qdf);
7674 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7675 hdd_ctx->config->qdf_trace_enable_sap);
7676 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7677 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7678 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7679 hdd_ctx->config->qdf_trace_enable_bmi);
7680 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7681 hdd_ctx->config->qdf_trace_enable_cfg);
7682 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7683 hdd_ctx->config->qdf_trace_enable_epping);
7684 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7685 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7686 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007687 hdd_ctx->config->qdf_trace_enable_txrx);
7688 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7689 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307690 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7691 hdd_ctx->config->qdf_trace_enable_htc);
7692 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7693 hdd_ctx->config->qdf_trace_enable_hif);
7694 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7695 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7696 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7697 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007698 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7699 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007700 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7701 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007702 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7703 hdd_ctx->config->qdf_trace_enable_regulatory);
7704
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007705 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007706}
7707
7708/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007709 * hdd_context_init() - Initialize HDD context
7710 * @hdd_ctx: HDD context.
7711 *
7712 * Initialize HDD context along with all the feature specific contexts.
7713 *
7714 * return: 0 on success and errno on failure.
7715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007716static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007717{
7718 int ret;
7719
7720 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7721 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7722
7723 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307724 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007725
7726 init_completion(&hdd_ctx->mc_sus_event_var);
7727 init_completion(&hdd_ctx->ready_to_suspend);
7728
7729 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307730 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007731 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307732
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007733 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007734
7735 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7736
7737 ret = hdd_scan_context_init(hdd_ctx);
7738 if (ret)
7739 goto list_destroy;
7740
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007741 hdd_rx_wake_lock_create(hdd_ctx);
7742
7743 ret = hdd_sap_context_init(hdd_ctx);
7744 if (ret)
7745 goto scan_destroy;
7746
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007747 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7748
7749 hdd_init_offloaded_packets_ctx(hdd_ctx);
7750
7751 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7752 hdd_ctx->config);
7753 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08007754 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007755
7756 return 0;
7757
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007758sap_destroy:
7759 hdd_sap_context_destroy(hdd_ctx);
7760
7761scan_destroy:
7762 hdd_scan_context_destroy(hdd_ctx);
7763 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007764list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007765 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007766
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007767 return ret;
7768}
7769
7770/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307771 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7772 * @hdd_ctx: pointer to hdd context
7773 *
7774 * Return: status of initialization
7775 * 0 - success
7776 * negative value - failure
7777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007778static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307779{
7780 int ret;
7781
7782 if (!hdd_ctx->config->probe_req_ie_whitelist)
7783 return 0;
7784
7785 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7786 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7787 hdd_ctx->config->probe_req_ie_whitelist = false;
7788 return -EINVAL;
7789 }
7790
7791 /* parse ini string probe req oui */
7792 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7793 if (ret) {
7794 hdd_err("parsing error: disable ie whitelisting");
7795 hdd_ctx->config->probe_req_ie_whitelist = false;
7796 }
7797
7798 return ret;
7799}
7800
7801/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007802 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307803 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007804 *
7805 * Allocate and initialize HDD context. HDD context is allocated as part of
7806 * wiphy allocation and then context is initialized.
7807 *
7808 * Return: HDD context on success and ERR_PTR on failure
7809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007810static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007811{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307812 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007813 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007814 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815
7816 ENTER();
7817
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007818 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007819 if (hdd_ctx == NULL) {
7820 ret = -ENOMEM;
7821 goto err_out;
7822 }
7823
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007824 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307825 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307827 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007828 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007829 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007830 ret = -ENOMEM;
7831 goto err_free_hdd_context;
7832 }
7833
7834 /* Read and parse the qcom_cfg.ini file */
7835 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307836 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307837 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007838 WLAN_INI_FILE);
7839 ret = -EINVAL;
7840 goto err_free_config;
7841 }
7842
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307843 ie_whitelist_attrs_init(hdd_ctx);
7844
Dustin Brown7f939932017-05-18 15:02:17 -07007845 hdd_debug("setting timer multiplier: %u",
7846 hdd_ctx->config->timer_multiplier);
7847 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7848
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007849
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307850 if (hdd_ctx->config->fhostNSOffload)
7851 hdd_ctx->ns_offload_enable = true;
7852
Abhishek Singh5ea86532016-04-27 14:10:53 +05307853 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7854
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007855 hdd_override_ini_config(hdd_ctx);
7856
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007857 ret = hdd_context_init(hdd_ctx);
7858
7859 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007860 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007861
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007862 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307863 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007864
Anurag Chouhan6d760662016-02-20 16:05:43 +05307865 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007866 goto skip_multicast_logging;
7867
7868 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7869
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007870 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7871 if (ret)
7872 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307873
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007874 ret = hdd_init_netlink_services(hdd_ctx);
7875 if (ret)
7876 goto err_deinit_txrx_histogram;
7877
Dustin Brown7b3dea22017-07-10 13:02:47 -07007878 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7879 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307880
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007881skip_multicast_logging:
7882 hdd_set_trace_level_for_each(hdd_ctx);
7883
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007884 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7885
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007886 EXIT();
7887
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007888 return hdd_ctx;
7889
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007890err_deinit_txrx_histogram:
7891 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7892
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007893err_deinit_hdd_context:
7894 hdd_context_deinit(hdd_ctx);
7895
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007896err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307897 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007898
7899err_free_hdd_context:
7900 wiphy_free(hdd_ctx->wiphy);
7901
7902err_out:
7903 return ERR_PTR(ret);
7904}
7905
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007906#ifdef WLAN_OPEN_P2P_INTERFACE
7907/**
7908 * hdd_open_p2p_interface - Open P2P interface
7909 * @hdd_ctx: HDD context
7910 * @rtnl_held: True if RTNL lock held
7911 *
7912 * Open P2P interface during probe. This function called to open the P2P
7913 * interface at probe along with STA interface.
7914 *
7915 * Return: 0 on success and errno on failure
7916 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007917static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007918{
Jeff Johnson9d295242017-08-29 14:39:48 -07007919 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007920 uint8_t *p2p_dev_addr;
7921
7922 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7923 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007924 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007925 hdd_ctx->config->intfMacAddr[0].bytes,
7926 sizeof(tSirMacAddr));
7927
7928 /*
7929 * Generate the P2P Device Address. This consists of
7930 * the device's primary MAC address with the locally
7931 * administered bit set.
7932 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007933 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007934 } else {
7935 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7936 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007937 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007938 return -ENOSPC;
7939 }
7940
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007941 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
7942 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007943 }
7944
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007945 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07007946 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007947 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007948
7949 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007950 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007951 return -ENOSPC;
7952 }
7953
7954 return 0;
7955}
7956#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007957static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007958 bool rtnl_held)
7959{
7960 return 0;
7961}
7962#endif
7963
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007964static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007965{
Jeff Johnson9d295242017-08-29 14:39:48 -07007966 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007967 int ret = 0;
7968
7969 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7970 wlan_hdd_get_intf_addr(hdd_ctx),
7971 NET_NAME_UNKNOWN, rtnl_held);
7972 if (adapter == NULL) {
7973 hdd_err("Failed to open 802.11p interface");
7974 ret = -ENOSPC;
7975 }
7976
7977 return ret;
7978}
7979
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007980/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307981 * hdd_start_station_adapter()- Start the Station Adapter
7982 * @adapter: HDD adapter
7983 *
7984 * This function initializes the adapter for the station mode.
7985 *
7986 * Return: 0 on success or errno on failure.
7987 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007988int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307989{
7990 QDF_STATUS status;
7991
7992 ENTER_DEV(adapter->dev);
7993
7994 status = hdd_init_station_mode(adapter);
7995
7996 if (QDF_STATUS_SUCCESS != status) {
7997 hdd_err("Error Initializing station mode: %d", status);
7998 return qdf_status_to_os_return(status);
7999 }
8000
Arun Khandavallifae92942016-08-01 13:31:08 +05308001 hdd_register_tx_flow_control(adapter,
8002 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008003 hdd_tx_resume_cb,
8004 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308005
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308006 EXIT();
8007 return 0;
8008}
8009
8010/**
8011 * hdd_start_ap_adapter()- Start AP Adapter
8012 * @adapter: HDD adapter
8013 *
8014 * This function initializes the adapter for the AP mode.
8015 *
8016 * Return: 0 on success errno on failure.
8017 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008018int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308019{
8020 QDF_STATUS status;
8021
8022 ENTER();
8023
Arun Khandavallicc544b32017-01-30 19:52:16 +05308024 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308025
8026 if (QDF_STATUS_SUCCESS != status) {
8027 hdd_err("Error Initializing the AP mode: %d", status);
8028 return qdf_status_to_os_return(status);
8029 }
8030
Arun Khandavallifae92942016-08-01 13:31:08 +05308031 hdd_register_tx_flow_control(adapter,
8032 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008033 hdd_softap_tx_resume_cb,
8034 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308035
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308036 EXIT();
8037 return 0;
8038}
8039
8040/**
8041 * hdd_start_ftm_adapter()- Start FTM adapter
8042 * @adapter: HDD adapter
8043 *
8044 * This function initializes the adapter for the FTM mode.
8045 *
8046 * Return: 0 on success or errno on failure.
8047 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008048int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308049{
8050 QDF_STATUS qdf_status;
8051
8052 ENTER_DEV(adapter->dev);
8053
8054 qdf_status = hdd_init_tx_rx(adapter);
8055
8056 if (QDF_STATUS_SUCCESS != qdf_status) {
8057 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8058 return qdf_status_to_os_return(qdf_status);
8059 }
8060
8061 return 0;
8062 EXIT();
8063}
8064
8065/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008066 * hdd_open_interfaces - Open all required interfaces
8067 * hdd_ctx: HDD context
8068 * rtnl_held: True if RTNL lock is held
8069 *
8070 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8071 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008072 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008073 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008074static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008075{
Jeff Johnson9d295242017-08-29 14:39:48 -07008076 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008077 int ret;
8078
Ravi Joshia307f632017-07-17 23:41:41 -07008079 /* open monitor mode adapter if con_mode is monitor mode */
8080 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8081 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8082 wlan_hdd_get_intf_addr(hdd_ctx),
8083 NET_NAME_UNKNOWN, rtnl_held);
8084 if (!adapter) {
8085 hdd_err("open adapter failed");
8086 return -ENOSPC;
8087 }
8088 return 0;
8089 }
8090
Jeff Johnson957bc272017-02-02 08:54:48 -08008091 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308092 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008093 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008094
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008095 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008096 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008097 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008098
8099 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008100 return -ENOSPC;
8101
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008102 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8103 adapter->fast_roaming_allowed = true;
8104
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008105 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8106 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008107 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008108
8109 /* Open 802.11p Interface */
8110 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008111 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8112 if (ret)
8113 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008114 }
8115
Jeff Johnson957bc272017-02-02 08:54:48 -08008116 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008117
Jeff Johnson957bc272017-02-02 08:54:48 -08008118err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008119 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008120 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008121}
8122
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008123/**
8124 * hdd_update_country_code - Update country code
8125 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008126 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008127 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008128 *
8129 * Return: 0 on success and errno on failure
8130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008131static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008132{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008133 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008134 return 0;
8135
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008136 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008137}
8138
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308139#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8140/**
8141 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8142 * @cds_cfg: CDS Configuration
8143 * @hdd_ctx: Pointer to hdd context
8144 *
8145 * Return: none
8146 */
8147static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8148 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008149 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308150{
8151 cds_cfg->tx_flow_stop_queue_th =
8152 hdd_ctx->config->TxFlowStopQueueThreshold;
8153 cds_cfg->tx_flow_start_queue_offset =
8154 hdd_ctx->config->TxFlowStartQueueOffset;
8155}
8156#else
8157static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8158 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008159 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308160{
8161}
8162#endif
8163
8164#ifdef FEATURE_WLAN_RA_FILTERING
8165/**
8166 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8167 * @cds_cfg: CDS Configuration
8168 * @hdd_ctx: Pointer to hdd context
8169 *
8170 * Return: none
8171 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308172static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008173 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308174{
8175 cds_cfg->ra_ratelimit_interval =
8176 hdd_ctx->config->RArateLimitInterval;
8177 cds_cfg->is_ra_ratelimit_enabled =
8178 hdd_ctx->config->IsRArateLimitEnabled;
8179}
8180#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308181static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008182 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308183{
8184}
8185#endif
8186
8187/**
8188 * hdd_update_cds_config() - API to update cds configuration parameters
8189 * @hdd_ctx: HDD Context
8190 *
8191 * Return: 0 for Success, errno on failure
8192 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008193static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308194{
8195 struct cds_config_info *cds_cfg;
8196
8197 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8198 if (!cds_cfg) {
8199 hdd_err("failed to allocate cds config");
8200 return -ENOMEM;
8201 }
8202
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008203 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008204 if (!hdd_ctx->config->nMaxPsPoll ||
8205 !hdd_ctx->config->enablePowersaveOffload) {
8206 cds_cfg->powersave_offload_enabled =
8207 hdd_ctx->config->enablePowersaveOffload;
8208 } else {
8209 if ((hdd_ctx->config->enablePowersaveOffload ==
8210 PS_QPOWER_NODEEPSLEEP) ||
8211 (hdd_ctx->config->enablePowersaveOffload ==
8212 PS_LEGACY_NODEEPSLEEP))
8213 cds_cfg->powersave_offload_enabled =
8214 PS_LEGACY_NODEEPSLEEP;
8215 else
8216 cds_cfg->powersave_offload_enabled =
8217 PS_LEGACY_DEEPSLEEP;
8218 hdd_info("Qpower disabled in cds config, %d",
8219 cds_cfg->powersave_offload_enabled);
8220 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308221 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8222 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8223 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8224 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8225 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8226
8227 /* Here ol_ini_info is used to store ini status of arp offload
8228 * ns offload and others. Currently 1st bit is used for arp
8229 * off load and 2nd bit for ns offload currently, rest bits are unused
8230 */
8231 if (hdd_ctx->config->fhostArpOffload)
8232 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8233 if (hdd_ctx->config->fhostNSOffload)
8234 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8235
8236 /*
8237 * Copy the DFS Phyerr Filtering Offload status.
8238 * This parameter reflects the value of the
8239 * dfs_phyerr_filter_offload flag as set in the ini.
8240 */
8241 cds_cfg->dfs_phyerr_filter_offload =
8242 hdd_ctx->config->fDfsPhyerrFilterOffload;
8243 if (hdd_ctx->config->ssdp)
8244 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8245
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308246 cds_cfg->force_target_assert_enabled =
8247 hdd_ctx->config->crash_inject_enabled;
8248
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308249 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8250 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8251
8252 cds_cfg->ap_maxoffload_reorderbuffs =
8253 hdd_ctx->config->apMaxOffloadReorderBuffs;
8254
8255 cds_cfg->ap_disable_intrabss_fwd =
8256 hdd_ctx->config->apDisableIntraBssFwd;
8257
8258 cds_cfg->dfs_pri_multiplier =
8259 hdd_ctx->config->dfsRadarPriMultiplier;
8260 cds_cfg->reorder_offload =
8261 hdd_ctx->config->reorderOffloadSupport;
8262
8263 /* IPA micro controller data path offload resource config item */
8264 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008265 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8266 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008267 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008268 hdd_ctx->config->IpaUcTxBufCount);
8269 hdd_ctx->config->IpaUcTxBufCount =
8270 rounddown_pow_of_two(
8271 hdd_ctx->config->IpaUcTxBufCount);
8272 if (!hdd_ctx->config->IpaUcTxBufCount) {
8273 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308274 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008275 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008276 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008277 hdd_ctx->config->IpaUcTxBufCount);
8278 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308279 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8280 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008281 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8282 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008283 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008284 hdd_ctx->config->IpaUcRxIndRingCount);
8285 hdd_ctx->config->IpaUcRxIndRingCount =
8286 rounddown_pow_of_two(
8287 hdd_ctx->config->IpaUcRxIndRingCount);
8288 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8289 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308290 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008291 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008292 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008293 hdd_ctx->config->IpaUcRxIndRingCount);
8294 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308295 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008296 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308297 cds_cfg->uc_tx_partition_base =
8298 hdd_ctx->config->IpaUcTxPartitionBase;
8299 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8300
8301 cds_cfg->ip_tcp_udp_checksum_offload =
8302 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008303 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308304 cds_cfg->ce_classify_enabled =
8305 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008306 cds_cfg->bpf_packet_filter_enable =
8307 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308308 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8309 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8310 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008311 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008312 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008313 cds_cfg->max_msdus_per_rxinorderind =
8314 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008315 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008316 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308317 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8318 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308319 cds_cfg->auto_power_save_fail_mode =
8320 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308321
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308322 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008323 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308324
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308325 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8326 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8327 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008328 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308329 cds_init_ini_config(cds_cfg);
8330 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308331
8332exit:
8333 qdf_mem_free(cds_cfg);
8334 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308335}
8336
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008337/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008338 * hdd_update_user_config() - API to update user configuration
8339 * parameters to obj mgr which are used by multiple components
8340 * @hdd_ctx: HDD Context
8341 *
8342 * Return: 0 for Success, errno on failure
8343 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008344static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008345{
8346 struct wlan_objmgr_psoc_user_config *user_config;
8347
8348 user_config = qdf_mem_malloc(sizeof(*user_config));
8349 if (user_config == NULL) {
8350 hdd_alert("Failed to alloc memory for user_config!");
8351 return -ENOMEM;
8352 }
8353
8354 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8355 user_config->dual_mac_feature_disable =
8356 hdd_ctx->config->dual_mac_feature_disable;
8357 user_config->indoor_channel_support =
8358 hdd_ctx->config->indoor_channel_support;
8359 user_config->is_11d_support_enabled =
8360 hdd_ctx->config->Is11dSupportEnabled;
8361 user_config->is_11h_support_enabled =
8362 hdd_ctx->config->Is11hSupportEnabled;
8363 user_config->optimize_chan_avoid_event =
8364 hdd_ctx->config->goptimize_chan_avoid_event;
8365 user_config->skip_dfs_chnl_in_p2p_search =
8366 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008367 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008368 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8369
8370 qdf_mem_free(user_config);
8371 return 0;
8372}
8373
8374/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008375 * hdd_init_thermal_info - Initialize thermal level
8376 * @hdd_ctx: HDD context
8377 *
8378 * Initialize thermal level at SME layer and set the thermal level callback
8379 * which would be called when a configured thermal threshold is hit.
8380 *
8381 * Return: 0 on success and errno on failure
8382 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008383static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008384{
8385 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308386 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008387
8388 thermal_param.smeThermalMgmtEnabled =
8389 hdd_ctx->config->thermalMitigationEnable;
8390 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8391
Poddar, Siddarth83905022016-04-16 17:56:08 -07008392 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8393 hdd_ctx->config->throttle_dutycycle_level0;
8394 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8395 hdd_ctx->config->throttle_dutycycle_level1;
8396 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8397 hdd_ctx->config->throttle_dutycycle_level2;
8398 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8399 hdd_ctx->config->throttle_dutycycle_level3;
8400
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008401 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8402 hdd_ctx->config->thermalTempMinLevel0;
8403 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8404 hdd_ctx->config->thermalTempMaxLevel0;
8405 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8406 hdd_ctx->config->thermalTempMinLevel1;
8407 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8408 hdd_ctx->config->thermalTempMaxLevel1;
8409 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8410 hdd_ctx->config->thermalTempMinLevel2;
8411 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8412 hdd_ctx->config->thermalTempMaxLevel2;
8413 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8414 hdd_ctx->config->thermalTempMinLevel3;
8415 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8416 hdd_ctx->config->thermalTempMaxLevel3;
8417
8418 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8419
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308420 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308421 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008422
8423 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8424 hdd_set_thermal_level_cb);
8425
8426 return 0;
8427
8428}
8429
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008430#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8431/**
8432 * hdd_hold_rtnl_lock - Hold RTNL lock
8433 *
8434 * Hold RTNL lock
8435 *
8436 * Return: True if held and false otherwise
8437 */
8438static inline bool hdd_hold_rtnl_lock(void)
8439{
8440 rtnl_lock();
8441 return true;
8442}
8443
8444/**
8445 * hdd_release_rtnl_lock - Release RTNL lock
8446 *
8447 * Release RTNL lock
8448 *
8449 * Return: None
8450 */
8451static inline void hdd_release_rtnl_lock(void)
8452{
8453 rtnl_unlock();
8454}
8455#else
8456static inline bool hdd_hold_rtnl_lock(void) { return false; }
8457static inline void hdd_release_rtnl_lock(void) { }
8458#endif
8459
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008460#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008461
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308462/* MAX iwpriv command support */
8463#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308464#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308465#define MAX_PKTLOG_SIZE 16
8466
8467/**
8468 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8469 * @hdd_ctx: hdd context
8470 * @set_value2: pktlog buffer size value
8471 *
8472 *
8473 * Return: 0 for success or error.
8474 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008475static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308476{
8477 struct sir_wifi_start_log start_log = { 0 };
8478 QDF_STATUS status;
8479
8480 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8481 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8482 start_log.ini_triggered = cds_is_packet_log_enabled();
8483 start_log.user_triggered = 1;
8484 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308485 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308486
8487 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8488 if (!QDF_IS_STATUS_SUCCESS(status)) {
8489 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8490 EXIT();
8491 return -EINVAL;
8492 }
8493
8494 return 0;
8495}
8496
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008497/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308498 * hdd_pktlog_clear_buff() - clear pktlog buffer
8499 * @hdd_ctx: hdd context
8500 *
8501 * Return: 0 for success or error.
8502 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008503static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308504{
8505 struct sir_wifi_start_log start_log;
8506 QDF_STATUS status;
8507
8508 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8509 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8510 start_log.ini_triggered = cds_is_packet_log_enabled();
8511 start_log.user_triggered = 1;
8512 start_log.size = 0;
8513 start_log.is_pktlog_buff_clear = true;
8514
8515 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8516 if (!QDF_IS_STATUS_SUCCESS(status)) {
8517 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8518 EXIT();
8519 return -EINVAL;
8520 }
8521
8522 return 0;
8523}
8524
8525
8526/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008527 * hdd_process_pktlog_command() - process pktlog command
8528 * @hdd_ctx: hdd context
8529 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308530 * @set_value2: pktlog buffer size value
8531 *
8532 * This function process pktlog command.
8533 * set_value2 only matters when set_value is 3 (set buff size)
8534 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008535 *
8536 * Return: 0 for success or error.
8537 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008538int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308539 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008540{
8541 int ret;
8542 bool enable;
8543 uint8_t user_triggered = 0;
8544
8545 ret = wlan_hdd_validate_context(hdd_ctx);
8546 if (0 != ret)
8547 return ret;
8548
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008549 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008550
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308551 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008552 hdd_err("invalid pktlog value %d", set_value);
8553 return -EINVAL;
8554 }
8555
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308556 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8557 if (set_value2 <= 0) {
8558 hdd_err("invalid pktlog size %d", set_value2);
8559 return -EINVAL;
8560 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8561 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8562 return -EINVAL;
8563 }
8564 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308565 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8566 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308567 }
8568
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008569 /*
8570 * set_value = 0 then disable packetlog
8571 * set_value = 1 enable packetlog forcefully
8572 * set_vlaue = 2 then disable packetlog if disabled through ini or
8573 * enable packetlog with AUTO type.
8574 */
8575 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8576 true : false;
8577
8578 if (1 == set_value) {
8579 enable = true;
8580 user_triggered = 1;
8581 }
8582
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308583 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008584}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008585
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008586/**
8587 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8588 * @hdd_ctx: HDD context
8589 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308590 * @user_triggered: triggered through iwpriv
8591 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008592 *
8593 * Return: 0 on success; error number otherwise
8594 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008595int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308596 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008597{
8598 struct sir_wifi_start_log start_log;
8599 QDF_STATUS status;
8600
8601 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8602 start_log.verbose_level =
8603 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008604 start_log.ini_triggered = cds_is_packet_log_enabled();
8605 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308606 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308607 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308608 /*
8609 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8610 * commands. Host uses this flag to decide whether to send pktlog
8611 * disable command to fw without sending pktlog enable command
8612 * previously. For eg, If vendor sends pktlog disable command without
8613 * sending pktlog enable command, then host discards the packet
8614 * but for iwpriv command, host will send it to fw.
8615 */
8616 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008617 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8618 if (!QDF_IS_STATUS_SUCCESS(status)) {
8619 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8620 EXIT();
8621 return -EINVAL;
8622 }
8623
8624 return 0;
8625}
8626#endif /* REMOVE_PKT_LOG */
8627
Komal Seelam92fff912016-03-24 11:51:41 +05308628/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008629 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8630 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308631 * @dev: Device Pointer
8632 * @num: Number of Valid Mac address
8633 *
8634 * Return: Pointer to MAC address buffer
8635 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008636static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8637 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308638{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008639 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308640}
Komal Seelam92fff912016-03-24 11:51:41 +05308641
8642/**
8643 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8644 * @hdd_ctx: HDD Context
8645 * @num: Number of random mac addresses needed
8646 *
8647 * Generate random addresses using bit manipulation on the base mac address
8648 *
8649 * Return: None
8650 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008651void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308652{
8653 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8654 uint32_t iter;
8655 struct hdd_config *ini = hdd_ctx->config;
8656 uint8_t *buf = NULL;
8657 uint8_t macaddr_b3, tmp_br3;
8658 uint8_t *src = ini->intfMacAddr[0].bytes;
8659
8660 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8661 buf = ini->intfMacAddr[iter].bytes;
8662 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8663 macaddr_b3 = buf[3];
8664 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8665 INTF_MACADDR_MASK;
8666 macaddr_b3 += tmp_br3;
8667 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8668 buf[0] |= 0x02;
8669 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008670 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308671 }
8672}
8673
8674/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008675 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308676 * @hdd_ctx: HDD Context
8677 *
8678 * API to get mac addresses from platform driver and update the driver
8679 * structures and configure FW with the base mac address.
8680 * Return: int
8681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008682static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308683{
8684 uint32_t no_of_mac_addr, iter;
8685 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8686 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8687 uint8_t *addr, *buf;
8688 struct device *dev = hdd_ctx->parent_dev;
8689 struct hdd_config *ini = hdd_ctx->config;
8690 tSirMacAddr mac_addr;
8691 QDF_STATUS status;
8692
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008693 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308694
8695 if (no_of_mac_addr == 0 || !addr) {
8696 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8697 return -EINVAL;
8698 }
8699
8700 if (no_of_mac_addr > max_mac_addr)
8701 no_of_mac_addr = max_mac_addr;
8702
8703 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8704
8705 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8706 buf = ini->intfMacAddr[iter].bytes;
8707 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008708 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308709 }
8710
8711 status = sme_set_custom_mac_addr(mac_addr);
8712
8713 if (!QDF_IS_STATUS_SUCCESS(status))
8714 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008715
Komal Seelam92fff912016-03-24 11:51:41 +05308716 if (no_of_mac_addr < max_mac_addr)
8717 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8718 no_of_mac_addr);
8719 return 0;
8720}
8721
8722/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008723 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8724 * @hdd_ctx: HDD Context
8725 *
8726 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8727 * will generate its own MAC and update it to FW.
8728 *
8729 * Return: 0 for success
8730 * Non-zero error code for failure
8731 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008732static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008733{
8734 tSirMacAddr customMacAddr;
8735 QDF_STATUS status;
8736
8737 qdf_mem_copy(&customMacAddr,
8738 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8739 sizeof(tSirMacAddr));
8740 status = sme_set_custom_mac_addr(customMacAddr);
8741 if (!QDF_IS_STATUS_SUCCESS(status))
8742 return -EAGAIN;
8743 return 0;
8744}
8745
8746/**
Komal Seelam92fff912016-03-24 11:51:41 +05308747 * hdd_initialize_mac_address() - API to get wlan mac addresses
8748 * @hdd_ctx: HDD Context
8749 *
8750 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8751 * is provisioned with mac addresses, driver uses it, else it will use
8752 * wlan_mac.bin to update HW MAC addresses.
8753 *
8754 * Return: None
8755 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008756static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308757{
8758 QDF_STATUS status;
8759 int ret;
8760
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008761 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308762 if (ret == 0)
8763 return;
8764
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008765 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8766 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308767
8768 status = hdd_update_mac_config(hdd_ctx);
8769
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008770 if (QDF_IS_STATUS_SUCCESS(status))
8771 return;
8772
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008773 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8774 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008775
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008776 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008777 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008778 if (ret != 0) {
8779 hdd_err("MAC address out-of-sync, ret:%d", ret);
8780 QDF_ASSERT(ret);
8781 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008782 }
Komal Seelam92fff912016-03-24 11:51:41 +05308783}
8784
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008785static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008786{
8787 int vdev_id = 0;
8788 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8789 int value = hdd_ctx->config->smart_chainmask_enabled;
8790 int vpdev = PDEV_CMD;
8791 int ret;
8792
Naveen Rawat247a8682017-06-05 15:00:31 -07008793 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008794 if (ret)
8795 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8796
8797 return ret;
8798}
8799
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008800static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008801{
8802 int vdev_id = 0;
8803 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8804 int value = hdd_ctx->config->alternative_chainmask_enabled;
8805 int vpdev = PDEV_CMD;
8806 int ret;
8807
Naveen Rawat247a8682017-06-05 15:00:31 -07008808 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008809 if (ret)
8810 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8811 ret);
8812
8813 return ret;
8814}
8815
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008816static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008817{
8818 int vdev_id = 0;
8819 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8820 int value = hdd_ctx->config->ani_enabled;
8821 int vpdev = PDEV_CMD;
8822 int ret;
8823
Naveen Rawat247a8682017-06-05 15:00:31 -07008824 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008825 if (ret)
8826 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8827
8828 return ret;
8829}
8830
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008831/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008832 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8833 * @hdd_ctx: HDD context
8834 *
8835 * Pre configurations to be done at lower layer before calling cds enable.
8836 *
8837 * Return: 0 on success and errno on failure.
8838 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008839static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008840{
8841 int ret;
8842 QDF_STATUS status;
8843 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008844 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008845
Leo Changfdb45c32016-10-28 11:09:23 -07008846 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008847 /*
8848 * Set 802.11p config
8849 * TODO-OCB: This has been temporarily added here to ensure this
8850 * parameter is set in CSR when we init the channel list. This should
8851 * be removed once the 5.9 GHz channels are added to the regulatory
8852 * domain.
8853 */
8854 hdd_set_dot11p_config(hdd_ctx);
8855
8856 /*
8857 * Note that the cds_pre_enable() sequence triggers the cfg download.
8858 * The cfg download must occur before we update the SME config
8859 * since the SME config operation must access the cfg database
8860 */
8861 status = hdd_set_sme_config(hdd_ctx);
8862
8863 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008864 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008865 ret = qdf_status_to_os_return(status);
8866 goto out;
8867 }
8868
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008869 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8870 if (QDF_STATUS_SUCCESS != status) {
8871 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8872 ret = qdf_status_to_os_return(status);
8873 goto out;
8874 }
8875
Naveen Rawat247a8682017-06-05 15:00:31 -07008876 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008877 hdd_ctx->config->tx_chain_mask_1ss,
8878 PDEV_CMD);
8879 if (0 != ret) {
8880 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8881 goto out;
8882 }
8883
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008884 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8885 if (ret)
8886 goto out;
8887
8888 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8889 if (ret)
8890 goto out;
8891
Jeff Johnson12a744b2017-04-04 08:19:37 -07008892 ret = hdd_set_ani_enabled(hdd_ctx);
8893 if (ret)
8894 goto out;
8895
Naveen Rawat247a8682017-06-05 15:00:31 -07008896 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008897 hdd_ctx->config->arp_ac_category,
8898 PDEV_CMD);
8899 if (0 != ret) {
8900 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8901 hdd_ctx->config->arp_ac_category, ret);
8902 goto out;
8903 }
8904
8905
Prashanth Bhatta07998752016-04-28 12:35:33 -07008906 status = hdd_set_sme_chan_list(hdd_ctx);
8907 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008908 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008909 ret = qdf_status_to_os_return(status);
8910 goto out;
8911 }
8912
8913 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008914 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008915 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008916 ret = -EINVAL;
8917 goto out;
8918 }
8919
Prashanth Bhatta07998752016-04-28 12:35:33 -07008920 /*
8921 * Set the MAC Address Currently this is used by HAL to add self sta.
8922 * Remove this once self sta is added as part of session open.
8923 */
8924 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8925 hdd_ctx->config->intfMacAddr[0].bytes,
8926 sizeof(hdd_ctx->config->intfMacAddr[0]));
8927
8928 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8929 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8930 hal_status, hal_status);
8931 ret = -EINVAL;
8932 goto out;
8933 }
8934
8935 hdd_init_channel_avoidance(hdd_ctx);
8936
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308937 /* update enable sap mandatory chan list */
8938 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8939 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008940out:
8941 return ret;
8942}
8943
8944/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008945 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8946 * @context_ptr - hdd context pointer
8947 * @event_ptr - event structure pointer
8948 *
8949 * This is the p2p listen offload stop event handler, it sends vendor
8950 * event back to supplicant to notify the stop reason.
8951 *
8952 * Return: None
8953 */
8954static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8955 void *event_ptr)
8956{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008957 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008958 struct sir_p2p_lo_event *evt = event_ptr;
8959 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008960 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008961
8962 ENTER();
8963
8964 if (hdd_ctx == NULL) {
8965 hdd_err("Invalid HDD context pointer");
8966 return;
8967 }
8968
Peng Xu5c682812017-08-06 07:39:13 -07008969 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8970 if (!adapter) {
8971 hdd_err("Cannot find adapter by vdev_id = %d",
8972 evt->vdev_id);
8973 return;
8974 }
8975
Peng Xu8fdaa492016-06-22 10:20:47 -07008976 vendor_event =
8977 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008978 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008979 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8980 GFP_KERNEL);
8981
8982 if (!vendor_event) {
8983 hdd_err("cfg80211_vendor_event_alloc failed");
8984 return;
8985 }
8986
8987 if (nla_put_u32(vendor_event,
8988 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8989 evt->reason_code)) {
8990 hdd_err("nla put failed");
8991 kfree_skb(vendor_event);
8992 return;
8993 }
8994
8995 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008996 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8997 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008998}
8999
9000/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309001 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9002 * @hdd_ctx: HDD context
9003 *
9004 * This function sends the adaptive dwell time config configuration to the
9005 * firmware via WMA
9006 *
9007 * Return: 0 - success, < 0 - failure
9008 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009009static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309010{
9011 QDF_STATUS status;
9012 struct adaptive_dwelltime_params dwelltime_params;
9013
9014 dwelltime_params.is_enabled =
9015 hdd_ctx->config->adaptive_dwell_mode_enabled;
9016 dwelltime_params.dwelltime_mode =
9017 hdd_ctx->config->global_adapt_dwelltime_mode;
9018 dwelltime_params.lpf_weight =
9019 hdd_ctx->config->adapt_dwell_lpf_weight;
9020 dwelltime_params.passive_mon_intval =
9021 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9022 dwelltime_params.wifi_act_threshold =
9023 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9024
9025 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9026 &dwelltime_params);
9027
9028 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9029 if (!QDF_IS_STATUS_SUCCESS(status)) {
9030 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9031 return -EAGAIN;
9032 }
9033 return 0;
9034}
9035
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009036int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309037{
9038 QDF_STATUS status;
9039 struct wmi_dbs_scan_sel_params dbs_scan_params;
9040 uint32_t i = 0;
9041 uint8_t count = 0, numentries = 0;
9042 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9043 * CDS_DBS_SCAN_CLIENTS_MAX];
9044
9045 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009046 if (hdd_ctx->config->dual_mac_feature_disable ==
9047 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309048 return -EINVAL;
9049
9050 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9051 dbs_scan_config, &numentries,
9052 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9053 * CDS_DBS_SCAN_CLIENTS_MAX));
9054
9055 hdd_info("numentries %hu", numentries);
9056 if (!numentries) {
9057 hdd_info("Donot send scan_selection_config");
9058 return 0;
9059 }
9060
9061 /* hdd_set_fw_log_params */
9062 dbs_scan_params.num_clients = 0;
9063 while (count < (numentries - 2)) {
9064 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9065 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9066 dbs_scan_params.num_non_dbs_scans[i] =
9067 dbs_scan_config[count + 2];
9068 dbs_scan_params.num_clients++;
9069 hdd_debug("module:%d NDS:%d NNDS:%d",
9070 dbs_scan_params.module_id[i],
9071 dbs_scan_params.num_dbs_scans[i],
9072 dbs_scan_params.num_non_dbs_scans[i]);
9073 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9074 i++;
9075 }
9076
9077 dbs_scan_params.pdev_id = 0;
9078
9079 hdd_debug("clients:%d pdev:%d",
9080 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9081
9082 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9083 &dbs_scan_params);
9084 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9085 if (!QDF_IS_STATUS_SUCCESS(status)) {
9086 hdd_err("Failed to send DBS Scan selection configuration!");
9087 return -EAGAIN;
9088 }
9089 return 0;
9090}
9091
Arun Khandavallid4349a92016-07-25 11:10:43 +05309092#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9093/**
9094 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9095 * @hdd_ctx: HDD context
9096 *
9097 * Set auto shutdown callback to get indications from firmware to indicate
9098 * userspace to shutdown WLAN after a configured amount of inactivity.
9099 *
9100 * Return: 0 on success and errno on failure.
9101 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009102static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309103{
9104 QDF_STATUS status;
9105
9106 if (!hdd_ctx->config->WlanAutoShutdown)
9107 return 0;
9108
9109 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9110 wlan_hdd_auto_shutdown_cb);
9111 if (status != QDF_STATUS_SUCCESS)
9112 hdd_err("Auto shutdown feature could not be enabled: %d",
9113 status);
9114
9115 return qdf_status_to_os_return(status);
9116}
9117#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009118static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309119{
9120 return 0;
9121}
9122#endif
9123
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009124static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009125{
9126 QDF_STATUS status = QDF_STATUS_SUCCESS;
9127
9128 switch (hdd_ctx->config->dual_mac_feature_disable) {
9129 case DISABLE_DBS_CXN_AND_SCAN:
9130 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9131 if (status != QDF_STATUS_SUCCESS)
9132 hdd_err("Failed to disable dual mac features");
9133 break;
9134 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9135 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9136 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9137 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9138 if (status != QDF_STATUS_SUCCESS)
9139 hdd_err("Failed to set dbs scan and fw mode config");
9140 break;
9141 default:
9142 break;
9143 }
9144
9145 return status;
9146}
9147
Arun Khandavallid4349a92016-07-25 11:10:43 +05309148/**
9149 * hdd_features_init() - Init features
9150 * @hdd_ctx: HDD context
9151 * @adapter: Primary adapter context
9152 *
9153 * Initialize features and their feature context after WLAN firmware is up.
9154 *
9155 * Return: 0 on success and errno on failure.
9156 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009157static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309158{
9159 tSirTxPowerLimit hddtxlimit;
9160 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309161 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309162 int ret;
9163
9164 ENTER();
9165
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009166 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309167 if (ret) {
9168 hdd_err("Failed to update country code: %d", ret);
9169 goto out;
9170 }
9171
9172 /* FW capabilities received, Set the Dot11 mode */
9173 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009174 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9175 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309176
Arun Khandavallid4349a92016-07-25 11:10:43 +05309177
9178 if (hdd_ctx->config->fIsImpsEnabled)
9179 hdd_set_idle_ps_config(hdd_ctx, true);
9180 else
9181 hdd_set_idle_ps_config(hdd_ctx, false);
9182
Poddar, Siddarth37033032017-10-11 15:47:40 +05309183 /* Send Enable/Disable data stall detection cmd to FW */
9184 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9185 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9186
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309187 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009188 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309189
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309190 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9191 hdd_warn("Error in setting Voltage Corner mode config to FW");
9192
Arun Khandavallid4349a92016-07-25 11:10:43 +05309193 if (hdd_lro_init(hdd_ctx))
9194 hdd_err("Unable to initialize LRO in fw");
9195
9196 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9197 hdd_err("Unable to send adaptive dwelltime setting to FW");
9198
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309199 if (hdd_dbs_scan_selection_init(hdd_ctx))
9200 hdd_err("Unable to send DBS scan selection setting to FW");
9201
Arun Khandavallid4349a92016-07-25 11:10:43 +05309202 ret = hdd_init_thermal_info(hdd_ctx);
9203 if (ret) {
9204 hdd_err("Error while initializing thermal information");
9205 goto deregister_frames;
9206 }
9207
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309208 if (cds_is_packet_log_enabled())
9209 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9210
Arun Khandavallid4349a92016-07-25 11:10:43 +05309211 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9212 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9213 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9214 if (!QDF_IS_STATUS_SUCCESS(status))
9215 hdd_err("Error setting txlimit in sme: %d", status);
9216
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009217 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309218
Arun Khandavallid4349a92016-07-25 11:10:43 +05309219 ret = hdd_register_cb(hdd_ctx);
9220 if (ret) {
9221 hdd_err("Failed to register HDD callbacks!");
9222 goto deregister_frames;
9223 }
9224
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009225 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9226 if (!QDF_IS_STATUS_SUCCESS(status)) {
9227 hdd_err("Failed to set dbs scan and fw mode cfg");
9228 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309229 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009230
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309231 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9232 status = sme_enable_disable_chanavoidind_event(
9233 hdd_ctx->hHal, 0);
9234 if (!QDF_IS_STATUS_SUCCESS(status)) {
9235 hdd_err("Failed to disable Chan Avoidance Indication");
9236 goto deregister_cb;
9237 }
9238 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309239
Manjeet Singha9cae432017-02-28 11:58:22 +05309240 if (hdd_ctx->config->enable_5g_band_pref) {
9241 band_pref_params.rssi_boost_threshold_5g =
9242 hdd_ctx->config->rssi_boost_threshold_5g;
9243 band_pref_params.rssi_boost_factor_5g =
9244 hdd_ctx->config->rssi_boost_factor_5g;
9245 band_pref_params.max_rssi_boost_5g =
9246 hdd_ctx->config->max_rssi_boost_5g;
9247 band_pref_params.rssi_penalize_threshold_5g =
9248 hdd_ctx->config->rssi_penalize_threshold_5g;
9249 band_pref_params.rssi_penalize_factor_5g =
9250 hdd_ctx->config->rssi_penalize_factor_5g;
9251 band_pref_params.max_rssi_penalize_5g =
9252 hdd_ctx->config->max_rssi_penalize_5g;
9253 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9254 }
9255
Arun Khandavallid4349a92016-07-25 11:10:43 +05309256 /* register P2P Listen Offload event callback */
9257 if (wma_is_p2p_lo_capable())
9258 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9259 wlan_hdd_p2p_lo_event_callback);
9260
9261 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9262
9263 if (ret)
9264 goto deregister_cb;
9265
9266 EXIT();
9267 return 0;
9268
9269deregister_cb:
9270 hdd_deregister_cb(hdd_ctx);
9271deregister_frames:
9272 wlan_hdd_cfg80211_deregister_frames(adapter);
9273out:
9274 return -EINVAL;
9275
9276}
9277
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009278/**
9279 * hdd_features_deinit() - Deinit features
9280 * @hdd_ctx: HDD context
9281 *
9282 * De-Initialize features and their feature context.
9283 *
9284 * Return: none.
9285 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009286static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009287{
9288 wlan_hdd_tsf_deinit(hdd_ctx);
9289}
9290
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309291/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009292 * hdd_register_bcn_cb() - register scan beacon callback
9293 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309294 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009295 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009297static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309298{
9299 QDF_STATUS status;
9300
9301 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9302 wlan_cfg80211_inform_bss_frame,
9303 SCAN_CB_TYPE_INFORM_BCN);
9304 if (!QDF_IS_STATUS_SUCCESS(status)) {
9305 hdd_err("failed with status code %08d [x%08x]",
9306 status, status);
9307 return status;
9308 }
9309
9310 return QDF_STATUS_SUCCESS;
9311}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309312
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309313/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309314 * hdd_configure_cds() - Configure cds modules
9315 * @hdd_ctx: HDD context
9316 * @adapter: Primary adapter context
9317 *
9318 * Enable Cds modules after WLAN firmware is up.
9319 *
9320 * Return: 0 on success and errno on failure.
9321 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009322int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309323{
9324 int ret;
9325 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309326 int set_value;
9327 uint32_t num_abg_tx_chains = 0;
9328 uint32_t num_11b_tx_chains = 0;
9329 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009330 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309331
9332 if (hdd_ctx->config->sifs_burst_duration) {
9333 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9334 hdd_ctx->config->sifs_burst_duration;
9335
9336 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9337 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9338 set_value, PDEV_CMD);
9339 }
9340
9341 if (hdd_ctx->config->is_force_1x1)
9342 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9343 1, PDEV_CMD);
9344 /* set chip power save failure detected callback */
9345 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9346 hdd_chip_pwr_save_fail_detected_cb);
9347
9348 if (hdd_ctx->config->max_mpdus_inampdu) {
9349 set_value = hdd_ctx->config->max_mpdus_inampdu;
9350 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9351 set_value, PDEV_CMD);
9352 }
9353
9354 if (hdd_ctx->config->enable_rts_sifsbursting) {
9355 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9356 sme_cli_set_command(0,
9357 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9358 set_value, PDEV_CMD);
9359 }
9360
9361 if (hdd_ctx->config->sap_get_peer_info) {
9362 set_value = hdd_ctx->config->sap_get_peer_info;
9363 sme_cli_set_command(0,
9364 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9365 set_value, PDEV_CMD);
9366 }
9367
9368 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9369 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9370 if (!hdd_ctx->config->enable2x2) {
9371 if (num_11b_tx_chains > 1)
9372 num_11b_tx_chains = 1;
9373 if (num_11ag_tx_chains > 1)
9374 num_11ag_tx_chains = 1;
9375 }
9376 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9377 num_11b_tx_chains);
9378 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9379 num_11ag_tx_chains);
9380 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9381 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309382
9383 ret = hdd_pre_enable_configure(hdd_ctx);
9384 if (ret) {
9385 hdd_err("Failed to pre-configure cds");
9386 goto out;
9387 }
9388
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009389 /* Always get latest IPA resources allocated from cds_open and configure
9390 * IPA module before configuring them to FW. Sequence required as crash
9391 * observed otherwise.
9392 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009393 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9394 hdd_err("Failed to setup pipes");
9395 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009396 }
9397
Arun Khandavallifae92942016-08-01 13:31:08 +05309398 /*
9399 * Start CDS which starts up the SME/MAC/HAL modules and everything
9400 * else
9401 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009402 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309403
9404 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009405 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309406 goto out;
9407 }
9408
9409 status = hdd_post_cds_enable_config(hdd_ctx);
9410 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009411 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009412 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309413 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309414 status = hdd_register_bcn_cb(hdd_ctx);
9415 if (!QDF_IS_STATUS_SUCCESS(status)) {
9416 hdd_alert("hdd_post_cds_enable_config failed");
9417 goto cds_disable;
9418 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309419
9420 ret = hdd_features_init(hdd_ctx, adapter);
9421 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009422 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309423
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009424 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009425 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009426 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9427 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009428 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009429 goto cds_disable;
9430 }
9431
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309432 if (hdd_enable_egap(hdd_ctx))
9433 hdd_debug("enhance green ap is not enabled");
9434
Nachiket Kukadedd302662017-07-13 17:31:44 +05309435 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9436 hdd_debug("Failed to set wow pulse");
9437
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309438 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9439 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9440
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309441
9442 if (hdd_ctx->config->enable_phy_reg_retention)
9443 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9444 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9445
Arun Khandavallifae92942016-08-01 13:31:08 +05309446 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009447
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009448cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009449 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009450
Arun Khandavallifae92942016-08-01 13:31:08 +05309451out:
9452 return -EINVAL;
9453}
9454
9455/**
9456 * hdd_deconfigure_cds() -De-Configure cds
9457 * @hdd_ctx: HDD context
9458 *
9459 * Deconfigure Cds modules before WLAN firmware is down.
9460 *
9461 * Return: 0 on success and errno on failure.
9462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009463static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309464{
9465 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009466 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309467
9468 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009469
9470 /* De-init features */
9471 hdd_features_deinit(hdd_ctx);
9472
Arun Khandavallifae92942016-08-01 13:31:08 +05309473 /* De-register the SME callbacks */
9474 hdd_deregister_cb(hdd_ctx);
9475
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009476 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309477 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9478 hdd_err("Failed to Disable the CDS Modules! :%d",
9479 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009480 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309481 }
9482
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309483 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9484 hdd_err("Failed to disconnect pipes");
9485 ret = -EINVAL;
9486 }
9487
Arun Khandavallifae92942016-08-01 13:31:08 +05309488 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009489 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309490}
9491
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009492#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9493static void hdd_deregister_policy_manager_callback(
9494 struct wlan_objmgr_psoc *psoc)
9495{
9496 if (QDF_STATUS_SUCCESS !=
9497 policy_mgr_deregister_hdd_cb(psoc)) {
9498 hdd_err("HDD callback deregister with policy manager failed");
9499 }
9500}
9501#else
9502static void hdd_deregister_policy_manager_callback(
9503 struct wlan_objmgr_psoc *psoc)
9504{
9505}
9506#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309507
9508/**
9509 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9510 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009511 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309512 *
9513 * This function maintains the driver state machine it will be invoked from
9514 * exit, shutdown and con_mode change handler. Depending on the driver state
9515 * shall perform the stopping/closing of the modules.
9516 *
9517 * Return: 0 for success; non-zero for failure
9518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009519int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309520{
9521 void *hif_ctx;
9522 qdf_device_t qdf_ctx;
9523 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309524 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009525 bool is_idle_stop = !cds_is_driver_unloading() &&
9526 !cds_is_driver_recovering();
9527 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309528
9529 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009530 hdd_alert("stop WLAN module: entering driver status=%d",
9531 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309532
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009533 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9534
Arun Khandavallifae92942016-08-01 13:31:08 +05309535 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9536 if (!qdf_ctx) {
9537 hdd_err("QDF device context NULL");
9538 return -EINVAL;
9539 }
9540
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309541 mutex_lock(&hdd_ctx->iface_change_lock);
9542 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009543 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309544
Dustin Brown70111822017-03-30 15:31:40 -07009545 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009546 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009547 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -07009548 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -07009549
9550 cds_print_external_threads();
9551
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009552 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009553 mutex_unlock(&hdd_ctx->iface_change_lock);
9554 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009555 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309556 hdd_prevent_suspend_timeout(
9557 hdd_ctx->config->iface_change_wait_time,
9558 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009559 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009560 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009561 return 0;
9562 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009563 }
9564
Arun Khandavallifae92942016-08-01 13:31:08 +05309565 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9566
9567 switch (hdd_ctx->driver_status) {
9568 case DRIVER_MODULES_UNINITIALIZED:
9569 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309570 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309571 case DRIVER_MODULES_CLOSED:
9572 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309573 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309574 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309575 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309576 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009577 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309578 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309579 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309580 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009581 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309582 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9583 break;
9584 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009585 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309586 break;
9587 default:
9588 hdd_err("Trying to stop wlan in a wrong state: %d",
9589 hdd_ctx->driver_status);
9590 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309591 ret = -EINVAL;
9592 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309593 }
9594
Rajeev Kumarbe021242017-02-16 16:12:23 -08009595 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309596 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9597 hdd_err("Failed to process post CDS disable Modules! :%d",
9598 qdf_status);
9599 ret = -EINVAL;
9600 QDF_ASSERT(0);
9601 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009602
9603 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9604 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9605 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9606 ret = -EINVAL;
9607 QDF_ASSERT(0);
9608 }
9609
Jeff Johnsone4b14592017-09-13 14:23:33 -07009610 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309611 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009612 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309613 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309614 QDF_ASSERT(0);
9615 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009616
Arun Khandavallifae92942016-08-01 13:31:08 +05309617 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9618 if (!hif_ctx) {
9619 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309620 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309621 }
9622
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309623 hdd_runtime_suspend_context_deinit(hdd_ctx);
9624
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309625 if (hdd_ctx->target_hw_name) {
9626 qdf_mem_free(hdd_ctx->target_hw_name);
9627 hdd_ctx->target_hw_name = NULL;
9628 }
9629
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309630 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309631
9632 ol_cds_free();
9633
Dustin Brown70111822017-03-30 15:31:40 -07009634 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309635 ret = pld_power_off(qdf_ctx->dev);
9636 if (ret)
9637 hdd_err("CNSS power down failed put device into Low power mode:%d",
9638 ret);
9639 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309640
9641 /* Once the firmware sequence is completed reset this flag */
9642 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309643 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009644 /*
9645 * Reset total mac phy during module stop such that during
9646 * next module start same psoc is used to populate new service
9647 * ready data
9648 */
9649 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309650
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309651done:
9652 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009653 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309654 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07009655 hdd_alert("stop WLAN module: exit driver status=%d",
9656 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309657 EXIT();
9658
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309659 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309660
9661}
9662
9663/**
9664 * hdd_iface_change_callback() - Function invoked when stop modules expires
9665 * @priv: pointer to hdd context
9666 *
9667 * This function is invoked when the timer waiting for the interface change
9668 * expires, it shall cut-down the power to wlan and stop all the modules.
9669 *
9670 * Return: void
9671 */
9672static void hdd_iface_change_callback(void *priv)
9673{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009674 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309675 int ret;
9676 int status = wlan_hdd_validate_context(hdd_ctx);
9677
9678 if (status)
9679 return;
9680
9681 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009682 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009683 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309684 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009685 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309686 EXIT();
9687}
9688
9689/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309690 * hdd_state_info_dump() - prints state information of hdd layer
9691 * @buf: buffer pointer
9692 * @size: size of buffer to be filled
9693 *
9694 * This function is used to dump state information of hdd layer
9695 *
9696 * Return: None
9697 */
9698static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9699{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009700 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309701 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9702 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009703 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009704 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309705 uint16_t len = 0;
9706 char *buf = *buf_ptr;
9707
9708 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9709 if (!hdd_ctx) {
9710 hdd_err("Failed to get hdd context ");
9711 return;
9712 }
9713
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009714 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309715
9716 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -07009717 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309718 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009719 "\n is_scheduler_suspended %d",
9720 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309721
9722 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9723
9724 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009725 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309726 if (adapter->dev)
9727 len += scnprintf(buf + len, *size - len,
9728 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009729 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309730 "\n device_mode: %d", adapter->device_mode);
9731 switch (adapter->device_mode) {
9732 case QDF_STA_MODE:
9733 case QDF_P2P_CLIENT_MODE:
9734 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9735 len += scnprintf(buf + len, *size - len,
9736 "\n connState: %d",
9737 hdd_sta_ctx->conn_info.connState);
9738 break;
9739
9740 default:
9741 break;
9742 }
9743 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9744 adapter_node = next;
9745 }
9746
9747 *size -= len;
9748 *buf_ptr += len;
9749}
9750
9751/**
9752 * hdd_register_debug_callback() - registration function for hdd layer
9753 * to print hdd state information
9754 *
9755 * Return: None
9756 */
9757static void hdd_register_debug_callback(void)
9758{
9759 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9760}
9761
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309762/*
9763 * wlan_init_bug_report_lock() - Initialize bug report lock
9764 *
9765 * This function is used to create bug report lock
9766 *
9767 * Return: None
9768 */
9769static void wlan_init_bug_report_lock(void)
9770{
9771 p_cds_contextType p_cds_context;
9772
9773 p_cds_context = cds_get_global_context();
9774 if (!p_cds_context) {
9775 hdd_err("cds context is NULL");
9776 return;
9777 }
9778
9779 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9780}
9781
Mohit Khannaf8f96822017-05-17 17:11:59 -07009782void hdd_dp_trace_init(struct hdd_config *config)
9783{
9784
9785 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9786 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9787 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9788 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9789 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9790 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9791 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +08009792 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009793
9794 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9795 &num_entries, sizeof(config_params));
9796
9797 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +08009798 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
9799 if (bw_compute_interval)
9800 thresh_time_limit = 1000 / bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -07009801 else
9802 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9803
9804 switch (num_entries) {
9805 case 4:
9806 proto_bitmap = config_params[3];
9807 case 3:
9808 verbosity = config_params[2];
9809 case 2:
9810 thresh = config_params[1];
9811 case 1:
9812 live_mode = config_params[0];
9813 default:
9814 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9815 live_mode, thresh, thresh_time_limit,
9816 verbosity, proto_bitmap);
9817 };
9818
9819 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9820 verbosity, proto_bitmap);
9821
9822}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309823/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009824 * hdd_wlan_startup() - HDD init function
9825 * @dev: Pointer to the underlying device
9826 *
9827 * This is the driver startup code executed once a WLAN device has been detected
9828 *
9829 * Return: 0 for success, < 0 for failure
9830 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309831int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009832{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309833 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009834 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009835 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009836 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009837
9838 ENTER();
9839
Arun Khandavallifae92942016-08-01 13:31:08 +05309840 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009841
9842 if (IS_ERR(hdd_ctx))
9843 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009844
Abhishek Singhe9068f12017-03-31 14:14:52 +05309845 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9846 DEFAULT_PSOC_ID);
9847 if (ret) {
9848 hdd_err("Psoc creation fails!");
9849 QDF_BUG(0);
9850 goto err_hdd_free_context;
9851 }
9852
Arun Khandavallifae92942016-08-01 13:31:08 +05309853 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9854 hdd_iface_change_callback, (void *)hdd_ctx);
9855
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309856 qdf_nbuf_init_replenish_timer();
9857
Arun Khandavallifae92942016-08-01 13:31:08 +05309858 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309859#ifdef FEATURE_WLAN_CH_AVOID
9860 mutex_init(&hdd_ctx->avoid_freq_lock);
9861#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309862
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009863 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009864 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309865
Jeff Johnson957bc272017-02-02 08:54:48 -08009866 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309867 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009868 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009869 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009870 }
9871
Yingying Tang80e15f32016-09-27 18:23:01 +08009872 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873
Anurag Chouhan6d760662016-02-20 16:05:43 +05309874 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009875
9876 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009877 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309878 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009879 }
9880
Prashanth Bhatta07998752016-04-28 12:35:33 -07009881 ret = hdd_wiphy_init(hdd_ctx);
9882 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009883 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309884 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009885 }
9886
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309887 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009888 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309889
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309890 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009891 goto err_wiphy_unregister;
9892
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309893 wlan_hdd_init_chan_info(hdd_ctx);
9894
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009895 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009896
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309897 ret = hdd_register_notifiers(hdd_ctx);
9898 if (ret)
9899 goto err_ipa_cleanup;
9900
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009901 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009902
Jeff Johnson957bc272017-02-02 08:54:48 -08009903 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9904 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009905 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009906 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009907 }
9908
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009909 hdd_release_rtnl_lock();
9910 rtnl_held = false;
9911
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009912 wlan_hdd_update_11n_mode(hdd_ctx->config);
9913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009914#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309915 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309916 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009917 hdd_skip_acs_scan_timer_handler,
9918 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309919 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009920 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009921 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009922#endif
9923
Prashanth Bhattaab004382016-10-11 16:08:11 -07009924 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009925
Jeff Johnson9afc5012016-09-23 13:56:27 -07009926 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009927
Nirav Shahbd36b062016-07-18 11:12:59 +05309928 if (hdd_ctx->rps)
9929 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009930
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309931 status = wlansap_global_init();
9932 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009933 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009934
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009935 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309936 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009937
Arun Khandavallifae92942016-08-01 13:31:08 +05309938 if (hdd_ctx->config->fIsImpsEnabled)
9939 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -07009940 else
9941 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309942
Mukul Sharma07bd8752017-10-10 16:58:14 +05309943 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309944 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309945 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309946 hdd_prevent_suspend_timeout(
9947 hdd_ctx->config->iface_change_wait_time,
9948 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
9949 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309950
Sachin Ahujadddd2632017-03-07 19:07:24 +05309951 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009952 goto success;
9953
Jeff Johnson957bc272017-02-02 08:54:48 -08009954err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009955 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009956
Jeff Johnson46bde382017-02-01 15:31:16 -08009957err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309958 if (rtnl_held)
9959 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009960
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309961 unregister_netdevice_notifier(&hdd_netdev_notifier);
9962
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309963err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309964 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009966err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009967 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009968
Arun Khandavallifae92942016-08-01 13:31:08 +05309969err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009970 hdd_wlan_stop_modules(hdd_ctx, false);
Dustin Brown792513d2017-11-07 11:07:09 -08009971 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309972
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009973err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309974 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009975 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309976 if (!QDF_IS_STATUS_SUCCESS(status)) {
9977 hdd_err("Failed to close CDS Scheduler");
9978 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009980 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009981
Houston Hoffman47a4a052016-11-14 23:22:44 -08009982 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009983 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009984 hdd_exit_netlink_services(hdd_ctx);
9985
Dustin Brown20912462017-06-07 13:48:25 -07009986 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9987
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009988err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309989 if (cds_is_fw_down())
9990 hdd_err("Not setting the complete event as fw is down");
9991 else
9992 hdd_start_complete(ret);
9993
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05309994 qdf_nbuf_deinit_replenish_timer();
Arun Khandavallifae92942016-08-01 13:31:08 +05309995 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9996 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009997 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07009998 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009999
10000success:
10001 EXIT();
10002 return 0;
10003}
10004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010005/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010006 * hdd_wlan_update_target_info() - update target type info
10007 * @hdd_ctx: HDD context
10008 * @context: hif context
10009 *
10010 * Update target info received from firmware in hdd context
10011 * Return:None
10012 */
10013
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010014void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010015{
10016 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10017
10018 if (!tgt_info) {
10019 hdd_err("Target info is Null");
10020 return;
10021 }
10022
10023 hdd_ctx->target_type = tgt_info->target_type;
10024}
10025
10026/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010027 * hdd_get_nud_stats_cb() - callback api to update the stats
10028 * received from the firmware
10029 * @data: pointer to adapter.
10030 * @rsp: pointer to data received from FW.
10031 *
10032 * This is called when wlan driver received response event for
10033 * get arp stats to firmware.
10034 *
10035 * Return: None
10036 */
10037static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10038{
10039 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10040 struct hdd_nud_stats_context *context;
10041 int status;
10042 struct hdd_adapter *adapter = NULL;
10043
10044 ENTER();
10045
10046 if (!rsp) {
10047 hdd_err("data is null");
10048 return;
10049 }
10050
10051 status = wlan_hdd_validate_context(hdd_ctx);
10052 if (0 != status)
10053 return;
10054
10055 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10056 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10057 hdd_err("Invalid adapter or adapter has invalid magic");
10058 return;
10059 }
10060
10061 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10062 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10063 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10064 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10065 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10066 rsp->out_of_order_arp_rsp_drop_cnt);
10067 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10068 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10069 hdd_notice("rsp->ba_session_establishment_status :%x",
10070 rsp->ba_session_establishment_status);
10071
10072 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10073 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10074 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10075 adapter->dad |= rsp->dad_detected;
10076 adapter->con_status = rsp->connect_status;
10077
10078 spin_lock(&hdd_context_lock);
10079 context = &hdd_ctx->nud_stats_context;
10080 complete(&context->response_event);
10081 spin_unlock(&hdd_context_lock);
10082
10083 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010084}
10085
10086/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010087 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010088 * @hdd_ctx: HDD context
10089 *
10090 * Register the HDD callbacks to CDS/SME.
10091 *
10092 * Return: 0 for success or Error code for failure
10093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010094int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010095{
10096 QDF_STATUS status;
10097 int ret = 0;
10098
10099 ENTER();
10100
10101 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10102
10103 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10104 hdd_send_oem_data_rsp_msg);
10105
10106 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10107 wlan_hdd_cfg80211_fw_mem_dump_cb);
10108 if (!QDF_IS_STATUS_SUCCESS(status)) {
10109 hdd_err("Failed to register memdump callback");
10110 ret = -EINVAL;
10111 return ret;
10112 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010113 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10114 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010115 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10116 sme_nan_register_callback(hdd_ctx->hHal,
10117 wlan_hdd_cfg80211_nan_callback);
10118 sme_stats_ext_register_callback(hdd_ctx->hHal,
10119 wlan_hdd_cfg80211_stats_ext_callback);
10120
10121 sme_ext_scan_register_callback(hdd_ctx->hHal,
10122 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010123 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10124 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010125
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010126 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10127 hdd_rssi_threshold_breached);
10128
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010129 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10130
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010131 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10132 wlan_hdd_cfg80211_link_layer_stats_callback);
10133
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010134 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10135
Zhang Qianca38fb12016-12-23 11:10:48 +080010136 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10137 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10138
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010139 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10140 hdd_lost_link_info_cb);
10141 /* print error and not block the startup process */
10142 if (!QDF_IS_STATUS_SUCCESS(status))
10143 hdd_err("set lost link info callback failed");
10144
Poddar, Siddarth34872782017-08-10 14:08:51 +053010145 ret = hdd_register_data_stall_detect_cb();
10146 if (ret) {
10147 hdd_err("Register data stall detect detect callback failed.");
10148 return ret;
10149 }
10150
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010151 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10152
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010153 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010154 hdd_set_connection_in_progress,
10155 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010156
10157 status = sme_congestion_register_callback(hdd_ctx->hHal,
10158 hdd_update_cca_info_cb);
10159 if (!QDF_IS_STATUS_SUCCESS(status))
10160 hdd_err("set congestion callback failed");
10161
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010162 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10163 hdd_bt_activity_cb);
10164 if (!QDF_IS_STATUS_SUCCESS(status))
10165 hdd_err("set bt activity info callback failed");
10166
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010167 EXIT();
10168
10169 return ret;
10170}
10171
10172/**
10173 * hdd_deregister_cb() - De-Register HDD callbacks.
10174 * @hdd_ctx: HDD context
10175 *
10176 * De-Register the HDD callbacks to CDS/SME.
10177 *
10178 * Return: void
10179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010180void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010181{
10182 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010183 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010184
10185 ENTER();
10186
10187 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10188 if (!QDF_IS_STATUS_SUCCESS(status))
10189 hdd_err("De-register of dcc stats callback failed: %d",
10190 status);
10191
10192 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010193 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10194
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010195 sme_stats_ext_register_callback(hdd_ctx->hHal,
10196 wlan_hdd_cfg80211_stats_ext_callback);
10197
10198 sme_nan_deregister_callback(hdd_ctx->hHal);
10199 status = sme_reset_tsfcb(hdd_ctx->hHal);
10200 if (!QDF_IS_STATUS_SUCCESS(status))
10201 hdd_err("Failed to de-register tsfcb the callback:%d",
10202 status);
10203 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10204 if (!QDF_IS_STATUS_SUCCESS(status))
10205 hdd_err("Failed to de-register the fw mem dump callback: %d",
10206 status);
10207
Poddar, Siddarth34872782017-08-10 14:08:51 +053010208 ret = hdd_deregister_data_stall_detect_cb();
10209 if (ret)
10210 hdd_err("Failed to de-register data stall detect event callback");
10211
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010212 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10213 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10214
10215 EXIT();
10216}
10217
10218/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219 * hdd_softap_sta_deauth() - handle deauth req from HDD
10220 * @adapter: Pointer to the HDD
10221 * @enable: bool value
10222 *
10223 * This to take counter measure to handle deauth req from HDD
10224 *
10225 * Return: None
10226 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010227QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010228 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010230 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010231
10232 ENTER();
10233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010234 /* Ignore request to deauth bcmc station */
10235 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010236 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010237
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010238 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010239 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10240 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010241
10242 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010243 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010244}
10245
10246/**
10247 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10248 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010249 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010250 *
10251 * This to take counter measure to handle deauth req from HDD
10252 *
10253 * Return: None
10254 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010255void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010256 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010257{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010258 ENTER();
10259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010260 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010261 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010262 return;
10263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010264 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010265 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010266}
10267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268/**
10269 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10270 * @hdd_ctx: HDD Context
10271 *
10272 * API to find if there is any STA or P2P-Client is connected
10273 *
10274 * Return: true if connected; false otherwise
10275 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010276QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010277{
10278 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10279}
10280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281/**
10282 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10283 * @adapter: HDD adapter pointer
10284 *
10285 * This function loop through each adapter and disable roaming on each STA
10286 * device mode except the input adapter.
10287 *
10288 * Note: On the input adapter roaming is not enabled yet hence no need to
10289 * disable.
10290 *
10291 * Return: None
10292 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010293void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010294{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010295 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010296 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010297 hdd_adapter_list_node_t *adapterNode = NULL;
10298 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010299 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010300
10301 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010302 hdd_ctx->config->isRoamOffloadScanEnabled &&
10303 QDF_STA_MODE == adapter->device_mode &&
10304 policy_mgr_is_sta_active_connection_exists(
10305 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010306 hdd_debug("Connect received on STA session Id(%d)",
10307 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010308 /*
10309 * Loop through adapter and disable roaming for each STA device
10310 * mode except the input adapter.
10311 */
10312 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10313
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010314 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010315 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010316
Jeff Johnson1b780e42017-10-31 14:11:45 -070010317 if (QDF_STA_MODE == adapterIdx->device_mode &&
10318 adapter->session_id != adapterIdx->session_id) {
10319 hdd_debug("Disable Roaming on session Id(%d)",
10320 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010321 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10322 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010323 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010324 }
10325
10326 status = hdd_get_next_adapter(hdd_ctx,
10327 adapterNode,
10328 &pNext);
10329 adapterNode = pNext;
10330 }
10331 }
10332}
10333
10334/**
10335 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10336 * @adapter: HDD adapter pointer
10337 *
10338 * This function loop through each adapter and enable roaming on each STA
10339 * device mode except the input adapter.
10340 * Note: On the input adapter no need to enable roaming because link got
10341 * disconnected on this.
10342 *
10343 * Return: None
10344 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010345void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010346{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010347 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010348 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010349 hdd_adapter_list_node_t *adapterNode = NULL;
10350 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010351 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010352
10353 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010354 hdd_ctx->config->isRoamOffloadScanEnabled &&
10355 QDF_STA_MODE == adapter->device_mode &&
10356 policy_mgr_is_sta_active_connection_exists(
10357 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010358 hdd_debug("Disconnect received on STA session Id(%d)",
10359 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010360 /*
10361 * Loop through adapter and enable roaming for each STA device
10362 * mode except the input adapter.
10363 */
10364 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10365
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010366 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010367 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010368
Jeff Johnson1b780e42017-10-31 14:11:45 -070010369 if (QDF_STA_MODE == adapterIdx->device_mode &&
10370 adapter->session_id != adapterIdx->session_id) {
10371 hdd_debug("Enabling Roaming on session Id(%d)",
10372 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010373 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10374 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010375 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010376 REASON_CONNECT);
10377 }
10378
10379 status = hdd_get_next_adapter(hdd_ctx,
10380 adapterNode,
10381 &pNext);
10382 adapterNode = pNext;
10383 }
10384 }
10385}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010386
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010387/**
10388 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10389 * @skb: sk buffer pointer
10390 *
10391 * Sends the bcast message to SVC multicast group with generic nl socket
10392 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10393 *
10394 * Return: None
10395 */
10396static void nl_srv_bcast_svc(struct sk_buff *skb)
10397{
10398#ifdef CNSS_GENL
10399 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10400#else
10401 nl_srv_bcast(skb);
10402#endif
10403}
10404
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010405void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010406{
10407 struct sk_buff *skb;
10408 struct nlmsghdr *nlh;
10409 tAniMsgHdr *ani_hdr;
10410 void *nl_data = NULL;
10411 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010412 struct radio_index_tlv *radio_info;
10413 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010414
10415 if (in_interrupt() || irqs_disabled() || in_atomic())
10416 flags = GFP_ATOMIC;
10417
10418 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10419
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010420 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010421 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010422
10423 nlh = (struct nlmsghdr *)skb->data;
10424 nlh->nlmsg_pid = 0; /* from kernel */
10425 nlh->nlmsg_flags = 0;
10426 nlh->nlmsg_seq = 0;
10427 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10428
10429 ani_hdr = NLMSG_DATA(nlh);
10430 ani_hdr->type = type;
10431
10432 switch (type) {
10433 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010434 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010436 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010437 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010438 ani_hdr->length = 0;
10439 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440 break;
10441 case WLAN_SVC_WLAN_STATUS_IND:
10442 case WLAN_SVC_WLAN_VERSION_IND:
10443 case WLAN_SVC_DFS_CAC_START_IND:
10444 case WLAN_SVC_DFS_CAC_END_IND:
10445 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10446 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10447 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010448 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010449 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010450 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010451 ani_hdr->length = len;
10452 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10453 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10454 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010455 break;
10456
10457 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010458 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010459 type);
10460 kfree_skb(skb);
10461 return;
10462 }
10463
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010464 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010465 * Add radio index at the end of the svc event in TLV format
10466 * to maintain the backward compatibility with userspace
10467 * applications.
10468 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010469
10470 tlv_len = 0;
10471
10472 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10473 < WLAN_NL_MAX_PAYLOAD) {
10474 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10475 sizeof(*ani_hdr) + len);
10476 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10477 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10478 radio_info->radio = radio;
10479 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010480 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010481 "Added radio index tlv - radio index %d",
10482 radio_info->radio);
10483 }
10484
10485 nlh->nlmsg_len += tlv_len;
10486 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10487
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010488 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010489}
10490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010491#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10492void wlan_hdd_auto_shutdown_cb(void)
10493{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010494 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010495
10496 if (!hdd_ctx)
10497 return;
10498
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010499 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010500 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10501 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010502}
10503
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010504void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010505{
10506 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010507 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010508 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010509 bool ap_connected = false, sta_connected = false;
10510 tHalHandle hal_handle;
10511
10512 hal_handle = hdd_ctx->hHal;
10513 if (hal_handle == NULL)
10514 return;
10515
10516 if (hdd_ctx->config->WlanAutoShutdown == 0)
10517 return;
10518
10519 if (enable == false) {
10520 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010521 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010522 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010523 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010524 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010525 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010526 return;
10527 }
10528
10529 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010530 if (policy_mgr_concurrent_open_sessions_running(
10531 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010534 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010535 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010536 if (adapter
10537 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010538 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010539 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10540 conn_info.connState ==
10541 eConnectionState_Associated) {
10542 sta_connected = true;
10543 break;
10544 }
10545 }
10546 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010547 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010548 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010549 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010550 ap_connected = true;
10551 break;
10552 }
10553 }
10554 status = hdd_get_next_adapter(hdd_ctx,
10555 adapterNode,
10556 &pNext);
10557 adapterNode = pNext;
10558 }
10559 }
10560
10561 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010562 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010563 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010564 }
Jeff Johnson68755312017-02-10 11:46:55 -080010565
10566 if (sme_set_auto_shutdown_timer(hal_handle,
10567 hdd_ctx->config->WlanAutoShutdown)
10568 != QDF_STATUS_SUCCESS)
10569 hdd_err("Failed to start wlan auto shutdown timer");
10570 else
10571 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10572 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010573}
10574#endif
10575
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010576struct hdd_adapter *
10577hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10578 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010580 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010581 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010582 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10584
10585 con_sap_adapter = NULL;
10586
10587 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010588 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010589 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010590 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10591 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010592 adapter != this_sap_adapter) {
10593 if (check_start_bss) {
10594 if (test_bit(SOFTAP_BSS_STARTED,
10595 &adapter->event_flags)) {
10596 con_sap_adapter = adapter;
10597 break;
10598 }
10599 } else {
10600 con_sap_adapter = adapter;
10601 break;
10602 }
10603 }
10604 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10605 adapterNode = pNext;
10606 }
10607
10608 return con_sap_adapter;
10609}
10610
10611#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010612static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010613{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010614 return adapter->device_mode == QDF_STA_MODE ||
10615 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010616}
10617
Jeff Johnson9d295242017-08-29 14:39:48 -070010618static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010619{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010620 return adapter->device_mode == QDF_SAP_MODE ||
10621 adapter->device_mode == QDF_P2P_GO_MODE;
10622}
10623
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010624static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010625{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010626 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010627 hdd_adapter_list_node_t *node;
10628
10629 status = hdd_get_front_adapter(hdd_ctx, &node);
10630 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010631 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010632
10633 if (adapter &&
10634 hdd_adapter_is_sta(adapter) &&
10635 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10636 conn_info.connState == eConnectionState_Associated) {
10637 return true;
10638 }
10639
10640 if (adapter &&
10641 hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010642 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010643 return true;
10644 }
10645
10646 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10647 }
10648
10649 return false;
10650}
10651
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010652static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010653{
10654 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010656 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010657 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010658 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659
Dustin Brown5ec6b552017-03-31 12:11:40 -070010660 return is_running;
10661}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010662
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010663static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010664{
10665 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10666 hdd_ctx->bus_bw_timer_running = true;
10667 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10668 hdd_ctx->config->busBandwidthComputeInterval);
10669 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10670}
10671
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010672void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010673{
10674 ENTER();
10675
10676 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10677 hdd_debug("Bandwidth compute timer already started");
10678 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010679 }
10680
Dustin Brown5ec6b552017-03-31 12:11:40 -070010681 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10682
10683 EXIT();
10684}
10685
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010686void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010687{
10688 ENTER();
10689
10690 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10691 hdd_debug("Bandwidth compute timer already started");
10692 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010693 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010694
10695 if (hdd_any_adapter_is_assoc(hdd_ctx))
10696 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10697
10698 EXIT();
10699}
10700
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010701static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010702{
10703 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10704
10705 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10706 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10707 hdd_ctx->bus_bw_timer_running = false;
10708 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10709
10710 hdd_reset_tcp_delack(hdd_ctx);
10711}
10712
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010713void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010714{
10715 ENTER();
10716
10717 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10718 hdd_debug("Bandwidth compute timer already stopped");
10719 return;
10720 }
10721
10722 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10723
10724 EXIT();
10725}
10726
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010727void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010728{
10729 ENTER();
10730
10731 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10732 hdd_debug("Bandwidth compute timer already stopped");
10733 return;
10734 }
10735
10736 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10737 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10738
10739 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740}
10741#endif
10742
10743/**
10744 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10745 * and sta's operating channel.
10746 * @sta_adapter: Describe the first argument to foobar.
10747 * @ap_adapter: Describe the second argument to foobar.
10748 * @roam_profile: Roam profile of AP to which STA wants to connect.
10749 * @concurrent_chnl_same: If both SAP and STA channels are same then
10750 * set this flag to true else false.
10751 *
10752 * This function checks the sap's operating channel and sta's operating channel.
10753 * if both are same then it will return false else it will restart the sap in
10754 * sta's channel and return true.
10755 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010756 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010758QDF_STATUS
10759wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10760 struct hdd_adapter *ap_adapter,
10761 tCsrRoamProfile *roam_profile,
10762 tScanResultHandle *scan_cache,
10763 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010764{
Jeff Johnson87251032017-08-29 13:31:11 -070010765 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010766 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010767 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080010768 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769 *concurrent_chnl_same = true;
10770
10771 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10772 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010773 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010774 scan_cache,
10775 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010776 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010777 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010778 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010779 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010781 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010782 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010783 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010784 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070010785 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010786 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010787 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010788 }
10789 }
10790 } else {
10791 /*
10792 * Lets handle worst case scenario here, Scan cache lookup is
10793 * failed so we have to stop the SAP to avoid any channel
10794 * discrepancy between SAP's channel and STA's channel.
10795 * Return the status as failure so caller function could know
10796 * that scan look up is failed.
10797 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010798 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010799 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010800 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010801 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010802}
10803
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010804/**
10805 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10806 * @ap_adapter: SAP adapter
10807 *
10808 * This function will process the stopping of sap adapter.
10809 *
10810 * Return: None
10811 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010812void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010813{
Jeff Johnson87251032017-08-29 13:31:11 -070010814 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010815 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010816 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010817 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010818
10819 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010820 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010821 return;
10822 }
10823
10824 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10825 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010826 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010827 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010828
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010829 mutex_lock(&hdd_ctx->sap_lock);
10830 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010831 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010832 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010833 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010834 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010835 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010836 sap_context)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010837 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010838 qdf_stop_bss_event,
10839 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010840 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010841 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010842 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010843 return;
10844 }
10845 }
10846 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010847 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10848 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070010849 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010850 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010851 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010852 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010853 }
10854 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010855}
10856
10857/**
10858 * wlan_hdd_start_sap() - this function starts bss of SAP.
10859 * @ap_adapter: SAP adapter
10860 *
10861 * This function will process the starting of sap adapter.
10862 *
10863 * Return: None
10864 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010865void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866{
Jeff Johnson87251032017-08-29 13:31:11 -070010867 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010868 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010869 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010870 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010871 tsap_Config_t *sap_config;
10872
10873 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010874 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010875 return;
10876 }
10877
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010878 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010879 hdd_err("SoftAp role has not been enabled");
10880 return;
10881 }
10882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010883 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10884 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10885 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070010886 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010888 mutex_lock(&hdd_ctx->sap_lock);
10889 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10890 goto end;
10891
10892 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010893 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10895 goto end;
10896 }
10897
Wei Song2f76f642016-11-18 16:32:53 +080010898 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070010899 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070010900 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010901 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010902 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010903 goto end;
10904
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010905 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010906 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010907 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010908 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010909 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010910 goto end;
10911 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010912 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070010914 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010915 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10916 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070010917 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053010918 mutex_unlock(&hdd_ctx->sap_lock);
10919
10920 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921end:
10922 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010923 /* SAP context and beacon cleanup will happen during driver unload
10924 * in hdd_stop_adapter
10925 */
10926 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010928}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010929
10930/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010931 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10932 * mac scan config
10933 * @status: Status of set antenna mode
10934 *
10935 * Callback on setting the dual mac configuration
10936 *
10937 * Return: None
10938 */
10939void wlan_hdd_soc_set_antenna_mode_cb(
10940 enum set_antenna_mode_status status)
10941{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010942 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010943
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010944 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010945
10946 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10947 if (0 != wlan_hdd_validate_context(hdd_ctx))
10948 return;
10949
10950 /* Signal the completion of set dual mac config */
10951 complete(&hdd_ctx->set_antenna_mode_cmpl);
10952}
10953
10954/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010955 * hdd_get_fw_version() - Get FW version
10956 * @hdd_ctx: pointer to HDD context.
10957 * @major_spid: FW version - major spid.
10958 * @minor_spid: FW version - minor spid
10959 * @ssid: FW version - ssid
10960 * @crmid: FW version - crmid
10961 *
10962 * This function is called to get the firmware build version stored
10963 * as part of the HDD context
10964 *
10965 * Return: None
10966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010967void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010968 uint32_t *major_spid, uint32_t *minor_spid,
10969 uint32_t *siid, uint32_t *crmid)
10970{
10971 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10972 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10973 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10974 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10975}
10976
10977#ifdef QCA_CONFIG_SMP
10978/**
10979 * wlan_hdd_get_cpu() - get cpu_index
10980 *
10981 * Return: cpu_index
10982 */
10983int wlan_hdd_get_cpu(void)
10984{
10985 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010987 put_cpu();
10988 return cpu_index;
10989}
10990#endif
10991
10992/**
10993 * hdd_get_fwpath() - get framework path
10994 *
10995 * This function is used to get the string written by
10996 * userspace to start the wlan driver
10997 *
10998 * Return: string
10999 */
11000const char *hdd_get_fwpath(void)
11001{
11002 return fwpath.string;
11003}
11004
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011005static int hdd_qdf_print_init(void)
11006{
11007 int qdf_print_idx;
11008 QDF_STATUS status;
11009
11010 status = qdf_print_setup();
11011 if (status != QDF_STATUS_SUCCESS) {
11012 pr_err("qdf_print_setup failed\n");
11013 return -EINVAL;
11014 }
11015
11016 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11017
11018 if (qdf_print_idx < 0) {
11019 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11020 qdf_print_idx);
11021 return -EINVAL;
11022 }
11023
11024 qdf_set_pidx(qdf_print_idx);
11025
11026 return 0;
11027}
11028
11029static void hdd_qdf_print_deinit(void)
11030{
11031 int qdf_print_idx;
11032
11033 qdf_print_idx = qdf_get_pidx();
11034 qdf_print_ctrl_cleanup(qdf_print_idx);
11035}
11036
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011037/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011038 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011039 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011040 * This function initilizes CDS global context with the help of cds_init. This
11041 * has to be the first function called after probe to get a valid global
11042 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011043 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011044 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011045 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011046int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011047{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011048 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011049 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011050
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011051 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011052 if (QDF_IS_STATUS_ERROR(status)) {
11053 hdd_err("Failed to allocate CDS context");
11054 ret = -ENOMEM;
11055 goto err_out;
11056 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011057
11058 wlan_init_bug_report_lock();
11059
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011060#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11061 wlan_logging_sock_init_svc();
11062#endif
11063
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011064 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11065 (void *)hdd_drv_ops_inactivity_handler, NULL,
11066 QDF_TIMER_TYPE_SW);
11067
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011068 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011069 hdd_qdf_print_init();
11070
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011071 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011072
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011073err_out:
11074 return ret;
11075}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011076
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011077/**
11078 * hdd_deinit() - Deinitialize Driver
11079 *
11080 * This function frees CDS global context with the help of cds_deinit. This
11081 * has to be the last function call in remove callback to free the global
11082 * context.
11083 */
11084void hdd_deinit(void)
11085{
Dustin Brownedce4a52017-05-10 11:59:15 -070011086 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011087 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011088
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011089 wlan_destroy_bug_report_lock();
11090 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011091
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011092 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011093#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11094 wlan_logging_sock_deinit_svc();
11095#endif
11096}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011097
Yue Ma6e7b1a02017-04-03 14:17:46 -070011098#ifdef QCA_WIFI_NAPIER_EMULATION
11099#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11100#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011101#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011102#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011103
Sachin Ahujadddd2632017-03-07 19:07:24 +053011104static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11105 struct file *file)
11106{
11107 return 0;
11108}
11109
11110static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11111 const char __user *user_buf,
11112 size_t count,
11113 loff_t *f_pos)
11114{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011115 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011116 static const char wlan_off_str[] = "OFF";
11117 static const char wlan_on_str[] = "ON";
11118 int ret;
11119 unsigned long rc;
11120
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011121 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011122 pr_err("Failed to read buffer\n");
11123 return -EINVAL;
11124 }
11125
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011126 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011127 pr_debug("Wifi turning off from UI\n");
11128 goto exit;
11129 }
11130
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011131 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011132 pr_err("Invalid value received from framework");
11133 goto exit;
11134 }
11135
11136 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011137 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011138 rc = wait_for_completion_timeout(&wlan_start_comp,
11139 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11140 if (!rc) {
11141 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11142 ret = -EINVAL;
11143 hdd_start_complete(ret);
11144 return ret;
11145 }
11146
11147 hdd_start_complete(0);
11148 }
11149
11150exit:
11151 return count;
11152}
11153
11154
11155const struct file_operations wlan_hdd_state_fops = {
11156 .owner = THIS_MODULE,
11157 .open = wlan_hdd_state_ctrl_param_open,
11158 .write = wlan_hdd_state_ctrl_param_write,
11159};
11160
11161static int wlan_hdd_state_ctrl_param_create(void)
11162{
11163 unsigned int wlan_hdd_state_major = 0;
11164 int ret;
11165 struct device *dev;
11166
11167 device = MKDEV(wlan_hdd_state_major, 0);
11168
11169 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11170 if (ret) {
11171 pr_err("Failed to register qcwlanstate");
11172 goto dev_alloc_err;
11173 }
11174 wlan_hdd_state_major = MAJOR(device);
11175
11176 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11177 if (IS_ERR(class)) {
11178 pr_err("wlan_hdd_state class_create error");
11179 goto class_err;
11180 }
11181
11182 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11183 if (IS_ERR(dev)) {
11184 pr_err("wlan_hdd_statedevice_create error");
11185 goto err_class_destroy;
11186 }
11187
11188 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11189 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11190 if (ret) {
11191 pr_err("Failed to add cdev error");
11192 goto cdev_add_err;
11193 }
11194
11195 pr_info("wlan_hdd_state %s major(%d) initialized",
11196 WLAN_MODULE_NAME, wlan_hdd_state_major);
11197
11198 return 0;
11199
11200cdev_add_err:
11201 device_destroy(class, device);
11202err_class_destroy:
11203 class_destroy(class);
11204class_err:
11205 unregister_chrdev_region(device, dev_num);
11206dev_alloc_err:
11207 return -ENODEV;
11208}
11209
11210static void wlan_hdd_state_ctrl_param_destroy(void)
11211{
11212 cdev_del(&wlan_hdd_state_cdev);
11213 device_destroy(class, device);
11214 class_destroy(class);
11215 unregister_chrdev_region(device, dev_num);
11216
11217 pr_info("Device node unregistered");
11218}
11219
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011220/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011221 * component_init - API to init cld component's
11222 *
11223 * Return: None
11224 */
11225static void component_init(void)
11226{
11227 pmo_init();
11228}
11229
11230/**
11231 * component_deinit - API to deinit cld component's
11232 *
11233 * Return: None
11234 */
11235static void component_deinit(void)
11236{
11237 pmo_deinit();
11238}
11239
11240/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011241 * __hdd_module_init - Module init helper
11242 *
11243 * Module init helper function used by both module and static driver.
11244 *
11245 * Return: 0 for success, errno on failure
11246 */
11247static int __hdd_module_init(void)
11248{
11249 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011250
Dustin Brown96cd9632017-11-13 12:45:04 -080011251 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011252 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011253 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011254 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011255
Sachin Ahujadddd2632017-03-07 19:07:24 +053011256 ret = wlan_hdd_state_ctrl_param_create();
11257 if (ret) {
11258 pr_err("wlan_hdd_state_create:%x\n", ret);
11259 goto err_dev_state;
11260 }
11261
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011262 pld_init();
11263
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011264 ret = hdd_init();
11265 if (ret) {
11266 pr_err("hdd_init failed %x\n", ret);
11267 goto err_hdd_init;
11268 }
11269
Rajeev Kumar97767a02016-11-30 11:20:40 -080011270 dispatcher_init();
11271
Mukul Sharmad75a6672017-06-22 15:40:53 +053011272 /* Ensure to call post objmgr init */
11273 component_init();
11274
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011275 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011276
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011277 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011278
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011279 ret = wlan_hdd_register_driver();
11280 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011281 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11282 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011283 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011284 }
11285
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011286 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011287
11288 return 0;
11289out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011290 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011291 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011292 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011293 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011294
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011295err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011296 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011297 wlan_hdd_state_ctrl_param_destroy();
11298err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011299 return ret;
11300}
11301
11302/**
11303 * __hdd_module_exit - Module exit helper
11304 *
11305 * Module exit helper function used by both module and static driver.
11306 */
11307static void __hdd_module_exit(void)
11308{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011309
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011310 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11311 QWLAN_VERSIONSTR);
11312
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011313 hdd_wait_for_recovery_completion();
11314
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011315 wlan_hdd_unregister_driver();
11316
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011317 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011318
Mukul Sharmad75a6672017-06-22 15:40:53 +053011319 /* Ensure to call prior to objmgr deinit */
11320 component_deinit();
11321
Rajeev Kumar97767a02016-11-30 11:20:40 -080011322 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011323 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011324 pld_deinit();
11325
Sachin Ahujadddd2632017-03-07 19:07:24 +053011326 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011327}
11328
Arun Khandavallifae92942016-08-01 13:31:08 +053011329#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011330/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 * wlan_boot_cb() - Wlan boot callback
11332 * @kobj: object whose directory we're creating the link in.
11333 * @attr: attribute the user is interacting with
11334 * @buff: the buffer containing the user data
11335 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011336 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011337 * This callback is invoked when the fs is ready to start the
11338 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011339 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011340 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011341 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011342static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011343 struct kobj_attribute *attr,
11344 const char *buf,
11345 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011346{
Arun Khandavallifae92942016-08-01 13:31:08 +053011347
Arun Khandavallifae92942016-08-01 13:31:08 +053011348 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011349 pr_err("%s: wlan driver already initialized\n", __func__);
11350 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 }
11352
Arun Khandavallifae92942016-08-01 13:31:08 +053011353 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011354 pr_err("%s: wlan driver initialization failed\n", __func__);
11355 return -EIO;
11356 }
11357
11358 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011359
11360 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011361}
Arun Khandavallifae92942016-08-01 13:31:08 +053011362
11363/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011364 * hdd_sysfs_cleanup() - cleanup sysfs
11365 *
11366 * Return: None
11367 *
11368 */
11369static void hdd_sysfs_cleanup(void)
11370{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011371 /* remove from group */
11372 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11373 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11374 wlan_loader->attr_group);
11375
11376 /* unlink the object from parent */
11377 kobject_del(wlan_loader->boot_wlan_obj);
11378
11379 /* free the object */
11380 kobject_put(wlan_loader->boot_wlan_obj);
11381
11382 kfree(wlan_loader->attr_group);
11383 kfree(wlan_loader);
11384
11385 wlan_loader = NULL;
11386}
11387
11388/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011389 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11390 * ready
11391 *
11392 * This is creates the syfs entry boot_wlan. Which shall be invoked
11393 * when the filesystem is ready.
11394 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011395 * QDF API cannot be used here since this function is called even before
11396 * initializing WLAN driver.
11397 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011398 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011399 */
11400static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011401{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011402 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011403
11404 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011405 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011406 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011407
11408 wlan_loader->boot_wlan_obj = NULL;
11409 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11410 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011411 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011412 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011413
11414 wlan_loader->loaded_state = 0;
11415 wlan_loader->attr_group->attrs = attrs;
11416
11417 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11418 kernel_kobj);
11419 if (!wlan_loader->boot_wlan_obj) {
11420 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011421 goto error_return;
11422 }
11423
11424 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11425 wlan_loader->attr_group);
11426 if (ret) {
11427 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11428 goto error_return;
11429 }
11430
11431 return 0;
11432
11433error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011434 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011435
11436 return ret;
11437}
11438
11439/**
11440 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11441 *
11442 * Return: 0 on success or errno on failure
11443 */
11444static int wlan_deinit_sysfs(void)
11445{
Arun Khandavallifae92942016-08-01 13:31:08 +053011446 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011447 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011448 return -EINVAL;
11449 }
11450
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011451 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011452 return 0;
11453}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011454
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011455#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011456
11457#ifdef MODULE
11458/**
11459 * __hdd_module_init - Module init helper
11460 *
11461 * Module init helper function used by both module and static driver.
11462 *
11463 * Return: 0 for success, errno on failure
11464 */
11465static int hdd_module_init(void)
11466{
Arun Khandavallifae92942016-08-01 13:31:08 +053011467 if (__hdd_module_init()) {
11468 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011469 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011470 }
11471
Dustin Brownab482ac2017-06-09 17:00:44 -070011472 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011473}
11474#else
11475static int __init hdd_module_init(void)
11476{
11477 int ret = -EINVAL;
11478
11479 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011480 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011481 pr_err("Failed to create sysfs entry for loading wlan");
11482
11483 return ret;
11484}
11485#endif
11486
11487
11488#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011489/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011490 * hdd_module_exit() - Exit function
11491 *
11492 * This is the driver exit point (invoked when module is unloaded using rmmod)
11493 *
11494 * Return: None
11495 */
11496static void __exit hdd_module_exit(void)
11497{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011498 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011499}
Arun Khandavallifae92942016-08-01 13:31:08 +053011500#else
11501static void __exit hdd_module_exit(void)
11502{
11503 __hdd_module_exit();
11504 wlan_deinit_sysfs();
11505}
11506#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011507
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011508static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11509{
11510 return param_set_copystring(kmessage, kp);
11511}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011512
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011513/**
11514 * is_con_mode_valid() check con mode is valid or not
11515 * @mode: global con mode
11516 *
11517 * Return: TRUE on success FALSE on failure
11518 */
11519static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11520{
11521 switch (mode) {
11522 case QDF_GLOBAL_MONITOR_MODE:
11523 case QDF_GLOBAL_FTM_MODE:
11524 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011525 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011526 return true;
11527 default:
11528 return false;
11529 }
11530}
11531
11532/**
11533 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11534 * @mode: global con mode
11535 *
11536 * Return: adapter mode
11537 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011538static enum QDF_OPMODE hdd_get_adpter_mode(
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011539 enum tQDF_GLOBAL_CON_MODE mode)
11540{
11541
11542 switch (mode) {
11543 case QDF_GLOBAL_MISSION_MODE:
11544 return QDF_STA_MODE;
11545 case QDF_GLOBAL_MONITOR_MODE:
11546 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011547 case QDF_GLOBAL_EPPING_MODE:
11548 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011549 case QDF_GLOBAL_FTM_MODE:
11550 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011551 case QDF_GLOBAL_QVIT_MODE:
11552 return QDF_QVIT_MODE;
11553 default:
11554 return QDF_MAX_NO_OF_MODE;
11555 }
11556}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011557
Dustin Brown27cd9942017-09-27 16:11:44 -070011558static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11559 enum tQDF_GLOBAL_CON_MODE curr_mode)
11560{
11561 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11562 return;
11563
11564 switch (curr_mode) {
11565 case QDF_GLOBAL_MISSION_MODE:
11566 case QDF_GLOBAL_MONITOR_MODE:
11567 case QDF_GLOBAL_FTM_MODE:
11568 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11569 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11570
11571 /* re-use the existing session */
11572 hdd_stop_all_adapters(hdd_ctx, false);
11573 break;
11574 default:
11575 break;
11576 }
11577}
11578
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011579static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011580 enum tQDF_GLOBAL_CON_MODE curr_mode)
11581{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011582 int driver_status;
11583
11584 driver_status = hdd_ctx->driver_status;
11585
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011586 switch (curr_mode) {
11587 case QDF_GLOBAL_MISSION_MODE:
11588 case QDF_GLOBAL_MONITOR_MODE:
11589 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011590 hdd_deinit_all_adapters(hdd_ctx, false);
11591 hdd_close_all_adapters(hdd_ctx, false);
11592 break;
11593 case QDF_GLOBAL_EPPING_MODE:
11594 epping_disable();
11595 epping_close();
11596 break;
11597 default:
11598 return;
11599 }
11600}
11601
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011602static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011603 enum tQDF_GLOBAL_CON_MODE mode)
11604{
Jeff Johnson9d295242017-08-29 14:39:48 -070011605 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011606 int ret = 0;
11607 bool rtnl_held;
11608 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11609 QDF_STATUS status;
11610
11611 if (!qdf_dev) {
11612 hdd_err("qdf device context is Null return!");
11613 return -EINVAL;
11614 }
11615
11616 rtnl_held = hdd_hold_rtnl_lock();
11617 switch (mode) {
11618 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011619 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11620 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011621 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011622 break;
11623 case QDF_GLOBAL_FTM_MODE:
11624 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11625 wlan_hdd_get_intf_addr(hdd_ctx),
11626 NET_NAME_UNKNOWN, rtnl_held);
11627 if (adapter == NULL)
11628 ret = -EINVAL;
11629 break;
11630 case QDF_GLOBAL_MONITOR_MODE:
11631 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11632 wlan_hdd_get_intf_addr(hdd_ctx),
11633 NET_NAME_UNKNOWN, rtnl_held);
11634 if (adapter == NULL)
11635 ret = -EINVAL;
11636 break;
11637 case QDF_GLOBAL_EPPING_MODE:
11638 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011639 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011640 hdd_err("Failed to open in eeping mode: %d", status);
11641 ret = -EINVAL;
11642 break;
11643 }
11644 ret = epping_enable(qdf_dev->dev);
11645 if (ret) {
11646 hdd_err("Failed to enable in epping mode : %d", ret);
11647 epping_close();
11648 }
11649 break;
11650 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011651 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011652 ret = -ENOTSUPP;
11653 break;
11654 }
11655 hdd_release_rtnl_lock();
11656 rtnl_held = false;
11657 return ret;
11658}
11659
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011660/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011661 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011662 * @kmessage: con mode name on which driver to be bring up
11663 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011664 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011665 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011666 * This function is invoked when user updates con mode using sys entry,
11667 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011668 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011669 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011670 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011671static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011672 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011673{
11674 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011675 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011676 enum tQDF_GLOBAL_CON_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011677 enum QDF_OPMODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011678
Dustin Brownab6029b2017-05-24 13:04:19 -070011679 hdd_info("con_mode handler: %s", kmessage);
11680
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011681 ret = wlan_hdd_validate_context(hdd_ctx);
11682 if (ret)
11683 return ret;
11684
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011685 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011686
11687 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011688
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011689 if (!(is_con_mode_valid(con_mode))) {
11690 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011691 ret = -EINVAL;
11692 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011693 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011694
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011695 curr_mode = hdd_get_conparam();
11696 if (curr_mode == con_mode) {
11697 hdd_err("curr mode: %d is same as user triggered mode %d",
11698 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011699 ret = 0;
11700 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011701 }
11702
Dustin Brown27cd9942017-09-27 16:11:44 -070011703 /* ensure adapters are stopped */
11704 hdd_stop_present_mode(hdd_ctx, curr_mode);
11705
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011706 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011707 if (ret) {
11708 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011709 goto reset_flags;
11710 }
11711
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011712 /* Cleanup present mode before switching to new mode */
11713 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11714
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011715 hdd_set_conparam(con_mode);
11716
11717 /* Register for new con_mode & then kick_start modules again */
11718 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11719 if (ret) {
11720 hdd_err("Failed to register for new mode");
11721 goto reset_flags;
11722 }
11723
11724 adapter_mode = hdd_get_adpter_mode(con_mode);
11725 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11726 hdd_err("invalid adapter");
11727 ret = -EINVAL;
11728 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011729 }
11730
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011731 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011732 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011733 hdd_err("Failed to get adapter:%d", adapter_mode);
11734 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011735 }
11736
11737 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11738 if (ret) {
11739 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011740 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011741 }
11742
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011743 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011744 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011745 if (hdd_start_adapter(adapter)) {
11746 hdd_err("Failed to start %s adapter", kmessage);
11747 ret = -EINVAL;
11748 goto reset_flags;
11749 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011750 }
11751
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011752 hdd_info("Mode successfully changed to %s", kmessage);
11753 ret = 0;
11754
11755reset_flags:
11756 cds_set_load_in_progress(false);
11757 return ret;
11758}
11759
11760
11761static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11762{
11763 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011764 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011765
11766 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11767 ret = wlan_hdd_validate_context(hdd_ctx);
11768 if (ret)
11769 return ret;
11770
11771 cds_ssr_protect(__func__);
11772 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11773 cds_ssr_unprotect(__func__);
11774
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011775 return ret;
11776}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011777
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011778static int con_mode_handler_ftm(const char *kmessage,
11779 struct kernel_param *kp)
11780{
11781 int ret;
11782
11783 ret = param_set_int(kmessage, kp);
11784
11785 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11786 pr_err("Only FTM mode supported!");
11787 return -ENOTSUPP;
11788 }
11789
11790 hdd_set_conparam(con_mode_ftm);
11791 con_mode = con_mode_ftm;
11792
11793 return ret;
11794}
11795
Ravi Joshia307f632017-07-17 23:41:41 -070011796static int con_mode_handler_monitor(const char *kmessage,
11797 struct kernel_param *kp)
11798{
11799 int ret;
11800
11801 ret = param_set_int(kmessage, kp);
11802
11803 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11804 pr_err("Only Monitor mode supported!");
11805 return -ENOTSUPP;
11806 }
11807
11808 hdd_set_conparam(con_mode_monitor);
11809 con_mode = con_mode_monitor;
11810
11811 return ret;
11812}
11813
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011814/**
11815 * hdd_get_conparam() - driver exit point
11816 *
11817 * This is the driver exit point (invoked when module is unloaded using rmmod)
11818 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011819 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011820 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011821enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011822{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011823 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011824}
11825
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011826void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011827{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011828 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011829}
11830
Komal Seelamc11bb222016-01-27 18:57:10 +053011831/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011832 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11833 * @hdd_ctx: HDD context
11834 *
11835 * Cleans up the pre cac interface, if it exists
11836 *
11837 * Return: None
11838 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011839void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011840{
11841 uint8_t session_id;
11842 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011843 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011844
11845 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11846 if (QDF_IS_STATUS_ERROR(status)) {
11847 hdd_err("failed to get pre cac vdev id");
11848 return;
11849 }
11850
11851 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11852 if (!precac_adapter) {
11853 hdd_err("invalid pre cac adapater");
11854 return;
11855 }
11856
11857 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11858 wlan_hdd_sap_pre_cac_failure,
11859 (void *)precac_adapter);
11860 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11861
11862}
11863
11864/**
Komal Seelamec702b02016-02-24 18:42:16 +053011865 * hdd_update_ol_config - API to update ol configuration parameters
11866 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011867 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011868 * Return: void
11869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011870static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011871{
Komal Seelamec702b02016-02-24 18:42:16 +053011872 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011873 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011874
Komal Seelamec702b02016-02-24 18:42:16 +053011875 if (!ol_ctx)
11876 return;
11877
11878 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11879 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11880 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11881 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011882 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011883
11884 ol_init_ini_config(ol_ctx, &cfg);
11885}
11886
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011887#ifdef FEATURE_RUNTIME_PM
11888/**
11889 * hdd_populate_runtime_cfg() - populate runtime configuration
11890 * @hdd_ctx: hdd context
11891 * @cfg: pointer to the configuration memory being populated
11892 *
11893 * Return: void
11894 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011895static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011896 struct hif_config_info *cfg)
11897{
11898 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11899 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11900}
11901#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011902static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011903 struct hif_config_info *cfg)
11904{
11905}
11906#endif
11907
Komal Seelamec702b02016-02-24 18:42:16 +053011908/**
11909 * hdd_update_hif_config - API to update HIF configuration parameters
11910 * @hdd_ctx: HDD Context
11911 *
11912 * Return: void
11913 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011914static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011915{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011916 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011917 struct hif_config_info cfg;
11918
11919 if (!scn)
11920 return;
11921
11922 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011923 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011924 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011925
11926 if (hdd_ctx->config->prevent_link_down)
11927 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011928}
11929
11930/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011931 * hdd_update_dp_config() - Propagate config parameters to Lithium
11932 * datapath
11933 * @hdd_ctx: HDD Context
11934 *
11935 * Return: 0 for success/errno for failure
11936 */
11937static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
11938{
11939 struct cdp_config_params params;
11940 QDF_STATUS status;
11941
11942 params.tso_enable = hdd_ctx->config->tso_enable;
11943 params.lro_enable = hdd_ctx->config->lro_enable;
11944#ifdef QCA_LL_TX_FLOW_CONTROL_V2
11945 params.tx_flow_stop_queue_threshold =
11946 hdd_ctx->config->TxFlowStopQueueThreshold;
11947 params.tx_flow_start_queue_offset =
11948 hdd_ctx->config->TxFlowStartQueueOffset;
11949#endif
11950 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
11951 params.napi_enable = hdd_ctx->napi_enable;
11952 params.tcp_udp_checksumoffload =
11953 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
11954
11955 status = cdp_update_config_parameters(
11956 cds_get_context(QDF_MODULE_ID_SOC),
11957 &params);
11958 if (status) {
11959 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11960 "%s: Failed to attach config parameters", __func__);
11961 return status;
11962 }
11963
11964 return 0;
11965}
11966
11967/**
Komal Seelamec702b02016-02-24 18:42:16 +053011968 * hdd_update_config() - Initialize driver per module ini parameters
11969 * @hdd_ctx: HDD Context
11970 *
11971 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011972 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011973 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011974int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011975{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011976 int ret;
11977
Komal Seelamec702b02016-02-24 18:42:16 +053011978 hdd_update_ol_config(hdd_ctx);
11979 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011980 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11981 ret = hdd_update_cds_config_ftm(hdd_ctx);
11982 else
11983 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011984 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011985
11986 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011987}
11988
Mukul Sharma9d797a02017-01-05 20:26:03 +053011989#ifdef FEATURE_WLAN_RA_FILTERING
11990/**
11991 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11992 * @psoc_cfg: pmo psoc Configuration
11993 * @hdd_ctx: Pointer to hdd context
11994 *
11995 * Return: none
11996 */
11997static inline void hdd_ra_populate_pmo_config(
11998 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011999 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012000{
12001 psoc_cfg->ra_ratelimit_interval =
12002 hdd_ctx->config->RArateLimitInterval;
12003 psoc_cfg->ra_ratelimit_enable =
12004 hdd_ctx->config->IsRArateLimitEnabled;
12005}
12006#else
12007static inline void hdd_ra_populate_pmo_config(
12008 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012009 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012010{
12011}
12012#endif
12013/**
12014 * hdd_update_pmo_config - API to update pmo configuration parameters
12015 * @hdd_ctx: HDD context
12016 *
12017 * Return: void
12018 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012019static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012020{
12021 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12022 struct pmo_psoc_cfg psoc_cfg;
12023 QDF_STATUS status;
12024
12025 /*
12026 * Value of hdd_ctx->wowEnable can be,
12027 * 0 - Disable both magic pattern match and pattern byte match.
12028 * 1 - Enable magic pattern match on all interfaces.
12029 * 2 - Enable pattern byte match on all interfaces.
12030 * 3 - Enable both magic patter and pattern byte match on
12031 * all interfaces.
12032 */
12033 psoc_cfg.magic_ptrn_enable =
12034 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12035 psoc_cfg.ptrn_match_enable_all_vdev =
12036 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012037 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12038 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012039 psoc_cfg.bpf_enable =
12040 hdd_ctx->config->bpf_packet_filter_enable;
12041 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012042 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012043 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12044 if (hdd_ctx->config->fhostNSOffload)
12045 psoc_cfg.ns_offload_enable_dynamic = true;
12046 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12047 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12048 psoc_cfg.active_mode_offload =
12049 hdd_ctx->config->active_mode_offload;
12050 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
12051 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012052 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12053 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12054 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12055 psoc_cfg.power_save_mode =
12056 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012057 psoc_cfg.auto_power_save_fail_mode =
12058 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012059
12060 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012061 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12062 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012063 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012064 if (status != QDF_STATUS_SUCCESS) {
12065 hdd_err("failed pmo psoc configuration");
12066 return -EINVAL;
12067 }
12068
12069 return 0;
12070}
12071
Abhishek Singhb20db962017-03-03 21:28:46 +053012072#ifdef FEATURE_WLAN_SCAN_PNO
12073static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12074 struct hdd_config *cfg)
12075{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012076 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12077
Abhishek Singhb20db962017-03-03 21:28:46 +053012078 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12079 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12080 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12081 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12082 pno_cfg->channel_prediction_full_scan =
12083 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012084 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12085 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12086 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12087 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012088}
12089#else
12090static inline void
12091hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012092 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012093{
Abhishek Singhb20db962017-03-03 21:28:46 +053012094}
12095#endif
12096
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012097void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12098 struct hdd_config *cfg)
12099{
12100 uint8_t i = 0;
12101
12102 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12103 if (!ie_whitelist->white_list)
12104 return;
12105
12106 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12107 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12108 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12109 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12110 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12111 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12112 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12113 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12114
12115 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12116 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12117 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12118}
12119
Abhishek Singh257a9482017-03-06 16:52:39 +053012120/**
12121 * hdd_update_scan_config - API to update scan configuration parameters
12122 * @hdd_ctx: HDD context
12123 *
12124 * Return: 0 if success else err
12125 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012126static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012127{
12128 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12129 struct scan_user_cfg scan_cfg;
12130 struct hdd_config *cfg = hdd_ctx->config;
12131 QDF_STATUS status;
12132
12133 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12134 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12135 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12136 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12137 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12138 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12139 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012140 /* convert to ms */
12141 scan_cfg.scan_cache_aging_time =
12142 cfg->scanAgingTimeout * 1000;
12143 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12144 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12145 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12146 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012147 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012148 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012149 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12150 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012151 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012152 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012153
Abhishek Singhb20db962017-03-03 21:28:46 +053012154 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012155 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012156
Abhishek Singh257a9482017-03-06 16:52:39 +053012157 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12158 if (status != QDF_STATUS_SUCCESS) {
12159 hdd_err("failed pmo psoc configuration");
12160 return -EINVAL;
12161 }
12162
12163 return 0;
12164}
Abhishek Singh257a9482017-03-06 16:52:39 +053012165
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012166static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012167{
12168 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12169 struct tdls_start_params tdls_cfg;
12170 struct tdls_user_config *config = &tdls_cfg.config;
12171 struct hdd_config *cfg = hdd_ctx->config;
12172 QDF_STATUS status;
12173
12174 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12175 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12176 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12177 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12178 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12179 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12180 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12181 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12182 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12183 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12184 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12185 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12186 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12187 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12188 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12189 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12190 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12191 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12192 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12193 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12194 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12195 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12196 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12197 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12198 (cfg->fEnableTDLSImplicitTrigger ?
12199 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12200 (cfg->fTDLSExternalControl ?
12201 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12202
12203 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12204 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12205 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12206 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012207 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012208 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012209 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12210 tdls_cfg.tdls_evt_cb_data = psoc;
12211 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12212 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12213 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012214 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12215 tdls_cfg.tdls_wmm_cb_data = psoc;
12216 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12217 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012218 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012219
12220 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12221 if (status != QDF_STATUS_SUCCESS) {
12222 hdd_err("failed pmo psoc configuration");
12223 return -EINVAL;
12224 }
12225
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012226 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012227 /* enable napier specific tdls data path */
12228 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012229
Frank Liud4b2fa02017-03-29 11:46:48 +080012230 return 0;
12231}
Frank Liud4b2fa02017-03-29 11:46:48 +080012232
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012233int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012234{
12235 int ret;
12236
12237 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012238 if (ret)
12239 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012240
Abhishek Singh257a9482017-03-06 16:52:39 +053012241 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012242 if (ret)
12243 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012244
Frank Liud4b2fa02017-03-29 11:46:48 +080012245 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012246 if (ret)
12247 return ret;
12248
12249 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012250
12251 return ret;
12252}
12253
Agrawal Ashish65634612016-08-18 13:24:32 +053012254/**
12255 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12256 * @mode : cfg80211 DFS mode
12257 *
12258 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12259 */
12260enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12261{
12262 switch (mode) {
12263 case DFS_MODE_ENABLE:
12264 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012265 case DFS_MODE_DISABLE:
12266 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012267 case DFS_MODE_DEPRIORITIZE:
12268 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012269 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012270 hdd_debug("ACS dfs mode is NONE");
12271 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012272 }
12273}
12274
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012275/**
12276 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12277 * @hddctx: pointer to hdd context
12278 * @set_value: enable/disable
12279 *
12280 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12281 * Host(even though it is duplicate). When Host send vendor command
12282 * disable,FW doesn't perform any action. Whenever any change in
12283 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12284 *
12285 * return - 0 on success, appropriate error values on failure.
12286 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012287int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012288{
12289 QDF_STATUS status;
12290
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012291 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012292 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012293
12294 if (!hddctx->config->goptimize_chan_avoid_event) {
12295 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12296 return -EINVAL;
12297 }
12298
12299 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12300 if (!QDF_IS_STATUS_SUCCESS(status)) {
12301 hdd_err("Failed to send chan avoid command to SME");
12302 return -EINVAL;
12303 }
12304 return 0;
12305}
Agrawal Ashish65634612016-08-18 13:24:32 +053012306
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012307/**
12308 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12309 * @value: value to set
12310 *
12311 * This function will set the passed value to roaming in progress flag.
12312 *
12313 * Return: None
12314 */
12315void hdd_set_roaming_in_progress(bool value)
12316{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012317 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012318
12319 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12320 if (!hdd_ctx) {
12321 hdd_err("HDD context is NULL");
12322 return;
12323 }
12324
12325 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012326 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012327}
12328
12329/**
12330 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012331 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012332 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012333 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012334 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012335bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012336{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012337 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012338 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012339
12340 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12341 if (!hdd_ctx) {
12342 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012343 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012344 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012345 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12346 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012347 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12348 hdd_ctx->roaming_in_progress);
12349
12350 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012351}
12352
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012353/**
12354 * hdd_is_connection_in_progress() - check if connection is in
12355 * progress
12356 * @session_id: session id
12357 * @reason: scan reject reason
12358 *
12359 * Go through each adapter and check if Connection is in progress
12360 *
12361 * Return: true if connection is in progress else false
12362 */
12363bool hdd_is_connection_in_progress(uint8_t *session_id,
12364 enum scan_reject_states *reason)
12365{
12366 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012367 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012368 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012369 QDF_STATUS status = 0;
12370 uint8_t sta_id = 0;
12371 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012372 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012373
12374 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12375 if (!hdd_ctx) {
12376 hdd_err("HDD context is NULL");
12377 return false;
12378 }
12379
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012380 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12381 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012382 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012383 if (!adapter)
12384 goto end;
12385
12386 hdd_info("Adapter with device mode %s(%d) exists",
12387 hdd_device_mode_to_string(adapter->device_mode),
12388 adapter->device_mode);
12389 if (((QDF_STA_MODE == adapter->device_mode)
12390 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12391 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12392 && (eConnectionState_Connecting ==
12393 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12394 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012395 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012396 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012397 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012398 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012399 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012400 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012401 }
12402 return true;
12403 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012404 /*
12405 * sme_neighbor_middle_of_roaming is for LFR2
12406 * hdd_is_roaming_in_progress is for LFR3
12407 */
12408 if (((QDF_STA_MODE == adapter->device_mode) &&
12409 sme_neighbor_middle_of_roaming(
12410 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012411 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012412 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012413 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012414 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012415 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012416 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012417 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012418 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012419 }
12420 return true;
12421 }
12422 if ((QDF_STA_MODE == adapter->device_mode) ||
12423 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12424 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12425 hdd_sta_ctx =
12426 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12427 if ((eConnectionState_Associated ==
12428 hdd_sta_ctx->conn_info.connState)
12429 && (false ==
12430 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12431 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012432 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012433 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012434 " is in middle of WPS/EAPOL exchange.",
12435 MAC_ADDR_ARRAY(sta_mac));
12436 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012437 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012438 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012439 }
12440 return true;
12441 }
12442 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12443 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12444 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12445 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012446 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012447 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012448 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012449 continue;
12450
12451 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012452 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012453 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012454 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012455 " of SAP/GO is in middle of WPS/EAPOL exchange",
12456 MAC_ADDR_ARRAY(sta_mac));
12457 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012458 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012459 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012460 }
12461 return true;
12462 }
12463 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012464 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012465 return true;
12466 }
12467 }
12468end:
12469 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12470 adapter_node = next;
12471 }
12472 return false;
12473}
12474
12475/**
12476 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012477 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012478 *
12479 * Return: None
12480 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012481void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012482{
Jeff Johnson87251032017-08-29 13:31:11 -070012483 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012484 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012485 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012486 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012487 tsap_Config_t *sap_config;
12488 void *sap_ctx;
12489
12490 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012491 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012492 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012493
12494 mutex_lock(&hdd_ctx->sap_lock);
12495 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12496 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012497 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12498 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12499 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12500 qdf_status =
12501 qdf_wait_single_event(&hostapd_state->
12502 qdf_stop_bss_event,
12503 SME_CMD_TIMEOUT_VALUE);
12504
12505 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012506 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012507 goto end;
12508 }
12509 }
12510 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012511 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012512 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012513 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012514
12515 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012516 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012517 wlansap_reset_sap_config_add_ie(sap_config,
12518 eUPDATE_IE_ALL);
12519 goto end;
12520 }
12521
12522 qdf_event_reset(&hostapd_state->qdf_event);
12523 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12524 sap_config,
12525 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012526 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012527 wlansap_reset_sap_config_add_ie(sap_config,
12528 eUPDATE_IE_ALL);
12529 goto end;
12530 }
12531
Jeff Johnson6867ec32017-09-29 20:30:20 -070012532 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012533 qdf_status =
12534 qdf_wait_single_event(&hostapd_state->qdf_event,
12535 SME_CMD_TIMEOUT_VALUE);
12536 wlansap_reset_sap_config_add_ie(sap_config,
12537 eUPDATE_IE_ALL);
12538 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012539 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012540 goto end;
12541 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012542 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012543 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012544 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012545 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12546 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012547 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012548 }
12549end:
12550 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012551}
12552
12553/**
12554 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12555 * with non dfs acs
12556 *
12557 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12558 *
12559 * Return: None
12560 */
12561void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12562{
Jeff Johnson9d295242017-08-29 14:39:48 -070012563 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012564 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012565 cds_context_type *cds_ctx;
12566
12567 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12568 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012569 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012570 return;
12571 }
12572
12573 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12574 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012575 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012576 return;
12577 }
12578
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012579 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12580 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012581 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012582 return;
12583 }
12584
12585 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012586 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12587 &ap_adapter->event_flags) &&
12588 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070012589 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012590
Jeff Johnson6867ec32017-09-29 20:30:20 -070012591 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070012592 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012593 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070012594 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012595 acs_cfg.acs_mode = true;
12596
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012597 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012598 }
12599}
12600
12601/**
12602 * hdd_set_connection_in_progress() - to set the connection in
12603 * progress flag
12604 * @value: value to set
12605 *
12606 * This function will set the passed value to connection in progress flag.
12607 * If value is previously being set to true then no need to set it again.
12608 *
12609 * Return: true if value is being set correctly and false otherwise.
12610 */
12611bool hdd_set_connection_in_progress(bool value)
12612{
12613 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012614 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012615
12616 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12617 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012618 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012619 return false;
12620 }
12621
12622 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12623 /*
12624 * if the value is set to true previously and if someone is
12625 * trying to make it true again then it could be some race
12626 * condition being triggered. Avoid this situation by returning
12627 * false
12628 */
12629 if (hdd_ctx->connection_in_progress && value)
12630 status = false;
12631 else
12632 hdd_ctx->connection_in_progress = value;
12633 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12634 return status;
12635}
12636
Jeff Johnson9d295242017-08-29 14:39:48 -070012637int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012638{
12639 if (!adapter) {
12640 hdd_err("Invalid adapter");
12641 return -EINVAL;
12642 }
12643 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012644 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012645 WMA_VDEV_MCC_SET_TIME_QUOTA,
12646 set_value, VDEV_CMD);
12647 return 0;
12648
12649}
12650
Jeff Johnson9d295242017-08-29 14:39:48 -070012651int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012652{
12653 if (!adapter) {
12654 hdd_err("Invalid adapter");
12655 return -EINVAL;
12656 }
12657
12658 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070012659 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012660 WMA_VDEV_MCC_SET_TIME_LATENCY,
12661 set_value, VDEV_CMD);
12662 return 0;
12663}
12664
Jeff Johnson9d295242017-08-29 14:39:48 -070012665struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012666 *psoc, uint8_t vdev_id)
12667{
Jeff Johnson9d295242017-08-29 14:39:48 -070012668 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012669 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012670
12671 /*
12672 * Currently PSOC is not being used. But this logic will
12673 * change once we have the converged implementation of
12674 * HDD context per PSOC in place. This would break if
12675 * multiple vdev objects reuse the vdev id.
12676 */
12677 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12678 if (!adapter)
12679 hdd_err("Get adapter by vdev id failed");
12680
12681 return adapter;
12682}
12683
Jeff Johnson9d295242017-08-29 14:39:48 -070012684int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012685 int8_t *rssi, int8_t *snr)
12686{
12687 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012688 struct hdd_wext_state *wext_state =
12689 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012690 tCsrRoamProfile *profile = &wext_state->roamProfile;
12691
12692 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12693 profile, bssid, rssi, snr);
12694 if (QDF_STATUS_SUCCESS != status) {
12695 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12696 return -EINVAL;
12697 }
12698
12699 return 0;
12700}
12701
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012702/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012703 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12704 * @adapter - HDD adapter
12705 * @tos - type of service
12706 * @status - status of the traffic
12707 *
12708 * Return: 0 on success and non zero value on failure
12709 */
12710
12711int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12712 bool is_tos_active)
12713{
12714 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012715 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012716 uint32_t max_off_chan_time = 0;
12717 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012718 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012719 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012720
12721 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12722 ret = wlan_hdd_validate_context(hdd_ctx);
12723
12724 if (ret < 0) {
12725 hdd_err("failed to set limit off chan params");
12726 return ret;
12727 }
12728
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012729 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12730
12731 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012732 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012733 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012734 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012735
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012736 if (adapter->active_ac) {
12737 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012738 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012739 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12740 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12741 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012742 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012743 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012744 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12745 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12746 PM_LATENCY);
12747 } else {
12748 /*ignore this command if only BE/BK is active */
12749 is_tos_active = false;
12750 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12751 hdd_ctx->config->conc_system_pref);
12752 }
12753 } else {
12754 /* No active tos */
12755 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12756 hdd_ctx->config->conc_system_pref);
12757 }
12758
Jeff Johnson1b780e42017-10-31 14:11:45 -070012759 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012760 is_tos_active, max_off_chan_time,
12761 hdd_ctx->config->nRestTimeConc, true);
12762 if (!QDF_IS_STATUS_SUCCESS(status)) {
12763 hdd_err("failed to set limit off chan params");
12764 ret = -EINVAL;
12765 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012766
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012767 return ret;
12768}
12769
12770/**
12771 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
12772 * @adapter - HDD adapter
12773 *
12774 * Return: 0 on success and non zero value on failure
12775 */
12776int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
12777{
12778 struct hdd_context *hdd_ctx;
12779 int ret;
12780 QDF_STATUS status;
12781 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
12782
12783 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12784 ret = wlan_hdd_validate_context(hdd_ctx);
12785 if (ret < 0)
12786 return ret;
12787
12788 /* set the system preferece to default */
12789 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12790 hdd_ctx->config->conc_system_pref);
12791
12792 /* clear the bitmap */
12793 adapter->active_ac = 0;
12794
12795 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070012796 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012797
Jeff Johnson1b780e42017-10-31 14:11:45 -070012798 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053012799 false, 0, 0, false);
12800 if (!QDF_IS_STATUS_SUCCESS(status)) {
12801 hdd_err("failed to reset limit off chan params");
12802 ret = -EINVAL;
12803 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012804
12805 return ret;
12806}
12807
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012808/**
12809 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12810 * @drv_op: Enum indicating driver op
12811 *
12812 * Return: none
12813 */
12814void hdd_start_driver_ops_timer(int drv_op)
12815{
12816 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12817 switch (drv_op) {
12818 case eHDD_DRV_OP_PROBE:
12819 memcpy(drv_ops_string, "probe", sizeof("probe"));
12820 break;
12821 case eHDD_DRV_OP_REMOVE:
12822 memcpy(drv_ops_string, "remove", sizeof("remove"));
12823 break;
12824 case eHDD_DRV_OP_SHUTDOWN:
12825 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12826 break;
12827 case eHDD_DRV_OP_REINIT:
12828 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12829 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053012830 case eHDD_DRV_OP_IFF_UP:
12831 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
12832 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012833 }
12834
12835 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12836 HDD_OPS_INACTIVITY_TIMEOUT);
12837}
12838
12839/**
12840 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12841 *
12842 * Return: none
12843 */
12844void hdd_stop_driver_ops_timer(void)
12845{
12846 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12847}
12848
12849/**
12850 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12851 * inactivity timer
12852 *
12853 * Return: None
12854 */
12855void hdd_drv_ops_inactivity_handler(void)
12856{
12857 hdd_err("%s: %d Sec timer expired while in .%s",
12858 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12859
12860 /* Driver shutdown is stuck, no recovery possible at this point */
12861 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12862 sizeof("shutdown")))
12863 QDF_BUG(0);
12864
12865 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012866 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012867 else
12868 QDF_BUG(0);
12869}
12870
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012871void hdd_pld_ipa_uc_shutdown_pipes(void)
12872{
12873 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12874
12875 if (!hdd_ctx)
12876 return;
12877
12878 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12879}
12880
Yun Parkff6a16a2017-09-26 16:38:18 -070012881/**
12882 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
12883 * @struct hdd_context *hdd_ctx
12884 * @struct hdd_adapter *padapter
12885 * @bool enble
12886 *
12887 * Return: none
12888 */
12889void hdd_set_rx_mode_rps(bool enable)
12890{
12891 struct cds_config_info *cds_cfg = cds_get_ini_config();
12892 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12893 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
12894
12895 if (adapter && hdd_ctx &&
12896 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
12897 if (enable && !cds_cfg->rps_enabled)
12898 hdd_send_rps_ind(adapter);
12899 else if (!enable && cds_cfg->rps_enabled)
12900 hdd_send_rps_disable_ind(adapter);
12901 }
12902}
12903
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012904/* Register the module init/exit functions */
12905module_init(hdd_module_init);
12906module_exit(hdd_module_exit);
12907
12908MODULE_LICENSE("Dual BSD/GPL");
12909MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12910MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12911
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012912module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12913 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012914
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012915module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12916 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12917
Ravi Joshia307f632017-07-17 23:41:41 -070012918module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12919 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12920
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012921module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12922 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12923
12924module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12925
12926module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12927
12928module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);