blob: 5dc84dd3aca01af0a0084081d22bdc1a84fb5ff6 [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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800126
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530127#ifdef CNSS_GENL
128#include <net/cnss_nl.h>
129#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800130#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530131
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800132#ifdef MODULE
133#define WLAN_MODULE_NAME module_name(THIS_MODULE)
134#else
135#define WLAN_MODULE_NAME "wlan"
136#endif
137
138#ifdef TIMER_MANAGER
139#define TIMER_MANAGER_STR " +TIMER_MANAGER"
140#else
141#define TIMER_MANAGER_STR ""
142#endif
143
144#ifdef MEMORY_DEBUG
145#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
146#else
147#define MEMORY_DEBUG_STR ""
148#endif
149
Sachin Ahujadddd2632017-03-07 19:07:24 +0530150int wlan_start_ret_val;
151static DECLARE_COMPLETION(wlan_start_comp);
152static unsigned int dev_num = 1;
153static struct cdev wlan_hdd_state_cdev;
154static struct class *class;
155static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530156#ifndef MODULE
157static struct gwlan_loader *wlan_loader;
158static ssize_t wlan_boot_cb(struct kobject *kobj,
159 struct kobj_attribute *attr,
160 const char *buf, size_t count);
161struct gwlan_loader {
162 bool loaded_state;
163 struct kobject *boot_wlan_obj;
164 struct attribute_group *attr_group;
165};
166
167static struct kobj_attribute wlan_boot_attribute =
168 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
169
170static struct attribute *attrs[] = {
171 &wlan_boot_attribute.attr,
172 NULL,
173};
174
175#define MODULE_INITIALIZED 1
176#endif
177
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530178#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
179#define MAX_OPS_NAME_STRING_SIZE 20
180
181static qdf_timer_t hdd_drv_ops_inactivity_timer;
182static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800184/* the Android framework expects this param even though we don't use it */
185#define BUF_LEN 20
186static char fwpath_buffer[BUF_LEN];
187static struct kparam_string fwpath = {
188 .string = fwpath_buffer,
189 .maxlen = BUF_LEN,
190};
191
192static char *country_code;
193static int enable_11d = -1;
194static int enable_dfs_chan_scan = -1;
195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800196/*
197 * spinlock for synchronizing asynchronous request/response
198 * (full description of use in wlan_hdd_main.h)
199 */
200DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530201DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800203#define WLAN_NLINK_CESIUM 30
204
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530205static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206
207#define WOW_MAX_FILTER_LISTS 1
208#define WOW_MAX_FILTERS_PER_LIST 4
209#define WOW_MIN_PATTERN_SIZE 6
210#define WOW_MAX_PATTERN_SIZE 64
211
212#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
213static const struct wiphy_wowlan_support wowlan_support_reg_init = {
214 .flags = WIPHY_WOWLAN_ANY |
215 WIPHY_WOWLAN_MAGIC_PKT |
216 WIPHY_WOWLAN_DISCONNECT |
217 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
218 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
219 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
220 WIPHY_WOWLAN_4WAY_HANDSHAKE |
221 WIPHY_WOWLAN_RFKILL_RELEASE,
222 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
223 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
224 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
225};
226#endif
227
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700228static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
229 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
241 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
242 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
245 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700263 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700264};
265
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530266int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
267 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
268 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
269 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
270 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
271};
272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530274struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275
276struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700278static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279#endif
280
Sachin Ahujadddd2632017-03-07 19:07:24 +0530281void hdd_start_complete(int ret)
282{
283 wlan_start_ret_val = ret;
284
285 complete(&wlan_start_comp);
286}
287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800288/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530289 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700290 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530291 *
292 * Return: none
293 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700294static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530295{
Jeff Johnson9d295242017-08-29 14:39:48 -0700296 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530297 hdd_adapter_list_node_t *adapter_node, *next;
298 QDF_STATUS status = QDF_STATUS_SUCCESS;
299
300 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
301 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -0700302 adapter = adapter_node->adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530303 if (NULL != adapter)
304 hdd_send_rps_ind(adapter);
305 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
306 adapter_node = next;
307 }
308}
309
310/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
312 * @vdev_id: vdev_id
313 * @action: action type
314 * @reason: reason type
315 *
316 * Return: none
317 */
318void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
319 enum netif_action_type action, enum netif_reason_type reason)
320{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700321 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700322 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323
324 if (!hdd_ctx) {
325 hdd_err("hdd ctx is NULL");
326 return;
327 }
328 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
329
330 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331}
332
333/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700334 * Store WLAN driver version and timestamp info in global variables such that
335 * crash debugger can extract them from driver debug symbol and crashdump for
336 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800337 */
338uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700339
340#ifndef BUILD_TIMESTAMP
341#define BUILD_TIMESTAMP ""
342#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700343uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800344
345/**
346 * hdd_device_mode_to_string() - return string conversion of device mode
347 * @device_mode: device mode
348 *
349 * This utility function helps log string conversion of device mode.
350 *
351 * Return: string conversion of device mode, if match found;
352 * "Unknown" otherwise.
353 */
354const char *hdd_device_mode_to_string(uint8_t device_mode)
355{
356 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800357 CASE_RETURN_STRING(QDF_STA_MODE);
358 CASE_RETURN_STRING(QDF_SAP_MODE);
359 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
360 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
361 CASE_RETURN_STRING(QDF_FTM_MODE);
362 CASE_RETURN_STRING(QDF_IBSS_MODE);
363 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
364 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700365 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800366 default:
367 return "Unknown";
368 }
369}
370
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530371/**
372 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
373 * @adapter: HDD adapter
374 * @chan_number: Channel number
375 * @chan_bw: Bandwidth
376 *
377 * Checks if the given bandwidth is valid for the given channel number.
378 *
379 * Return: 0 for success, non-zero for failure
380 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700381int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530382 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800383 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530384{
385 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
386 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
387 bool found = false;
388 tHalHandle hal;
389
390 hal = WLAN_HDD_GET_HAL_CTX(adapter);
391 if (!hal) {
392 hdd_err("Invalid HAL context");
393 return -EINVAL;
394 }
395
396 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
397 hdd_err("No valid channel list");
398 return -EOPNOTSUPP;
399 }
400
401 for (i = 0; i < len; i++) {
402 if (chan[i] == chan_number) {
403 found = true;
404 break;
405 }
406 }
407
408 if (found == false) {
409 hdd_err("Channel not in driver's valid channel list");
410 return -EOPNOTSUPP;
411 }
412
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700413 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
414 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530415 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
416 return -EINVAL;
417 }
418
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700419 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530420 if (chan_bw == CH_WIDTH_80MHZ) {
421 hdd_err("BW80 not possible in 2.4GHz band");
422 return -EINVAL;
423 }
424 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
425 (chan_bw != CH_WIDTH_MAX)) {
426 hdd_err("Only BW20 possible on channel 14");
427 return -EINVAL;
428 }
429 }
430
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700431 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530432 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
433 (chan_bw != CH_WIDTH_MAX)) {
434 hdd_err("Only BW20 possible on channel 165");
435 return -EINVAL;
436 }
437 }
438
439 return 0;
440}
441
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530442/**
443 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
444 *
445 * Block the unloading of the driver (or) interface up until the
446 * cds recovery is completed
447 *
448 * Return: true for recovery completion else false
449 */
450static bool hdd_wait_for_recovery_completion(void)
451{
452 int retry = 0;
453
454 /* Wait for recovery to complete */
455 while (cds_is_driver_recovering()) {
456 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
457 hdd_err("Recovery in progress; wait here!!!");
458 msleep(1000);
459 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
460 hdd_err("SSR never completed, error");
461 /*
462 * Trigger the bug_on in the internal builds, in the
463 * customer builds self-recovery will be enabled
464 * in those cases just return error.
465 */
466 if (cds_is_self_recovery_enabled())
467 return false;
468 QDF_BUG(0);
469 }
470 }
471
472 hdd_info("Recovery completed successfully!");
473 return true;
474}
475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800476static int __hdd_netdev_notifier_call(struct notifier_block *nb,
477 unsigned long state, void *data)
478{
479#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
480 struct netdev_notifier_info *dev_notif_info = data;
481 struct net_device *dev = dev_notif_info->dev;
482#else
483 struct net_device *dev = data;
484#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700485 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700486 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800487
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800488 ENTER_DEV(dev);
489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800490 /* Make sure that this callback corresponds to our device. */
491 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
492 return NOTIFY_DONE;
493
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530494 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800495 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700496 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 return NOTIFY_DONE;
498 }
499
500 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700501 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502 return NOTIFY_DONE;
503 }
504
505 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
506 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800507 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530508 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800509 return NOTIFY_DONE;
510 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530511 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512 return NOTIFY_DONE;
513
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800514 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800515 dev->name, state);
516
517 switch (state) {
518 case NETDEV_REGISTER:
519 break;
520
521 case NETDEV_UNREGISTER:
522 break;
523
524 case NETDEV_UP:
525 sme_ch_avoid_update_req(hdd_ctx->hHal);
526 break;
527
528 case NETDEV_DOWN:
529 break;
530
531 case NETDEV_CHANGE:
532 if (true == adapter->isLinkUpSvcNeeded)
533 complete(&adapter->linkup_event_var);
534 break;
535
536 case NETDEV_GOING_DOWN:
537 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530538 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
539 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800540 } else {
hqueaa33ee2017-05-04 17:56:35 +0800541 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800542 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 }
544 break;
545
546 default:
547 break;
548 }
549
550 return NOTIFY_DONE;
551}
552
553/**
554 * hdd_netdev_notifier_call() - netdev notifier callback function
555 * @nb: pointer to notifier block
556 * @state: state
557 * @ndev: ndev pointer
558 *
559 * Return: 0 on success, error number otherwise.
560 */
561static int hdd_netdev_notifier_call(struct notifier_block *nb,
562 unsigned long state,
563 void *ndev)
564{
565 int ret;
566
567 cds_ssr_protect(__func__);
568 ret = __hdd_netdev_notifier_call(nb, state, ndev);
569 cds_ssr_unprotect(__func__);
570
571 return ret;
572}
573
574struct notifier_block hdd_netdev_notifier = {
575 .notifier_call = hdd_netdev_notifier_call,
576};
577
578/* variable to hold the insmod parameters */
579static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800580
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530581static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700582int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530583
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800584/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800586
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530587/**
588 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
589 * @ch_width: NL channel width
590 *
591 * Converts the NL channel width to the driver's internal representation
592 *
593 * Return: Converted channel width. In case of non matching NL channel width,
594 * CH_WIDTH_MAX will be returned.
595 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800596enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530597{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800598 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700599
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800600 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530601 switch (ch_width) {
602 case NL80211_CHAN_WIDTH_20_NOHT:
603 case NL80211_CHAN_WIDTH_20:
604 return CH_WIDTH_20MHZ;
605 case NL80211_CHAN_WIDTH_40:
606 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530607 case NL80211_CHAN_WIDTH_80:
608 return CH_WIDTH_80MHZ;
609 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800610 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
611 return CH_WIDTH_80P80MHZ;
612 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
613 return CH_WIDTH_160MHZ;
614 else
615 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530616 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800617 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
618 return CH_WIDTH_160MHZ;
619 else
620 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530621 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800622 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530623 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800624 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530625 default:
626 hdd_err("Invalid channel width %d, setting to default",
627 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800628 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530629 }
630}
631
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530632/* wlan_hdd_find_opclass() - Find operating class for a channel
633 * @hal: handler to HAL
634 * @channel: channel id
635 * @bw_offset: bandwidth offset
636 *
637 * Function invokes sme api to find the operating class
638 *
639 * Return: operating class
640 */
641uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
642 uint8_t bw_offset)
643{
644 uint8_t opclass = 0;
645
646 sme_get_opclass(hal, channel, bw_offset, &opclass);
647 return opclass;
648}
649
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800650/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530651 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530652 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653 * @bitmask: Bitmask of log levels to be enabled
654 *
655 * Called immediately after the cfg.ini is read in order to configure
656 * the desired trace levels.
657 *
658 * Return: None
659 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530660int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530662 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530663 int qdf_print_idx = -1;
664 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800665 /*
666 * if the bitmask is the default value, then a bitmask was not
667 * specified in cfg.ini, so leave the logging level alone (it
668 * will remain at the "compiled in" default value)
669 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700670 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530671 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800672
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530673 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530675 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530676 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530677 QDF_TRACE_LEVEL_NONE, 0);
678
679 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530680 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530682 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 while (0 != bitmask) {
684 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530685 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530686 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530687 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530688 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800689 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 level++;
692 bitmask >>= 1;
693 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530694 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695}
696
697/**
Chris Guo1751acf2017-07-03 14:09:01 +0800698 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
699 * @hdd_ctx: HDD context pointer
700 *
701 * Return: 0 if the context is valid. Error code otherwise
702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700703int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800704{
705 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
706 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
707 return -ENODEV;
708 }
709
710 if (cds_is_driver_recovering()) {
711 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
712 (void *)_RET_IP_, cds_get_driver_state());
713 return -EAGAIN;
714 }
715
716 if (hdd_ctx->start_modules_in_progress ||
717 hdd_ctx->stop_modules_in_progress) {
718 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
719 (void *)_RET_IP_);
720 return -EAGAIN;
721 }
722
723 return 0;
724}
725
726
727/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 * wlan_hdd_validate_context() - check the HDD context
729 * @hdd_ctx: HDD context pointer
730 *
731 * Return: 0 if the context is valid. Error code otherwise
732 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700733int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530736 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737 return -ENODEV;
738 }
739
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800740 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800741 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530742 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 return -EAGAIN;
744 }
745
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700746 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530748
749 if (hdd_ctx->start_modules_in_progress ||
750 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800751 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530752 (void *)_RET_IP_);
753 return -EAGAIN;
754 }
755
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530756 if (cds_is_driver_in_bad_state()) {
757 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
758 (void *)_RET_IP_, cds_get_driver_state());
759 return -ENODEV;
760 }
761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 return 0;
763}
764
Jeff Johnson9d295242017-08-29 14:39:48 -0700765int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700766{
767 if (!adapter) {
768 hdd_err("adapter is null");
769 return -EINVAL;
770 }
771
772 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
773 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
774 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
775 return -EINVAL;
776 }
777
778 if (!adapter->dev) {
779 hdd_err("adapter net_device is null");
780 return -EINVAL;
781 }
782
783 if (!(adapter->dev->flags & IFF_UP)) {
784 hdd_info("adapter net_device is not up");
785 return -EAGAIN;
786 }
787
788 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
789 hdd_info("adapter session is not open");
790 return -EAGAIN;
791 }
792
793 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
794 hdd_err("bad adapter session Id: %u", adapter->sessionId);
795 return -EINVAL;
796 }
797
798 return 0;
799}
800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530802 * wlan_hdd_validate_modules_state() - Check modules status
803 * @hdd_ctx: HDD context pointer
804 *
805 * Check's the driver module's state and returns true if the
806 * modules are enabled returns false if modules are closed.
807 *
808 * Return: True if modules are enabled or false.
809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700810bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530811{
812 mutex_lock(&hdd_ctx->iface_change_lock);
813 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
814 mutex_unlock(&hdd_ctx->iface_change_lock);
815 hdd_notice("Modules not enabled, Present status: %d",
816 hdd_ctx->driver_status);
817 return false;
818 }
819 mutex_unlock(&hdd_ctx->iface_change_lock);
820 return true;
821}
822
823/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700825 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 *
827 * This function sets the IBSS power save config parameters to WMA
828 * which will send it to firmware if FW supports IBSS power save
829 * before vdev start.
830 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530831 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800832 * on failure.
833 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700834QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835{
836 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700837 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838
839 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700840 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530841 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 }
843
Naveen Rawat247a8682017-06-05 15:00:31 -0700844 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
846 hdd_ctx->config->ibssATIMWinSize,
847 VDEV_CMD);
848 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700849 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530850 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 }
852
Naveen Rawat247a8682017-06-05 15:00:31 -0700853 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
855 hdd_ctx->config->isIbssPowerSaveAllowed,
856 VDEV_CMD);
857 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700858 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
859 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530860 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 }
862
Naveen Rawat247a8682017-06-05 15:00:31 -0700863 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
865 hdd_ctx->config->
866 isIbssPowerCollapseAllowed, VDEV_CMD);
867 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700868 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
869 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530870 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800871 }
872
Naveen Rawat247a8682017-06-05 15:00:31 -0700873 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
875 hdd_ctx->config->isIbssAwakeOnTxRx,
876 VDEV_CMD);
877 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700878 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530879 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880 }
881
Naveen Rawat247a8682017-06-05 15:00:31 -0700882 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
884 hdd_ctx->config->ibssInactivityCount,
885 VDEV_CMD);
886 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700887 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530888 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800889 }
890
Naveen Rawat247a8682017-06-05 15:00:31 -0700891 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
893 hdd_ctx->config->ibssTxSpEndInactivityTime,
894 VDEV_CMD);
895 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700896 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
897 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530898 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899 }
900
Naveen Rawat247a8682017-06-05 15:00:31 -0700901 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
903 hdd_ctx->config->ibssPsWarmupTime,
904 VDEV_CMD);
905 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700906 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
907 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530908 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 }
910
Naveen Rawat247a8682017-06-05 15:00:31 -0700911 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
913 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
914 VDEV_CMD);
915 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700916 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
917 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530918 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 }
920
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530921 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800922}
923
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924#define INTF_MACADDR_MASK 0x7
925
926/**
927 * hdd_update_macaddr() - update mac address
928 * @config: hdd configuration
929 * @hw_macaddr: mac address
930 *
931 * Mac address for multiple virtual interface is found as following
932 * i) The mac address of the first interface is just the actual hw mac address.
933 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
934 * define the mac address for the remaining interfaces and locally
935 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
936 * supported virtual interfaces, right now this is 0x07 (meaning 8
937 * interface).
938 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
939 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
940 *
941 * Return: None
942 */
943void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530944 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945{
946 int8_t i;
947 uint8_t macaddr_b3, tmp_br3;
948
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530949 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530950 QDF_MAC_ADDR_SIZE);
951 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530952 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530953 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 macaddr_b3 = config->intfMacAddr[i].bytes[3];
955 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
956 INTF_MACADDR_MASK;
957 macaddr_b3 += tmp_br3;
958
959 /* XOR-ing bit-24 of the mac address. This will give enough
960 * mac address range before collision
961 */
962 macaddr_b3 ^= (1 << 7);
963
964 /* Set locally administered bit */
965 config->intfMacAddr[i].bytes[0] |= 0x02;
966 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800967 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 MAC_ADDRESS_STR, i,
969 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
970 }
971}
972
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700973static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 struct wma_tgt_services *cfg)
975{
976 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977
978 /* Set up UAPSD */
979 config->apUapsdEnabled &= cfg->uapsd;
980
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800981 /* 11AX mode support */
982 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
983 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
984 config->dot11Mode = eHDD_DOT11_MODE_11ac;
985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 /* 11AC mode support */
987 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
988 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
989 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990
991 /* ARP offload: override user setting if invalid */
992 config->fhostArpOffload &= cfg->arp_offload;
993
994#ifdef FEATURE_WLAN_SCAN_PNO
995 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800996 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 if (cfg->pno_offload)
998 config->PnoOffload = true;
999#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000#ifdef FEATURE_WLAN_TDLS
1001 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301002 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1003 cfg->en_tdls_offchan;
1004 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1005 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001006 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001008 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1012 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1013#endif
Will Huang496b36c2017-07-11 16:38:50 +08001014 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001015 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016
1017}
1018
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001019/**
1020 * hdd_update_vdev_nss() - sets the vdev nss
1021 * @hdd_ctx: HDD context
1022 *
1023 * Sets the Nss per vdev type based on INI
1024 *
1025 * Return: None
1026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001027static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001028{
1029 struct hdd_config *cfg_ini = hdd_ctx->config;
1030 uint8_t max_supp_nss = 1;
1031
Naveen Rawat10b1c152017-01-18 11:16:06 -08001032 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001033 max_supp_nss = 2;
1034
1035 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1036 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1037
1038 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1039 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1040}
1041
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301042/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301043 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1044 * @hdd_ctx: HDD context
1045 *
1046 * Updates wiphy vhtcap fields
1047 *
1048 * Return: None
1049 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001050static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301051{
1052 struct ieee80211_supported_band *band_5g =
1053 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1054 uint32_t val;
1055
1056 if (!band_5g) {
1057 hdd_debug("5GHz band disabled, skipping capability population");
1058 return;
1059 }
1060
1061 val = hdd_ctx->config->txBFCsnValue;
1062 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1063
1064 val = NUM_OF_SOUNDING_DIMENSIONS;
1065 band_5g->vht_cap.cap |=
1066 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1067
1068 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1069 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1070}
1071
1072/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301073 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1074 * @hdd_ctx: HDD context
1075 *
1076 * Sets the DBS capability as per INI and firmware capability
1077 *
1078 * Return: None
1079 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001080static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301081{
1082 struct hdd_config *cfg_ini = hdd_ctx->config;
1083 uint8_t hw_dbs_capable = 0;
1084
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001085 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1086 ((cfg_ini->dual_mac_feature_disable ==
1087 ENABLE_DBS_CXN_AND_SCAN) ||
1088 (cfg_ini->dual_mac_feature_disable ==
1089 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301090 hw_dbs_capable = 1;
1091
1092 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1093}
1094
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001095static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 struct wma_tgt_ht_cap *cfg)
1097{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301098 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001099 uint32_t value, val32;
1100 uint16_t val16;
1101 struct hdd_config *pconfig = hdd_ctx->config;
1102 tSirMacHTCapabilityInfo *phtCapInfo;
1103 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1104 uint8_t enable_tx_stbc;
1105
1106 /* check and update RX STBC */
1107 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1108 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1109
1110 /* get the MPDU density */
1111 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1112
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301113 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001114 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 value = 0;
1116 }
1117
1118 /*
1119 * MPDU density:
1120 * override user's setting if value is larger
1121 * than the one supported by target
1122 */
1123 if (value > cfg->mpdu_density) {
1124 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1125 cfg->mpdu_density);
1126
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301127 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001128 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 }
1130
1131 /* get the HT capability info */
1132 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301133 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001134 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 return;
1136 }
1137 val16 = (uint16_t) val32;
1138 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1139
1140 /* Set the LDPC capability */
1141 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1142
1143 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1144 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1145
1146 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1147 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1148
1149 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1150 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1151
1152 enable_tx_stbc = pconfig->enableTxSTBC;
1153
1154 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1155 pconfig->enable2x2 = 1;
1156 } else {
1157 pconfig->enable2x2 = 0;
1158 enable_tx_stbc = 0;
1159
1160 /* 1x1 */
1161 /* Update Rx Highest Long GI data Rate */
1162 if (sme_cfg_set_int(hdd_ctx->hHal,
1163 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001164 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301165 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001166 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167 }
1168
1169 /* Update Tx Highest Long GI data Rate */
1170 if (sme_cfg_set_int
1171 (hdd_ctx->hHal,
1172 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001173 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301174 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001175 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 }
1177 }
1178 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1179 enable_tx_stbc = 0;
1180 phtCapInfo->txSTBC = enable_tx_stbc;
1181
1182 val32 = val16;
1183 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301184 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001185 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001186#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1187 value = SIZE_OF_SUPPORTED_MCS_SET;
1188 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301189 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001190 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001191
1192 if (pconfig->enable2x2) {
1193 for (value = 0; value < cfg->num_rf_chains; value++)
1194 mcs_set[value] =
1195 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1196
1197 status =
1198 sme_cfg_set_str(hdd_ctx->hHal,
1199 WNI_CFG_SUPPORTED_MCS_SET,
1200 mcs_set,
1201 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301202 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001203 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 }
1205 }
1206#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1207}
1208
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001209static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001210 struct wma_tgt_vht_cap *cfg)
1211{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301212 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213 uint32_t value = 0;
1214 struct hdd_config *pconfig = hdd_ctx->config;
1215 struct wiphy *wiphy = hdd_ctx->wiphy;
1216 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001217 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001218 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001219 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001220 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221
Dustin Brown5e06bd32016-10-04 12:49:10 -07001222 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001223 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001224 return;
1225 }
1226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001227 /* Get the current MPDU length */
1228 status =
1229 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1230 &value);
1231
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301232 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001233 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 value = 0;
1235 }
1236
1237 /*
1238 * VHT max MPDU length:
1239 * override if user configured value is too high
1240 * that the target cannot support
1241 */
1242 if (value > cfg->vht_max_mpdu) {
1243 status = sme_cfg_set_int(hdd_ctx->hHal,
1244 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1245 cfg->vht_max_mpdu);
1246
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001247 if (status == QDF_STATUS_E_FAILURE)
1248 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 }
1250
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001251 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1252 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1253
1254 if (pconfig->enable2x2)
1255 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1256
1257 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1258 QDF_STATUS_E_FAILURE) {
1259 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1260 }
1261
1262 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1263 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1264 if (pconfig->enable2x2)
1265 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1266
1267 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1268 QDF_STATUS_E_FAILURE) {
1269 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1270 }
1271
1272 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1273 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1274 if (pconfig->enable2x2)
1275 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1276
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001277 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001278 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1279
1280 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1281 QDF_STATUS_E_FAILURE) {
1282 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1283 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001285 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 &value);
1287
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301288 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001289 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 value = 0;
1291 }
1292
jiad4a7a33c2017-08-08 15:32:24 +08001293 /* Set HW RX LDPC capability */
1294 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1295 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 status = sme_cfg_set_int(hdd_ctx->hHal,
1297 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001298 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001300 if (status == QDF_STATUS_E_FAILURE)
1301 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 }
1303
1304 /* Get current GI 80 value */
1305 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1306 &value);
1307
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301308 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001309 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001310 value = 0;
1311 }
1312
1313 /* set the Guard interval 80MHz */
1314 if (value && !cfg->vht_short_gi_80) {
1315 status = sme_cfg_set_int(hdd_ctx->hHal,
1316 WNI_CFG_VHT_SHORT_GI_80MHZ,
1317 cfg->vht_short_gi_80);
1318
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001319 if (status == QDF_STATUS_E_FAILURE)
1320 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 }
1322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 /* Get VHT TX STBC cap */
1324 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1325
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301326 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001327 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 value = 0;
1329 }
1330
1331 /* VHT TX STBC cap */
1332 if (value && !cfg->vht_tx_stbc) {
1333 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1334 cfg->vht_tx_stbc);
1335
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001336 if (status == QDF_STATUS_E_FAILURE)
1337 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338 }
1339
1340 /* Get VHT RX STBC cap */
1341 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301343 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001344 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 value = 0;
1346 }
1347
1348 /* VHT RX STBC cap */
1349 if (value && !cfg->vht_rx_stbc) {
1350 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1351 cfg->vht_rx_stbc);
1352
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001353 if (status == QDF_STATUS_E_FAILURE)
1354 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 }
1356
1357 /* Get VHT SU Beamformer cap */
1358 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1359 &value);
1360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301361 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001362 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 value = 0;
1364 }
1365
1366 /* set VHT SU Beamformer cap */
1367 if (value && !cfg->vht_su_bformer) {
1368 status = sme_cfg_set_int(hdd_ctx->hHal,
1369 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1370 cfg->vht_su_bformer);
1371
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001372 if (status == QDF_STATUS_E_FAILURE)
1373 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 }
1375
1376 /* check and update SU BEAMFORMEE capabality */
1377 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1378 pconfig->enableTxBF = cfg->vht_su_bformee;
1379
1380 status = sme_cfg_set_int(hdd_ctx->hHal,
1381 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1382 pconfig->enableTxBF);
1383
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001384 if (status == QDF_STATUS_E_FAILURE)
1385 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386
1387 /* Get VHT MU Beamformer cap */
1388 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1389 &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 MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 value = 0;
1394 }
1395
1396 /* set VHT MU Beamformer cap */
1397 if (value && !cfg->vht_mu_bformer) {
1398 status = sme_cfg_set_int(hdd_ctx->hHal,
1399 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1400 cfg->vht_mu_bformer);
1401
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001402 if (status == QDF_STATUS_E_FAILURE)
1403 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 }
1405
1406 /* Get VHT MU Beamformee cap */
1407 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1408 &value);
1409
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301410 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001411 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 value = 0;
1413 }
1414
1415 /* set VHT MU Beamformee cap */
1416 if (value && !cfg->vht_mu_bformee) {
1417 status = sme_cfg_set_int(hdd_ctx->hHal,
1418 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1419 cfg->vht_mu_bformee);
1420
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001421 if (status == QDF_STATUS_E_FAILURE)
1422 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001423 }
1424
1425 /* Get VHT MAX AMPDU Len exp */
1426 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1427 &value);
1428
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301429 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001430 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431 value = 0;
1432 }
1433
1434 /*
1435 * VHT max AMPDU len exp:
1436 * override if user configured value is too high
1437 * that the target cannot support.
1438 * Even though Rome publish ampdu_len=7, it can
1439 * only support 4 because of some h/w bug.
1440 */
1441
1442 if (value > cfg->vht_max_ampdu_len_exp) {
1443 status = sme_cfg_set_int(hdd_ctx->hHal,
1444 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1445 cfg->vht_max_ampdu_len_exp);
1446
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001447 if (status == QDF_STATUS_E_FAILURE)
1448 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 }
1450
1451 /* Get VHT TXOP PS CAP */
1452 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1453
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301454 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001455 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 value = 0;
1457 }
1458
1459 /* set VHT TXOP PS cap */
1460 if (value && !cfg->vht_txop_ps) {
1461 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1462 cfg->vht_txop_ps);
1463
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001464 if (status == QDF_STATUS_E_FAILURE)
1465 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 }
1467
1468 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1469 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1470 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1471 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1472 else
1473 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1474
1475
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001476 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1477 status = sme_cfg_set_int(hdd_ctx->hHal,
1478 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1479 VHT_CAP_160_AND_80P80_SUPP);
1480 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001481 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482 band_5g->vht_cap.cap |=
1483 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001484 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1485 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1486 status = sme_cfg_set_int(hdd_ctx->hHal,
1487 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1488 VHT_CAP_160_SUPP);
1489 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001490 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 band_5g->vht_cap.cap |=
1492 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001493 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1494 }
1495 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1496 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301497 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001498 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301499 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001500 &value);
1501 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301502 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001503 value = 0;
1504 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301505 /* set the Guard interval 160MHz */
1506 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001507 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301508 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1509 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001510
1511 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301512 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001513 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514
1515 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1516 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1517
1518 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1519 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1520 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1521 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1522
1523 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1524 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1525
1526 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1527 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1528 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1529 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1530 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1531 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1532
1533 band_5g->vht_cap.cap |=
1534 (cfg->vht_max_ampdu_len_exp <<
1535 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1536
1537 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1538 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1539 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1540 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1541 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1542 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1543 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1544 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1545
1546 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1547 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1548
1549}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001551/**
1552 * hdd_generate_macaddr_auto() - Auto-generate mac address
1553 * @hdd_ctx: Pointer to the HDD context
1554 *
1555 * Auto-generate mac address using device serial number.
1556 * Keep the first 3 bytes of OUI as before and replace
1557 * the last 3 bytes with the lower 3 bytes of serial number.
1558 *
1559 * Return: 0 for success
1560 * Non zero failure code for errors
1561 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001562static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001563{
1564 unsigned int serialno = 0;
1565 struct qdf_mac_addr mac_addr = {
1566 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1567 };
1568
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001569 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001570 if (serialno == 0)
1571 return -EINVAL;
1572
1573 serialno &= 0x00ffffff;
1574
1575 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1576 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1577 mac_addr.bytes[5] = serialno & 0xff;
1578
1579 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1580 return 0;
1581}
1582
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301583/**
1584 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1585 * configuration to cfg_ini in HDD
1586 * @hdd_ctx: Pointer to hdd_ctx
1587 * @cfg: target configuration
1588 *
1589 * Return: None
1590 */
1591#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001592static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301593 struct wma_tgt_cfg *cfg)
1594{
1595 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1596}
1597#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001598static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301599 struct wma_tgt_cfg *cfg)
1600{
1601}
1602#endif
1603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604void hdd_update_tgt_cfg(void *context, void *param)
1605{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001606 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001607 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 struct wma_tgt_cfg *cfg = param;
1609 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001610 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301611 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301612
Yue Mae3e86ab2017-05-08 10:48:24 -07001613 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301614 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1615 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1616 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1617 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1618 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001619 /* Restore pdev to MAC/WMA contexts */
1620 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001621 } else {
1622 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1623 if (ret) {
1624 hdd_err("pdev creation fails!");
1625 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301626 } else
1627 hdd_debug("New pdev has been created with pdev_id = %u",
1628 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301629 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001630
Naveen Rawat64e477e2016-05-20 10:34:56 -07001631 if (cds_cfg) {
1632 if (hdd_ctx->config->enable_sub_20_channel_width !=
1633 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1634 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1635 cds_cfg->sub_20_channel_width =
1636 WLAN_SUB_20_CH_WIDTH_NONE;
1637 } else {
1638 cds_cfg->sub_20_channel_width =
1639 hdd_ctx->config->enable_sub_20_channel_width;
1640 }
1641 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642
1643 /* first store the INI band capability */
1644 temp_band_cap = hdd_ctx->config->nBandCapability;
1645
1646 hdd_ctx->config->nBandCapability = cfg->band_cap;
1647
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001648 /*
1649 * now overwrite the target band capability with INI
1650 * setting if INI setting is a subset
1651 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652
1653 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1654 (temp_band_cap != eCSR_BAND_ALL))
1655 hdd_ctx->config->nBandCapability = temp_band_cap;
1656 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1657 (temp_band_cap != eCSR_BAND_ALL) &&
1658 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001659 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001660 }
1661
Amar Singhal58b45ef2017-08-01 13:43:54 -07001662 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1663
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301664 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001665 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1666 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1667 }
1668
1669 /* This can be extended to other configurations like ht, vht cap... */
1670
Anurag Chouhanc5548422016-02-24 18:33:27 +05301671 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001673 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001675 static struct qdf_mac_addr default_mac_addr = {
1676 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1677 };
1678 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1679 &default_mac_addr)) {
1680 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1681 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1682 MAC_ADDRESS_STR,
1683 MAC_ADDR_ARRAY(hdd_ctx->config->
1684 intfMacAddr[0].bytes));
1685 } else {
1686 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1687 MAC_ADDRESS_STR,
1688 MAC_ADDR_ARRAY(hdd_ctx->config->
1689 intfMacAddr[0].bytes));
1690 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001691 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001692 }
1693
1694 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001695 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696
1697 hdd_ctx->max_intf_count = cfg->max_intf_count;
1698
Jeff Johnsonc875e242016-09-23 18:12:34 -07001699 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001700 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1703 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1704
1705 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1706
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001708 if (cfg->services.en_11ax) {
1709 hdd_info("11AX: 11ax is enabled - update HDD config");
1710 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1711 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001712
1713 hdd_update_vdev_nss(hdd_ctx);
1714
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301715 hdd_update_hw_dbs_capable(hdd_ctx);
1716
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001717 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001718 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001719 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001720 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001721
Nitesh Shahe50711f2017-04-26 16:30:45 +05301722 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1723 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1724 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001725 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001726 hdd_ctx->current_antenna_mode);
1727
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001728 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1729 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301730 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301731
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301732 if ((hdd_ctx->config->txBFCsnValue >
1733 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1734 !cfg->tx_bfee_8ss_enabled)
1735 hdd_ctx->config->txBFCsnValue =
1736 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1737
1738 if (sme_cfg_set_int(hdd_ctx->hHal,
1739 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1740 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1741 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1742
1743
1744 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1745 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1746 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301747
1748 /*
1749 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1750 */
1751 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301752
1753 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1754
Arun Khandavallid454d422016-08-17 12:47:05 +05301755 /*
1756 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1757 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1758 * configure the STA mode wow pattern.
1759 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301760 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301761 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301762
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301763 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1764
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001765 /* Configure NAN datapath features */
1766 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001767 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768}
1769
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001770bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001773 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301774 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001775 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776
Arif Hussaincd151632017-02-11 16:57:19 -08001777 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001778 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001779 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301780 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001781 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782
Arif Hussaincd151632017-02-11 16:57:19 -08001783 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1784 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001785 adapter = adapterNode->adapter;
Arif Hussaincd151632017-02-11 16:57:19 -08001786 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1787
1788 if ((QDF_SAP_MODE == adapter->device_mode ||
1789 QDF_P2P_GO_MODE == adapter->device_mode) &&
1790 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1791 ap_ctx->operatingChannel))) {
1792 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1793 true;
1794 hdd_info("tx blocked for session: %d",
1795 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301796 }
Arif Hussaincd151632017-02-11 16:57:19 -08001797 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1798 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001799 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301800
1801 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001802}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803
1804/**
1805 * hdd_is_valid_mac_address() - validate MAC address
1806 * @pMacAddr: Pointer to the input MAC address
1807 *
1808 * This function validates whether the given MAC address is valid or not
1809 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1810 * where X is the hexa decimal digit character and separated by ':'
1811 * This algorithm works even if MAC address is not separated by ':'
1812 *
1813 * This code checks given input string mac contains exactly 12 hexadecimal
1814 * digits and a separator colon : appears in the input string only after
1815 * an even number of hex digits.
1816 *
1817 * Return: 1 for valid and 0 for invalid
1818 */
1819bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1820{
1821 int xdigit = 0;
1822 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001824 while (*pMacAddr) {
1825 if (isxdigit(*pMacAddr)) {
1826 xdigit++;
1827 } else if (':' == *pMacAddr) {
1828 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1829 break;
1830
1831 ++separator;
1832 } else {
1833 /* Invalid MAC found */
1834 return 0;
1835 }
1836 ++pMacAddr;
1837 }
1838 return xdigit == 12 && (separator == 5 || separator == 0);
1839}
1840
1841/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301842 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1843 * @dev: Handle to struct net_device to be updated.
1844 *
1845 * Return: None
1846 */
1847static void hdd_mon_mode_ether_setup(struct net_device *dev)
1848{
1849 dev->header_ops = NULL;
1850 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1851 dev->hard_header_len = ETH_HLEN;
1852 dev->mtu = ETH_DATA_LEN;
1853 dev->addr_len = ETH_ALEN;
1854 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1855 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1856 dev->priv_flags |= IFF_TX_SKB_SHARING;
1857
1858 memset(dev->broadcast, 0xFF, ETH_ALEN);
1859}
1860
1861/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001862 * __hdd__mon_open() - HDD Open function
1863 * @dev: Pointer to net_device structure
1864 *
1865 * This is called in response to ifconfig up
1866 *
1867 * Return: 0 for success; non-zero for failure
1868 */
1869static int __hdd_mon_open(struct net_device *dev)
1870{
1871 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001872 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1873 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001874
1875 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001876
1877 ret = wlan_hdd_validate_context(hdd_ctx);
1878 if (ret)
1879 return ret;
1880
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301881 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001882
1883 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1884 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1885 if (ret) {
1886 hdd_err("Failed to start WLAN modules return");
1887 return ret;
1888 }
1889 hdd_err("hdd_wlan_start_modules() successful !");
1890
1891 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1892 ret = hdd_start_adapter(adapter);
1893 if (ret) {
1894 hdd_err("Failed to start adapter :%d",
1895 adapter->device_mode);
1896 return ret;
1897 }
1898 hdd_err("hdd_start_adapters() successful !");
1899 }
1900 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1901 }
1902
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001903 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001904
1905 if (!ret)
1906 ret = hdd_enable_monitor_mode(dev);
1907
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001908 return ret;
1909}
1910
1911/**
1912 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1913 * @dev: Pointer to net_device structure
1914 *
1915 * This is called in response to ifconfig up
1916 *
1917 * Return: 0 for success; non-zero for failure
1918 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001919static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001920{
1921 int ret;
1922
1923 cds_ssr_protect(__func__);
1924 ret = __hdd_mon_open(dev);
1925 cds_ssr_unprotect(__func__);
1926
1927 return ret;
1928}
1929
1930/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301931 * hdd_start_adapter() - Wrapper function for device specific adapter
1932 * @adapter: pointer to HDD adapter
1933 *
1934 * This function is called to start the device specific adapter for
1935 * the mode passed in the adapter's device_mode.
1936 *
1937 * Return: 0 for success; non-zero for failure
1938 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001939int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301940{
1941
1942 int ret;
1943 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1944
1945 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001946 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301947
1948 switch (device_mode) {
1949 case QDF_P2P_CLIENT_MODE:
1950 case QDF_P2P_DEVICE_MODE:
1951 case QDF_OCB_MODE:
1952 case QDF_STA_MODE:
1953 case QDF_MONITOR_MODE:
1954 ret = hdd_start_station_adapter(adapter);
1955 if (ret)
1956 goto err_start_adapter;
1957 break;
1958 case QDF_P2P_GO_MODE:
1959 case QDF_SAP_MODE:
1960 ret = hdd_start_ap_adapter(adapter);
1961 if (ret)
1962 goto err_start_adapter;
1963 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301964 case QDF_IBSS_MODE:
1965 /*
1966 * For IBSS interface is initialized as part of
1967 * hdd_init_station_mode()
1968 */
1969 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301970 case QDF_FTM_MODE:
1971 ret = hdd_start_ftm_adapter(adapter);
1972 if (ret)
1973 goto err_start_adapter;
1974 break;
1975 default:
1976 hdd_err("Invalid session type %d", device_mode);
1977 QDF_ASSERT(0);
1978 goto err_start_adapter;
1979 }
1980 if (hdd_set_fw_params(adapter))
1981 hdd_err("Failed to set the FW params for the adapter!");
1982
1983 /*
1984 * Action frame registered in one adapter which will
1985 * applicable to all interfaces
1986 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301987 ret = wlan_hdd_cfg80211_register_frames(adapter);
1988 if (ret < 0) {
1989 hdd_err("Failed to register frames - ret %d", ret);
1990 goto err_start_adapter;
1991 }
1992
Arun Khandavallifae92942016-08-01 13:31:08 +05301993 EXIT();
1994 return 0;
1995err_start_adapter:
1996 return -EINVAL;
1997}
1998
1999/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302000 * hdd_enable_power_management() - API to Enable Power Management
2001 *
2002 * API invokes Bus Interface Layer power management functionality
2003 *
2004 * Return: None
2005 */
2006static void hdd_enable_power_management(void)
2007{
2008 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2009
2010 if (!hif_ctx) {
2011 hdd_err("Bus Interface Context is Invalid");
2012 return;
2013 }
2014
2015 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2016}
2017
2018/**
2019 * hdd_disable_power_management() - API to disable Power Management
2020 *
2021 * API disable Bus Interface Layer Power management functionality
2022 *
2023 * Return: None
2024 */
2025static void hdd_disable_power_management(void)
2026{
2027 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2028
2029 if (!hif_ctx) {
2030 hdd_err("Bus Interface Context is Invalid");
2031 return;
2032 }
2033
2034 hif_disable_power_management(hif_ctx);
2035}
2036
2037/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302038 * hdd_update_hw_sw_info() - API to update the HW/SW information
2039 *
2040 * API to update the HW and SW information in the driver
2041 *
2042 * Return: None
2043 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002044static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302045{
2046 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002047 size_t target_hw_name_len;
2048 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302049
2050 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2051 if (!hif_sc) {
2052 hdd_err("HIF context is NULL");
2053 return;
2054 }
2055
2056 /*
2057 * target hw version/revision would only be retrieved after firmware
2058 * download
2059 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002060 hif_get_hw_info(hif_sc,
2061 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302062 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002063 &target_hw_name);
2064
2065 if (hdd_ctx->target_hw_name)
2066 qdf_mem_free(hdd_ctx->target_hw_name);
2067
2068 target_hw_name_len = strlen(target_hw_name) + 1;
2069 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2070 if (hdd_ctx->target_hw_name)
2071 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2072 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302073
2074 /* Get the wlan hw/fw version */
2075 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302076}
2077
2078/**
gbian62edd7e2017-03-07 13:12:13 +08002079 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2080 * @hdd_ctx: Pointer to hdd context
2081 *
2082 * Return: none
2083 */
2084static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002085hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002086{
2087 uint8_t num_entries = 0;
2088 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2089 uint8_t *tx_sched_wrr_ac;
2090 int i;
2091 cds_context_type *cds_ctx;
2092
2093 if (NULL == hdd_ctx)
2094 return;
2095
2096 if (NULL == hdd_ctx->config) {
2097 /* Do nothing if hdd_ctx is invalid */
2098 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2099 return;
2100 }
2101
2102 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2103
2104 if (!cds_ctx) {
2105 hdd_err("Invalid CDS Context");
2106 return;
2107 }
2108
2109 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2110 switch (i) {
2111 case OL_TX_WMM_AC_BE:
2112 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2113 break;
2114 case OL_TX_WMM_AC_BK:
2115 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2116 break;
2117 case OL_TX_WMM_AC_VI:
2118 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2119 break;
2120 case OL_TX_WMM_AC_VO:
2121 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2122 break;
2123 default:
2124 tx_sched_wrr_ac = NULL;
2125 break;
2126 }
2127
2128 hdd_string_to_u8_array(tx_sched_wrr_ac,
2129 tx_sched_wrr_param,
2130 &num_entries,
2131 sizeof(tx_sched_wrr_param));
2132
2133 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2134 cds_ctx->ac_specs[i].wrr_skip_weight =
2135 tx_sched_wrr_param[0];
2136 cds_ctx->ac_specs[i].credit_threshold =
2137 tx_sched_wrr_param[1];
2138 cds_ctx->ac_specs[i].send_limit =
2139 tx_sched_wrr_param[2];
2140 cds_ctx->ac_specs[i].credit_reserve =
2141 tx_sched_wrr_param[3];
2142 cds_ctx->ac_specs[i].discard_weight =
2143 tx_sched_wrr_param[4];
2144 }
2145
2146 num_entries = 0;
2147 }
2148}
2149
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002150#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002151static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2152 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2153{
Jeff Johnson9d295242017-08-29 14:39:48 -07002154 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002155 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002156
2157 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2158 if (!adapter) {
2159 hdd_err("Adapter is NULL");
2160 return PM_MAX_NUM_OF_MODE;
2161 }
2162
2163 return policy_mgr_convert_device_mode_to_qdf_type(
2164 adapter->device_mode);
2165}
2166
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002167static void hdd_register_policy_manager_callback(
2168 struct wlan_objmgr_psoc *psoc)
2169{
2170 struct policy_mgr_hdd_cbacks hdd_cbacks;
2171 hdd_cbacks.sap_restart_chan_switch_cb =
2172 sap_restart_chan_switch_cb;
2173 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2174 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002175 hdd_cbacks.get_mode_for_non_connected_vdev =
2176 wlan_hdd_get_mode_for_non_connected_vdev;
2177
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002178 if (QDF_STATUS_SUCCESS !=
2179 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2180 hdd_err("HDD callback registration with policy manager failed");
2181 }
2182}
2183#else
2184static void hdd_register_policy_manager_callback(
2185 struct wlan_objmgr_psoc *psoc)
2186{
2187}
2188#endif
2189
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002190#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002191static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002192{
2193 struct nan_callbacks cb_obj = {0};
2194
2195 cb_obj.ndi_open = hdd_ndi_open;
2196 cb_obj.ndi_close = hdd_ndi_close;
2197 cb_obj.ndi_start = hdd_ndi_start;
2198 cb_obj.ndi_delete = hdd_ndi_delete;
2199 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2200 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2201
Naveen Rawat37f62c82017-03-26 22:24:43 -07002202 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2203 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002204 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002205
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002206 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2207}
2208#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002209static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002210{
2211}
2212#endif
2213
gbian62edd7e2017-03-07 13:12:13 +08002214/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302215 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2216 * @hdd_ctx: HDD context
2217 * @adapter: HDD adapter
2218 * @reinit: flag to indicate from SSR or normal path
2219 *
2220 * This function maintains the driver state machine it will be invoked from
2221 * startup, reinit and change interface. Depending on the driver state shall
2222 * perform the opening of the modules.
2223 *
2224 * Return: 0 for success; non-zero for failure
2225 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002226int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2227 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302228 bool reinit)
2229{
2230 int ret;
2231 qdf_device_t qdf_dev;
2232 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302233 bool unint = false;
2234 void *hif_ctx;
2235
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002236 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302237
2238 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2239 if (!qdf_dev) {
2240 hdd_err("QDF Device Context is Invalid return");
2241 return -EINVAL;
2242 }
2243
2244 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302245 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302246
2247 if (QDF_TIMER_STATE_RUNNING ==
2248 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2249
2250 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002251 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302252 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2253 }
2254
2255 switch (hdd_ctx->driver_status) {
2256 case DRIVER_MODULES_UNINITIALIZED:
2257 unint = true;
2258 /* Fall through dont add break here */
2259 case DRIVER_MODULES_CLOSED:
2260 if (!reinit && !unint) {
2261 ret = pld_power_on(qdf_dev->dev);
2262 if (ret) {
2263 hdd_err("Failed to Powerup the device: %d", ret);
2264 goto release_lock;
2265 }
2266 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002267
2268 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2269 hdd_ctx->config->enable_fw_log);
2270
Arun Khandavallifae92942016-08-01 13:31:08 +05302271 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2272 qdf_dev->bus_type,
2273 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2274 HIF_ENABLE_TYPE_PROBE);
2275 if (ret) {
2276 hdd_err("Failed to open hif: %d", ret);
2277 goto power_down;
2278 }
2279
2280 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302281 if (!hif_ctx) {
2282 hdd_err("hif context is null!!");
2283 goto power_down;
2284 }
2285
Arun Khandavallifae92942016-08-01 13:31:08 +05302286 status = ol_cds_init(qdf_dev, hif_ctx);
2287 if (status != QDF_STATUS_SUCCESS) {
2288 hdd_err("No Memory to Create BMI Context :%d", status);
2289 goto hif_close;
2290 }
2291
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002292 ret = hdd_update_config(hdd_ctx);
2293 if (ret) {
2294 hdd_err("Failed to update configuration :%d", ret);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002295 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002296 }
2297
gbian62edd7e2017-03-07 13:12:13 +08002298 hdd_update_cds_ac_specs_params(hdd_ctx);
2299
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302300 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302301 if (!QDF_IS_STATUS_SUCCESS(status)) {
2302 hdd_err("Failed to Open CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002303 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302304 }
2305
Mukul Sharma9d797a02017-01-05 20:26:03 +05302306 /* initalize components configurations after psoc open */
2307 ret = hdd_update_components_config(hdd_ctx);
2308 if (ret) {
2309 hdd_err("Failed to update components configs :%d",
2310 ret);
2311 goto close;
2312 }
2313
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002314 /*
2315 * NAN compoenet requires certian operations like, open adapter,
2316 * close adapter, etc. to be initiated by HDD, for those
2317 * register HDD callbacks with UMAC's NAN componenet.
2318 */
2319 hdd_nan_register_callbacks(hdd_ctx);
2320
Arun Khandavallifae92942016-08-01 13:31:08 +05302321 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2322
Jeff Johnson3a280122017-09-13 07:42:00 -07002323 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302324 if (!QDF_IS_STATUS_SUCCESS(status)) {
2325 hdd_err("Failed to pre-enable CDS: %d", status);
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002326 goto close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 }
2328
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002329 hdd_register_policy_manager_callback(
2330 hdd_ctx->hdd_psoc);
2331
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302332 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302333 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302334
Arun Khandavallifae92942016-08-01 13:31:08 +05302335 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2336 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2337 hdd_ftm_mc_process_msg);
2338 break;
2339 }
2340 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002341 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 break;
2343 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302344
2345 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002346 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2347 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002348 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002349 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302350 }
2351
Arun Khandavallifae92942016-08-01 13:31:08 +05302352 /* Fall through dont add break here */
2353 case DRIVER_MODULES_OPENED:
2354 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002355 hdd_alert("adapter is Null");
2356 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302357 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302358 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2359 hdd_err("in ftm mode, no need to configure cds modules");
2360 break;
2361 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302362 if (hdd_configure_cds(hdd_ctx, adapter)) {
2363 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002364 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302365 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302366 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302367 hdd_info("Driver Modules Successfully Enabled");
2368 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2369 break;
2370 case DRIVER_MODULES_ENABLED:
2371 hdd_info("Driver modules already Enabled");
2372 break;
2373 default:
2374 hdd_err("WLAN start invoked in wrong state! :%d\n",
2375 hdd_ctx->driver_status);
2376 goto release_lock;
2377 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302378 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302379 mutex_unlock(&hdd_ctx->iface_change_lock);
2380 EXIT();
2381 return 0;
2382
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002383post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002384 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002385
Arun Khandavallifae92942016-08-01 13:31:08 +05302386close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002387 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002388 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302389
Venkata Sharath Chandra Manchala9abac312017-10-04 16:29:15 -07002390ol_cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302391 ol_cds_free();
2392
2393hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002394 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2395 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302396power_down:
2397 if (!reinit && !unint)
2398 pld_power_off(qdf_dev->dev);
2399release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302400 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302401 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302402 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002403
Arun Khandavallifae92942016-08-01 13:31:08 +05302404 return -EINVAL;
2405}
2406
Naveen Rawat910726a2017-03-06 11:42:51 -08002407#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002408static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002409{
2410 int ret = os_if_wifi_pos_register_nl();
2411
2412 if (ret)
2413 hdd_err("os_if_wifi_pos_register_nl failed");
2414
2415 return ret;
2416}
2417
2418static int hdd_deactivate_wifi_pos(void)
2419{
2420 int ret = os_if_wifi_pos_deregister_nl();
2421
2422 if (ret)
2423 hdd_err("os_if_wifi_pos_deregister_nl failed");
2424
2425 return ret;
2426}
2427
2428/**
2429 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2430 * @hdd_ctx: hdd context
2431 *
2432 * Return: status of operation
2433 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002434static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002435{
2436 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2437 struct hdd_config *cfg = hdd_ctx->config;
2438
2439 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2440 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2441 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2442 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2443 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2444 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2445 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2446 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2447}
2448#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002449static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002450{
2451 return oem_activate_service(hdd_ctx);
2452}
2453
2454static int hdd_deactivate_wifi_pos(void)
2455{
2456 return 0;
2457}
2458
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002459static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002460{
2461}
2462#endif
2463
Arun Khandavallifae92942016-08-01 13:31:08 +05302464/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002465 * __hdd_open() - HDD Open function
2466 * @dev: Pointer to net_device structure
2467 *
2468 * This is called in response to ifconfig up
2469 *
2470 * Return: 0 for success; non-zero for failure
2471 */
2472static int __hdd_open(struct net_device *dev)
2473{
Jeff Johnson9d295242017-08-29 14:39:48 -07002474 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002475 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002476 int ret;
2477
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002478 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302479 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302480 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002481
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302482 if (!hdd_wait_for_recovery_completion()) {
2483 hdd_err("Recovery failed");
2484 return -EIO;
2485 }
2486
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302487 /* Nothing to be done if device is unloading */
2488 if (cds_is_driver_unloading()) {
2489 hdd_err("Driver is unloading can not open the hdd");
2490 return -EBUSY;
2491 }
2492
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302493 mutex_lock(&hdd_init_deinit_lock);
2494
2495 /*
2496 * This scenario can be hit in cases where in the wlan driver after
2497 * registering the netdevices and there is a failure in driver
2498 * initialization. So return error gracefully because the netdevices
2499 * will be de-registered as part of the load failure.
2500 */
2501
2502 if (!cds_is_driver_loaded()) {
2503 hdd_err("Failed to start the wlan driver!!");
2504 ret = -EIO;
2505 goto err_hdd_hdd_init_deinit_lock;
2506 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002508
Arun Khandavallifae92942016-08-01 13:31:08 +05302509 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2510 if (ret) {
2511 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302512 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302513 }
2514
2515
2516 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2517 ret = hdd_start_adapter(adapter);
2518 if (ret) {
2519 hdd_err("Failed to start adapter :%d",
2520 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302521 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302522 }
2523 }
2524
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002525 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2526 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002527 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002528 /* Enable TX queues only when we are connected */
2529 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302530 WLAN_START_ALL_NETIF_QUEUE,
2531 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002532 }
2533
Naveen Rawat286def52016-09-23 15:38:02 -07002534 /* Enable carrier and transmit queues for NDI */
2535 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002536 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002537 wlan_hdd_netif_queue_control(adapter,
2538 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2539 WLAN_CONTROL_PATH);
2540 }
2541
Naveen Rawat910726a2017-03-06 11:42:51 -08002542 hdd_populate_wifi_pos_cfg(hdd_ctx);
2543
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302544err_hdd_hdd_init_deinit_lock:
2545 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002546 return ret;
2547}
2548
Arun Khandavallifae92942016-08-01 13:31:08 +05302549
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002550/**
2551 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2552 * @dev: Pointer to net_device structure
2553 *
2554 * This is called in response to ifconfig up
2555 *
2556 * Return: 0 for success; non-zero for failure
2557 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002558static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002559{
2560 int ret;
2561
2562 cds_ssr_protect(__func__);
2563 ret = __hdd_open(dev);
2564 cds_ssr_unprotect(__func__);
2565
2566 return ret;
2567}
2568
2569/**
2570 * __hdd_stop() - HDD stop function
2571 * @dev: Pointer to net_device structure
2572 *
2573 * This is called in response to ifconfig down
2574 *
2575 * Return: 0 for success; non-zero for failure
2576 */
2577static int __hdd_stop(struct net_device *dev)
2578{
Jeff Johnson9d295242017-08-29 14:39:48 -07002579 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002580 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581 int ret;
2582
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002583 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002584
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302585 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586 adapter->sessionId, adapter->device_mode));
2587
2588 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302589 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002591
2592 /* Nothing to be done if the interface is not opened */
2593 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002594 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002595 return -ENODEV;
2596 }
2597
2598 /* Make sure the interface is marked as closed */
2599 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302600
2601 hdd_debug("Disabling Auto Power save timer");
2602 sme_ps_disable_auto_ps_timer(
2603 WLAN_HDD_GET_HAL_CTX(adapter),
2604 adapter->sessionId);
2605
2606 /*
2607 * Disable TX on the interface, after this hard_start_xmit() will not
2608 * be called on that interface
2609 */
2610 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302611 wlan_hdd_netif_queue_control(adapter,
2612 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2613 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614
2615 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002616 * NAN data interface is different in some sense. The traffic on NDI is
2617 * bursty in nature and depends on the need to transfer. The service
2618 * layer may down the interface after the usage and up again when
2619 * required. In some sense, the NDI is expected to be available
2620 * (like SAP) iface until NDI delete request is issued by the service
2621 * layer. Skip BSS termination and adapter deletion for NAN Data
2622 * interface (NDI).
2623 */
2624 if (WLAN_HDD_IS_NDI(adapter))
2625 return 0;
2626
2627 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 * The interface is marked as down for outside world (aka kernel)
2629 * But the driver is pretty much alive inside. The driver needs to
2630 * tear down the existing connection on the netdev (session)
2631 * cleanup the data pipes and wait until the control plane is stabilized
2632 * for this interface. The call also needs to wait until the above
2633 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002634 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635 * That is intentional to be able to scan if it is a STA/P2P interface
2636 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302637 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638
2639 /* DeInit the adapter. This ensures datapath cleanup as well */
2640 hdd_deinit_adapter(hdd_ctx, adapter, true);
2641
Arun Khandavallifae92942016-08-01 13:31:08 +05302642
2643 /*
2644 * Find if any iface is up. If any iface is up then can't put device to
2645 * sleep/power save mode
2646 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302647 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002648 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302649 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302650 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302651 }
2652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002653 EXIT();
2654 return 0;
2655}
2656
2657/**
2658 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2659 * @dev: pointer to net_device structure
2660 *
2661 * This is called in response to ifconfig down
2662 *
2663 * Return: 0 for success and error number for failure
2664 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002665static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002666{
2667 int ret;
2668
2669 cds_ssr_protect(__func__);
2670 ret = __hdd_stop(dev);
2671 cds_ssr_unprotect(__func__);
2672
2673 return ret;
2674}
2675
2676/**
2677 * __hdd_uninit() - HDD uninit function
2678 * @dev: Pointer to net_device structure
2679 *
2680 * This is called during the netdev unregister to uninitialize all data
2681 * associated with the device
2682 *
2683 * Return: None
2684 */
2685static void __hdd_uninit(struct net_device *dev)
2686{
Jeff Johnson9d295242017-08-29 14:39:48 -07002687 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002688 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002689
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002690 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691
2692 do {
2693 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002694 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 break;
2696 }
2697
Jeff Johnson399c6272017-08-30 10:51:00 -07002698 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2699 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002700 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701 break;
2702 }
2703
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002704 if (dev != adapter->dev)
2705 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002706
Jeff Johnson399c6272017-08-30 10:51:00 -07002707 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002708
2709 /* after uninit our adapter structure will no longer be valid */
2710 adapter->dev = NULL;
2711 adapter->magic = 0;
2712 } while (0);
2713
2714 EXIT();
2715}
2716
2717/**
2718 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2719 * @dev: pointer to net_device structure
2720 *
2721 * This is called during the netdev unregister to uninitialize all data
2722 * associated with the device
2723 *
2724 * Return: none
2725 */
2726static void hdd_uninit(struct net_device *dev)
2727{
2728 cds_ssr_protect(__func__);
2729 __hdd_uninit(dev);
2730 cds_ssr_unprotect(__func__);
2731}
2732
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002733static int hdd_open_cesium_nl_sock(void)
2734{
2735#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2736 struct netlink_kernel_cfg cfg = {
2737 .groups = WLAN_NLINK_MCAST_GRP_ID,
2738 .input = NULL
2739 };
2740#endif
2741 int ret = 0;
2742
2743#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2744 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2745#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2746 THIS_MODULE,
2747#endif
2748 &cfg);
2749#else
2750 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2751 WLAN_NLINK_MCAST_GRP_ID,
2752 NULL, NULL, THIS_MODULE);
2753#endif
2754
2755 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002756 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002757 ret = -ECONNREFUSED;
2758 }
2759
2760 return ret;
2761}
2762
2763static void hdd_close_cesium_nl_sock(void)
2764{
2765 if (NULL != cesium_nl_srv_sock) {
2766 netlink_kernel_release(cesium_nl_srv_sock);
2767 cesium_nl_srv_sock = NULL;
2768 }
2769}
2770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002771/**
2772 * __hdd_set_mac_address() - set the user specified mac address
2773 * @dev: Pointer to the net device.
2774 * @addr: Pointer to the sockaddr.
2775 *
2776 * This function sets the user specified mac address using
2777 * the command ifconfig wlanX hw ether <mac adress>.
2778 *
2779 * Return: 0 for success, non zero for failure
2780 */
2781static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2782{
Jeff Johnson9d295242017-08-29 14:39:48 -07002783 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002784 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302786 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 int ret;
2788
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002789 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002790
2791 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2792 ret = wlan_hdd_validate_context(hdd_ctx);
2793 if (0 != ret)
2794 return ret;
2795
2796 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2797 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2798
2799 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302800 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801}
2802
2803/**
2804 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2805 * function from SSR
2806 * @dev: pointer to net_device structure
2807 * @addr: Pointer to the sockaddr
2808 *
2809 * This function sets the user specified mac address using
2810 * the command ifconfig wlanX hw ether <mac adress>.
2811 *
2812 * Return: 0 for success.
2813 */
2814static int hdd_set_mac_address(struct net_device *dev, void *addr)
2815{
2816 int ret;
2817
2818 cds_ssr_protect(__func__);
2819 ret = __hdd_set_mac_address(dev, addr);
2820 cds_ssr_unprotect(__func__);
2821
2822 return ret;
2823}
2824
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002825uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826{
2827 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002828
Anurag Chouhan6d760662016-02-20 16:05:43 +05302829 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2831 break;
2832 }
2833
Anurag Chouhan6d760662016-02-20 16:05:43 +05302834 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002835 return NULL;
2836
2837 hdd_ctx->config->intfAddrMask |= (1 << i);
2838 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2839}
2840
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002841void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842{
2843 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002844
Anurag Chouhan6d760662016-02-20 16:05:43 +05302845 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002846 if (!memcmp(releaseAddr,
2847 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2848 6)) {
2849 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2850 break;
2851 }
2852 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853}
2854
2855#ifdef WLAN_FEATURE_PACKET_FILTERING
2856/**
2857 * __hdd_set_multicast_list() - set the multicast address list
2858 * @dev: Pointer to the WLAN device.
2859 * @skb: Pointer to OS packet (sk_buff).
2860 *
2861 * This funciton sets the multicast address list.
2862 *
2863 * Return: None
2864 */
2865static void __hdd_set_multicast_list(struct net_device *dev)
2866{
Jeff Johnson9d295242017-08-29 14:39:48 -07002867 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002868 int i = 0, status;
2869 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002870 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302871 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2872 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2873 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002875 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302876 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302877 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302880 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302881 goto out;
2882
Dustin Brownc788acb2017-08-01 17:43:51 -07002883 status = hdd_validate_adapter(adapter);
2884 if (status)
2885 goto out;
2886
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302887 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2888 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002889 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302890 goto out;
2891 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302893 /* Delete already configured multicast address list */
2894 if (adapter->mc_addr_list.mc_cnt > 0) {
2895 hdd_info("clear previously configured MC address list");
2896 hdd_disable_and_flush_mc_addr_list(adapter,
2897 pmo_mc_list_change_notify);
2898 }
2899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002901 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302902 hdd_disable_and_flush_mc_addr_list(adapter,
2903 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904 } else {
2905 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302906 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002907 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302908 pmo_ucfg_max_mc_addr_supported(psoc));
2909 hdd_disable_and_flush_mc_addr_list(adapter,
2910 pmo_mc_list_change_notify);
2911 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002912 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002914 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302915 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916 if (i == mc_count)
2917 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302918 memset(&(mc_list_request->mc_addr[i].bytes),
2919 0, ETH_ALEN);
2920 memcpy(&(mc_list_request->mc_addr[i].bytes),
2921 ha->addr, ETH_ALEN);
2922 hdd_info("mlist[%d] = %pM", i,
2923 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924 i++;
2925 }
2926 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302927
2928 mc_list_request->psoc = psoc;
2929 mc_list_request->vdev_id = adapter->sessionId;
2930 mc_list_request->count = mc_count;
2931 status = hdd_cache_mc_addr_list(mc_list_request);
2932 if (status == 0) {
2933 hdd_enable_mc_addr_filtering(adapter,
2934 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302936 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002937 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302938out:
2939 if (mc_list_request)
2940 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302941 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942}
2943
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945/**
2946 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2947 * @dev: pointer to net_device
2948 *
2949 * Return: none
2950 */
2951static void hdd_set_multicast_list(struct net_device *dev)
2952{
2953 cds_ssr_protect(__func__);
2954 __hdd_set_multicast_list(dev);
2955 cds_ssr_unprotect(__func__);
2956}
2957#endif
2958
2959/**
2960 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2961 * @dev: Pointer to the WLAN device.
2962 * @skb: Pointer to OS packet (sk_buff).
2963 *
2964 * This function is registered with the Linux OS for network
2965 * core to decide which queue to use first.
2966 *
2967 * Return: ac, Queue Index/access category corresponding to UP in IP header
2968 */
2969static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2970#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2971 , void *accel_priv
2972#endif
2973#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2974 , select_queue_fallback_t fallback
2975#endif
2976)
2977{
2978 return hdd_wmm_select_queue(dev, skb);
2979}
2980
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002981static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 .ndo_open = hdd_open,
2983 .ndo_stop = hdd_stop,
2984 .ndo_uninit = hdd_uninit,
2985 .ndo_start_xmit = hdd_hard_start_xmit,
2986 .ndo_tx_timeout = hdd_tx_timeout,
2987 .ndo_get_stats = hdd_get_stats,
2988 .ndo_do_ioctl = hdd_ioctl,
2989 .ndo_set_mac_address = hdd_set_mac_address,
2990 .ndo_select_queue = hdd_select_queue,
2991#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993#endif
2994};
2995
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002996/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002997static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002998 .ndo_open = hdd_mon_open,
2999 .ndo_stop = hdd_stop,
3000 .ndo_get_stats = hdd_get_stats,
3001};
3002
3003/**
3004 * hdd_set_station_ops() - update net_device ops for monitor mode
3005 * @pWlanDev: Handle to struct net_device to be updated.
3006 * Return: None
3007 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008void hdd_set_station_ops(struct net_device *pWlanDev)
3009{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003010 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3011 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3012 else
3013 pWlanDev->netdev_ops = &wlan_drv_ops;
3014}
3015
Komal Seelama89be8d2016-09-29 11:09:26 +05303016#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05303017/**
3018 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
3019 * @hdd_ctx: HDD context
3020 *
3021 * Return: None
3022 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003023static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303024{
3025 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3026
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003027 qdf_runtime_lock_init(&ctx->roc);
3028 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05303029}
3030
3031/**
3032 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
3033 * @hdd_ctx: HDD Context
3034 *
3035 * Return: None
3036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003037static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303038{
3039 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3040
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003041 qdf_runtime_lock_deinit(&ctx->roc);
3042 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05303043
3044 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05303045}
3046
Jeff Johnson9d295242017-08-29 14:39:48 -07003047static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303048{
3049 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3050
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003051 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303052}
3053
Jeff Johnson9d295242017-08-29 14:39:48 -07003054static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303055{
3056 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3057
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003058 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303059}
3060#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003061static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3062static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003063static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3064static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303065#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003066/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003067 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3068 * @hdd_ctx: global hdd context
3069 * @macAddr: mac address to assign to the interface
3070 * @name: User-visible name of the interface
3071 *
3072 * hdd adapter pointer would point to the netdev->priv space, this function
3073 * would retrive the pointer, and setup the hdd adapter configuration.
3074 *
3075 * Return: the pointer to hdd adapter, otherwise NULL
3076 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003077static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003078 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003079 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 const char *name)
3081{
3082 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003083 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003084 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085 /*
3086 * cfg80211 initialization and registration....
3087 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003088 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003089#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3090 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003092 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3093 hdd_mon_mode_ether_setup : ether_setup),
3094 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095
3096 if (pWlanDev != NULL) {
3097
3098 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003099 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100
Jeff Johnson9d295242017-08-29 14:39:48 -07003101 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303102 sta_ctx = &adapter->sessionCtx.station;
3103 qdf_mem_set(sta_ctx->conn_info.staId,
3104 sizeof(sta_ctx->conn_info.staId),
3105 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003107 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303109 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110
3111 init_completion(&adapter->session_open_comp_var);
3112 init_completion(&adapter->session_close_comp_var);
3113 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303114 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 init_completion(&adapter->linkup_event_var);
3116 init_completion(&adapter->cancel_rem_on_chan_var);
3117 init_completion(&adapter->rem_on_chan_ready_event);
3118 init_completion(&adapter->sta_authorized_event);
3119 init_completion(&adapter->offchannel_tx_event);
3120 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003121 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 init_completion(&adapter->change_country_code);
3123
3124
3125 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303126 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127
3128 adapter->offloads_configured = false;
3129 adapter->isLinkUpSvcNeeded = false;
3130 adapter->higherDtimTransition = true;
3131 /* Init the net_device structure */
3132 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3133
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303134 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303136 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 sizeof(tSirMacAddr));
3138 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003139
3140 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3141 pWlanDev->features |=
3142 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3143 pWlanDev->features |= NETIF_F_RXCSUM;
3144
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003145 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003147 hdd_set_station_ops(adapter->dev);
3148
Dustin Brownc81dd412017-08-15 16:26:28 -07003149 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003151 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152 adapter->wdev.wiphy = hdd_ctx->wiphy;
3153 adapter->wdev.netdev = pWlanDev;
3154 /* set pWlanDev's parent to underlying device */
3155 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3156 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303157 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303159 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 }
3161
3162 return adapter;
3163}
3164
Jeff Johnson9d295242017-08-29 14:39:48 -07003165static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003167 struct net_device *dev = adapter->dev;
3168 int ret;
3169
3170 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003172 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003173 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3174
3175 ret = dev_alloc_name(dev, dev->name);
3176 if (ret < 0) {
3177 hdd_err(
3178 "unable to get dev name: %s, err = 0x%x",
3179 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303180 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 }
3182 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003183
3184 ret = register_netdevice(dev);
3185 if (ret) {
3186 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3187 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303188 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189 }
3190 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003191 ret = register_netdev(dev);
3192 if (ret) {
3193 hdd_err("register_netdev(%s) failed, err = 0x%x",
3194 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303195 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196 }
3197 }
3198 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3199
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003200 EXIT();
3201
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303202 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203}
3204
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003205QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206{
Jeff Johnson9d295242017-08-29 14:39:48 -07003207 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208
3209 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003210 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303211 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 }
3213
3214 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003215 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303216 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 }
3218
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003219 /*
3220 * For NAN Data interface, the close session results in the final
3221 * indication to the userspace
3222 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003223 if (adapter->device_mode == QDF_NDI_MODE)
3224 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228 /*
3229 * We can be blocked while waiting for scheduled work to be
3230 * flushed, and the adapter structure can potentially be freed, in
3231 * which case the magic will have been reset. So make sure the
3232 * magic is still good, and hence the adapter structure is still
3233 * valid, before signaling completion
3234 */
3235 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3236 complete(&adapter->session_close_comp_var);
3237
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303238 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239}
3240
Jeff Johnson9d295242017-08-29 14:39:48 -07003241int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242{
Dustin Brownd28772b2017-03-17 14:16:07 -07003243 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244
Dustin Brownd28772b2017-03-17 14:16:07 -07003245 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003246 if (QDF_IS_STATUS_ERROR(status))
3247 return qdf_status_to_os_return(status);
3248
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003249 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003250 if (QDF_IS_STATUS_ERROR(status))
3251 return qdf_status_to_os_return(status);
3252
3253 if (wma_capability_enhanced_mcast_filter())
3254 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3255 else
3256 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003257
3258 return qdf_status_to_os_return(status);
3259}
3260
Jeff Johnson9d295242017-08-29 14:39:48 -07003261int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003262{
3263 QDF_STATUS status;
3264 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003265 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003266 unsigned long rc;
3267
3268 hdd_info("destroying vdev %d", adapter->sessionId);
3269
3270 /* vdev created sanity check */
3271 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3272 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3273 return -EINVAL;
3274 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003275 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003276 /*
3277 * In SSR case, there is no need to destroy vdev in firmware since
3278 * it has already asserted. vdev can be released directly.
3279 */
3280 if (cds_is_driver_recovering())
3281 goto release_vdev;
3282
Dustin Brownd28772b2017-03-17 14:16:07 -07003283 /* close sme session (destroy vdev in firmware via legacy API) */
3284 INIT_COMPLETION(adapter->session_close_comp_var);
3285 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3286 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3287 hdd_sme_close_session_callback, adapter);
3288 if (QDF_IS_STATUS_ERROR(status)) {
3289 hdd_err("failed to close sme session: %d", status);
3290 return qdf_status_to_os_return(status);
3291 }
3292
3293 /* block on a completion variable until sme session is closed */
3294 rc = wait_for_completion_timeout(
3295 &adapter->session_close_comp_var,
3296 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3297 if (!rc) {
3298 hdd_err("timed out waiting for close sme session: %ld", rc);
3299 if (adapter->device_mode == QDF_NDI_MODE)
3300 hdd_ndp_session_end_handler(adapter);
3301 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3302 return -ETIMEDOUT;
3303 }
Yue Maf9782842017-05-08 12:49:49 -07003304release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003305 /* do vdev logical destroy via objmgr */
3306 errno = hdd_objmgr_destroy_vdev(adapter);
3307 if (errno) {
3308 hdd_err("failed to destroy objmgr vdev: %d", errno);
3309 return errno;
3310 }
3311
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003312 /* now that sme session is closed, allow physical vdev destroy */
3313 errno = hdd_objmgr_release_vdev(adapter);
3314 if (errno) {
3315 hdd_err("failed to release objmgr vdev: %d", errno);
3316 return errno;
3317 }
3318
Dustin Brownd28772b2017-03-17 14:16:07 -07003319 hdd_info("vdev destroyed successfully");
3320
3321 return 0;
3322}
3323
Jeff Johnson9d295242017-08-29 14:39:48 -07003324int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003325{
3326 QDF_STATUS status;
3327 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003328 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003329 uint32_t type;
3330 uint32_t sub_type;
3331 unsigned long rc;
3332
3333 hdd_info("creating new vdev");
3334
3335 /* determine vdev (sub)type */
3336 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303337 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003338 hdd_err("failed to get vdev type: %d", status);
3339 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003341
3342 /* do vdev create via objmgr */
3343 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003344 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003345 if (errno) {
3346 hdd_err("failed to create objmgr vdev: %d", errno);
3347 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003349
3350 /* Open a SME session (prepare vdev in firmware via legacy API) */
3351 INIT_COMPLETION(adapter->session_open_comp_var);
3352 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3353 (uint8_t *)&adapter->macAddressCurrent,
3354 adapter->sessionId, type, sub_type);
3355 if (QDF_IS_STATUS_ERROR(status)) {
3356 hdd_err("failed to open sme session: %d", status);
3357 errno = qdf_status_to_os_return(status);
3358 goto objmgr_vdev_destroy;
3359 }
3360
3361 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362 rc = wait_for_completion_timeout(
3363 &adapter->session_open_comp_var,
3364 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3365 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003366 hdd_err("timed out waiting for open sme session: %ld", rc);
3367 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303368 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3369 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003370 }
3371
3372 /* firmware ready for component communication, raise vdev_ready event */
3373 errno = hdd_vdev_ready(adapter);
3374 if (errno) {
3375 hdd_err("failed to dispatch vdev ready event: %d", errno);
3376 goto hdd_vdev_destroy;
3377 }
3378
3379 hdd_info("vdev %d created successfully", adapter->sessionId);
3380
3381 return 0;
3382
3383 /*
3384 * Due to legacy constraints, we need to destroy in the same order as
3385 * create. So, split error handling into 2 cases to accommodate.
3386 */
3387
3388objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003389 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003390
3391 return errno;
3392
3393hdd_vdev_destroy:
3394 QDF_BUG(!hdd_vdev_destroy(adapter));
3395
3396 return errno;
3397}
3398
Jeff Johnson9d295242017-08-29 14:39:48 -07003399QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003400{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003401 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003402 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003403 QDF_STATUS status;
3404 int ret_val;
3405
3406 ret_val = hdd_vdev_create(adapter);
3407 if (ret_val) {
3408 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303409 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 }
3411
Dustin Brownd28772b2017-03-17 14:16:07 -07003412 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3413 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3414 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003415 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003418 status = hdd_register_wext(adapter->dev);
3419 if (QDF_IS_STATUS_ERROR(status)) {
3420 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 goto error_register_wext;
3422 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003423 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303425 qdf_mem_set(pHddStaCtx->conn_info.staId,
3426 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3427
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003428 /* set fast roaming capability in sme session */
3429 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3430 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 /* Set the default operation channel */
3432 pHddStaCtx->conn_info.operationChannel =
3433 hdd_ctx->config->OperatingChannel;
3434
3435 /* Make the default Auth Type as OPEN */
3436 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3437
3438 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303439 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003440 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 status, status);
3442 goto error_init_txrx;
3443 }
3444
3445 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3446
3447 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303448 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003449 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 status, status);
3451 goto error_wmm_init;
3452 }
3453
3454 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3455
Naveen Rawat247a8682017-06-05 15:00:31 -07003456 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457 WMI_PDEV_PARAM_BURST_ENABLE,
3458 hdd_ctx->config->enableSifsBurst,
3459 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003460 if (ret_val)
3461 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003463 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303464 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466error_wmm_init:
3467 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3468 hdd_deinit_tx_rx(adapter);
3469error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003470 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003472 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 return status;
3475}
3476
Jeff Johnson9d295242017-08-29 14:39:48 -07003477void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478{
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003479 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480
3481 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3482
3483 if (NULL != cfgState->buf) {
3484 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 rc = wait_for_completion_timeout(
3487 &adapter->tx_action_cnf_event,
3488 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3489 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003490 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303491 /*
3492 * Inform tx status as FAILURE to upper layer and free
3493 * cfgState->buf
3494 */
3495 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496 }
3497 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498}
3499
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303500/**
3501 * hdd_station_adapter_deinit() - De-initialize the station adapter
3502 * @hdd_ctx: global hdd context
3503 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003504 * @rtnl_held: Used to indicate whether or not the caller is holding
3505 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303506 *
3507 * This function De-initializes the STA/P2P/OCB adapter.
3508 *
3509 * Return: None.
3510 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003511static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003512 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003513 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303514{
3515 ENTER_DEV(adapter->dev);
3516
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303517 if (adapter->dev) {
3518 if (rtnl_held)
3519 adapter->dev->wireless_handlers = NULL;
3520 else {
3521 rtnl_lock();
3522 adapter->dev->wireless_handlers = NULL;
3523 rtnl_unlock();
3524 }
3525 }
3526
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303527 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3528 hdd_deinit_tx_rx(adapter);
3529 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3530 }
3531
3532 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3533 hdd_wmm_adapter_close(adapter);
3534 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3535 }
3536
3537 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303538
3539 EXIT();
3540}
3541
3542/**
3543 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3544 * @hdd_ctx: global hdd context
3545 * @adapter: HDD adapter
3546 * @rtnl_held: the rtnl lock hold flag
3547 * This function De-initializes the AP/P2PGo adapter.
3548 *
3549 * Return: None.
3550 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003551static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003552 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003553 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303554{
3555 ENTER_DEV(adapter->dev);
3556
3557 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3558 hdd_wmm_adapter_close(adapter);
3559 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3560 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003561 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303562
3563 hdd_cleanup_actionframe(hdd_ctx, adapter);
3564
3565 hdd_unregister_hostapd(adapter, rtnl_held);
3566
3567 EXIT();
3568}
3569
Jeff Johnson9d295242017-08-29 14:39:48 -07003570void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571 bool rtnl_held)
3572{
3573 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003576 case QDF_STA_MODE:
3577 case QDF_P2P_CLIENT_MODE:
3578 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303580 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 break;
3582 }
3583
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003584 case QDF_SAP_MODE:
3585 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586 {
3587
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303588 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 break;
3590 }
3591
3592 default:
3593 break;
3594 }
3595
3596 EXIT();
3597}
3598
Jeff Johnson9d295242017-08-29 14:39:48 -07003599static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003600 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601{
3602 struct net_device *pWlanDev = NULL;
3603
3604 if (adapter)
3605 pWlanDev = adapter->dev;
3606 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003607 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 return;
3609 }
3610
Rajeev Kumardca5f812016-02-04 17:28:06 -08003611 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303612
3613 if (adapter->scan_info.default_scan_ies) {
3614 qdf_mem_free(adapter->scan_info.default_scan_ies);
3615 adapter->scan_info.default_scan_ies = NULL;
3616 }
3617
Komal Seelama89be8d2016-09-29 11:09:26 +05303618 hdd_adapter_runtime_suspend_denit(adapter);
3619
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 /*
3621 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3622 * the driver is almost closed and cannot handle either control
3623 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003624 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3625 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 * is not right. Setting this flag helps hdd_stop() to recognize that
3627 * the interface is closed and restricts any operations on that
3628 */
3629 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3630
3631 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003632 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003634 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 /*
3637 * Note that the adapter is no longer valid at this point
3638 * since the memory has been reclaimed
3639 */
3640 }
3641}
3642
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003643static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003644 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645{
3646 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003647 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303648 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003649
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303651 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003652 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303654 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303656 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 }
3658 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3659 adapterNode = pNext;
3660 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303661 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003663
Arun Khandavalli2358d522016-05-16 18:05:37 +05303664#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3665/**
3666 * hdd_set_fw_log_params() - Set log parameters to FW
3667 * @hdd_ctx: HDD Context
3668 * @adapter: HDD Adapter
3669 *
3670 * This function set the FW Debug log level based on the INI.
3671 *
3672 * Return: None
3673 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003674static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003675 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303676{
3677 uint8_t count = 0, numentries = 0,
3678 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3679 uint32_t value = 0;
3680 int ret;
3681
Arun Khandavallifae92942016-08-01 13:31:08 +05303682 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3683 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003684 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303685 return;
3686 }
3687
Arun Khandavallifae92942016-08-01 13:31:08 +05303688 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303689 hdd_ctx->fw_log_settings.dl_type =
3690 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003691 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303692 WMI_DBGLOG_TYPE,
3693 hdd_ctx->config->enableFwLogType,
3694 DBG_CMD);
3695 if (ret != 0)
3696 hdd_err("Failed to enable FW log type ret %d",
3697 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303698
3699 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303700 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003701 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303702 WMI_DBGLOG_LOG_LEVEL,
3703 hdd_ctx->config->enableFwLogLevel,
3704 DBG_CMD);
3705 if (ret != 0)
3706 hdd_err("Failed to enable FW log level ret %d",
3707 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303708
3709 hdd_string_to_u8_array(
3710 hdd_ctx->config->enableFwModuleLogLevel,
3711 moduleloglevel,
3712 &numentries,
3713 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3714
3715 while (count < numentries) {
3716 /*
3717 * FW module log level input string looks like
3718 * below:
3719 * gFwDebugModuleLoglevel=<FW Module ID>,
3720 * <Log Level>,...
3721 * For example:
3722 * gFwDebugModuleLoglevel=
3723 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3724 * Above input string means :
3725 * For FW module ID 1 enable log level 0
3726 * For FW module ID 2 enable log level 1
3727 * For FW module ID 3 enable log level 2
3728 * For FW module ID 4 enable log level 3
3729 * For FW module ID 5 enable log level 4
3730 * For FW module ID 6 enable log level 5
3731 * For FW module ID 7 enable log level 6
3732 */
3733
Nishank Aggarwale239d962017-03-03 12:26:02 +05303734 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3735 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3736 hdd_err("Module id %d and dbglog level %d input length is more than max",
3737 moduleloglevel[count],
3738 moduleloglevel[count + 1]);
3739 return;
3740 }
3741
3742 value = moduleloglevel[count] << 16;
3743 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003744 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303745 WMI_DBGLOG_MOD_LOG_LEVEL,
3746 value, DBG_CMD);
3747 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303748 hdd_err("Failed to enable FW module log level %d ret %d",
3749 value, ret);
3750
3751 count += 2;
3752 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303753
Arun Khandavalli2358d522016-05-16 18:05:37 +05303754}
3755#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003756static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003757 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303758{
3759}
3760
3761#endif
3762
3763/**
3764 * hdd_set_fw_params() - Set parameters to firmware
3765 * @adapter: HDD adapter
3766 *
3767 * This function Sets various parameters to fw once the
3768 * adapter is started.
3769 *
3770 * Return: 0 on success or errno on failure
3771 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003772int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303773{
3774 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003775 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303776
3777 ENTER_DEV(adapter->dev);
3778
3779 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3780 if (!hdd_ctx)
3781 return -EINVAL;
3782
Dustin Brown732ab9c2017-06-15 13:24:09 -07003783 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3784 hdd_debug("FTM Mode is active; nothing to do");
3785 return 0;
3786 }
3787
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303788 ret = sme_cli_set_command(adapter->sessionId,
3789 WMI_PDEV_PARAM_DTIM_SYNTH,
3790 hdd_ctx->config->enable_lprx, PDEV_CMD);
3791 if (ret) {
3792 hdd_err("Failed to set LPRx");
3793 goto error;
3794 }
3795
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303796 if (adapter->device_mode == QDF_STA_MODE) {
3797 sme_set_smps_cfg(adapter->sessionId,
3798 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3799 hdd_ctx->config->upper_brssi_thresh);
3800
3801 sme_set_smps_cfg(adapter->sessionId,
3802 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3803 hdd_ctx->config->lower_brssi_thresh);
3804
3805 sme_set_smps_cfg(adapter->sessionId,
3806 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3807 hdd_ctx->config->enable_dtim_1chrx);
3808 }
3809
Dustin Brown732ab9c2017-06-15 13:24:09 -07003810 if (hdd_ctx->config->enable2x2) {
3811 hdd_debug("configuring 2x2 mode fw params");
3812
Naveen Rawat247a8682017-06-05 15:00:31 -07003813 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003814 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3815 hdd_ctx->config->enable_cck_tx_fir_override,
3816 PDEV_CMD);
3817 if (ret) {
3818 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3819 ret);
3820 goto error;
3821 }
3822 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303823#define HDD_DTIM_1CHAIN_RX_ID 0x5
3824#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003825 hdd_debug("configuring 1x1 mode fw params");
3826
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003827 /*
3828 * Disable DTIM 1 chain Rx when in 1x1,
3829 * we are passing two value
3830 * as param_id << 29 | param_value.
3831 * Below param_value = 0(disable)
3832 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003833 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003834 WMI_STA_SMPS_PARAM_CMDID,
3835 HDD_DTIM_1CHAIN_RX_ID <<
3836 HDD_SMPS_PARAM_VALUE_S,
3837 VDEV_CMD);
3838 if (ret) {
3839 hdd_err("DTIM 1 chain set failed %d", ret);
3840 goto error;
3841 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303842
Naveen Rawat247a8682017-06-05 15:00:31 -07003843 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003844 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3845 hdd_ctx->config->txchainmask1x1,
3846 PDEV_CMD);
3847 if (ret) {
3848 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3849 ret);
3850 goto error;
3851 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852
Naveen Rawat247a8682017-06-05 15:00:31 -07003853 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003854 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3855 hdd_ctx->config->rxchainmask1x1,
3856 PDEV_CMD);
3857 if (ret) {
3858 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3859 ret);
3860 goto error;
3861 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303862#undef HDD_DTIM_1CHAIN_RX_ID
3863#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003864 }
3865
Naveen Rawat247a8682017-06-05 15:00:31 -07003866 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003867 WMI_PDEV_PARAM_HYST_EN,
3868 hdd_ctx->config->enableMemDeepSleep,
3869 PDEV_CMD);
3870 if (ret) {
3871 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3872 goto error;
3873 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303874
Naveen Rawat247a8682017-06-05 15:00:31 -07003875 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003876 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3877 hdd_ctx->config->rts_profile,
3878 VDEV_CMD);
3879 if (ret) {
3880 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3881 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303882 }
3883
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003884 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3885
3886 ret = wma_cli_set_command(adapter->sessionId,
3887 GEN_VDEV_PARAM_AMSDU,
3888 hdd_ctx->config->max_amsdu_num,
3889 GEN_CMD);
3890 if (ret != 0) {
3891 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3892 goto error;
3893 }
3894
Arun Khandavalli2358d522016-05-16 18:05:37 +05303895 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303896 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003897
Arun Khandavalli2358d522016-05-16 18:05:37 +05303898 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303899
Arun Khandavalli2358d522016-05-16 18:05:37 +05303900error:
3901 return -EINVAL;
3902}
3903
Ryan Hsu07495ea2016-01-21 15:25:39 -08003904/**
3905 * hdd_open_adapter() - open and setup the hdd adatper
3906 * @hdd_ctx: global hdd context
3907 * @session_type: type of the interface to be created
3908 * @iface_name: User-visible name of the interface
3909 * @macAddr: MAC address to assign to the interface
3910 * @name_assign_type: the name of assign type of the netdev
3911 * @rtnl_held: the rtnl lock hold flag
3912 *
3913 * This function open and setup the hdd adpater according to the device
3914 * type request, assign the name, the mac address assigned, and then prepared
3915 * the hdd related parameters, queue, lock and ready to start.
3916 *
3917 * Return: the pointer of hdd adapter, otherwise NULL.
3918 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003919struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003921 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003922 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923{
Jeff Johnson9d295242017-08-29 14:39:48 -07003924 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303926 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Jeff Johnson5e4b93c2017-09-30 18:09:16 -07003927 struct hdd_cfg80211_state *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929
3930 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3931 /*
3932 * Max limit reached on the number of vdevs configured by the
3933 * host. Return error
3934 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303935 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3936 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 return NULL;
3938 }
3939
3940 if (macAddr == NULL) {
3941 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303942 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 return NULL;
3944 }
3945 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303946 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303947 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3948 " already exists",
3949 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 return NULL;
3951 }
3952
3953 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003954 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003955 /* Reset locally administered bit if the device mode is STA */
3956 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303957 hdd_info("locally administered bit reset in sta mode: "
3958 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003960 case QDF_P2P_CLIENT_MODE:
3961 case QDF_P2P_DEVICE_MODE:
3962 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003963 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303964 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003965 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3966 name_assign_type,
3967 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968
3969 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303970 hdd_err("failed to allocate adapter for session %d",
3971 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return NULL;
3973 }
3974
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003975 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003977 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303979 else if (QDF_MONITOR_MODE == session_type)
3980 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 else
3982 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3983
3984 adapter->device_mode = session_type;
3985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 /*
3988 * Workqueue which gets scheduled in IPv4 notification
3989 * callback
3990 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3992 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993
3994#ifdef WLAN_NS_OFFLOAD
3995 /*
3996 * Workqueue which gets scheduled in IPv6
3997 * notification callback.
3998 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4000 hdd_ipv6_notifier_work_queue);
4001#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304003 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304005 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 }
4007
4008 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004009 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304011 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4012 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304013
Ravi Joshi1a292562017-05-18 16:28:54 -07004014 /* Initialize NAN Data Interface */
4015 if (QDF_NDI_MODE == session_type) {
4016 status = hdd_init_nan_data_mode(adapter);
4017 if (QDF_STATUS_SUCCESS != status)
4018 goto err_free_netdev;
4019 }
4020
4021 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004023 case QDF_P2P_GO_MODE:
4024 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004025 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4026 name_assign_type,
4027 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004029 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304030 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 return NULL;
4032 }
4033
4034 adapter->wdev.iftype =
4035 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004036 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037 NL80211_IFTYPE_P2P_GO;
4038 adapter->device_mode = session_type;
4039
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004040 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304041 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4043 goto err_free_netdev;
4044 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004045 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304047 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4048 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304050 case QDF_FTM_MODE:
4051 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4052 name_assign_type,
4053 "wlan0");
4054 if (NULL == adapter) {
4055 hdd_err("Failed to allocate adapter for FTM mode");
4056 return NULL;
4057 }
4058 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4059 adapter->device_mode = session_type;
4060 status = hdd_register_interface(adapter, rtnl_held);
4061 if (QDF_STATUS_SUCCESS != status) {
4062 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4063 goto err_free_netdev;
4064 }
4065 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004066 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304067 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304068 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4069 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304070 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004072 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304073 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 return NULL;
4075 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076
hqueaa33ee2017-05-04 17:56:35 +08004077 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4080 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4081
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304082 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 /* Add it to the hdd's session list. */
4084 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304085 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304087 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004088 } else {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004089 pHddAdapterNode->adapter = adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4091 }
4092 }
4093
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304094 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 if (NULL != adapter) {
4096 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4097 adapter = NULL;
4098 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004099 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304100 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004101
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 return NULL;
4103 }
4104
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304105 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004106 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4107 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 /* Adapter successfully added. Increment the vdev count */
4110 hdd_ctx->current_intf_count++;
4111
Jeff Johnson5880d792016-08-15 13:32:30 -07004112 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004113 hdd_ctx->current_intf_count);
4114
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004115 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 }
4117
Rajeev Kumardca5f812016-02-04 17:28:06 -08004118 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004119 hdd_err("Interface %s wow debug_fs init failed",
4120 netdev_name(adapter->dev));
4121
4122 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4123 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124
4125 return adapter;
4126
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304129 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130
4131 return NULL;
4132}
4133
Jeff Johnson9d295242017-08-29 14:39:48 -07004134QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004135 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004136{
4137 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304138 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139
4140 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304141 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004142 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143 status);
4144 return status;
4145 }
4146
Jeff Johnson57eb2732017-10-02 11:40:20 -07004147 while (pCurrent->adapter != adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304149 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 break;
4151
4152 pCurrent = pNext;
4153 }
4154 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304155 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004156 /*
4157 * Here we are stopping global bus_bw timer & work per adapter.
4158 *
4159 * The reason is to fix one race condition between
4160 * bus bandwidth work and cleaning up an adapter.
4161 * Under some conditions, it is possible for the bus bandwidth
4162 * work to access a particularly destroyed adapter, leading to
4163 * use-after-free.
4164 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004165 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004166 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004167 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004168
4169 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004170 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4171 adapter->device_mode);
Jeff Johnson57eb2732017-10-02 11:40:20 -07004172 hdd_cleanup_adapter(hdd_ctx, adapterNode->adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304174 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 adapterNode = NULL;
4176
Dustin Brown5ec6b552017-03-31 12:11:40 -07004177 /* conditionally restart the bw timer */
4178 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 /* Adapter removed. Decrement vdev count */
4181 if (hdd_ctx->current_intf_count != 0)
4182 hdd_ctx->current_intf_count--;
4183
4184 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304185 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304187
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304188 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189}
4190
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004191/**
4192 * hdd_close_all_adapters - Close all open adapters
4193 * @hdd_ctx: Hdd context
4194 * rtnl_held: True if RTNL lock held
4195 *
4196 * Close all open adapters.
4197 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304198 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004199 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004200QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201{
4202 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304203 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204
4205 ENTER();
4206
4207 do {
4208 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304209 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304210 wlan_hdd_release_intf_addr(hdd_ctx,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004211 pHddAdapterNode->adapter->macAddressCurrent.bytes);
4212 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004213 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304214 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304215 /* Adapter removed. Decrement vdev count */
4216 if (hdd_ctx->current_intf_count != 0)
4217 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304219 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220
4221 EXIT();
4222
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304223 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224}
4225
Jeff Johnson9d295242017-08-29 14:39:48 -07004226void wlan_hdd_reset_prob_rspies(struct hdd_adapter *pHostapdAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304228 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004232 case QDF_STA_MODE:
4233 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004235 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004237 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 break;
4239 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004240 case QDF_SAP_MODE:
4241 case QDF_P2P_GO_MODE:
4242 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004244 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 break;
4246 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004247 case QDF_FTM_MODE:
4248 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249 default:
4250 /*
4251 * wlan_hdd_reset_prob_rspies should not have been called
4252 * for these kind of devices
4253 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004254 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255 pHostapdAdapter->device_mode);
4256 return;
4257 }
4258
Anurag Chouhanc5548422016-02-24 18:33:27 +05304259 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4261 updateIE.ieBufferlength = 0;
4262 updateIE.pAdditionIEBuffer = NULL;
4263 updateIE.append = true;
4264 updateIE.notify = false;
4265 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4266 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304267 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004268 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 }
4270}
4271
Jeff Johnson9d295242017-08-29 14:39:48 -07004272QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273 const bool bCloseSession)
4274{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304275 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004276 struct hdd_wext_state *pWextState =
4277 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 union iwreq_data wrqu;
4279 tSirUpdateIE updateIE;
4280 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004281 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282
4283 ENTER();
4284
Sachin Ahuja988fd102016-09-15 17:16:25 +05304285 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004286 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304287 wlan_hdd_netif_queue_control(adapter,
4288 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4289 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004291 case QDF_STA_MODE:
4292 case QDF_P2P_CLIENT_MODE:
4293 case QDF_IBSS_MODE:
4294 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004295 case QDF_NDI_MODE:
4296 if ((QDF_NDI_MODE == adapter->device_mode) ||
4297 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4299 hdd_is_connecting(
4300 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004301 INIT_COMPLETION(adapter->disconnect_comp_var);
4302 /*
4303 * For NDI do not use pWextState from sta_ctx, if needed
4304 * extract from ndi_ctx.
4305 */
4306 if (QDF_NDI_MODE == adapter->device_mode)
4307 qdf_ret_status = sme_roam_disconnect(
4308 hdd_ctx->hHal,
4309 adapter->sessionId,
4310 eCSR_DISCONNECT_REASON_NDI_DELETE);
4311 else if (pWextState->roamProfile.BSSType ==
4312 eCSR_BSS_TYPE_START_IBSS)
4313 qdf_ret_status = sme_roam_disconnect(
4314 hdd_ctx->hHal,
4315 adapter->sessionId,
4316 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004317 else if (QDF_STA_MODE == adapter->device_mode)
4318 qdf_ret_status =
4319 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004321 qdf_ret_status = sme_roam_disconnect(
4322 hdd_ctx->hHal,
4323 adapter->sessionId,
4324 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004325 /* success implies disconnect command got
4326 * queued up successfully
4327 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004328 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4329 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 rc = wait_for_completion_timeout(
4331 &adapter->disconnect_comp_var,
4332 msecs_to_jiffies
4333 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004334 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004335 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004336 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004337 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4338 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 memset(&wrqu, '\0', sizeof(wrqu));
4340 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4341 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4342 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4343 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304344 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004345 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304346 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004347
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304348 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304349 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350
4351#ifdef WLAN_OPEN_SOURCE
4352 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4353#endif
4354
4355 hdd_deregister_tx_flow_control(adapter);
4356
4357#ifdef WLAN_NS_OFFLOAD
4358#ifdef WLAN_OPEN_SOURCE
4359 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4360#endif
4361#endif
4362
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304363 if (adapter->device_mode == QDF_STA_MODE)
4364 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4365 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 /*
4367 * It is possible that the caller of this function does not
4368 * wish to close the session
4369 */
Krunal Soni985b8132017-02-10 18:49:08 -08004370 if (true == bCloseSession) {
4371 if (0 != wlan_hdd_try_disconnect(adapter)) {
4372 hdd_err("Error: Can't disconnect adapter");
4373 return QDF_STATUS_E_FAILURE;
4374 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004375 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004376 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 break;
4378
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004379 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304380 /* Flush IPA exception path packets */
4381 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004382 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004384 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4386
4387 hdd_deregister_tx_flow_control(adapter);
4388
Kapil Guptac1224bf2017-06-22 21:22:40 +05304389 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390 mutex_lock(&hdd_ctx->sap_lock);
4391 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304392 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304393 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394
4395 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 status = wlansap_stop_bss(
4397 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304399 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004400 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004401 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304402 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304403 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304404 qdf_status =
4405 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004406 qdf_stop_bss_event,
4407 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408
Anurag Chouhance0dc992016-02-16 18:18:03 +05304409 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004410 hdd_err("failure waiting for wlansap_stop_bss %d",
4411 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 }
4413 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004414 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 }
4416 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004417 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4418 adapter->device_mode,
4419 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420
Anurag Chouhanc5548422016-02-24 18:33:27 +05304421 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004422 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004423 updateIE.smeSessionId = adapter->sessionId;
4424 updateIE.ieBufferlength = 0;
4425 updateIE.pAdditionIEBuffer = NULL;
4426 updateIE.append = false;
4427 updateIE.notify = false;
4428 /* Probe bcn reset */
4429 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4430 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304431 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004432 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 }
4434 /* Assoc resp reset */
4435 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4436 &updateIE,
4437 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304438 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004439 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440 }
4441 /* Reset WNI_CFG_PROBE_RSP Flags */
4442 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004444 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4445 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304446 /*
4447 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4448 */
4449 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4450 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4451
Peng Xu66162de2016-02-11 17:01:20 -08004452 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004453 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004454 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004456 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004457 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004458 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004459 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460 break;
4461 default:
4462 break;
4463 }
4464
4465 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304466 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467}
4468
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304469/**
4470 * hdd_deinit_all_adapters - deinit all adapters
4471 * @hdd_ctx: HDD context
4472 * @rtnl_held: True if RTNL lock held
4473 *
4474 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004475void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304476{
4477 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4478 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004479 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304480
4481 ENTER();
4482
4483 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4484
4485 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004486 adapter = adapter_node->adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304487 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4488 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4489 adapter_node = next;
4490 }
4491
4492 EXIT();
4493}
4494
Dustin Brown27cd9942017-09-27 16:11:44 -07004495QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4496 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004497{
4498 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304499 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004500 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004501
4502 ENTER();
4503
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304504 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4507
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304508 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004509 adapter = adapterNode->adapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004510 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4512 adapterNode = pNext;
4513 }
4514
4515 EXIT();
4516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304517 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518}
4519
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004520QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521{
4522 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304523 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004524 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004525 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004526 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527
4528 ENTER();
4529
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304530 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304534 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07004535 adapter = adapterNode->adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004536 hdd_notice("Disabling queues for adapter type: %d",
4537 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304538
4539 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004540 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304541 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004542 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304543
Arun Khandavallicc544b32017-01-30 19:52:16 +05304544 if (hdd_ctx->config->sap_internal_restart &&
4545 adapter->device_mode == QDF_SAP_MODE) {
4546 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304547 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304548 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004549 if (test_bit(SOFTAP_BSS_STARTED,
4550 &adapter->event_flags)) {
4551 hdd_sap_indicate_disconnect_for_sta(adapter);
4552 hdd_cleanup_actionframe(hdd_ctx, adapter);
4553 hdd_sap_destroy_events(adapter);
4554 }
4555 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4556 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304557 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304558 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004560 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561
4562 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4563
4564 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004565 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4566 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4568 hdd_wmm_adapter_close(adapter);
4569 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4570 }
4571
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304572 if (adapter->device_mode == QDF_STA_MODE)
4573 hdd_clear_fils_connection_info(adapter);
4574
Wu Gao3545e642017-07-14 19:24:41 +08004575 if (adapter->device_mode == QDF_SAP_MODE) {
4576 /*
4577 * If adapter is SAP, set session ID to invalid
4578 * since SAP session will be cleanup during SSR.
4579 */
Wu Gao36717432016-11-21 15:09:48 +08004580 wlansap_set_invalid_session(
4581 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4582
Wu Gao3545e642017-07-14 19:24:41 +08004583 wlansap_cleanup_cac_timer(
4584 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4585 }
4586
Yue Mad5b4b9f2017-05-26 16:23:40 -07004587 /* Delete peers if any for STA and P2P client modes */
4588 if (adapter->device_mode == QDF_STA_MODE ||
4589 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4590 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4591 qdf_copy_macaddr(&peerMacAddr,
4592 &pHddStaCtx->conn_info.bssId);
4593
4594 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4595 peerMacAddr.bytes);
4596 }
4597
Yue Maf9782842017-05-08 12:49:49 -07004598 /* Destroy vdev which will be recreated during reinit. */
4599 hdd_vdev_destroy(adapter);
4600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4602 adapterNode = pNext;
4603 }
4604
4605 EXIT();
4606
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304607 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004608}
4609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004610bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304611{
4612 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4613 QDF_STATUS status;
4614 bool close_modules = true;
4615
Arun Khandavalliba479c42017-07-26 21:29:40 +05304616 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4617 hdd_info("FTM mode, don't close the module");
4618 return false;
4619 }
4620
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304621 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4622 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4623 if (test_bit(DEVICE_IFACE_OPENED,
Jeff Johnson57eb2732017-10-02 11:40:20 -07004624 &adapter_node->adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004625 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304626 close_modules = false;
4627 break;
4628 }
4629 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4630 adapter_node = next;
4631 }
4632
4633 return close_modules;
4634}
4635
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304636bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304637{
4638 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4639 return true;
4640 else
4641 return false;
4642}
4643
Anurag Chouhanc4092922016-09-08 15:56:11 +05304644#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004645 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304646struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4647 struct ieee80211_channel *channel,
4648 const u8 *bssid, const u8 *ssid,
4649 size_t ssid_len)
4650{
4651 return cfg80211_get_bss(wiphy, channel, bssid,
4652 ssid, ssid_len,
4653 WLAN_CAPABILITY_ESS,
4654 WLAN_CAPABILITY_ESS);
4655}
4656#else
4657struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4658 struct ieee80211_channel *channel,
4659 const u8 *bssid, const u8 *ssid,
4660 size_t ssid_len)
4661{
4662 return cfg80211_get_bss(wiphy, channel, bssid,
4663 ssid, ssid_len,
4664 IEEE80211_BSS_TYPE_ESS,
4665 IEEE80211_PRIVACY_ANY);
4666}
4667#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304668
Abhishek Singha84d3952016-09-13 13:45:05 +05304669#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304670#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4671 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4672/**
4673 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4674 * @timeout_reason: reason for connect timeout
4675 *
4676 * This function is used to convert host timeout
4677 * reason enum to kernel specific enum.
4678 *
4679 * Return: nl timeout enum
4680 */
4681static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4682 tSirResultCodes timeout_reason)
4683{
4684 switch (timeout_reason) {
4685 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4686 return NL80211_TIMEOUT_SCAN;
4687 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4688 return NL80211_TIMEOUT_AUTH;
4689 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4690 return NL80211_TIMEOUT_ASSOC;
4691 default:
4692 return NL80211_TIMEOUT_UNSPECIFIED;
4693 }
4694}
4695
4696/**
4697 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4698 * @dev: network device
4699 * @bssid: bssid to which we want to associate
4700 * @timeout_reason: reason for connect timeout
4701 *
4702 * This API is used to send connection timeout reason to supplicant
4703 *
4704 * Return: void
4705 */
4706static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4707 const u8 *bssid,
4708 tSirResultCodes timeout_reason)
4709{
4710 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004711
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304712 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4713
4714 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4715 nl_timeout_reason);
4716}
4717
4718/**
4719 * __hdd_connect_bss() - API to send connection status to supplicant
4720 * @dev: network device
4721 * @bssid: bssid to which we want to associate
4722 * @req_ie: Request Information Element
4723 * @req_ie_len: len of the req IE
4724 * @resp_ie: Response IE
4725 * @resp_ie_len: len of ht response IE
4726 * @status: status
4727 * @gfp: Kernel Flag
4728 * @timeout_reason: reason for connect timeout
4729 *
4730 * Return: void
4731 */
4732static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4733 struct cfg80211_bss *bss, const u8 *req_ie,
4734 size_t req_ie_len, const u8 *resp_ie,
4735 size_t resp_ie_len, int status, gfp_t gfp,
4736 tSirResultCodes timeout_reason)
4737{
4738 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004739
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304740 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4741
4742 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4743 resp_ie, resp_ie_len, status, gfp,
4744 nl_timeout_reason);
4745}
4746#else
4747#if defined CFG80211_CONNECT_TIMEOUT
4748static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4749 const u8 *bssid,
4750 tSirResultCodes timeout_reason)
4751{
4752 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4753}
4754#endif
4755
4756static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4757 struct cfg80211_bss *bss, const u8 *req_ie,
4758 size_t req_ie_len, const u8 *resp_ie,
4759 size_t resp_ie_len, int status, gfp_t gfp,
4760 tSirResultCodes timeout_reason)
4761{
4762 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4763 resp_ie, resp_ie_len, status, gfp);
4764}
4765#endif
4766
Abhishek Singha84d3952016-09-13 13:45:05 +05304767/**
4768 * hdd_connect_bss() - API to send connection status to supplicant
4769 * @dev: network device
4770 * @bssid: bssid to which we want to associate
4771 * @req_ie: Request Information Element
4772 * @req_ie_len: len of the req IE
4773 * @resp_ie: Response IE
4774 * @resp_ie_len: len of ht response IE
4775 * @status: status
4776 * @gfp: Kernel Flag
4777 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304778 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304779 *
4780 * The API is a wrapper to send connection status to supplicant
4781 *
4782 * Return: Void
4783 */
4784#if defined CFG80211_CONNECT_TIMEOUT
4785static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4786 struct cfg80211_bss *bss, const u8 *req_ie,
4787 size_t req_ie_len, const u8 *resp_ie,
4788 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304789 bool connect_timeout,
4790 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304791{
4792 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304793 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304794 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304795 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4796 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304797}
4798#else
4799static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4800 struct cfg80211_bss *bss, const u8 *req_ie,
4801 size_t req_ie_len, const u8 *resp_ie,
4802 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304803 bool connect_timeout,
4804 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304805{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304806 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4807 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304808}
4809#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304810
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304811#ifdef WLAN_FEATURE_FILS_SK
4812#ifdef CFG80211_CONNECT_DONE
4813#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4814/**
4815 * hdd_populate_fils_params() - Populate FILS keys to connect response
4816 * @fils_params: connect response to supplicant
4817 * @fils_kek: FILS kek
4818 * @fils_kek_len: FILS kek length
4819 * @pmk: FILS PMK
4820 * @pmk_len: FILS PMK length
4821 * @pmkid: PMKID
4822 * @fils_seq_num: FILS Seq number
4823 *
4824 * Return: None
4825 */
4826static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4827 *fils_params, const uint8_t *fils_kek,
4828 size_t fils_kek_len, const uint8_t *pmk,
4829 size_t pmk_len, const uint8_t *pmkid,
4830 uint16_t fils_seq_num)
4831{
4832 /* Increament seq number to be used for next FILS */
4833 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4834 fils_params->update_erp_next_seq_num = true;
4835 fils_params->fils_kek = fils_kek;
4836 fils_params->fils_kek_len = fils_kek_len;
4837 fils_params->pmk = pmk;
4838 fils_params->pmk_len = pmk_len;
4839 fils_params->pmkid = pmkid;
4840}
4841#else
4842static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4843 *fils_params, const uint8_t
4844 *fils_kek, size_t fils_kek_len,
4845 const uint8_t *pmk, size_t pmk_len,
4846 const uint8_t *pmkid,
4847 uint16_t fils_seq_num)
4848{ }
4849#endif
4850
4851/**
4852 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4853 * @dev: network device
4854 * @bssid: bssid to which we want to associate
4855 * @bss: cfg80211 bss info
4856 * @roam_info: information about connected bss
4857 * @req_ie: Request Information Element
4858 * @req_ie_len: len of the req IE
4859 * @resp_ie: Response IE
4860 * @resp_ie_len: len of ht response IE
4861 * @status: status
4862 * @gfp: allocation flags
4863 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4864 * @timeout_reason: reason for connect timeout
4865 * @roam_fils_params: FILS join response params
4866 *
4867 * This API is used as wrapper to send FILS key/sequence number
4868 * params etc. to supplicant in case of FILS connection
4869 *
4870 * Return: None
4871 */
4872static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4873 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4874 const u8 *req_ie, size_t req_ie_len,
4875 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4876 gfp_t gfp, bool connect_timeout, tSirResultCodes
4877 timeout_reason, struct fils_join_rsp_params
4878 *roam_fils_params)
4879{
4880 struct cfg80211_connect_resp_params fils_params;
4881 qdf_mem_zero(&fils_params, sizeof(fils_params));
4882
4883 if (!roam_fils_params) {
4884 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4885 } else {
4886 fils_params.status = status;
4887 fils_params.bssid = bssid;
4888 fils_params.timeout_reason = timeout_reason;
4889 fils_params.req_ie = req_ie;
4890 fils_params.req_ie_len = req_ie_len;
4891 fils_params.resp_ie = resp_ie;
4892 fils_params.resp_ie_len = resp_ie_len;
4893 fils_params.bss = bss;
4894 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4895 roam_fils_params->kek_len,
4896 roam_fils_params->fils_pmk,
4897 roam_fils_params->fils_pmk_len,
4898 roam_fils_params->fils_pmkid,
4899 roam_info->fils_seq_num);
4900 }
4901 hdd_debug("FILS indicate connect status %d seq no %d",
4902 fils_params.status,
4903 fils_params.fils_erp_next_seq_num);
4904
4905 cfg80211_connect_done(dev, &fils_params, gfp);
4906
4907 /* Clear all the FILS key info */
4908 if (roam_fils_params && roam_fils_params->fils_pmk)
4909 qdf_mem_free(roam_fils_params->fils_pmk);
4910 if (roam_fils_params)
4911 qdf_mem_free(roam_fils_params);
4912 roam_info->fils_join_rsp = NULL;
4913}
4914#else
4915static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4916 struct cfg80211_bss *bss, tCsrRoamInfo
4917 *roam_info, const u8 *req_ie,
4918 size_t req_ie_len, const u8 *resp_ie,
4919 size_t resp_ie_len, u16 status, gfp_t gfp,
4920 bool connect_timeout, tSirResultCodes
4921 timeout_reason, struct fils_join_rsp_params
4922 *roam_fils_params)
4923{ }
4924#endif
4925#endif
4926
4927#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4928/**
4929 * hdd_fils_update_connect_results() - API to send fils connection status to
4930 * supplicant.
4931 * @dev: network device
4932 * @bssid: bssid to which we want to associate
4933 * @bss: cfg80211 bss info
4934 * @roam_info: information about connected bss
4935 * @req_ie: Request Information Element
4936 * @req_ie_len: len of the req IE
4937 * @resp_ie: Response IE
4938 * @resp_ie_len: len of ht response IE
4939 * @status: status
4940 * @gfp: allocation flags
4941 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4942 * @timeout_reason: reason for connect timeout
4943 *
4944 * The API is a wrapper to send connection status to supplicant
4945 *
4946 * Return: 0 if success else failure
4947 */
4948static int hdd_fils_update_connect_results(struct net_device *dev,
4949 const u8 *bssid,
4950 struct cfg80211_bss *bss,
4951 tCsrRoamInfo *roam_info, const u8 *req_ie,
4952 size_t req_ie_len, const u8 *resp_ie,
4953 size_t resp_ie_len, u16 status, gfp_t gfp,
4954 bool connect_timeout,
4955 tSirResultCodes timeout_reason)
4956{
4957 ENTER();
4958 if (!roam_info || !roam_info->is_fils_connection)
4959 return -EINVAL;
4960
4961 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4962 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4963 timeout_reason, roam_info->fils_join_rsp);
4964 return 0;
4965}
4966#else
4967static inline int hdd_fils_update_connect_results(struct net_device *dev,
4968 const u8 *bssid,
4969 struct cfg80211_bss *bss,
4970 tCsrRoamInfo *roam_info, const u8 *req_ie,
4971 size_t req_ie_len, const u8 *resp_ie,
4972 size_t resp_ie_len, u16 status, gfp_t gfp,
4973 bool connect_timeout,
4974 tSirResultCodes timeout_reason)
4975{
4976 return -EINVAL;
4977}
4978#endif
4979
Anurag Chouhanc4092922016-09-08 15:56:11 +05304980/**
4981 * hdd_connect_result() - API to send connection status to supplicant
4982 * @dev: network device
4983 * @bssid: bssid to which we want to associate
4984 * @roam_info: information about connected bss
4985 * @req_ie: Request Information Element
4986 * @req_ie_len: len of the req IE
4987 * @resp_ie: Response IE
4988 * @resp_ie_len: len of ht response IE
4989 * @status: status
4990 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304991 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304992 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304993 *
4994 * The API is a wrapper to send connection status to supplicant
4995 * and allow runtime suspend
4996 *
4997 * Return: Void
4998 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304999void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5000 tCsrRoamInfo *roam_info, const u8 *req_ie,
5001 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305002 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305003 bool connect_timeout,
5004 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305005{
Jeff Johnson9d295242017-08-29 14:39:48 -07005006 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305007 struct cfg80211_bss *bss = NULL;
5008
5009 if (WLAN_STATUS_SUCCESS == status) {
5010 struct ieee80211_channel *chan;
5011 int freq;
5012 int chan_no = roam_info->pBssDesc->channelId;
5013
5014 if (chan_no <= 14)
5015 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005016 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305017 else
5018 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005019 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305020
5021 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5022 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5023 roam_info->u.pConnectedProfile->SSID.ssId,
5024 roam_info->u.pConnectedProfile->SSID.length);
5025 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305026
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305027 if (hdd_fils_update_connect_results(dev, bssid, bss,
5028 roam_info, req_ie, req_ie_len, resp_ie,
5029 resp_ie_len, status, gfp, connect_timeout,
5030 timeout_reason) != 0) {
5031 hdd_connect_bss(dev, bssid, bss, req_ie,
5032 req_ie_len, resp_ie, resp_ie_len,
5033 status, gfp, connect_timeout, timeout_reason);
5034 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305035
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005036 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005037 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305038}
5039#else
5040void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5041 tCsrRoamInfo *roam_info, const u8 *req_ie,
5042 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305043 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305044 bool connect_timeout,
5045 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305046{
Jeff Johnson9d295242017-08-29 14:39:48 -07005047 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305048
Anurag Chouhanc4092922016-09-08 15:56:11 +05305049 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5050 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005051
5052 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005053 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305054}
5055#endif
5056
5057
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005058QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059{
5060 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305061 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005062 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305064 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065#endif
5066 eConnectionState connState;
5067
5068 ENTER();
5069
5070 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305071 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005072 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073
Arun Khandavallifae92942016-08-01 13:31:08 +05305074 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305075 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 hdd_wmm_init(adapter);
5078
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005079 adapter->scan_info.mScanPending = false;
5080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005082 case QDF_STA_MODE:
5083 case QDF_P2P_CLIENT_MODE:
5084 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005085
5086 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5087 ->conn_info.connState;
5088
5089 hdd_init_station_mode(adapter);
5090 /* Open the gates for HDD to receive Wext commands */
5091 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005093 /* Indicate disconnect event to supplicant
5094 * if associated previously
5095 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005097 eConnectionState_IbssConnected == connState ||
5098 eConnectionState_NotConnected == connState ||
5099 eConnectionState_IbssDisconnected == connState ||
5100 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005102
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005103 memset(&wrqu, '\0', sizeof(wrqu));
5104 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5105 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5106 wireless_send_event(adapter->dev, SIOCGIWAP,
5107 &wrqu, NULL);
5108 adapter->sessionCtx.station.
5109 hdd_ReassocScenario = false;
5110
5111 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305112 wlan_hdd_cfg80211_indicate_disconnect(
5113 adapter->dev, false,
5114 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 } else if (eConnectionState_Connecting == connState) {
5116 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005117 * Indicate connect failure to supplicant if we
5118 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305120 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305121 NULL, 0, NULL, 0,
5122 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005123 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 }
5125
5126 hdd_register_tx_flow_control(adapter,
5127 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005128 hdd_tx_resume_cb,
5129 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130
5131 break;
5132
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005133 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005134 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305135 hdd_init_ap_mode(adapter, true);
5136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 break;
5138
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005139 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005141 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5143#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005144 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145 /* event supplicant to restart */
5146 cfg80211_del_sta(adapter->dev,
5147 (const u8 *)&bcastMac.bytes[0],
5148 GFP_KERNEL);
5149#endif
5150 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305151 case QDF_MONITOR_MODE:
5152 hdd_init_station_mode(adapter);
5153 hdd_set_mon_rx_cb(adapter->dev);
5154 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5155 adapter->mon_bandwidth);
5156 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 default:
5158 break;
5159 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005160 /*
5161 * Action frame registered in one adapter which will
5162 * applicable to all interfaces
5163 */
5164 wlan_hdd_cfg80211_register_frames(adapter);
5165
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305166get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5168 adapterNode = pNext;
5169 }
5170
5171 EXIT();
5172
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305173 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174}
5175
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005176QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 hdd_adapter_list_node_t **padapterNode)
5178{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305179 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005180
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005181 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305182 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5183 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005184 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185 return status;
5186}
5187
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005188QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 hdd_adapter_list_node_t *adapterNode,
5190 hdd_adapter_list_node_t **pNextAdapterNode)
5191{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305192 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005193
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005194 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305195 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5196 (qdf_list_node_t *) adapterNode,
5197 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005199 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200 return status;
5201}
5202
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005203QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204 hdd_adapter_list_node_t *adapterNode)
5205{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305206 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005207
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005208 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305209 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005211 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 return status;
5213}
5214
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005215QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 hdd_adapter_list_node_t **padapterNode)
5217{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305218 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005219
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005220 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305221 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5222 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005223 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005224 return status;
5225}
5226
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005227QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228 hdd_adapter_list_node_t *adapterNode)
5229{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305230 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005231
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005232 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305233 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5234 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005235 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 return status;
5237}
5238
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005239QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 hdd_adapter_list_node_t *adapterNode)
5241{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305242 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005243
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005244 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305245 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5246 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005247 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248 return status;
5249}
5250
Jeff Johnson9d295242017-08-29 14:39:48 -07005251struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 tSirMacAddr macAddr)
5253{
5254 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005255 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305256 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257
5258 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5259
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305260 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005261 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262
5263 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305264 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005265 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5269 adapterNode = pNext;
5270 }
5271
5272 return NULL;
5273
5274}
5275
Jeff Johnson9d295242017-08-29 14:39:48 -07005276struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 uint32_t vdev_id)
5278{
5279 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005280 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305281 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305283 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305285 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005286 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287
5288 if (adapter->sessionId == vdev_id)
5289 return adapter;
5290
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305291 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5293 adapterNode = pNext;
5294 }
5295
Jeff Johnson5880d792016-08-15 13:32:30 -07005296 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297
5298 return NULL;
5299}
5300
Abhishek Singh7996eb72015-12-30 17:24:02 +05305301/**
5302 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5303 * the sessionid
5304 * @hdd_ctx: hdd context.
5305 * @sme_session_id: sme session is for the adapter to get.
5306 *
5307 * This function is used to get the adapter with provided session id
5308 *
5309 * Return: adapter pointer if found
5310 *
5311 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005312struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305313 uint32_t sme_session_id)
5314{
5315 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005316 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305317 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305318
5319
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305320 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305321
5322 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305323 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005324 adapter = adapter_node->adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305325
5326 if (adapter &&
5327 adapter->sessionId == sme_session_id)
5328 return adapter;
5329
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305330 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305331 hdd_get_next_adapter(hdd_ctx,
5332 adapter_node, &next);
5333 adapter_node = next;
5334 }
5335 return NULL;
5336}
5337
Jeff Johnson9d295242017-08-29 14:39:48 -07005338struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005339 const char *iface_name)
5340{
5341 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005342 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005343 QDF_STATUS qdf_status;
5344
5345 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5346
5347 while ((NULL != adapter_node) &&
5348 (QDF_STATUS_SUCCESS == qdf_status)) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005349 adapter = adapter_node->adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005350
5351 if (adapter &&
5352 !qdf_str_cmp(adapter->dev->name, iface_name))
5353 return adapter;
5354
5355 qdf_status =
5356 hdd_get_next_adapter(hdd_ctx,
5357 adapter_node, &next);
5358 adapter_node = next;
5359 }
5360 return NULL;
5361}
5362
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005363/**
5364 * hdd_get_adapter() - to get adapter matching the mode
5365 * @hdd_ctx: hdd context
5366 * @mode: adapter mode
5367 *
5368 * This routine will return the pointer to adapter matching
5369 * with the passed mode.
5370 *
5371 * Return: pointer to adapter or null
5372 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005373struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005374 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375{
5376 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005377 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305378 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005379
5380 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5381
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305382 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005383 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384
5385 if (adapter && (mode == adapter->device_mode))
5386 return adapter;
5387
5388 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5389 adapterNode = pNext;
5390 }
5391
5392 return NULL;
5393
5394}
5395
5396/**
5397 * hdd_get_operating_channel() - return operating channel of the device mode
5398 * @hdd_ctx: Pointer to the HDD context.
5399 * @mode: Device mode for which operating channel is required.
5400 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005401 * QDF_STA_MODE,
5402 * QDF_P2P_CLIENT_MODE,
5403 * QDF_SAP_MODE,
5404 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405 *
5406 * This API returns the operating channel of the requested device mode
5407 *
5408 * Return: channel number. "0" id the requested device is not found OR it is
5409 * not connected.
5410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005411uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005412 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413{
5414 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305415 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005416 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417 uint8_t operatingChannel = 0;
5418
5419 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305421 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005422 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423
5424 if (mode == adapter->device_mode) {
5425 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005426 case QDF_STA_MODE:
5427 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428 if (hdd_conn_is_connected
5429 (WLAN_HDD_GET_STATION_CTX_PTR
5430 (adapter))) {
5431 operatingChannel =
5432 (WLAN_HDD_GET_STATION_CTX_PTR
5433 (adapter))->conn_info.
5434 operationChannel;
5435 }
5436 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005437 case QDF_SAP_MODE:
5438 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005439 /* softap connection info */
5440 if (test_bit
5441 (SOFTAP_BSS_STARTED,
5442 &adapter->event_flags))
5443 operatingChannel =
5444 (WLAN_HDD_GET_AP_CTX_PTR
5445 (adapter))->operatingChannel;
5446 break;
5447 default:
5448 break;
5449 }
5450
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005451 /* Found the device of interest. break the loop */
5452 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453 }
5454
5455 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5456 adapterNode = pNext;
5457 }
5458 return operatingChannel;
5459}
5460
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005461static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462 hdd_ctx)
5463{
5464 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305465 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005466 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005467
5468 ENTER();
5469
5470 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305472 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005473 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005474 if ((adapter->device_mode == QDF_STA_MODE) ||
5475 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5476 (adapter->device_mode == QDF_IBSS_MODE) ||
5477 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5478 (adapter->device_mode == QDF_SAP_MODE) ||
5479 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480 wlan_hdd_cfg80211_deregister_frames(adapter);
5481 hdd_unregister_wext(adapter->dev);
5482 }
5483 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5484 adapterNode = pNext;
5485 }
5486
5487 EXIT();
5488
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305489 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490}
5491
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005492QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005493{
5494 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305495 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005496 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005497
5498 ENTER();
5499
5500 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305502 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005503 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005504 if ((adapter->device_mode == QDF_STA_MODE) ||
5505 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5506 (adapter->device_mode == QDF_IBSS_MODE) ||
5507 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5508 (adapter->device_mode == QDF_SAP_MODE) ||
5509 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305510 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5511 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005512 }
5513 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5514 adapterNode = pNext;
5515 }
5516
5517 EXIT();
5518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005520}
5521
Dustin Brownf27bce82016-11-03 12:52:27 -07005522/**
5523 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5524 * adapters
5525 * @hdd_ctx: The HDD context containing the adapters to operate on
5526 *
5527 * return: QDF_STATUS_SUCCESS
5528 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005529static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005530{
5531 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5532 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005533 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005534 int err;
5535
5536 ENTER();
5537
5538 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5539
5540 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07005541 adapter = adapter_node->adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005542 if ((adapter->device_mode == QDF_STA_MODE) ||
5543 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5544 (adapter->device_mode == QDF_IBSS_MODE) ||
5545 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5546 (adapter->device_mode == QDF_SAP_MODE) ||
5547 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5548 err = wlan_hdd_sched_scan_stop(adapter->dev);
5549 if (err)
5550 hdd_err("Unable to stop scheduled scan");
5551 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005552 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5553 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005554 adapter_node = next_node;
5555 }
5556
5557 EXIT();
5558
5559 return QDF_STATUS_SUCCESS;
5560}
5561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562#ifdef WLAN_NS_OFFLOAD
5563/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005564 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565 * @hdd_ctx: Pointer to hdd context
5566 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005567 * Unregister for IPv6 address change notifications.
5568 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005569 * Return: None
5570 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005571static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572{
5573 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005574}
5575
5576/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005577 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578 * @hdd_ctx: Pointer to hdd context
5579 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005580 * Register for IPv6 address change notifications.
5581 *
5582 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005583 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005584static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005585{
5586 int ret;
5587
5588 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5589 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005590 if (ret) {
5591 hdd_err("Failed to register IPv6 notifier: %d", ret);
5592 goto out;
5593 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005594
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005595 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005596out:
5597 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598}
5599#else
5600/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005601 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602 * @hdd_ctx: Pointer to hdd context
5603 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005604 * Unregister for IPv6 address change notifications.
5605 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005606 * Return: None
5607 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005608static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005609{
5610}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005612/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005613 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614 * @hdd_ctx: Pointer to hdd context
5615 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005616 * Register for IPv6 address change notifications.
5617 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005618 * Return: None
5619 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005620static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005622 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623}
5624#endif
5625
5626/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005627 * hdd_register_notifiers - Register netdev notifiers.
5628 * @hdd_ctx: HDD context
5629 *
5630 * Register netdev notifiers like IPv4 and IPv6.
5631 *
5632 * Return: 0 on success and errno on failure
5633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005634static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005635{
5636 int ret;
5637
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005638 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5639 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305640 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005641
5642 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5643 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5644 if (ret) {
5645 hdd_err("Failed to register IPv4 notifier: %d", ret);
5646 goto unregister_ip6_notifier;
5647 }
5648
5649 return 0;
5650
5651unregister_ip6_notifier:
5652 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005653out:
5654 return ret;
5655
5656}
5657
5658/**
5659 * hdd_unregister_notifiers - Unregister netdev notifiers.
5660 * @hdd_ctx: HDD context
5661 *
5662 * Unregister netdev notifiers like IPv4 and IPv6.
5663 *
5664 * Return: None.
5665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005666void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005667{
5668 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5669
5670 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005671}
5672
5673/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005674 * hdd_exit_netlink_services - Exit netlink services
5675 * @hdd_ctx: HDD context
5676 *
5677 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5678 * nl service.
5679 *
5680 * Return: None.
5681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005682static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005683{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005684 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005685 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005686 ptt_sock_deactivate_svc();
5687
5688 nl_srv_exit();
5689}
5690
5691/**
5692 * hdd_init_netlink_services- Init netlink services
5693 * @hdd_ctx: HDD context
5694 *
5695 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5696 * nl service.
5697 *
5698 * Return: 0 on success and errno on failure.
5699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005700static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005701{
5702 int ret;
5703
Ryan Hsuceddceb2016-04-28 10:20:14 -07005704 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005705 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005706 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005707 goto out;
5708 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005709 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005710
Naveen Rawat910726a2017-03-06 11:42:51 -08005711 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005712 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005713 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005714 goto err_nl_srv;
5715 }
5716
5717 ret = ptt_sock_activate_svc();
5718 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005719 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005720 goto err_nl_srv;
5721 }
5722
5723 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005724 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005725 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005726
5727 ret = cnss_diag_activate_service();
5728 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005729 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005730 goto err_close_cesium;
5731 }
5732
5733 return 0;
5734
5735err_close_cesium:
5736 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005737 ptt_sock_deactivate_svc();
5738err_nl_srv:
5739 nl_srv_exit();
5740out:
5741 return ret;
5742}
5743
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005744/**
5745 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5746 * @hdd_ctx: HDD context.
5747 *
5748 * Destroy RX wakelock.
5749 *
5750 * Return: None.
5751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005752static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005753{
5754 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5755}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005756
5757/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005758 * hdd_rx_wake_lock_create() - Create RX wakelock
5759 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005760 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005761 * Create RX wakelock.
5762 *
5763 * Return: None.
5764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005765static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005766{
5767 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5768}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005769
5770/**
5771 * hdd_roc_context_init() - Init ROC context
5772 * @hdd_ctx: HDD context.
5773 *
5774 * Initialize ROC context.
5775 *
5776 * Return: 0 on success and errno on failure.
5777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005778static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005779{
5780 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5781 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5782
5783 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5784
5785 return 0;
5786}
5787
5788/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305789 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5790 * @hdd_ctx: HDD context.
5791 *
5792 * Free memory allocations made in ROC Req Queue nodes.
5793 *
5794 * Return: None.
5795 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005796static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305797{
Jeff Johnson52b50602017-09-30 17:54:56 -07005798 struct hdd_roc_req *hdd_roc_req;
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305799 QDF_STATUS status;
5800
5801 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5802
5803 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5804 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5805 (qdf_list_node_t **) &hdd_roc_req);
5806
5807 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305808 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5809 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305810 QDF_ASSERT(0);
5811 return;
5812 }
5813
Jeff Johnson44d8af92017-10-02 12:25:55 -07005814 if (hdd_roc_req->remain_chan_ctx)
5815 qdf_mem_free(hdd_roc_req->remain_chan_ctx);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305816
5817 qdf_mem_free(hdd_roc_req);
5818 }
5819
5820 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5821}
5822
5823/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005824 * hdd_roc_context_destroy() - Destroy ROC context
5825 * @hdd_ctx: HDD context.
5826 *
5827 * Destroy roc list and flush the pending roc work.
5828 *
5829 * Return: None.
5830 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005831static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005832{
5833 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305834 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005835 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005836}
5837
5838/**
Houston Hoffman160db392016-10-10 17:37:51 -07005839 * hdd_context_deinit() - Deinitialize HDD context
5840 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005841 *
Houston Hoffman160db392016-10-10 17:37:51 -07005842 * Deinitialize HDD context along with all the feature specific contexts but
5843 * do not free hdd context itself. Caller of this API is supposed to free
5844 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005845 *
Houston Hoffman160db392016-10-10 17:37:51 -07005846 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005847 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005848static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005849{
Houston Hoffman160db392016-10-10 17:37:51 -07005850 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005851
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005852 hdd_roc_context_destroy(hdd_ctx);
5853
5854 hdd_sap_context_destroy(hdd_ctx);
5855
5856 hdd_rx_wake_lock_destroy(hdd_ctx);
5857
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005858 hdd_scan_context_destroy(hdd_ctx);
5859
5860 qdf_list_destroy(&hdd_ctx->hddAdapters);
5861
Houston Hoffman160db392016-10-10 17:37:51 -07005862 return 0;
5863}
5864
5865/**
5866 * hdd_context_destroy() - Destroy HDD context
5867 * @hdd_ctx: HDD context to be destroyed.
5868 *
5869 * Free config and HDD context as well as destroy all the resources.
5870 *
5871 * Return: None
5872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005873static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005874{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07005875 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305876
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305877 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5878
Houston Hoffman160db392016-10-10 17:37:51 -07005879 hdd_context_deinit(hdd_ctx);
5880
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305881 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005882 hdd_ctx->config = NULL;
5883
5884 wiphy_free(hdd_ctx->wiphy);
5885}
5886
5887/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305888 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5889 *
5890 * This function is used to destroy bug report lock
5891 *
5892 * Return: None
5893 */
5894static void wlan_destroy_bug_report_lock(void)
5895{
5896 p_cds_contextType p_cds_context;
5897
5898 p_cds_context = cds_get_global_context();
5899 if (!p_cds_context) {
5900 hdd_err("cds context is NULL");
5901 return;
5902 }
5903
5904 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5905}
5906
5907/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908 * hdd_wlan_exit() - HDD WLAN exit function
5909 * @hdd_ctx: Pointer to the HDD Context
5910 *
5911 * This is the driver exit point (invoked during rmmod)
5912 *
5913 * Return: None
5914 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005915static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305917 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005918 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305919 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920
5921 ENTER();
5922
Arun Khandavallifae92942016-08-01 13:31:08 +05305923 if (QDF_TIMER_STATE_RUNNING ==
5924 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005925 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305926 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927 }
5928
Arun Khandavallifae92942016-08-01 13:31:08 +05305929 if (!QDF_IS_STATUS_SUCCESS
5930 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5931 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005932
Arun Khandavallifae92942016-08-01 13:31:08 +05305933
5934 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935
Prashanth Bhattaab004382016-10-11 16:08:11 -07005936 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937
5938#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305939 if (QDF_TIMER_STATE_RUNNING ==
5940 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5941 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 }
5943
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305944 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305945 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005946 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005948 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5949 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5950 hdd_ctx->last_acs_channel_list = NULL;
5951 hdd_ctx->num_of_channels = 0;
5952 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005953#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954
Arun Khandavallifae92942016-08-01 13:31:08 +05305955 mutex_lock(&hdd_ctx->iface_change_lock);
5956 driver_status = hdd_ctx->driver_status;
5957 mutex_unlock(&hdd_ctx->iface_change_lock);
5958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 /*
5960 * Powersave Offload Case
5961 * Disable Idle Power Save Mode
5962 */
5963 hdd_set_idle_ps_config(hdd_ctx, false);
5964
Arun Khandavallifae92942016-08-01 13:31:08 +05305965 if (driver_status != DRIVER_MODULES_CLOSED) {
5966 hdd_unregister_wext_all_adapters(hdd_ctx);
5967 /*
5968 * Cancel any outstanding scan requests. We are about to close
5969 * all of our adapters, but an adapter structure is what SME
5970 * passes back to our callback function. Hence if there
5971 * are any outstanding scan requests then there is a
5972 * race condition between when the adapter is closed and
5973 * when the callback is invoked. We try to resolve that
5974 * race condition here by canceling any outstanding scans
5975 * before we close the adapters.
5976 * Note that the scans may be cancelled in an asynchronous
5977 * manner, so ideally there needs to be some kind of
5978 * synchronization. Rather than introduce a new
5979 * synchronization here, we will utilize the fact that we are
5980 * about to Request Full Power, and since that is synchronized,
5981 * the expectation is that by the time Request Full Power has
5982 * completed, all scans will be cancelled
5983 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005984 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305985 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005986 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07005987 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005988 }
5989
5990 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305991 * Close the scheduler before calling cds_close to make sure
5992 * no thread is scheduled after the each module close is
5993 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994 */
Jeff Johnson7d562272017-09-13 15:12:54 -07005995 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305996 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305997 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305998 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006000
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306001 unregister_netdevice_notifier(&hdd_netdev_notifier);
6002
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006003 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306004
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306005 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6006 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6007 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009 /*
6010 * Close CDS
6011 * This frees pMac(HAL) context. There should not be any call
6012 * that requires pMac access after this.
6013 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006014
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006015 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006016 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006018 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019
6020 hdd_ipa_cleanup(hdd_ctx);
6021
6022 /* Free up RoC request queue and flush workqueue */
6023 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006024
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306025 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306026 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306027 /*
6028 * If there is re_init failure wiphy would have already de-registered
6029 * check the wiphy status before un-registering again
6030 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306031 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306032 wiphy_unregister(wiphy);
6033 wlan_hdd_cfg80211_deinit(wiphy);
6034 hdd_lpass_notify_stop(hdd_ctx);
6035 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006036
Arun Khandavallifae92942016-08-01 13:31:08 +05306037 hdd_exit_netlink_services(hdd_ctx);
6038 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306039#ifdef FEATURE_WLAN_CH_AVOID
6040 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6041#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306042
6043 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6044 if (driver_status)
6045 hdd_err("Pdev delete failed");
6046
6047 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6048 if (driver_status)
6049 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006050
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006051 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006052}
6053
6054void __hdd_wlan_exit(void)
6055{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006056 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006057
6058 ENTER();
6059
Anurag Chouhan6d760662016-02-20 16:05:43 +05306060 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006061 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006062 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063 EXIT();
6064 return;
6065 }
6066
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006067 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306068 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070 /* Do all the cleanup before deregistering the driver */
6071 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006072
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073 EXIT();
6074}
6075
6076#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006077/**
6078 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006079 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006080 *
6081 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6082 * Then new ACS request will do a fresh scan without reusing the cached
6083 * scan information.
6084 *
6085 * Return: void
6086 */
Tang Yingying523322d2017-01-17 23:28:43 +08006087static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006088{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006089 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006091 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006093 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6094 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6095 hdd_ctx->last_acs_channel_list = NULL;
6096 hdd_ctx->num_of_channels = 0;
6097 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098
6099 if (!hdd_ctx->hHal)
6100 return;
6101 sme_scan_flush_result(hdd_ctx->hHal);
6102}
6103#endif
6104
6105#ifdef QCA_HT_2040_COEX
6106/**
6107 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6108 * @adapter: pointer to adapter
6109 * @staId: station id
6110 * @macAddrSTA: station MAC address
6111 * @channel_type: channel type
6112 *
6113 * This function notifies FW with HT20/HT40 mode
6114 *
6115 * Return: 0 if successful, error number otherwise
6116 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006117int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306118 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119{
6120 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306121 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006122 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006123
6124 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6125
6126 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306127 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006128 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130 if (!hdd_ctx->hHal)
6131 return -EINVAL;
6132
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306133 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006134 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306135 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006136 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006137 return -EINVAL;
6138 }
6139
6140 return 0;
6141}
6142#endif
6143
6144/**
6145 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6146 * @state: state
6147 *
6148 * This function notifies FW with modem power status
6149 *
6150 * Return: 0 if successful, error number otherwise
6151 */
6152int hdd_wlan_notify_modem_power_state(int state)
6153{
6154 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306155 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006156 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006157
Anurag Chouhan6d760662016-02-20 16:05:43 +05306158 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006159 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306160 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006163 if (!hdd_ctx->hHal)
6164 return -EINVAL;
6165
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306166 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6167 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006168 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 state);
6170 return -EINVAL;
6171 }
6172 return 0;
6173}
6174
6175/**
6176 *
6177 * hdd_post_cds_enable_config() - HDD post cds start config helper
6178 * @adapter - Pointer to the HDD
6179 *
6180 * Return: None
6181 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006182QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006183{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306184 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185
6186 /*
6187 * Send ready indication to the HDD. This will kick off the MAC
6188 * into a 'running' state and should kick off an initial scan.
6189 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306190 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6191 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006192 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6193 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306194 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195 }
6196
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306197 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198}
6199
6200/* wake lock APIs for HDD */
6201void hdd_prevent_suspend(uint32_t reason)
6202{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306203 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204}
6205
6206void hdd_allow_suspend(uint32_t reason)
6207{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306208 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209}
6210
6211void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6212{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306213 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6214 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215}
6216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006218QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006220
Amar Singhal6f8592b2017-04-26 14:31:58 -07006221 return sme_init_chan_list(hdd_ctx->hHal,
6222 hdd_ctx->reg.alpha2,
6223 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006224}
6225
6226/**
6227 * hdd_is_5g_supported() - check if hardware supports 5GHz
6228 * @hdd_ctx: Pointer to the hdd context
6229 *
6230 * HDD function to know if hardware supports 5GHz
6231 *
6232 * Return: true if hardware supports 5GHz
6233 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006234bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006236 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006237 return true;
6238
Amar Singhal58b45ef2017-08-01 13:43:54 -07006239 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006240 return true;
6241 else
6242 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243}
6244
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006245static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246{
6247 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006248 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249
6250 wiphy = hdd_ctx->wiphy;
6251
6252 /*
6253 * The channel information in
6254 * wiphy needs to be initialized before wiphy registration
6255 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006256 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6257 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006258 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006259 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260 }
6261
6262#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6263 wiphy->wowlan = &wowlan_support_reg_init;
6264#else
6265 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6266 WIPHY_WOWLAN_MAGIC_PKT |
6267 WIPHY_WOWLAN_DISCONNECT |
6268 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6269 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6270 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6271 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6272 WIPHY_WOWLAN_RFKILL_RELEASE;
6273
6274 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6275 WOW_MAX_FILTERS_PER_LIST);
6276 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6277 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6278#endif
6279
6280 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006281 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306282 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006283 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306284 return ret_val;
6285 }
6286
Amar Singhal5cccafe2017-02-15 12:42:58 -08006287 if (!hdd_ctx->reg_offload)
6288 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289
Amar Singhale4f28ee2015-10-21 14:36:56 -07006290 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291}
6292
Ravi Joshie2331e82015-07-01 18:18:54 -07006293/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006294 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006295 * @hdd_ctx - handle to hdd context
6296 * @tx_packets - transmit packet count
6297 * @rx_packets - receive packet count
6298 *
6299 * The function controls the bus bandwidth and dynamic control of
6300 * tcp delayed ack configuration
6301 *
6302 * Returns: None
6303 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006304#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006305static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006306 const uint64_t tx_packets,
6307 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006310 uint64_t temp_rx = 0;
6311 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006312 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006313 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006314 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006315 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006316 uint16_t index = 0;
6317 bool vote_level_change = false;
6318 bool rx_level_change = false;
6319 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006322 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006324 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006325 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006326 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006327 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006328 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006331 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6332 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006334 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006335 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306336 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306337 if (hdd_ctx->hbw_requested) {
6338 pld_remove_pm_qos(hdd_ctx->parent_dev);
6339 hdd_ctx->hbw_requested = false;
6340 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306341 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006342 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306343 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306344 if (!hdd_ctx->hbw_requested) {
6345 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6346 hdd_ctx->hbw_requested = true;
6347 }
6348
Nirav Shah3bbfa512016-05-12 16:43:49 +05306349 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006350 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306351 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006352 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006354
Mohit Khannaf8f96822017-05-17 17:11:59 -07006355 qdf_dp_trace_throttle_live_mode(
6356 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6357
Mohit Khannae71e2262015-11-10 09:37:24 -08006358 /* fine-tuning parameters for RX Flows */
6359 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006362
Ravi Joshifed83572016-10-07 16:20:37 -07006363 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6364 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6365 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6366 next_rx_level = WLAN_SVC_TP_HIGH;
6367 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006368 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006369 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006370 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006371 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006374 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006375 next_rx_level, temp_rx);
6376 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006377 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006378 /* Send throughput indication only if it is enabled.
6379 * Disabling tcp_del_ack will revert the tcp stack behavior
6380 * to default delayed ack. Note that this will disable the
6381 * dynamic delayed ack mechanism across the system
6382 */
6383 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306384 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6385 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386 &next_rx_level,
6387 sizeof(next_rx_level));
6388 }
6389
Mohit Khannae71e2262015-11-10 09:37:24 -08006390 /* fine-tuning parameters for TX Flows */
6391 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6392 hdd_ctx->prev_tx = tx_packets;
6393 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6394 next_tx_level = WLAN_SVC_TP_HIGH;
6395 else
6396 next_tx_level = WLAN_SVC_TP_LOW;
6397
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006398 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006399 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6400 next_tx_level, temp_tx);
6401 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006402 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306403 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6404 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006405 &next_tx_level,
6406 sizeof(next_tx_level));
6407 }
6408
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006409 index = hdd_ctx->hdd_txrx_hist_idx;
6410
6411 if (vote_level_change || tx_level_change || rx_level_change) {
6412 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6413 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6414 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6415 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6416 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6417 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6418 hdd_ctx->hdd_txrx_hist_idx++;
6419 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6420 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006421}
6422
6423#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306424static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006426 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306427 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006428 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306429 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306430 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6431 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006432 uint64_t total_tx = 0, total_rx = 0;
6433 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306434 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306435 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006436 bool connected = false;
6437 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6438
Prashanth Bhattaab004382016-10-11 16:08:11 -07006439 if (wlan_hdd_validate_context(hdd_ctx))
6440 return;
6441
Jingxiang Gec64e1932017-08-22 14:38:59 +08006442 if (hdd_ctx->isWiphySuspended)
6443 goto restart_timer;
6444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006445 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306446 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447 status =
6448 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6449
Jeff Johnson57eb2732017-10-02 11:40:20 -07006450 if (adapterNode->adapter == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451 continue;
Jeff Johnson57eb2732017-10-02 11:40:20 -07006452 adapter = adapterNode->adapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306453 /*
6454 * Validate magic so we don't end up accessing
6455 * an invalid adapter.
6456 */
6457 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6458 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006460 if ((adapter->device_mode == QDF_STA_MODE ||
6461 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6463 != eConnectionState_Associated) {
6464
6465 continue;
6466 }
6467
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006468 if ((adapter->device_mode == QDF_SAP_MODE ||
6469 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6471
6472 continue;
6473 }
6474
6475 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6476 adapter->prev_tx_packets);
6477 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6478 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306479
6480 if (adapter->device_mode == QDF_SAP_MODE ||
6481 adapter->device_mode == QDF_P2P_GO_MODE ||
6482 adapter->device_mode == QDF_IBSS_MODE) {
6483
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006484 ret = cdp_get_intra_bss_fwd_pkts_count(
6485 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306486 adapter->sessionId,
6487 &fwd_tx_packets, &fwd_rx_packets);
6488 if (ret == A_OK) {
6489 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6490 fwd_tx_packets,
6491 adapter->prev_fwd_tx_packets);
6492 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6493 fwd_tx_packets,
6494 adapter->prev_fwd_rx_packets);
6495 }
6496 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006497
6498 total_rx += adapter->stats.rx_packets;
6499 total_tx += adapter->stats.tx_packets;
6500
6501 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6502 adapter->prev_tx_packets = adapter->stats.tx_packets;
6503 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306504 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6505 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6507 connected = true;
6508 }
6509
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306510 /* add intra bss forwarded tx and rx packets */
6511 tx_packets += fwd_tx_packets_diff;
6512 rx_packets += fwd_rx_packets_diff;
6513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6515 tx_packets += (uint64_t)ipa_tx_packets;
6516 rx_packets += (uint64_t)ipa_rx_packets;
6517
6518 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006519 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 return;
6521 }
6522
Yuanyuan Liu13738502016-04-06 17:41:37 -07006523 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006524
6525 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6526 hdd_ipa_uc_stat_request(adapter, 2);
6527
Jingxiang Gec64e1932017-08-22 14:38:59 +08006528restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006529 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006530 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006531 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306532 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006533 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006534 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006536
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306537/**
6538 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6539 * @arg: Argument of timer function
6540 *
6541 * Schedule a workqueue in this function where all the processing is done.
6542 *
6543 * Return: None.
6544 */
6545static void __hdd_bus_bw_cbk(void *arg)
6546{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006547 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306548
6549 if (wlan_hdd_validate_context(hdd_ctx))
6550 return;
6551
6552 schedule_work(&hdd_ctx->bus_bw_work);
6553}
6554
6555/**
6556 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6557 * @arg: Argument of timer function
6558 *
6559 * Return: None.
6560 */
6561static void hdd_bus_bw_cbk(void *arg)
6562{
6563 cds_ssr_protect(__func__);
6564 __hdd_bus_bw_cbk(arg);
6565 cds_ssr_unprotect(__func__);
6566}
6567
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006568int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006569{
6570 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306571 INIT_WORK(&hdd_ctx->bus_bw_work,
6572 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006573 hdd_ctx->bus_bw_timer_running = false;
6574 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306575 qdf_timer_init(NULL,
6576 &hdd_ctx->bus_bw_timer,
6577 hdd_bus_bw_cbk, (void *)hdd_ctx,
6578 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006579
6580 return 0;
6581}
6582
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006583void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006584{
Dustin Brownfce08d12017-01-17 16:29:38 -08006585 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006586 hdd_reset_tcp_delack(hdd_ctx);
6587
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006588 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306589 cancel_work_sync(&hdd_ctx->bus_bw_work);
6590 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006591 hdd_ctx->bus_bw_timer_running = false;
6592 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006593}
Lin Baic5c06882017-09-21 13:58:43 +08006594
6595void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6596{
6597 if (hdd_ctx)
6598 cancel_work_sync(&hdd_ctx->bus_bw_work);
6599}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006600#endif
6601
6602/**
Nirav Shahed34b212016-04-25 10:59:16 +05306603 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6604 * @hdd_ctx: hdd context
6605 *
6606 * Return: 0 for success or error code
6607 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006608static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306609{
6610 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6611 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6612 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006613 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306614 return -ENOMEM;
6615 }
6616 return 0;
6617}
6618
6619/**
6620 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6621 * @hdd_ctx: hdd context
6622 *
6623 * Return: none
6624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006625void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306626{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306627 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6628 return;
6629
6630 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6631 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306632}
6633
Nirav Shahda008342016-05-17 18:50:40 +05306634static uint8_t *convert_level_to_string(uint32_t level)
6635{
6636 switch (level) {
6637 /* initialize the wlan sub system */
6638 case WLAN_SVC_TP_NONE:
6639 return "NONE";
6640 case WLAN_SVC_TP_LOW:
6641 return "LOW";
6642 case WLAN_SVC_TP_MEDIUM:
6643 return "MED";
6644 case WLAN_SVC_TP_HIGH:
6645 return "HIGH";
6646 default:
6647 return "INVAL";
6648 }
6649}
6650
Nirav Shahed34b212016-04-25 10:59:16 +05306651
6652/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6654 * @hdd_ctx: hdd context
6655 *
6656 * Return: none
6657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006658void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006659{
6660 int i;
6661
6662#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006663 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306664 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006665 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666 hdd_ctx->config->busBandwidthHighThreshold,
6667 hdd_ctx->config->busBandwidthMediumThreshold,
6668 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006669 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306670 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006671 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672 hdd_ctx->config->tcpDelackThresholdHigh,
6673 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006674 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306675 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006676#endif
6677
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006678 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306679 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6680
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006681 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682
6683 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006684 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006685 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006686 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006687 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6688 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006689 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006690 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6691 convert_level_to_string(
6692 hdd_ctx->hdd_txrx_hist[i].
6693 next_vote_level),
6694 convert_level_to_string(
6695 hdd_ctx->hdd_txrx_hist[i].
6696 next_rx_level),
6697 convert_level_to_string(
6698 hdd_ctx->hdd_txrx_hist[i].
6699 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006700 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006701
6702 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703}
6704
6705/**
6706 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6707 * @hdd_ctx: hdd context
6708 *
6709 * Return: none
6710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006711void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712{
6713 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306714 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6715 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716}
6717
6718/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006719 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006720 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006721 *
6722 * Return: none
6723 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006724void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725{
6726
Jeff Johnson9d295242017-08-29 14:39:48 -07006727 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306729 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306731 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006732
6733 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306734 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006735 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006737 hdd_debug("Netif queue operation statistics:");
6738 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306739 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006740 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306741 curr_time = qdf_system_ticks();
6742 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306743 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306744 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306745 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306746 unpause = adapter->total_unpause_time;
6747 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306748 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306749 pause = adapter->total_pause_time;
6750 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006751 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306752 qdf_system_ticks_to_msecs(total),
6753 qdf_system_ticks_to_msecs(pause),
6754 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006755 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006756
Nirav Shahda008342016-05-17 18:50:40 +05306757 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6758 qdf_time_t pause_delta = 0;
6759
6760 if (adapter->pause_map & (1 << i))
6761 pause_delta = delta;
6762
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006763 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006764 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006765 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766 hdd_reason_type_to_string(i),
6767 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306768 adapter->queue_oper_stats[i].unpause_count,
6769 qdf_system_ticks_to_msecs(
6770 adapter->queue_oper_stats[i].total_pause_time +
6771 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 }
6773
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006774 hdd_debug("Netif queue operation history:");
6775 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306776 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6777
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006778 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779
6780 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006781 /* using hdd_log to avoid printing function name */
6782 if (adapter->queue_oper_history[i].time == 0)
6783 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006784 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006785 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306786 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787 adapter->queue_oper_history[i].time),
6788 hdd_action_type_to_string(
6789 adapter->queue_oper_history[i].netif_action),
6790 hdd_reason_type_to_string(
6791 adapter->queue_oper_history[i].netif_reason),
6792 adapter->queue_oper_history[i].pause_map);
6793 }
6794
6795 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6796 adapter_node = next;
6797 }
6798
6799
6800}
6801
6802/**
6803 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6804 * @hdd_ctx: hdd context
6805 *
6806 * Return: none
6807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006808void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809{
Jeff Johnson9d295242017-08-29 14:39:48 -07006810 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306812 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813
6814 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306815 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07006816 adapter = adapter_node->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006817
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306818 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306820 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306822 adapter->history_index = 0;
6823 adapter->start_time = adapter->last_time = qdf_system_ticks();
6824 adapter->total_pause_time = 0;
6825 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6827 adapter_node = next;
6828 }
6829}
6830
6831/**
6832 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6833 * @halHandle: Hal handle
6834 * @pContext: Pointer to the context
6835 * @sessionId: Session ID
6836 * @scanId: Scan ID
6837 * @status: Status
6838 *
6839 * This is the callback to be executed when 11d scan is completed to flush out
6840 * the scan results
6841 *
6842 * 11d scan is done during driver load and is a passive scan on all
6843 * channels supported by the device, 11d scans may find some APs on
6844 * frequencies which are forbidden to be used in the regulatory domain
6845 * the device is operating in. If these APs are notified to the supplicant
6846 * it may try to connect to these APs, thus flush out all the scan results
6847 * which are present in SME after 11d scan is done.
6848 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306849 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006850 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306851static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852 uint8_t sessionId, uint32_t scanId,
6853 eCsrScanStatus status)
6854{
6855 ENTER();
6856
6857 sme_scan_flush_result(halHandle);
6858
6859 EXIT();
6860
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306861 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862}
6863
6864#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6865/**
6866 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6867 * @hdd_ctx: hdd global context
6868 *
6869 * Return: none
6870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006871static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872{
6873 uint8_t i;
6874
6875 mutex_init(&hdd_ctx->op_ctx.op_lock);
6876 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6877 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6878 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6879 }
6880}
6881#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006882static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883{
6884}
6885#endif
6886
Yingying Tang95409972016-10-20 15:16:15 +08006887#ifdef WLAN_FEATURE_WOW_PULSE
6888/**
6889 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006890 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006891 * @enable: enable or disable this behaviour
6892 *
6893 * Return: int
6894 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006895static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006896{
6897 struct hdd_config *pcfg_ini = phddctx->config;
6898 struct wow_pulse_mode wow_pulse_set_info;
6899 QDF_STATUS status;
6900
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006901 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006902
6903 if (false == phddctx->config->wow_pulse_support)
6904 return 0;
6905
6906 /* prepare the request to send to SME */
6907 if (enable == true) {
6908 wow_pulse_set_info.wow_pulse_enable = true;
6909 wow_pulse_set_info.wow_pulse_pin =
6910 pcfg_ini->wow_pulse_pin;
6911 wow_pulse_set_info.wow_pulse_interval_low =
6912 pcfg_ini->wow_pulse_interval_low;
6913 wow_pulse_set_info.wow_pulse_interval_high =
6914 pcfg_ini->wow_pulse_interval_high;
6915 } else {
6916 wow_pulse_set_info.wow_pulse_enable = false;
6917 wow_pulse_set_info.wow_pulse_pin = 0;
6918 wow_pulse_set_info.wow_pulse_interval_low = 0;
6919 wow_pulse_set_info.wow_pulse_interval_high = 0;
6920 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006921 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006922 wow_pulse_set_info.wow_pulse_enable,
6923 wow_pulse_set_info.wow_pulse_pin,
6924 wow_pulse_set_info.wow_pulse_interval_low,
6925 wow_pulse_set_info.wow_pulse_interval_high);
6926
6927 status = sme_set_wow_pulse(&wow_pulse_set_info);
6928 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006929 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006930 return -EIO;
6931 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006932 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006933 return 0;
6934}
6935#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006936static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006937{
6938 return 0;
6939}
6940#endif
6941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942#ifdef WLAN_FEATURE_FASTPATH
6943/**
6944 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6945 * @hdd_cfg: hdd config
6946 * @context: lower layer context
6947 *
6948 * Return: none
6949 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306950void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 void *context)
6952{
6953 if (hdd_cfg->fastpath_enable)
6954 hif_enable_fastpath(context);
6955}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956#endif
6957
Yuanyuan Liu13738502016-04-06 17:41:37 -07006958#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006959/**
6960 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006961 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962 * @level: thermal level
6963 *
6964 * Change IPA data path to SW path when the thermal throttle level greater
6965 * than 0, and restore the original data path when throttle level is 0
6966 *
6967 * Return: none
6968 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006969static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006970{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006971 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006973 /* Change IPA to SW path when throttle level greater than 0 */
6974 if (level > THROTTLE_LEVEL_0)
6975 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6976 else
6977 /* restore original concurrency mode */
6978 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6979}
6980
6981/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306982 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6983 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306984 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306986 * Get a safe channel to restart SAP. PCL already takes into account the
6987 * unsafe channels. So, the PCL is validated with the ACS range to provide
6988 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306990 * Return: Channel number to restart SAP in case of success. In case of any
6991 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306993static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07006994 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306996 struct sir_pcl_list pcl;
6997 QDF_STATUS status;
6998 uint32_t i, j;
6999 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007000 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307001 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007002
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307003 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7004 if (!hdd_ctx) {
7005 hdd_err("invalid HDD context");
7006 return INVALID_CHANNEL_ID;
7007 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007008
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307009 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7010 if (!hal_handle) {
7011 hdd_err("invalid HAL handle");
7012 return INVALID_CHANNEL_ID;
7013 }
7014
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007015 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7016 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007017 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7018 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307019 if (QDF_IS_STATUS_ERROR(status)) {
7020 hdd_err("Get PCL failed");
7021 return INVALID_CHANNEL_ID;
7022 }
7023
Frank Liudc2cefb2017-06-21 15:38:18 +08007024 /*
7025 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7026 * channel is unsafe channel, the pcl may be empty, instead of return,
7027 * try to choose a safe channel from acs range.
7028 */
7029 if (!pcl.pcl_len)
7030 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307031
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007032 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307033 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7034 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7035
7036 /* PCL already takes unsafe channel into account */
7037 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007038 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307039 if ((pcl.pcl_list[i] >=
7040 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7041 (pcl.pcl_list[i] <=
7042 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007043 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307044 return pcl.pcl_list[i];
7045 }
7046 }
7047
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007048 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049
7050 /* Try for safe channel from all valid channel */
7051 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007052 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307053 &pcl.pcl_len);
7054 if (QDF_IS_STATUS_ERROR(status)) {
7055 hdd_err("error in getting valid channel list");
7056 return INVALID_CHANNEL_ID;
7057 }
7058
7059 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007060 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061 found = false;
7062 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007063 if (pcl.pcl_list[i] ==
7064 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007065 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307066 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067 break;
7068 }
7069 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307070
7071 if (found)
7072 continue;
7073
7074 if ((pcl.pcl_list[i] >=
7075 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7076 (pcl.pcl_list[i] <=
7077 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007078 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307079 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080 }
7081 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307082
7083 return INVALID_CHANNEL_ID;
7084}
7085
7086/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007087 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307088 * @adapter: AP adapter
7089 * @channel: Channel
7090 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007091 * Moves the SAP interface by invoking the function which
7092 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307093 *
7094 * Return: None
7095 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007096void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307097{
Jeff Johnson87251032017-08-29 13:31:11 -07007098 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307099 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007100 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307101
7102 if (!adapter) {
7103 hdd_err("invalid adapter");
7104 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307106
7107 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7108
7109 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7110 if (!hal_handle) {
7111 hdd_err("invalid HAL handle");
7112 return;
7113 }
7114
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007115 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7116
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307117 hdd_ap_ctx->sapConfig.channel = channel;
7118 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7119 hdd_ap_ctx->sapConfig.ch_width_orig;
7120
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007121 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307122 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7123
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007124 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7125 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307126 hdd_ap_ctx->sapConfig.sec_ch,
7127 &hdd_ap_ctx->sapConfig.ch_params);
7128
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007129 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7130 adapter->sessionId, channel,
7131 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007132}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307133
Jeff Johnson9d295242017-08-29 14:39:48 -07007134int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307135{
7136 struct hdd_external_acs_timer_context *timer_context;
7137
7138 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7139
7140 if (QDF_TIMER_STATE_RUNNING ==
7141 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7142 ap.vendor_acs_timer)) {
7143 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7144 }
7145 timer_context = (struct hdd_external_acs_timer_context *)
7146 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7147 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307148 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307149 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307150 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7151 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307152 hdd_notice("Updated ACS config to nl with reason %d", reason);
7153
7154 return 0;
7155}
7156
Agrawal Ashish467dde42016-09-08 18:44:22 +05307157/**
7158 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7159 * @hdd_ctx: hdd context pointer
7160 *
7161 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7162 * and if ACS is enabled, driver will ask userspace to restart the
7163 * sap. User space on LTE coex indication restart driver.
7164 *
7165 * Return - none
7166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007167void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307168{
7169 QDF_STATUS status;
7170 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007171 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307172 uint32_t i;
7173 bool found = false;
7174 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175
Agrawal Ashish467dde42016-09-08 18:44:22 +05307176 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7177 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07007178 adapter_temp = adapter_node->adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307179
7180 if (!adapter_temp) {
7181 hdd_err("adapter is NULL, moving to next one");
7182 goto next_adapater;
7183 }
7184
7185 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7186 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007187 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307188 adapter_temp->device_mode,
7189 adapter_temp->sessionCtx.ap.sapConfig.
7190 acs_cfg.acs_mode);
7191 goto next_adapater;
7192 }
7193
7194 found = false;
7195 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007196 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307197 hdd_ctxt->unsafe_channel_list[i]) {
7198 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007199 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307200 adapter_temp->sessionCtx.ap.operatingChannel);
7201 break;
7202 }
7203 }
7204
7205 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007206 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307207 adapter_temp->sessionCtx.ap.operatingChannel);
7208 goto next_adapater;
7209 }
7210
Kapil Gupta8878ad92017-02-13 11:56:04 +05307211 if (hdd_ctxt->config->vendor_acs_support &&
7212 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7213 hdd_update_acs_timer_reason(adapter_temp,
7214 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7215 goto next_adapater;
7216 } else
7217 restart_chan =
7218 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307219 adapter_temp);
7220 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007221 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307222 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007223 /*
7224 * SAP restart due to unsafe channel. While
7225 * restarting the SAP, make sure to clear
7226 * acs_channel, channel to reset to
7227 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307228 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007229 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307230 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7231 adapter_temp->sessionCtx.ap.sapConfig.channel =
7232 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007233 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307234 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7235 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007236 hdd_debug("driver to start sap: %d",
7237 hdd_ctxt->config->sap_internal_restart);
7238 if (hdd_ctxt->config->sap_internal_restart)
7239 hdd_switch_sap_channel(adapter_temp, restart_chan);
7240 else
7241 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307242 }
7243
7244next_adapater:
7245 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7246 adapter_node = next;
7247 }
7248}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307249
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007251 * hdd_init_channel_avoidance() - Initialize channel avoidance
7252 * @hdd_ctx: HDD global context
7253 *
7254 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007255 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256 * down to the lower layers. Then subscribe to subsequent channel
7257 * avoidance events.
7258 *
7259 * Return: None
7260 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007261static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262{
7263 uint16_t unsafe_channel_count;
7264 int index;
7265
Yuanyuan Liu13738502016-04-06 17:41:37 -07007266 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7267 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007269 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007271 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007272 hdd_ctx->unsafe_channel_count);
7273
Anurag Chouhan6d760662016-02-20 16:05:43 +05307274 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007275 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007276
7277 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007278 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007279 hdd_ctx->unsafe_channel_list[index]);
7280
7281 }
7282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283}
Dustin Brown676a2322017-08-15 13:16:13 -07007284
Jeff Johnson9d295242017-08-29 14:39:48 -07007285static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007286 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007287{
7288 uint8_t restart_chan;
7289
7290 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7291 if (!restart_chan) {
7292 hdd_alert("fail to restart SAP");
7293 return;
7294 }
7295
7296 /* SAP restart due to unsafe channel. While restarting
7297 * the SAP, make sure to clear acs_channel, channel to
7298 * reset to 0. Otherwise these settings will override
7299 * the ACS while restart.
7300 */
7301 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7302 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7303
7304 hdd_debug("sending coex indication");
7305
7306 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7307 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7308 hdd_switch_sap_channel(adapter, restart_chan);
7309}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007310
7311int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7312 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7313{
7314 uint32_t size;
7315 uint16_t *unsafe_list;
7316 uint16_t chan_count;
7317
7318 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7319 return -EINVAL;
7320
7321 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7322 NUM_CHANNELS);
7323 if (chan_count) {
7324 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7325 unsafe_list = qdf_mem_malloc(size);
7326 if (!unsafe_list) {
7327 hdd_err("No memory for unsafe chan list size%d",
7328 size);
7329 return -ENOMEM;
7330 }
7331 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7332 } else {
7333 unsafe_list = NULL;
7334 }
7335
7336 *local_unsafe_list = unsafe_list;
7337 *local_unsafe_list_count = chan_count;
7338
7339 return 0;
7340}
7341
7342bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7343 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7344{
7345 int i, j;
7346
7347 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7348 return true;
7349 if (local_unsafe_list_count == 0)
7350 return false;
7351 for (i = 0; i < local_unsafe_list_count; i++) {
7352 for (j = 0; j < local_unsafe_list_count; j++)
7353 if (local_unsafe_list[i] ==
7354 hdd_ctx->unsafe_channel_list[j])
7355 break;
7356 if (j >= local_unsafe_list_count)
7357 break;
7358 }
7359 if (i >= local_unsafe_list_count) {
7360 hdd_info("unsafe chan list same");
7361 return false;
7362 }
7363
7364 return true;
7365}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007366#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007367static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007368{
7369}
Dustin Brown676a2322017-08-15 13:16:13 -07007370
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007371static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007372{
7373}
Dustin Brown676a2322017-08-15 13:16:13 -07007374
Jeff Johnson9d295242017-08-29 14:39:48 -07007375static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007376 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007377{
7378 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7379}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007380#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007381
7382/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007383 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7384 * user space
7385 * @frame_ind: Management frame data to be informed.
7386 *
7387 * This function is used to indicate management frame to
7388 * user space
7389 *
7390 * Return: None
7391 *
7392 */
7393void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7394{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007395 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007396 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007397 int i;
7398
Rajeev Kumard004abc2016-02-17 12:09:56 -08007399 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007400 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007401
7402 if (0 != wlan_hdd_validate_context(hdd_ctx))
7403 return;
7404
7405 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7406 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7407 adapter =
7408 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7409 if (adapter)
7410 break;
7411 }
7412 } else {
7413 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7414 frame_ind->sessionId);
7415 }
7416
7417 if ((NULL != adapter) &&
7418 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7419 __hdd_indicate_mgmt_frame(adapter,
7420 frame_ind->frame_len,
7421 frame_ind->frameBuf,
7422 frame_ind->frameType,
7423 frame_ind->rxChan,
7424 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007425}
7426
Kapil Gupta8878ad92017-02-13 11:56:04 +05307427void hdd_acs_response_timeout_handler(void *context)
7428{
7429 struct hdd_external_acs_timer_context *timer_context =
7430 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007431 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007432 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307433 uint8_t reason;
7434
7435 ENTER();
7436 if (!timer_context) {
7437 hdd_err("invlaid timer context");
7438 return;
7439 }
7440 adapter = timer_context->adapter;
7441 reason = timer_context->reason;
7442
7443
7444 if ((!adapter) ||
7445 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7446 hdd_err("invalid adapter or adapter has invalid magic");
7447 return;
7448 }
7449 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7450 if (wlan_hdd_validate_context(hdd_ctx))
7451 return;
7452
7453 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7454 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7455 else
7456 return;
7457
7458 hdd_err("ACS timeout happened for %s reason %d",
7459 adapter->dev->name, reason);
7460 switch (reason) {
7461 /* SAP init case */
7462 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7463 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7464 false);
7465 wlan_hdd_cfg80211_start_acs(adapter);
7466 break;
7467 /* DFS detected on current channel */
7468 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7469 wlan_sap_update_next_channel(
7470 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7471 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7472 adapter->sessionId);
7473 break;
7474 /* LTE coex event on current channel */
7475 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7476 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7477 break;
7478 default:
7479 hdd_info("invalid reason for timer invoke");
7480
7481 }
7482}
7483
Rajeev Kumard004abc2016-02-17 12:09:56 -08007484/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007485 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7486 * @hdd_ctx: HDD context
7487 *
7488 * Disables all the dual mac features like DBS, Agile DFS etc.
7489 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307490 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007491 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007492static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007494 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307495 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007496
7497 if (!hdd_ctx) {
7498 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307499 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500 }
7501
7502 cfg.scan_config = 0;
7503 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007504 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007505
7506 hdd_debug("Disabling all dual mac features...");
7507
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007508 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307509 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7511 return status;
7512 }
7513
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307514 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007515}
7516
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007517static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007518wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007519{
7520 struct policy_mgr_dual_mac_config cfg = {0};
7521 QDF_STATUS status;
7522
7523 if (!hdd_ctx) {
7524 hdd_err("HDD context is NULL");
7525 return QDF_STATUS_E_FAILURE;
7526 }
7527
7528 cfg.scan_config = 0;
7529 cfg.fw_mode_config = 0;
7530 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7531 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7532 hdd_ctx->hdd_psoc, &cfg.scan_config,
7533 &cfg.fw_mode_config,
7534 hdd_ctx->config->dual_mac_feature_disable);
7535
7536 if (status != QDF_STATUS_SUCCESS) {
7537 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7538 status);
7539 return status;
7540 }
7541
7542 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7543 cfg.scan_config, cfg.fw_mode_config);
7544
7545 status = sme_soc_set_dual_mac_config(cfg);
7546 if (status != QDF_STATUS_SUCCESS) {
7547 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7548 return status;
7549 }
7550
7551 return QDF_STATUS_SUCCESS;
7552}
7553
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007555 * hdd_override_ini_config - Override INI config
7556 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007557 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007558 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007559 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007560 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007562static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007565 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7566 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007567 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007568 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007570 if (0 == enable_11d || 1 == enable_11d) {
7571 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007572 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573 }
Leo Chang11545d62016-10-17 14:53:50 -07007574
7575 if (!hdd_ipa_is_present(hdd_ctx))
7576 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007577}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007578
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007579/**
7580 * hdd_set_trace_level_for_each - Set trace level for each INI config
7581 * @hdd_ctx - HDD context
7582 *
7583 * Set trace level for each module based on INI config.
7584 *
7585 * Return: None
7586 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007587static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007588{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307589 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7590 hdd_ctx->config->qdf_trace_enable_wdi);
7591 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7592 hdd_ctx->config->qdf_trace_enable_hdd);
7593 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7594 hdd_ctx->config->qdf_trace_enable_sme);
7595 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7596 hdd_ctx->config->qdf_trace_enable_pe);
7597 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7598 hdd_ctx->config->qdf_trace_enable_wma);
7599 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7600 hdd_ctx->config->qdf_trace_enable_sys);
7601 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7602 hdd_ctx->config->qdf_trace_enable_qdf);
7603 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7604 hdd_ctx->config->qdf_trace_enable_sap);
7605 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7606 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7607 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7608 hdd_ctx->config->qdf_trace_enable_bmi);
7609 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7610 hdd_ctx->config->qdf_trace_enable_cfg);
7611 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7612 hdd_ctx->config->qdf_trace_enable_epping);
7613 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7614 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7615 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007616 hdd_ctx->config->qdf_trace_enable_txrx);
7617 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7618 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307619 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7620 hdd_ctx->config->qdf_trace_enable_htc);
7621 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7622 hdd_ctx->config->qdf_trace_enable_hif);
7623 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7624 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7625 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7626 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007627 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7628 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007629 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7630 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007631 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7632 hdd_ctx->config->qdf_trace_enable_regulatory);
7633
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635}
7636
7637/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007638 * hdd_context_init() - Initialize HDD context
7639 * @hdd_ctx: HDD context.
7640 *
7641 * Initialize HDD context along with all the feature specific contexts.
7642 *
7643 * return: 0 on success and errno on failure.
7644 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007645static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007646{
7647 int ret;
7648
7649 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7650 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7651
7652 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307653 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007654
7655 init_completion(&hdd_ctx->mc_sus_event_var);
7656 init_completion(&hdd_ctx->ready_to_suspend);
7657
7658 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307659 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007660 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307661
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007662 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7663
7664 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7665
7666 ret = hdd_scan_context_init(hdd_ctx);
7667 if (ret)
7668 goto list_destroy;
7669
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007670 hdd_rx_wake_lock_create(hdd_ctx);
7671
7672 ret = hdd_sap_context_init(hdd_ctx);
7673 if (ret)
7674 goto scan_destroy;
7675
7676 ret = hdd_roc_context_init(hdd_ctx);
7677 if (ret)
7678 goto sap_destroy;
7679
7680 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7681
7682 hdd_init_offloaded_packets_ctx(hdd_ctx);
7683
7684 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7685 hdd_ctx->config);
7686 if (ret)
7687 goto roc_destroy;
7688
7689 return 0;
7690
7691roc_destroy:
7692 hdd_roc_context_destroy(hdd_ctx);
7693
7694sap_destroy:
7695 hdd_sap_context_destroy(hdd_ctx);
7696
7697scan_destroy:
7698 hdd_scan_context_destroy(hdd_ctx);
7699 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007700list_destroy:
7701 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007702
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007703 return ret;
7704}
7705
7706/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307707 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7708 * @hdd_ctx: pointer to hdd context
7709 *
7710 * Return: status of initialization
7711 * 0 - success
7712 * negative value - failure
7713 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007714static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307715{
7716 int ret;
7717
7718 if (!hdd_ctx->config->probe_req_ie_whitelist)
7719 return 0;
7720
7721 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7722 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7723 hdd_ctx->config->probe_req_ie_whitelist = false;
7724 return -EINVAL;
7725 }
7726
7727 /* parse ini string probe req oui */
7728 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7729 if (ret) {
7730 hdd_err("parsing error: disable ie whitelisting");
7731 hdd_ctx->config->probe_req_ie_whitelist = false;
7732 }
7733
7734 return ret;
7735}
7736
7737/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007738 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307739 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007740 *
7741 * Allocate and initialize HDD context. HDD context is allocated as part of
7742 * wiphy allocation and then context is initialized.
7743 *
7744 * Return: HDD context on success and ERR_PTR on failure
7745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007746static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007747{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307748 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007749 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007750 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007751
7752 ENTER();
7753
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007754 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007755 if (hdd_ctx == NULL) {
7756 ret = -ENOMEM;
7757 goto err_out;
7758 }
7759
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007760 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307761 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007762
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307763 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007764 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007765 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007766 ret = -ENOMEM;
7767 goto err_free_hdd_context;
7768 }
7769
7770 /* Read and parse the qcom_cfg.ini file */
7771 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307772 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307773 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007774 WLAN_INI_FILE);
7775 ret = -EINVAL;
7776 goto err_free_config;
7777 }
7778
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307779 ie_whitelist_attrs_init(hdd_ctx);
7780
Dustin Brown7f939932017-05-18 15:02:17 -07007781 hdd_debug("setting timer multiplier: %u",
7782 hdd_ctx->config->timer_multiplier);
7783 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7784
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007785
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307786 if (hdd_ctx->config->fhostNSOffload)
7787 hdd_ctx->ns_offload_enable = true;
7788
Abhishek Singh5ea86532016-04-27 14:10:53 +05307789 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7790
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007791 hdd_override_ini_config(hdd_ctx);
7792
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007793 ret = hdd_context_init(hdd_ctx);
7794
7795 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007796 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007797
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007798 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307799 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007800
Anurag Chouhan6d760662016-02-20 16:05:43 +05307801 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007802 goto skip_multicast_logging;
7803
7804 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7805
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007806 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7807 if (ret)
7808 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307809
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007810 ret = hdd_init_netlink_services(hdd_ctx);
7811 if (ret)
7812 goto err_deinit_txrx_histogram;
7813
Dustin Brown7b3dea22017-07-10 13:02:47 -07007814 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7815 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307816
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007817skip_multicast_logging:
7818 hdd_set_trace_level_for_each(hdd_ctx);
7819
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007820 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
7821
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007822 EXIT();
7823
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007824 return hdd_ctx;
7825
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007826err_deinit_txrx_histogram:
7827 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7828
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007829err_deinit_hdd_context:
7830 hdd_context_deinit(hdd_ctx);
7831
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007832err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307833 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007834
7835err_free_hdd_context:
7836 wiphy_free(hdd_ctx->wiphy);
7837
7838err_out:
7839 return ERR_PTR(ret);
7840}
7841
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007842#ifdef WLAN_OPEN_P2P_INTERFACE
7843/**
7844 * hdd_open_p2p_interface - Open P2P interface
7845 * @hdd_ctx: HDD context
7846 * @rtnl_held: True if RTNL lock held
7847 *
7848 * Open P2P interface during probe. This function called to open the P2P
7849 * interface at probe along with STA interface.
7850 *
7851 * Return: 0 on success and errno on failure
7852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007853static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007854{
Jeff Johnson9d295242017-08-29 14:39:48 -07007855 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007856 uint8_t *p2p_dev_addr;
7857
7858 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7859 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307860 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007861 hdd_ctx->config->intfMacAddr[0].bytes,
7862 sizeof(tSirMacAddr));
7863
7864 /*
7865 * Generate the P2P Device Address. This consists of
7866 * the device's primary MAC address with the locally
7867 * administered bit set.
7868 */
7869 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7870 } else {
7871 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7872 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007873 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007874 return -ENOSPC;
7875 }
7876
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307877 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307878 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007879 }
7880
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007881 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007882 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007883 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007884
7885 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007886 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007887 return -ENOSPC;
7888 }
7889
7890 return 0;
7891}
7892#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007893static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007894 bool rtnl_held)
7895{
7896 return 0;
7897}
7898#endif
7899
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007900static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007901{
Jeff Johnson9d295242017-08-29 14:39:48 -07007902 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007903 int ret = 0;
7904
7905 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7906 wlan_hdd_get_intf_addr(hdd_ctx),
7907 NET_NAME_UNKNOWN, rtnl_held);
7908 if (adapter == NULL) {
7909 hdd_err("Failed to open 802.11p interface");
7910 ret = -ENOSPC;
7911 }
7912
7913 return ret;
7914}
7915
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007916/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307917 * hdd_start_station_adapter()- Start the Station Adapter
7918 * @adapter: HDD adapter
7919 *
7920 * This function initializes the adapter for the station mode.
7921 *
7922 * Return: 0 on success or errno on failure.
7923 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007924int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307925{
7926 QDF_STATUS status;
7927
7928 ENTER_DEV(adapter->dev);
7929
7930 status = hdd_init_station_mode(adapter);
7931
7932 if (QDF_STATUS_SUCCESS != status) {
7933 hdd_err("Error Initializing station mode: %d", status);
7934 return qdf_status_to_os_return(status);
7935 }
7936
Arun Khandavallifae92942016-08-01 13:31:08 +05307937 hdd_register_tx_flow_control(adapter,
7938 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007939 hdd_tx_resume_cb,
7940 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307941
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307942 EXIT();
7943 return 0;
7944}
7945
7946/**
7947 * hdd_start_ap_adapter()- Start AP Adapter
7948 * @adapter: HDD adapter
7949 *
7950 * This function initializes the adapter for the AP mode.
7951 *
7952 * Return: 0 on success errno on failure.
7953 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007954int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307955{
7956 QDF_STATUS status;
7957
7958 ENTER();
7959
Arun Khandavallicc544b32017-01-30 19:52:16 +05307960 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307961
7962 if (QDF_STATUS_SUCCESS != status) {
7963 hdd_err("Error Initializing the AP mode: %d", status);
7964 return qdf_status_to_os_return(status);
7965 }
7966
Arun Khandavallifae92942016-08-01 13:31:08 +05307967 hdd_register_tx_flow_control(adapter,
7968 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007969 hdd_softap_tx_resume_cb,
7970 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307971
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307972 EXIT();
7973 return 0;
7974}
7975
7976/**
7977 * hdd_start_ftm_adapter()- Start FTM adapter
7978 * @adapter: HDD adapter
7979 *
7980 * This function initializes the adapter for the FTM mode.
7981 *
7982 * Return: 0 on success or errno on failure.
7983 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007984int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307985{
7986 QDF_STATUS qdf_status;
7987
7988 ENTER_DEV(adapter->dev);
7989
7990 qdf_status = hdd_init_tx_rx(adapter);
7991
7992 if (QDF_STATUS_SUCCESS != qdf_status) {
7993 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7994 return qdf_status_to_os_return(qdf_status);
7995 }
7996
7997 return 0;
7998 EXIT();
7999}
8000
8001/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008002 * hdd_open_interfaces - Open all required interfaces
8003 * hdd_ctx: HDD context
8004 * rtnl_held: True if RTNL lock is held
8005 *
8006 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8007 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008008 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008010static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008011{
Jeff Johnson9d295242017-08-29 14:39:48 -07008012 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008013 int ret;
8014
Ravi Joshia307f632017-07-17 23:41:41 -07008015 /* open monitor mode adapter if con_mode is monitor mode */
8016 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8017 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8018 wlan_hdd_get_intf_addr(hdd_ctx),
8019 NET_NAME_UNKNOWN, rtnl_held);
8020 if (!adapter) {
8021 hdd_err("open adapter failed");
8022 return -ENOSPC;
8023 }
8024 return 0;
8025 }
8026
Jeff Johnson957bc272017-02-02 08:54:48 -08008027 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308028 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008029 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008030
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008031 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008032 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008033 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008034
8035 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008036 return -ENOSPC;
8037
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008038 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8039 adapter->fast_roaming_allowed = true;
8040
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008041 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8042 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008043 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008044
8045 /* Open 802.11p Interface */
8046 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008047 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8048 if (ret)
8049 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008050 }
8051
Jeff Johnson957bc272017-02-02 08:54:48 -08008052 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008053
Jeff Johnson957bc272017-02-02 08:54:48 -08008054err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008055 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008056 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008057}
8058
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008059/**
8060 * hdd_update_country_code - Update country code
8061 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008062 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008063 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008064 *
8065 * Return: 0 on success and errno on failure
8066 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008067static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008068{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008069 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008070 return 0;
8071
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008072 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008073}
8074
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308075#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8076/**
8077 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8078 * @cds_cfg: CDS Configuration
8079 * @hdd_ctx: Pointer to hdd context
8080 *
8081 * Return: none
8082 */
8083static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8084 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008085 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308086{
8087 cds_cfg->tx_flow_stop_queue_th =
8088 hdd_ctx->config->TxFlowStopQueueThreshold;
8089 cds_cfg->tx_flow_start_queue_offset =
8090 hdd_ctx->config->TxFlowStartQueueOffset;
8091}
8092#else
8093static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8094 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008095 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308096{
8097}
8098#endif
8099
8100#ifdef FEATURE_WLAN_RA_FILTERING
8101/**
8102 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8103 * @cds_cfg: CDS Configuration
8104 * @hdd_ctx: Pointer to hdd context
8105 *
8106 * Return: none
8107 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308108static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008109 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308110{
8111 cds_cfg->ra_ratelimit_interval =
8112 hdd_ctx->config->RArateLimitInterval;
8113 cds_cfg->is_ra_ratelimit_enabled =
8114 hdd_ctx->config->IsRArateLimitEnabled;
8115}
8116#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308117static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008118 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308119{
8120}
8121#endif
8122
8123/**
8124 * hdd_update_cds_config() - API to update cds configuration parameters
8125 * @hdd_ctx: HDD Context
8126 *
8127 * Return: 0 for Success, errno on failure
8128 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008129static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308130{
8131 struct cds_config_info *cds_cfg;
8132
8133 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8134 if (!cds_cfg) {
8135 hdd_err("failed to allocate cds config");
8136 return -ENOMEM;
8137 }
8138
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008139 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008140 if (!hdd_ctx->config->nMaxPsPoll ||
8141 !hdd_ctx->config->enablePowersaveOffload) {
8142 cds_cfg->powersave_offload_enabled =
8143 hdd_ctx->config->enablePowersaveOffload;
8144 } else {
8145 if ((hdd_ctx->config->enablePowersaveOffload ==
8146 PS_QPOWER_NODEEPSLEEP) ||
8147 (hdd_ctx->config->enablePowersaveOffload ==
8148 PS_LEGACY_NODEEPSLEEP))
8149 cds_cfg->powersave_offload_enabled =
8150 PS_LEGACY_NODEEPSLEEP;
8151 else
8152 cds_cfg->powersave_offload_enabled =
8153 PS_LEGACY_DEEPSLEEP;
8154 hdd_info("Qpower disabled in cds config, %d",
8155 cds_cfg->powersave_offload_enabled);
8156 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308157 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8158 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8159 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8160 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8161 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8162
8163 /* Here ol_ini_info is used to store ini status of arp offload
8164 * ns offload and others. Currently 1st bit is used for arp
8165 * off load and 2nd bit for ns offload currently, rest bits are unused
8166 */
8167 if (hdd_ctx->config->fhostArpOffload)
8168 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8169 if (hdd_ctx->config->fhostNSOffload)
8170 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8171
8172 /*
8173 * Copy the DFS Phyerr Filtering Offload status.
8174 * This parameter reflects the value of the
8175 * dfs_phyerr_filter_offload flag as set in the ini.
8176 */
8177 cds_cfg->dfs_phyerr_filter_offload =
8178 hdd_ctx->config->fDfsPhyerrFilterOffload;
8179 if (hdd_ctx->config->ssdp)
8180 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8181
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308182 cds_cfg->force_target_assert_enabled =
8183 hdd_ctx->config->crash_inject_enabled;
8184
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308185 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8186 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8187
8188 cds_cfg->ap_maxoffload_reorderbuffs =
8189 hdd_ctx->config->apMaxOffloadReorderBuffs;
8190
8191 cds_cfg->ap_disable_intrabss_fwd =
8192 hdd_ctx->config->apDisableIntraBssFwd;
8193
8194 cds_cfg->dfs_pri_multiplier =
8195 hdd_ctx->config->dfsRadarPriMultiplier;
8196 cds_cfg->reorder_offload =
8197 hdd_ctx->config->reorderOffloadSupport;
8198
8199 /* IPA micro controller data path offload resource config item */
8200 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008201 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8202 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008203 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008204 hdd_ctx->config->IpaUcTxBufCount);
8205 hdd_ctx->config->IpaUcTxBufCount =
8206 rounddown_pow_of_two(
8207 hdd_ctx->config->IpaUcTxBufCount);
8208 if (!hdd_ctx->config->IpaUcTxBufCount) {
8209 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308210 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008211 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008212 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008213 hdd_ctx->config->IpaUcTxBufCount);
8214 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308215 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8216 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008217 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8218 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008219 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008220 hdd_ctx->config->IpaUcRxIndRingCount);
8221 hdd_ctx->config->IpaUcRxIndRingCount =
8222 rounddown_pow_of_two(
8223 hdd_ctx->config->IpaUcRxIndRingCount);
8224 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8225 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308226 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008227 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008228 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008229 hdd_ctx->config->IpaUcRxIndRingCount);
8230 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308231 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008232 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308233 cds_cfg->uc_tx_partition_base =
8234 hdd_ctx->config->IpaUcTxPartitionBase;
8235 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8236
8237 cds_cfg->ip_tcp_udp_checksum_offload =
8238 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308239 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308240 cds_cfg->ce_classify_enabled =
8241 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008242 cds_cfg->bpf_packet_filter_enable =
8243 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308244 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8245 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8246 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008247 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008248 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008249 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008250 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308251 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8252 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308253 cds_cfg->auto_power_save_fail_mode =
8254 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308255
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308256 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8257
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308258 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8259 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8260 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008261 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308262 cds_init_ini_config(cds_cfg);
8263 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308264
8265exit:
8266 qdf_mem_free(cds_cfg);
8267 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308268}
8269
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008270/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008271 * hdd_update_user_config() - API to update user configuration
8272 * parameters to obj mgr which are used by multiple components
8273 * @hdd_ctx: HDD Context
8274 *
8275 * Return: 0 for Success, errno on failure
8276 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008277static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008278{
8279 struct wlan_objmgr_psoc_user_config *user_config;
8280
8281 user_config = qdf_mem_malloc(sizeof(*user_config));
8282 if (user_config == NULL) {
8283 hdd_alert("Failed to alloc memory for user_config!");
8284 return -ENOMEM;
8285 }
8286
8287 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8288 user_config->dual_mac_feature_disable =
8289 hdd_ctx->config->dual_mac_feature_disable;
8290 user_config->indoor_channel_support =
8291 hdd_ctx->config->indoor_channel_support;
8292 user_config->is_11d_support_enabled =
8293 hdd_ctx->config->Is11dSupportEnabled;
8294 user_config->is_11h_support_enabled =
8295 hdd_ctx->config->Is11hSupportEnabled;
8296 user_config->optimize_chan_avoid_event =
8297 hdd_ctx->config->goptimize_chan_avoid_event;
8298 user_config->skip_dfs_chnl_in_p2p_search =
8299 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008300 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008301 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8302
8303 qdf_mem_free(user_config);
8304 return 0;
8305}
8306
8307/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008308 * hdd_init_thermal_info - Initialize thermal level
8309 * @hdd_ctx: HDD context
8310 *
8311 * Initialize thermal level at SME layer and set the thermal level callback
8312 * which would be called when a configured thermal threshold is hit.
8313 *
8314 * Return: 0 on success and errno on failure
8315 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008316static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008317{
8318 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308319 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008320
8321 thermal_param.smeThermalMgmtEnabled =
8322 hdd_ctx->config->thermalMitigationEnable;
8323 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8324
Poddar, Siddarth83905022016-04-16 17:56:08 -07008325 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8326 hdd_ctx->config->throttle_dutycycle_level0;
8327 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8328 hdd_ctx->config->throttle_dutycycle_level1;
8329 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8330 hdd_ctx->config->throttle_dutycycle_level2;
8331 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8332 hdd_ctx->config->throttle_dutycycle_level3;
8333
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008334 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8335 hdd_ctx->config->thermalTempMinLevel0;
8336 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8337 hdd_ctx->config->thermalTempMaxLevel0;
8338 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8339 hdd_ctx->config->thermalTempMinLevel1;
8340 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8341 hdd_ctx->config->thermalTempMaxLevel1;
8342 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8343 hdd_ctx->config->thermalTempMinLevel2;
8344 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8345 hdd_ctx->config->thermalTempMaxLevel2;
8346 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8347 hdd_ctx->config->thermalTempMinLevel3;
8348 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8349 hdd_ctx->config->thermalTempMaxLevel3;
8350
8351 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308353 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308354 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008355
8356 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8357 hdd_set_thermal_level_cb);
8358
8359 return 0;
8360
8361}
8362
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008363#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8364/**
8365 * hdd_hold_rtnl_lock - Hold RTNL lock
8366 *
8367 * Hold RTNL lock
8368 *
8369 * Return: True if held and false otherwise
8370 */
8371static inline bool hdd_hold_rtnl_lock(void)
8372{
8373 rtnl_lock();
8374 return true;
8375}
8376
8377/**
8378 * hdd_release_rtnl_lock - Release RTNL lock
8379 *
8380 * Release RTNL lock
8381 *
8382 * Return: None
8383 */
8384static inline void hdd_release_rtnl_lock(void)
8385{
8386 rtnl_unlock();
8387}
8388#else
8389static inline bool hdd_hold_rtnl_lock(void) { return false; }
8390static inline void hdd_release_rtnl_lock(void) { }
8391#endif
8392
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008393#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008394
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308395/* MAX iwpriv command support */
8396#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308397#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308398#define MAX_PKTLOG_SIZE 16
8399
8400/**
8401 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8402 * @hdd_ctx: hdd context
8403 * @set_value2: pktlog buffer size value
8404 *
8405 *
8406 * Return: 0 for success or error.
8407 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008408static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308409{
8410 struct sir_wifi_start_log start_log = { 0 };
8411 QDF_STATUS status;
8412
8413 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8414 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8415 start_log.ini_triggered = cds_is_packet_log_enabled();
8416 start_log.user_triggered = 1;
8417 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308418 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308419
8420 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8421 if (!QDF_IS_STATUS_SUCCESS(status)) {
8422 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8423 EXIT();
8424 return -EINVAL;
8425 }
8426
8427 return 0;
8428}
8429
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008430/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308431 * hdd_pktlog_clear_buff() - clear pktlog buffer
8432 * @hdd_ctx: hdd context
8433 *
8434 * Return: 0 for success or error.
8435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008436static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308437{
8438 struct sir_wifi_start_log start_log;
8439 QDF_STATUS status;
8440
8441 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8442 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8443 start_log.ini_triggered = cds_is_packet_log_enabled();
8444 start_log.user_triggered = 1;
8445 start_log.size = 0;
8446 start_log.is_pktlog_buff_clear = true;
8447
8448 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8449 if (!QDF_IS_STATUS_SUCCESS(status)) {
8450 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8451 EXIT();
8452 return -EINVAL;
8453 }
8454
8455 return 0;
8456}
8457
8458
8459/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008460 * hdd_process_pktlog_command() - process pktlog command
8461 * @hdd_ctx: hdd context
8462 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463 * @set_value2: pktlog buffer size value
8464 *
8465 * This function process pktlog command.
8466 * set_value2 only matters when set_value is 3 (set buff size)
8467 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008468 *
8469 * Return: 0 for success or error.
8470 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008471int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308472 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008473{
8474 int ret;
8475 bool enable;
8476 uint8_t user_triggered = 0;
8477
8478 ret = wlan_hdd_validate_context(hdd_ctx);
8479 if (0 != ret)
8480 return ret;
8481
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008482 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008483
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308484 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008485 hdd_err("invalid pktlog value %d", set_value);
8486 return -EINVAL;
8487 }
8488
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308489 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8490 if (set_value2 <= 0) {
8491 hdd_err("invalid pktlog size %d", set_value2);
8492 return -EINVAL;
8493 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8494 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8495 return -EINVAL;
8496 }
8497 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308498 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8499 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308500 }
8501
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008502 /*
8503 * set_value = 0 then disable packetlog
8504 * set_value = 1 enable packetlog forcefully
8505 * set_vlaue = 2 then disable packetlog if disabled through ini or
8506 * enable packetlog with AUTO type.
8507 */
8508 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8509 true : false;
8510
8511 if (1 == set_value) {
8512 enable = true;
8513 user_triggered = 1;
8514 }
8515
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308516 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008517}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008518/**
8519 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8520 * @hdd_ctx: HDD context
8521 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308522 * @user_triggered: triggered through iwpriv
8523 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008524 *
8525 * Return: 0 on success; error number otherwise
8526 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008527int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308528 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008529{
8530 struct sir_wifi_start_log start_log;
8531 QDF_STATUS status;
8532
8533 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8534 start_log.verbose_level =
8535 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008536 start_log.ini_triggered = cds_is_packet_log_enabled();
8537 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308538 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308539 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308540 /*
8541 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8542 * commands. Host uses this flag to decide whether to send pktlog
8543 * disable command to fw without sending pktlog enable command
8544 * previously. For eg, If vendor sends pktlog disable command without
8545 * sending pktlog enable command, then host discards the packet
8546 * but for iwpriv command, host will send it to fw.
8547 */
8548 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008549 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8550 if (!QDF_IS_STATUS_SUCCESS(status)) {
8551 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8552 EXIT();
8553 return -EINVAL;
8554 }
8555
8556 return 0;
8557}
8558#endif /* REMOVE_PKT_LOG */
8559
Komal Seelam92fff912016-03-24 11:51:41 +05308560/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008561 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8562 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308563 * @dev: Device Pointer
8564 * @num: Number of Valid Mac address
8565 *
8566 * Return: Pointer to MAC address buffer
8567 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008568static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8569 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308570{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008571 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308572}
Komal Seelam92fff912016-03-24 11:51:41 +05308573
8574/**
8575 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8576 * @hdd_ctx: HDD Context
8577 * @num: Number of random mac addresses needed
8578 *
8579 * Generate random addresses using bit manipulation on the base mac address
8580 *
8581 * Return: None
8582 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008583void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308584{
8585 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8586 uint32_t iter;
8587 struct hdd_config *ini = hdd_ctx->config;
8588 uint8_t *buf = NULL;
8589 uint8_t macaddr_b3, tmp_br3;
8590 uint8_t *src = ini->intfMacAddr[0].bytes;
8591
8592 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8593 buf = ini->intfMacAddr[iter].bytes;
8594 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8595 macaddr_b3 = buf[3];
8596 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8597 INTF_MACADDR_MASK;
8598 macaddr_b3 += tmp_br3;
8599 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8600 buf[0] |= 0x02;
8601 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008602 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308603 }
8604}
8605
8606/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008607 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308608 * @hdd_ctx: HDD Context
8609 *
8610 * API to get mac addresses from platform driver and update the driver
8611 * structures and configure FW with the base mac address.
8612 * Return: int
8613 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008614static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308615{
8616 uint32_t no_of_mac_addr, iter;
8617 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8618 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8619 uint8_t *addr, *buf;
8620 struct device *dev = hdd_ctx->parent_dev;
8621 struct hdd_config *ini = hdd_ctx->config;
8622 tSirMacAddr mac_addr;
8623 QDF_STATUS status;
8624
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008625 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308626
8627 if (no_of_mac_addr == 0 || !addr) {
8628 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8629 return -EINVAL;
8630 }
8631
8632 if (no_of_mac_addr > max_mac_addr)
8633 no_of_mac_addr = max_mac_addr;
8634
8635 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8636
8637 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8638 buf = ini->intfMacAddr[iter].bytes;
8639 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008640 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308641 }
8642
8643 status = sme_set_custom_mac_addr(mac_addr);
8644
8645 if (!QDF_IS_STATUS_SUCCESS(status))
8646 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008647
Komal Seelam92fff912016-03-24 11:51:41 +05308648 if (no_of_mac_addr < max_mac_addr)
8649 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8650 no_of_mac_addr);
8651 return 0;
8652}
8653
8654/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008655 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8656 * @hdd_ctx: HDD Context
8657 *
8658 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8659 * will generate its own MAC and update it to FW.
8660 *
8661 * Return: 0 for success
8662 * Non-zero error code for failure
8663 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008664static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008665{
8666 tSirMacAddr customMacAddr;
8667 QDF_STATUS status;
8668
8669 qdf_mem_copy(&customMacAddr,
8670 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8671 sizeof(tSirMacAddr));
8672 status = sme_set_custom_mac_addr(customMacAddr);
8673 if (!QDF_IS_STATUS_SUCCESS(status))
8674 return -EAGAIN;
8675 return 0;
8676}
8677
8678/**
Komal Seelam92fff912016-03-24 11:51:41 +05308679 * hdd_initialize_mac_address() - API to get wlan mac addresses
8680 * @hdd_ctx: HDD Context
8681 *
8682 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8683 * is provisioned with mac addresses, driver uses it, else it will use
8684 * wlan_mac.bin to update HW MAC addresses.
8685 *
8686 * Return: None
8687 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008688static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308689{
8690 QDF_STATUS status;
8691 int ret;
8692
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008693 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308694 if (ret == 0)
8695 return;
8696
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008697 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8698 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308699
8700 status = hdd_update_mac_config(hdd_ctx);
8701
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008702 if (QDF_IS_STATUS_SUCCESS(status))
8703 return;
8704
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008705 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8706 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008707
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008708 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008709 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008710 if (ret != 0) {
8711 hdd_err("MAC address out-of-sync, ret:%d", ret);
8712 QDF_ASSERT(ret);
8713 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008714 }
Komal Seelam92fff912016-03-24 11:51:41 +05308715}
8716
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008717static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008718{
8719 int vdev_id = 0;
8720 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8721 int value = hdd_ctx->config->smart_chainmask_enabled;
8722 int vpdev = PDEV_CMD;
8723 int ret;
8724
Naveen Rawat247a8682017-06-05 15:00:31 -07008725 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008726 if (ret)
8727 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8728
8729 return ret;
8730}
8731
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008732static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008733{
8734 int vdev_id = 0;
8735 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8736 int value = hdd_ctx->config->alternative_chainmask_enabled;
8737 int vpdev = PDEV_CMD;
8738 int ret;
8739
Naveen Rawat247a8682017-06-05 15:00:31 -07008740 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008741 if (ret)
8742 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8743 ret);
8744
8745 return ret;
8746}
8747
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008748static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008749{
8750 int vdev_id = 0;
8751 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8752 int value = hdd_ctx->config->ani_enabled;
8753 int vpdev = PDEV_CMD;
8754 int ret;
8755
Naveen Rawat247a8682017-06-05 15:00:31 -07008756 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008757 if (ret)
8758 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8759
8760 return ret;
8761}
8762
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008763/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008764 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8765 * @hdd_ctx: HDD context
8766 *
8767 * Pre configurations to be done at lower layer before calling cds enable.
8768 *
8769 * Return: 0 on success and errno on failure.
8770 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008771static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008772{
8773 int ret;
8774 QDF_STATUS status;
8775 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008776 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008777
Leo Changfdb45c32016-10-28 11:09:23 -07008778 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008779 /*
8780 * Set 802.11p config
8781 * TODO-OCB: This has been temporarily added here to ensure this
8782 * parameter is set in CSR when we init the channel list. This should
8783 * be removed once the 5.9 GHz channels are added to the regulatory
8784 * domain.
8785 */
8786 hdd_set_dot11p_config(hdd_ctx);
8787
8788 /*
8789 * Note that the cds_pre_enable() sequence triggers the cfg download.
8790 * The cfg download must occur before we update the SME config
8791 * since the SME config operation must access the cfg database
8792 */
8793 status = hdd_set_sme_config(hdd_ctx);
8794
8795 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008796 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008797 ret = qdf_status_to_os_return(status);
8798 goto out;
8799 }
8800
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008801 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8802 if (QDF_STATUS_SUCCESS != status) {
8803 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8804 ret = qdf_status_to_os_return(status);
8805 goto out;
8806 }
8807
Naveen Rawat247a8682017-06-05 15:00:31 -07008808 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008809 hdd_ctx->config->tx_chain_mask_1ss,
8810 PDEV_CMD);
8811 if (0 != ret) {
8812 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8813 goto out;
8814 }
8815
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008816 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8817 if (ret)
8818 goto out;
8819
8820 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8821 if (ret)
8822 goto out;
8823
Jeff Johnson12a744b2017-04-04 08:19:37 -07008824 ret = hdd_set_ani_enabled(hdd_ctx);
8825 if (ret)
8826 goto out;
8827
Naveen Rawat247a8682017-06-05 15:00:31 -07008828 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008829 hdd_ctx->config->arp_ac_category,
8830 PDEV_CMD);
8831 if (0 != ret) {
8832 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8833 hdd_ctx->config->arp_ac_category, ret);
8834 goto out;
8835 }
8836
8837
Prashanth Bhatta07998752016-04-28 12:35:33 -07008838 status = hdd_set_sme_chan_list(hdd_ctx);
8839 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008840 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008841 ret = qdf_status_to_os_return(status);
8842 goto out;
8843 }
8844
8845 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008846 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008847 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008848 ret = -EINVAL;
8849 goto out;
8850 }
8851
Prashanth Bhatta07998752016-04-28 12:35:33 -07008852 /*
8853 * Set the MAC Address Currently this is used by HAL to add self sta.
8854 * Remove this once self sta is added as part of session open.
8855 */
8856 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8857 hdd_ctx->config->intfMacAddr[0].bytes,
8858 sizeof(hdd_ctx->config->intfMacAddr[0]));
8859
8860 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8861 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8862 hal_status, hal_status);
8863 ret = -EINVAL;
8864 goto out;
8865 }
8866
8867 hdd_init_channel_avoidance(hdd_ctx);
8868
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308869 /* update enable sap mandatory chan list */
8870 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8871 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008872out:
8873 return ret;
8874}
8875
8876/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008877 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8878 * @context_ptr - hdd context pointer
8879 * @event_ptr - event structure pointer
8880 *
8881 * This is the p2p listen offload stop event handler, it sends vendor
8882 * event back to supplicant to notify the stop reason.
8883 *
8884 * Return: None
8885 */
8886static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8887 void *event_ptr)
8888{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008889 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008890 struct sir_p2p_lo_event *evt = event_ptr;
8891 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008892 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008893
8894 ENTER();
8895
8896 if (hdd_ctx == NULL) {
8897 hdd_err("Invalid HDD context pointer");
8898 return;
8899 }
8900
Peng Xu5c682812017-08-06 07:39:13 -07008901 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8902 if (!adapter) {
8903 hdd_err("Cannot find adapter by vdev_id = %d",
8904 evt->vdev_id);
8905 return;
8906 }
8907
Peng Xu8fdaa492016-06-22 10:20:47 -07008908 vendor_event =
8909 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008910 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008911 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8912 GFP_KERNEL);
8913
8914 if (!vendor_event) {
8915 hdd_err("cfg80211_vendor_event_alloc failed");
8916 return;
8917 }
8918
8919 if (nla_put_u32(vendor_event,
8920 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8921 evt->reason_code)) {
8922 hdd_err("nla put failed");
8923 kfree_skb(vendor_event);
8924 return;
8925 }
8926
8927 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008928 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8929 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008930}
8931
8932/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308933 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8934 * @hdd_ctx: HDD context
8935 *
8936 * This function sends the adaptive dwell time config configuration to the
8937 * firmware via WMA
8938 *
8939 * Return: 0 - success, < 0 - failure
8940 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008941static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308942{
8943 QDF_STATUS status;
8944 struct adaptive_dwelltime_params dwelltime_params;
8945
8946 dwelltime_params.is_enabled =
8947 hdd_ctx->config->adaptive_dwell_mode_enabled;
8948 dwelltime_params.dwelltime_mode =
8949 hdd_ctx->config->global_adapt_dwelltime_mode;
8950 dwelltime_params.lpf_weight =
8951 hdd_ctx->config->adapt_dwell_lpf_weight;
8952 dwelltime_params.passive_mon_intval =
8953 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8954 dwelltime_params.wifi_act_threshold =
8955 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8956
8957 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8958 &dwelltime_params);
8959
8960 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8961 if (!QDF_IS_STATUS_SUCCESS(status)) {
8962 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8963 return -EAGAIN;
8964 }
8965 return 0;
8966}
8967
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008968int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308969{
8970 QDF_STATUS status;
8971 struct wmi_dbs_scan_sel_params dbs_scan_params;
8972 uint32_t i = 0;
8973 uint8_t count = 0, numentries = 0;
8974 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8975 * CDS_DBS_SCAN_CLIENTS_MAX];
8976
8977 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008978 if (hdd_ctx->config->dual_mac_feature_disable ==
8979 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308980 return -EINVAL;
8981
8982 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8983 dbs_scan_config, &numentries,
8984 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8985 * CDS_DBS_SCAN_CLIENTS_MAX));
8986
8987 hdd_info("numentries %hu", numentries);
8988 if (!numentries) {
8989 hdd_info("Donot send scan_selection_config");
8990 return 0;
8991 }
8992
8993 /* hdd_set_fw_log_params */
8994 dbs_scan_params.num_clients = 0;
8995 while (count < (numentries - 2)) {
8996 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8997 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8998 dbs_scan_params.num_non_dbs_scans[i] =
8999 dbs_scan_config[count + 2];
9000 dbs_scan_params.num_clients++;
9001 hdd_debug("module:%d NDS:%d NNDS:%d",
9002 dbs_scan_params.module_id[i],
9003 dbs_scan_params.num_dbs_scans[i],
9004 dbs_scan_params.num_non_dbs_scans[i]);
9005 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9006 i++;
9007 }
9008
9009 dbs_scan_params.pdev_id = 0;
9010
9011 hdd_debug("clients:%d pdev:%d",
9012 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9013
9014 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9015 &dbs_scan_params);
9016 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9017 if (!QDF_IS_STATUS_SUCCESS(status)) {
9018 hdd_err("Failed to send DBS Scan selection configuration!");
9019 return -EAGAIN;
9020 }
9021 return 0;
9022}
9023
Arun Khandavallid4349a92016-07-25 11:10:43 +05309024#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9025/**
9026 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9027 * @hdd_ctx: HDD context
9028 *
9029 * Set auto shutdown callback to get indications from firmware to indicate
9030 * userspace to shutdown WLAN after a configured amount of inactivity.
9031 *
9032 * Return: 0 on success and errno on failure.
9033 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009034static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309035{
9036 QDF_STATUS status;
9037
9038 if (!hdd_ctx->config->WlanAutoShutdown)
9039 return 0;
9040
9041 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9042 wlan_hdd_auto_shutdown_cb);
9043 if (status != QDF_STATUS_SUCCESS)
9044 hdd_err("Auto shutdown feature could not be enabled: %d",
9045 status);
9046
9047 return qdf_status_to_os_return(status);
9048}
9049#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009050static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309051{
9052 return 0;
9053}
9054#endif
9055
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009056static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009057{
9058 QDF_STATUS status = QDF_STATUS_SUCCESS;
9059
9060 switch (hdd_ctx->config->dual_mac_feature_disable) {
9061 case DISABLE_DBS_CXN_AND_SCAN:
9062 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9063 if (status != QDF_STATUS_SUCCESS)
9064 hdd_err("Failed to disable dual mac features");
9065 break;
9066 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9067 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9068 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9069 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9070 if (status != QDF_STATUS_SUCCESS)
9071 hdd_err("Failed to set dbs scan and fw mode config");
9072 break;
9073 default:
9074 break;
9075 }
9076
9077 return status;
9078}
9079
Arun Khandavallid4349a92016-07-25 11:10:43 +05309080/**
9081 * hdd_features_init() - Init features
9082 * @hdd_ctx: HDD context
9083 * @adapter: Primary adapter context
9084 *
9085 * Initialize features and their feature context after WLAN firmware is up.
9086 *
9087 * Return: 0 on success and errno on failure.
9088 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009089static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309090{
9091 tSirTxPowerLimit hddtxlimit;
9092 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309093 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309094 int ret;
9095
9096 ENTER();
9097
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009098 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309099 if (ret) {
9100 hdd_err("Failed to update country code: %d", ret);
9101 goto out;
9102 }
9103
9104 /* FW capabilities received, Set the Dot11 mode */
9105 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009106 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9107 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309108
Arun Khandavallid4349a92016-07-25 11:10:43 +05309109
9110 if (hdd_ctx->config->fIsImpsEnabled)
9111 hdd_set_idle_ps_config(hdd_ctx, true);
9112 else
9113 hdd_set_idle_ps_config(hdd_ctx, false);
9114
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309115 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009116 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309117
Arun Khandavallid4349a92016-07-25 11:10:43 +05309118 if (hdd_lro_init(hdd_ctx))
9119 hdd_err("Unable to initialize LRO in fw");
9120
9121 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9122 hdd_err("Unable to send adaptive dwelltime setting to FW");
9123
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309124 if (hdd_dbs_scan_selection_init(hdd_ctx))
9125 hdd_err("Unable to send DBS scan selection setting to FW");
9126
Arun Khandavallid4349a92016-07-25 11:10:43 +05309127 ret = hdd_init_thermal_info(hdd_ctx);
9128 if (ret) {
9129 hdd_err("Error while initializing thermal information");
9130 goto deregister_frames;
9131 }
9132
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309133 if (cds_is_packet_log_enabled())
9134 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9135
Arun Khandavallid4349a92016-07-25 11:10:43 +05309136 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9137 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9138 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9139 if (!QDF_IS_STATUS_SUCCESS(status))
9140 hdd_err("Error setting txlimit in sme: %d", status);
9141
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009142 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309143
Arun Khandavallid4349a92016-07-25 11:10:43 +05309144 ret = hdd_register_cb(hdd_ctx);
9145 if (ret) {
9146 hdd_err("Failed to register HDD callbacks!");
9147 goto deregister_frames;
9148 }
9149
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009150 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9151 if (!QDF_IS_STATUS_SUCCESS(status)) {
9152 hdd_err("Failed to set dbs scan and fw mode cfg");
9153 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309154 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009155
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309156 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9157 status = sme_enable_disable_chanavoidind_event(
9158 hdd_ctx->hHal, 0);
9159 if (!QDF_IS_STATUS_SUCCESS(status)) {
9160 hdd_err("Failed to disable Chan Avoidance Indication");
9161 goto deregister_cb;
9162 }
9163 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309164
Manjeet Singha9cae432017-02-28 11:58:22 +05309165 if (hdd_ctx->config->enable_5g_band_pref) {
9166 band_pref_params.rssi_boost_threshold_5g =
9167 hdd_ctx->config->rssi_boost_threshold_5g;
9168 band_pref_params.rssi_boost_factor_5g =
9169 hdd_ctx->config->rssi_boost_factor_5g;
9170 band_pref_params.max_rssi_boost_5g =
9171 hdd_ctx->config->max_rssi_boost_5g;
9172 band_pref_params.rssi_penalize_threshold_5g =
9173 hdd_ctx->config->rssi_penalize_threshold_5g;
9174 band_pref_params.rssi_penalize_factor_5g =
9175 hdd_ctx->config->rssi_penalize_factor_5g;
9176 band_pref_params.max_rssi_penalize_5g =
9177 hdd_ctx->config->max_rssi_penalize_5g;
9178 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9179 }
9180
Arun Khandavallid4349a92016-07-25 11:10:43 +05309181 /* register P2P Listen Offload event callback */
9182 if (wma_is_p2p_lo_capable())
9183 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9184 wlan_hdd_p2p_lo_event_callback);
9185
9186 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9187
9188 if (ret)
9189 goto deregister_cb;
9190
9191 EXIT();
9192 return 0;
9193
9194deregister_cb:
9195 hdd_deregister_cb(hdd_ctx);
9196deregister_frames:
9197 wlan_hdd_cfg80211_deregister_frames(adapter);
9198out:
9199 return -EINVAL;
9200
9201}
9202
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009203/**
9204 * hdd_features_deinit() - Deinit features
9205 * @hdd_ctx: HDD context
9206 *
9207 * De-Initialize features and their feature context.
9208 *
9209 * Return: none.
9210 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009211static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009212{
9213 wlan_hdd_tsf_deinit(hdd_ctx);
9214}
9215
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309216/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009217 * hdd_register_bcn_cb() - register scan beacon callback
9218 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309219 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009220 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309221 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009222static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309223{
9224 QDF_STATUS status;
9225
9226 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9227 wlan_cfg80211_inform_bss_frame,
9228 SCAN_CB_TYPE_INFORM_BCN);
9229 if (!QDF_IS_STATUS_SUCCESS(status)) {
9230 hdd_err("failed with status code %08d [x%08x]",
9231 status, status);
9232 return status;
9233 }
9234
9235 return QDF_STATUS_SUCCESS;
9236}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309237
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309238/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309239 * hdd_configure_cds() - Configure cds modules
9240 * @hdd_ctx: HDD context
9241 * @adapter: Primary adapter context
9242 *
9243 * Enable Cds modules after WLAN firmware is up.
9244 *
9245 * Return: 0 on success and errno on failure.
9246 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009247int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309248{
9249 int ret;
9250 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309251 int set_value;
9252 uint32_t num_abg_tx_chains = 0;
9253 uint32_t num_11b_tx_chains = 0;
9254 uint32_t num_11ag_tx_chains = 0;
9255
9256 if (hdd_ctx->config->sifs_burst_duration) {
9257 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9258 hdd_ctx->config->sifs_burst_duration;
9259
9260 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9261 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9262 set_value, PDEV_CMD);
9263 }
9264
9265 if (hdd_ctx->config->is_force_1x1)
9266 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9267 1, PDEV_CMD);
9268 /* set chip power save failure detected callback */
9269 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9270 hdd_chip_pwr_save_fail_detected_cb);
9271
9272 if (hdd_ctx->config->max_mpdus_inampdu) {
9273 set_value = hdd_ctx->config->max_mpdus_inampdu;
9274 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9275 set_value, PDEV_CMD);
9276 }
9277
9278 if (hdd_ctx->config->enable_rts_sifsbursting) {
9279 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9280 sme_cli_set_command(0,
9281 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9282 set_value, PDEV_CMD);
9283 }
9284
9285 if (hdd_ctx->config->sap_get_peer_info) {
9286 set_value = hdd_ctx->config->sap_get_peer_info;
9287 sme_cli_set_command(0,
9288 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9289 set_value, PDEV_CMD);
9290 }
9291
9292 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9293 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9294 if (!hdd_ctx->config->enable2x2) {
9295 if (num_11b_tx_chains > 1)
9296 num_11b_tx_chains = 1;
9297 if (num_11ag_tx_chains > 1)
9298 num_11ag_tx_chains = 1;
9299 }
9300 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9301 num_11b_tx_chains);
9302 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9303 num_11ag_tx_chains);
9304 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9305 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309306
9307 ret = hdd_pre_enable_configure(hdd_ctx);
9308 if (ret) {
9309 hdd_err("Failed to pre-configure cds");
9310 goto out;
9311 }
9312
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009313 /* Always get latest IPA resources allocated from cds_open and configure
9314 * IPA module before configuring them to FW. Sequence required as crash
9315 * observed otherwise.
9316 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009317 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9318 hdd_err("Failed to setup pipes");
9319 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009320 }
9321
Arun Khandavallifae92942016-08-01 13:31:08 +05309322 /*
9323 * Start CDS which starts up the SME/MAC/HAL modules and everything
9324 * else
9325 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009326 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309327
9328 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009329 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309330 goto out;
9331 }
9332
9333 status = hdd_post_cds_enable_config(hdd_ctx);
9334 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009335 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009336 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309337 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309338 status = hdd_register_bcn_cb(hdd_ctx);
9339 if (!QDF_IS_STATUS_SUCCESS(status)) {
9340 hdd_alert("hdd_post_cds_enable_config failed");
9341 goto cds_disable;
9342 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309343
9344 ret = hdd_features_init(hdd_ctx, adapter);
9345 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009346 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309347
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309348 if (hdd_enable_egap(hdd_ctx))
9349 hdd_debug("enhance green ap is not enabled");
9350
Nachiket Kukadedd302662017-07-13 17:31:44 +05309351 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9352 hdd_debug("Failed to set wow pulse");
9353
Arun Khandavallifae92942016-08-01 13:31:08 +05309354 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009355
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009356cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009357 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009358
Arun Khandavallifae92942016-08-01 13:31:08 +05309359out:
9360 return -EINVAL;
9361}
9362
9363/**
9364 * hdd_deconfigure_cds() -De-Configure cds
9365 * @hdd_ctx: HDD context
9366 *
9367 * Deconfigure Cds modules before WLAN firmware is down.
9368 *
9369 * Return: 0 on success and errno on failure.
9370 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009371static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309372{
9373 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009374 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309375
9376 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009377
9378 /* De-init features */
9379 hdd_features_deinit(hdd_ctx);
9380
Arun Khandavallifae92942016-08-01 13:31:08 +05309381 /* De-register the SME callbacks */
9382 hdd_deregister_cb(hdd_ctx);
9383
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009384 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309385 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9386 hdd_err("Failed to Disable the CDS Modules! :%d",
9387 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009388 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309389 }
9390
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309391 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9392 hdd_err("Failed to disconnect pipes");
9393 ret = -EINVAL;
9394 }
9395
Arun Khandavallifae92942016-08-01 13:31:08 +05309396 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009397 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309398}
9399
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009400#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9401static void hdd_deregister_policy_manager_callback(
9402 struct wlan_objmgr_psoc *psoc)
9403{
9404 if (QDF_STATUS_SUCCESS !=
9405 policy_mgr_deregister_hdd_cb(psoc)) {
9406 hdd_err("HDD callback deregister with policy manager failed");
9407 }
9408}
9409#else
9410static void hdd_deregister_policy_manager_callback(
9411 struct wlan_objmgr_psoc *psoc)
9412{
9413}
9414#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309415
9416/**
9417 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9418 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009419 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309420 *
9421 * This function maintains the driver state machine it will be invoked from
9422 * exit, shutdown and con_mode change handler. Depending on the driver state
9423 * shall perform the stopping/closing of the modules.
9424 *
9425 * Return: 0 for success; non-zero for failure
9426 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009427int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309428{
9429 void *hif_ctx;
9430 qdf_device_t qdf_ctx;
9431 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309432 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009433 bool is_idle_stop = !cds_is_driver_unloading() &&
9434 !cds_is_driver_recovering();
9435 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309436
9437 ENTER();
9438
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009439 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9440
Arun Khandavallifae92942016-08-01 13:31:08 +05309441 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9442 if (!qdf_ctx) {
9443 hdd_err("QDF device context NULL");
9444 return -EINVAL;
9445 }
9446
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309447 mutex_lock(&hdd_ctx->iface_change_lock);
9448 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309449
Dustin Brown70111822017-03-30 15:31:40 -07009450 active_threads = cds_return_external_threads_count();
9451 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009452 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009453 active_threads, hdd_ctx->isWiphySuspended);
9454
9455 cds_print_external_threads();
9456
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009457 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009458 mutex_unlock(&hdd_ctx->iface_change_lock);
9459 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009460 hdd_ctx->config->iface_change_wait_time);
9461 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009462 return 0;
9463 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009464 }
9465
Arun Khandavallifae92942016-08-01 13:31:08 +05309466 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9467
9468 switch (hdd_ctx->driver_status) {
9469 case DRIVER_MODULES_UNINITIALIZED:
9470 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309471 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309472 case DRIVER_MODULES_CLOSED:
9473 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309474 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309475 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309476 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309477 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009478 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309479 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309480 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309481 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009482 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309483 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9484 break;
9485 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009486 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309487 break;
9488 default:
9489 hdd_err("Trying to stop wlan in a wrong state: %d",
9490 hdd_ctx->driver_status);
9491 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309492 ret = -EINVAL;
9493 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309494 }
9495
Rajeev Kumarbe021242017-02-16 16:12:23 -08009496 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309497 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9498 hdd_err("Failed to process post CDS disable Modules! :%d",
9499 qdf_status);
9500 ret = -EINVAL;
9501 QDF_ASSERT(0);
9502 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009503 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309504 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009505 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309506 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309507 QDF_ASSERT(0);
9508 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009509
Arun Khandavallifae92942016-08-01 13:31:08 +05309510 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9511 if (!hif_ctx) {
9512 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309513 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309514 }
9515
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309516 hdd_runtime_suspend_context_deinit(hdd_ctx);
9517
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309518 if (hdd_ctx->target_hw_name) {
9519 qdf_mem_free(hdd_ctx->target_hw_name);
9520 hdd_ctx->target_hw_name = NULL;
9521 }
9522
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309523 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309524
9525 ol_cds_free();
9526
Dustin Brown70111822017-03-30 15:31:40 -07009527 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309528 ret = pld_power_off(qdf_ctx->dev);
9529 if (ret)
9530 hdd_err("CNSS power down failed put device into Low power mode:%d",
9531 ret);
9532 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +05309533
9534 /* Once the firmware sequence is completed reset this flag */
9535 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05309536 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009537 /*
9538 * Reset total mac phy during module stop such that during
9539 * next module start same psoc is used to populate new service
9540 * ready data
9541 */
9542 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309543
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309544done:
9545 hdd_ctx->stop_modules_in_progress = false;
9546 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309547 EXIT();
9548
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309549 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309550
9551}
9552
9553/**
9554 * hdd_iface_change_callback() - Function invoked when stop modules expires
9555 * @priv: pointer to hdd context
9556 *
9557 * This function is invoked when the timer waiting for the interface change
9558 * expires, it shall cut-down the power to wlan and stop all the modules.
9559 *
9560 * Return: void
9561 */
9562static void hdd_iface_change_callback(void *priv)
9563{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009564 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309565 int ret;
9566 int status = wlan_hdd_validate_context(hdd_ctx);
9567
9568 if (status)
9569 return;
9570
9571 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009572 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009573 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309574 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009575 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309576 EXIT();
9577}
9578
9579/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309580 * hdd_state_info_dump() - prints state information of hdd layer
9581 * @buf: buffer pointer
9582 * @size: size of buffer to be filled
9583 *
9584 * This function is used to dump state information of hdd layer
9585 *
9586 * Return: None
9587 */
9588static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9589{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009590 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309591 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9592 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009593 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009594 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309595 uint16_t len = 0;
9596 char *buf = *buf_ptr;
9597
9598 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9599 if (!hdd_ctx) {
9600 hdd_err("Failed to get hdd context ");
9601 return;
9602 }
9603
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009604 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309605
9606 len += scnprintf(buf + len, *size - len,
9607 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9608 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009609 "\n is_scheduler_suspended %d",
9610 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309611
9612 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9613
9614 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07009615 adapter = adapter_node->adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309616 if (adapter->dev)
9617 len += scnprintf(buf + len, *size - len,
9618 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009619 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309620 "\n device_mode: %d", adapter->device_mode);
9621 switch (adapter->device_mode) {
9622 case QDF_STA_MODE:
9623 case QDF_P2P_CLIENT_MODE:
9624 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9625 len += scnprintf(buf + len, *size - len,
9626 "\n connState: %d",
9627 hdd_sta_ctx->conn_info.connState);
9628 break;
9629
9630 default:
9631 break;
9632 }
9633 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9634 adapter_node = next;
9635 }
9636
9637 *size -= len;
9638 *buf_ptr += len;
9639}
9640
9641/**
9642 * hdd_register_debug_callback() - registration function for hdd layer
9643 * to print hdd state information
9644 *
9645 * Return: None
9646 */
9647static void hdd_register_debug_callback(void)
9648{
9649 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9650}
9651
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309652/*
9653 * wlan_init_bug_report_lock() - Initialize bug report lock
9654 *
9655 * This function is used to create bug report lock
9656 *
9657 * Return: None
9658 */
9659static void wlan_init_bug_report_lock(void)
9660{
9661 p_cds_contextType p_cds_context;
9662
9663 p_cds_context = cds_get_global_context();
9664 if (!p_cds_context) {
9665 hdd_err("cds context is NULL");
9666 return;
9667 }
9668
9669 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9670}
9671
Mohit Khannaf8f96822017-05-17 17:11:59 -07009672void hdd_dp_trace_init(struct hdd_config *config)
9673{
9674
9675 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9676 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9677 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9678 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9679 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9680 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9681 uint8_t num_entries = 0;
9682
9683 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9684 &num_entries, sizeof(config_params));
9685
9686 /* calculating, num bw timer intervals in a second (1000ms) */
9687 if (config->busBandwidthComputeInterval)
9688 thresh_time_limit =
9689 (1000 / config->busBandwidthComputeInterval);
9690 else
9691 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9692
9693 switch (num_entries) {
9694 case 4:
9695 proto_bitmap = config_params[3];
9696 case 3:
9697 verbosity = config_params[2];
9698 case 2:
9699 thresh = config_params[1];
9700 case 1:
9701 live_mode = config_params[0];
9702 default:
9703 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9704 live_mode, thresh, thresh_time_limit,
9705 verbosity, proto_bitmap);
9706 };
9707
9708 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9709 verbosity, proto_bitmap);
9710
9711}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309712/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009713 * hdd_wlan_startup() - HDD init function
9714 * @dev: Pointer to the underlying device
9715 *
9716 * This is the driver startup code executed once a WLAN device has been detected
9717 *
9718 * Return: 0 for success, < 0 for failure
9719 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309720int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009721{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309722 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009723 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009724 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009725 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009726
9727 ENTER();
9728
Arun Khandavallifae92942016-08-01 13:31:08 +05309729 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009730
9731 if (IS_ERR(hdd_ctx))
9732 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009733
Abhishek Singhe9068f12017-03-31 14:14:52 +05309734 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9735 DEFAULT_PSOC_ID);
9736 if (ret) {
9737 hdd_err("Psoc creation fails!");
9738 QDF_BUG(0);
9739 goto err_hdd_free_context;
9740 }
9741
Arun Khandavallifae92942016-08-01 13:31:08 +05309742 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9743 hdd_iface_change_callback, (void *)hdd_ctx);
9744
9745 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309746#ifdef FEATURE_WLAN_CH_AVOID
9747 mutex_init(&hdd_ctx->avoid_freq_lock);
9748#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309749
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009750 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009751 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309752
Jeff Johnson957bc272017-02-02 08:54:48 -08009753 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309754 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009755 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009756 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009757 }
9758
Yingying Tang80e15f32016-09-27 18:23:01 +08009759 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009760
Anurag Chouhan6d760662016-02-20 16:05:43 +05309761 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009762
9763 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009764 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309765 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009766 }
9767
Prashanth Bhatta07998752016-04-28 12:35:33 -07009768 ret = hdd_wiphy_init(hdd_ctx);
9769 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009770 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309771 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009772 }
9773
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309774 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009775 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309777 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009778 goto err_wiphy_unregister;
9779
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309780 wlan_hdd_init_chan_info(hdd_ctx);
9781
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009782 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009783
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309784 ret = hdd_register_notifiers(hdd_ctx);
9785 if (ret)
9786 goto err_ipa_cleanup;
9787
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009788 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009789
Jeff Johnson957bc272017-02-02 08:54:48 -08009790 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9791 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009792 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009793 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009794 }
9795
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009796 hdd_release_rtnl_lock();
9797 rtnl_held = false;
9798
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009799 wlan_hdd_update_11n_mode(hdd_ctx->config);
9800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009801#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309802 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309803 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009804 hdd_skip_acs_scan_timer_handler,
9805 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309806 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009807 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009808 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009809#endif
9810
Prashanth Bhattaab004382016-10-11 16:08:11 -07009811 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009812
Jeff Johnson9afc5012016-09-23 13:56:27 -07009813 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009814
Nirav Shahbd36b062016-07-18 11:12:59 +05309815 if (hdd_ctx->rps)
9816 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009817
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309818 status = wlansap_global_init();
9819 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009820 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009821
Komal Seelam8634b772016-09-29 12:12:24 +05309822 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009823 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309824 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009825
Arun Khandavallifae92942016-08-01 13:31:08 +05309826 if (hdd_ctx->config->fIsImpsEnabled)
9827 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309828
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309829 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9830 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309831 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309832
Sachin Ahujadddd2632017-03-07 19:07:24 +05309833 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009834 goto success;
9835
Jeff Johnson957bc272017-02-02 08:54:48 -08009836err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009837 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009838
Jeff Johnson46bde382017-02-01 15:31:16 -08009839err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309840 if (rtnl_held)
9841 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009842
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309843 unregister_netdevice_notifier(&hdd_netdev_notifier);
9844
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309845err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309846 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009848err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009849 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009850
Arun Khandavallifae92942016-08-01 13:31:08 +05309851err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009852 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309853
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009854err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309855 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009856 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309857 if (!QDF_IS_STATUS_SUCCESS(status)) {
9858 hdd_err("Failed to close CDS Scheduler");
9859 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9860 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009861 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009862
Houston Hoffman47a4a052016-11-14 23:22:44 -08009863 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009864 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009865 hdd_exit_netlink_services(hdd_ctx);
9866
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309867 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009868
Dustin Brown20912462017-06-07 13:48:25 -07009869 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9870
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009871err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309872 if (cds_is_fw_down())
9873 hdd_err("Not setting the complete event as fw is down");
9874 else
9875 hdd_start_complete(ret);
9876
Arun Khandavallifae92942016-08-01 13:31:08 +05309877 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9878 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009879 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009880 return -EIO;
9881
9882success:
9883 EXIT();
9884 return 0;
9885}
9886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009887/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309888 * hdd_wlan_update_target_info() - update target type info
9889 * @hdd_ctx: HDD context
9890 * @context: hif context
9891 *
9892 * Update target info received from firmware in hdd context
9893 * Return:None
9894 */
9895
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009896void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309897{
9898 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9899
9900 if (!tgt_info) {
9901 hdd_err("Target info is Null");
9902 return;
9903 }
9904
9905 hdd_ctx->target_type = tgt_info->target_type;
9906}
9907
9908/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309909 * hdd_get_nud_stats_cb() - callback api to update the stats
9910 * received from the firmware
9911 * @data: pointer to adapter.
9912 * @rsp: pointer to data received from FW.
9913 *
9914 * This is called when wlan driver received response event for
9915 * get arp stats to firmware.
9916 *
9917 * Return: None
9918 */
9919static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9920{
9921 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
9922 struct hdd_nud_stats_context *context;
9923 int status;
9924 struct hdd_adapter *adapter = NULL;
9925
9926 ENTER();
9927
9928 if (!rsp) {
9929 hdd_err("data is null");
9930 return;
9931 }
9932
9933 status = wlan_hdd_validate_context(hdd_ctx);
9934 if (0 != status)
9935 return;
9936
9937 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
9938 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
9939 hdd_err("Invalid adapter or adapter has invalid magic");
9940 return;
9941 }
9942
9943 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
9944 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
9945 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
9946 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
9947 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
9948 rsp->out_of_order_arp_rsp_drop_cnt);
9949 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
9950 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
9951 hdd_notice("rsp->ba_session_establishment_status :%x",
9952 rsp->ba_session_establishment_status);
9953
9954 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
9955 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
9956 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
9957 adapter->dad |= rsp->dad_detected;
9958 adapter->con_status = rsp->connect_status;
9959
9960 spin_lock(&hdd_context_lock);
9961 context = &hdd_ctx->nud_stats_context;
9962 complete(&context->response_event);
9963 spin_unlock(&hdd_context_lock);
9964
9965 EXIT();
9966
9967 return;
9968}
9969
9970/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309971 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309972 * @hdd_ctx: HDD context
9973 *
9974 * Register the HDD callbacks to CDS/SME.
9975 *
9976 * Return: 0 for success or Error code for failure
9977 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009978int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309979{
9980 QDF_STATUS status;
9981 int ret = 0;
9982
9983 ENTER();
9984
9985 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9986
9987 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9988 hdd_send_oem_data_rsp_msg);
9989
9990 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9991 wlan_hdd_cfg80211_fw_mem_dump_cb);
9992 if (!QDF_IS_STATUS_SUCCESS(status)) {
9993 hdd_err("Failed to register memdump callback");
9994 ret = -EINVAL;
9995 return ret;
9996 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309997 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9998 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309999 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10000 sme_nan_register_callback(hdd_ctx->hHal,
10001 wlan_hdd_cfg80211_nan_callback);
10002 sme_stats_ext_register_callback(hdd_ctx->hHal,
10003 wlan_hdd_cfg80211_stats_ext_callback);
10004
10005 sme_ext_scan_register_callback(hdd_ctx->hHal,
10006 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010007 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10008 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010009
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010010 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10011 hdd_rssi_threshold_breached);
10012
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010013 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10014
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010015 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10016 wlan_hdd_cfg80211_link_layer_stats_callback);
10017
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010018 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10019
Zhang Qianca38fb12016-12-23 11:10:48 +080010020 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10021 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10022
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010023 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10024 hdd_lost_link_info_cb);
10025 /* print error and not block the startup process */
10026 if (!QDF_IS_STATUS_SUCCESS(status))
10027 hdd_err("set lost link info callback failed");
10028
Poddar, Siddarth34872782017-08-10 14:08:51 +053010029 ret = hdd_register_data_stall_detect_cb();
10030 if (ret) {
10031 hdd_err("Register data stall detect detect callback failed.");
10032 return ret;
10033 }
10034
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010035 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10036
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010037 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010038 hdd_set_connection_in_progress,
10039 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010040
10041 status = sme_congestion_register_callback(hdd_ctx->hHal,
10042 hdd_update_cca_info_cb);
10043 if (!QDF_IS_STATUS_SUCCESS(status))
10044 hdd_err("set congestion callback failed");
10045
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010046 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10047 hdd_bt_activity_cb);
10048 if (!QDF_IS_STATUS_SUCCESS(status))
10049 hdd_err("set bt activity info callback failed");
10050
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010051 EXIT();
10052
10053 return ret;
10054}
10055
10056/**
10057 * hdd_deregister_cb() - De-Register HDD callbacks.
10058 * @hdd_ctx: HDD context
10059 *
10060 * De-Register the HDD callbacks to CDS/SME.
10061 *
10062 * Return: void
10063 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010064void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010065{
10066 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010067 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010068
10069 ENTER();
10070
10071 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10072 if (!QDF_IS_STATUS_SUCCESS(status))
10073 hdd_err("De-register of dcc stats callback failed: %d",
10074 status);
10075
10076 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010077 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10078
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010079 sme_stats_ext_register_callback(hdd_ctx->hHal,
10080 wlan_hdd_cfg80211_stats_ext_callback);
10081
10082 sme_nan_deregister_callback(hdd_ctx->hHal);
10083 status = sme_reset_tsfcb(hdd_ctx->hHal);
10084 if (!QDF_IS_STATUS_SUCCESS(status))
10085 hdd_err("Failed to de-register tsfcb the callback:%d",
10086 status);
10087 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10088 if (!QDF_IS_STATUS_SUCCESS(status))
10089 hdd_err("Failed to de-register the fw mem dump callback: %d",
10090 status);
10091
Poddar, Siddarth34872782017-08-10 14:08:51 +053010092 ret = hdd_deregister_data_stall_detect_cb();
10093 if (ret)
10094 hdd_err("Failed to de-register data stall detect event callback");
10095
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010096 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10097 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10098
10099 EXIT();
10100}
10101
10102/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010103 * hdd_softap_sta_deauth() - handle deauth req from HDD
10104 * @adapter: Pointer to the HDD
10105 * @enable: bool value
10106 *
10107 * This to take counter measure to handle deauth req from HDD
10108 *
10109 * Return: None
10110 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010111QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010112 struct tagCsrDelStaParams *pDelStaParams)
10113{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010114 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010115
10116 ENTER();
10117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010118 /* Ignore request to deauth bcmc station */
10119 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010120 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010122 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010123 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10124 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010125
10126 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010127 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010128}
10129
10130/**
10131 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10132 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010133 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010134 *
10135 * This to take counter measure to handle deauth req from HDD
10136 *
10137 * Return: None
10138 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010139void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010140 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010141{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010142 ENTER();
10143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010144 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010145 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010146 return;
10147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010148 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010149 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010150}
10151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010152/**
10153 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10154 * @hdd_ctx: HDD Context
10155 *
10156 * API to find if there is any STA or P2P-Client is connected
10157 *
10158 * Return: true if connected; false otherwise
10159 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010160QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010161{
10162 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10163}
10164
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010165/**
10166 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10167 * @adapter: HDD adapter pointer
10168 *
10169 * This function loop through each adapter and disable roaming on each STA
10170 * device mode except the input adapter.
10171 *
10172 * Note: On the input adapter roaming is not enabled yet hence no need to
10173 * disable.
10174 *
10175 * Return: None
10176 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010177void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010179 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010180 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010181 hdd_adapter_list_node_t *adapterNode = NULL;
10182 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010183 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010184
10185 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010186 hdd_ctx->config->isRoamOffloadScanEnabled &&
10187 QDF_STA_MODE == adapter->device_mode &&
10188 policy_mgr_is_sta_active_connection_exists(
10189 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010190 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010191 adapter->sessionId);
10192 /*
10193 * Loop through adapter and disable roaming for each STA device
10194 * mode except the input adapter.
10195 */
10196 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10197
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010198 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010199 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010200
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010201 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010202 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010203 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010204 adapterIdx->sessionId);
10205 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10206 (adapterIdx),
10207 adapterIdx->sessionId, 0);
10208 }
10209
10210 status = hdd_get_next_adapter(hdd_ctx,
10211 adapterNode,
10212 &pNext);
10213 adapterNode = pNext;
10214 }
10215 }
10216}
10217
10218/**
10219 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10220 * @adapter: HDD adapter pointer
10221 *
10222 * This function loop through each adapter and enable roaming on each STA
10223 * device mode except the input adapter.
10224 * Note: On the input adapter no need to enable roaming because link got
10225 * disconnected on this.
10226 *
10227 * Return: None
10228 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010229void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010230{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010231 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010232 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010233 hdd_adapter_list_node_t *adapterNode = NULL;
10234 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010235 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010236
10237 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010238 hdd_ctx->config->isRoamOffloadScanEnabled &&
10239 QDF_STA_MODE == adapter->device_mode &&
10240 policy_mgr_is_sta_active_connection_exists(
10241 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010242 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243 adapter->sessionId);
10244 /*
10245 * Loop through adapter and enable roaming for each STA device
10246 * mode except the input adapter.
10247 */
10248 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10249
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010250 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010251 adapterIdx = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010252
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010253 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010254 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010255 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010256 adapterIdx->sessionId);
10257 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10258 (adapterIdx),
10259 adapterIdx->sessionId,
10260 REASON_CONNECT);
10261 }
10262
10263 status = hdd_get_next_adapter(hdd_ctx,
10264 adapterNode,
10265 &pNext);
10266 adapterNode = pNext;
10267 }
10268 }
10269}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010270
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010271/**
10272 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10273 * @skb: sk buffer pointer
10274 *
10275 * Sends the bcast message to SVC multicast group with generic nl socket
10276 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10277 *
10278 * Return: None
10279 */
10280static void nl_srv_bcast_svc(struct sk_buff *skb)
10281{
10282#ifdef CNSS_GENL
10283 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10284#else
10285 nl_srv_bcast(skb);
10286#endif
10287}
10288
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010289void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010290{
10291 struct sk_buff *skb;
10292 struct nlmsghdr *nlh;
10293 tAniMsgHdr *ani_hdr;
10294 void *nl_data = NULL;
10295 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010296 struct radio_index_tlv *radio_info;
10297 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010298
10299 if (in_interrupt() || irqs_disabled() || in_atomic())
10300 flags = GFP_ATOMIC;
10301
10302 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10303
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010304 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010305 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010306
10307 nlh = (struct nlmsghdr *)skb->data;
10308 nlh->nlmsg_pid = 0; /* from kernel */
10309 nlh->nlmsg_flags = 0;
10310 nlh->nlmsg_seq = 0;
10311 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10312
10313 ani_hdr = NLMSG_DATA(nlh);
10314 ani_hdr->type = type;
10315
10316 switch (type) {
10317 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010318 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010319 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010320 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010321 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010322 ani_hdr->length = 0;
10323 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010324 break;
10325 case WLAN_SVC_WLAN_STATUS_IND:
10326 case WLAN_SVC_WLAN_VERSION_IND:
10327 case WLAN_SVC_DFS_CAC_START_IND:
10328 case WLAN_SVC_DFS_CAC_END_IND:
10329 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10330 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10331 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010332 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010333 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010334 ani_hdr->length = len;
10335 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10336 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10337 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010338 break;
10339
10340 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010341 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010342 type);
10343 kfree_skb(skb);
10344 return;
10345 }
10346
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010347 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010348 * Add radio index at the end of the svc event in TLV format
10349 * to maintain the backward compatibility with userspace
10350 * applications.
10351 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010352
10353 tlv_len = 0;
10354
10355 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10356 < WLAN_NL_MAX_PAYLOAD) {
10357 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10358 sizeof(*ani_hdr) + len);
10359 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10360 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10361 radio_info->radio = radio;
10362 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010363 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010364 "Added radio index tlv - radio index %d",
10365 radio_info->radio);
10366 }
10367
10368 nlh->nlmsg_len += tlv_len;
10369 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10370
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010371 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010372}
10373
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010374#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10375void wlan_hdd_auto_shutdown_cb(void)
10376{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010377 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010378
10379 if (!hdd_ctx)
10380 return;
10381
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010382 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010383 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10384 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010385}
10386
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010387void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010388{
10389 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010390 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010391 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010392 bool ap_connected = false, sta_connected = false;
10393 tHalHandle hal_handle;
10394
10395 hal_handle = hdd_ctx->hHal;
10396 if (hal_handle == NULL)
10397 return;
10398
10399 if (hdd_ctx->config->WlanAutoShutdown == 0)
10400 return;
10401
10402 if (enable == false) {
10403 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010404 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010405 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010406 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010407 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010408 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409 return;
10410 }
10411
10412 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010413 if (policy_mgr_concurrent_open_sessions_running(
10414 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10416
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010417 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010418 adapter = adapterNode->adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010419 if (adapter
10420 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010421 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010422 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10423 conn_info.connState ==
10424 eConnectionState_Associated) {
10425 sta_connected = true;
10426 break;
10427 }
10428 }
10429 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010430 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10432 bApActive == true) {
10433 ap_connected = true;
10434 break;
10435 }
10436 }
10437 status = hdd_get_next_adapter(hdd_ctx,
10438 adapterNode,
10439 &pNext);
10440 adapterNode = pNext;
10441 }
10442 }
10443
10444 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010445 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010446 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 }
Jeff Johnson68755312017-02-10 11:46:55 -080010448
10449 if (sme_set_auto_shutdown_timer(hal_handle,
10450 hdd_ctx->config->WlanAutoShutdown)
10451 != QDF_STATUS_SUCCESS)
10452 hdd_err("Failed to start wlan auto shutdown timer");
10453 else
10454 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10455 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010456}
10457#endif
10458
Jeff Johnson9d295242017-08-29 14:39:48 -070010459struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460 bool check_start_bss)
10461{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010462 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010463 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010464 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10466
10467 con_sap_adapter = NULL;
10468
10469 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010470 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010471 adapter = adapterNode->adapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010472 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10473 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474 adapter != this_sap_adapter) {
10475 if (check_start_bss) {
10476 if (test_bit(SOFTAP_BSS_STARTED,
10477 &adapter->event_flags)) {
10478 con_sap_adapter = adapter;
10479 break;
10480 }
10481 } else {
10482 con_sap_adapter = adapter;
10483 break;
10484 }
10485 }
10486 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10487 adapterNode = pNext;
10488 }
10489
10490 return con_sap_adapter;
10491}
10492
10493#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010494static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010496 return adapter->device_mode == QDF_STA_MODE ||
10497 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010498}
10499
Jeff Johnson9d295242017-08-29 14:39:48 -070010500static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010501{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010502 return adapter->device_mode == QDF_SAP_MODE ||
10503 adapter->device_mode == QDF_P2P_GO_MODE;
10504}
10505
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010506static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010507{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010508 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010509 hdd_adapter_list_node_t *node;
10510
10511 status = hdd_get_front_adapter(hdd_ctx, &node);
10512 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070010513 struct hdd_adapter *adapter = node->adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010514
10515 if (adapter &&
10516 hdd_adapter_is_sta(adapter) &&
10517 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10518 conn_info.connState == eConnectionState_Associated) {
10519 return true;
10520 }
10521
10522 if (adapter &&
10523 hdd_adapter_is_ap(adapter) &&
10524 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10525 return true;
10526 }
10527
10528 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10529 }
10530
10531 return false;
10532}
10533
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010534static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010535{
10536 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010538 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010539 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010540 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010541
Dustin Brown5ec6b552017-03-31 12:11:40 -070010542 return is_running;
10543}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010544
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010545static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010546{
10547 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10548 hdd_ctx->bus_bw_timer_running = true;
10549 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10550 hdd_ctx->config->busBandwidthComputeInterval);
10551 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10552}
10553
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010554void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010555{
10556 ENTER();
10557
10558 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10559 hdd_debug("Bandwidth compute timer already started");
10560 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010561 }
10562
Dustin Brown5ec6b552017-03-31 12:11:40 -070010563 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10564
10565 EXIT();
10566}
10567
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010568void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010569{
10570 ENTER();
10571
10572 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10573 hdd_debug("Bandwidth compute timer already started");
10574 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010575 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010576
10577 if (hdd_any_adapter_is_assoc(hdd_ctx))
10578 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10579
10580 EXIT();
10581}
10582
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010583static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010584{
10585 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10586
10587 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10588 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10589 hdd_ctx->bus_bw_timer_running = false;
10590 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10591
10592 hdd_reset_tcp_delack(hdd_ctx);
10593}
10594
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010595void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010596{
10597 ENTER();
10598
10599 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10600 hdd_debug("Bandwidth compute timer already stopped");
10601 return;
10602 }
10603
10604 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10605
10606 EXIT();
10607}
10608
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010609void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010610{
10611 ENTER();
10612
10613 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10614 hdd_debug("Bandwidth compute timer already stopped");
10615 return;
10616 }
10617
10618 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10619 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10620
10621 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010622}
10623#endif
10624
10625/**
10626 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10627 * and sta's operating channel.
10628 * @sta_adapter: Describe the first argument to foobar.
10629 * @ap_adapter: Describe the second argument to foobar.
10630 * @roam_profile: Roam profile of AP to which STA wants to connect.
10631 * @concurrent_chnl_same: If both SAP and STA channels are same then
10632 * set this flag to true else false.
10633 *
10634 * This function checks the sap's operating channel and sta's operating channel.
10635 * if both are same then it will return false else it will restart the sap in
10636 * sta's channel and return true.
10637 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010638 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010640QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10641 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010642 tCsrRoamProfile *roam_profile,
10643 tScanResultHandle *scan_cache,
10644 bool *concurrent_chnl_same)
10645{
Jeff Johnson87251032017-08-29 13:31:11 -070010646 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010647 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010648 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010649 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010650 *concurrent_chnl_same = true;
10651
10652 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10653 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010654 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655 scan_cache,
10656 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010657 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010658 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10660 if (hdd_ap_ctx->operatingChannel != channel_id) {
10661 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010662 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010663 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010664 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010665 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10666 if (hdd_ap_ctx->operatingChannel != channel_id) {
10667 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010668 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010669 }
10670 }
10671 } else {
10672 /*
10673 * Lets handle worst case scenario here, Scan cache lookup is
10674 * failed so we have to stop the SAP to avoid any channel
10675 * discrepancy between SAP's channel and STA's channel.
10676 * Return the status as failure so caller function could know
10677 * that scan look up is failed.
10678 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010679 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010680 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010681 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010682 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683}
10684
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010685/**
10686 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10687 * @ap_adapter: SAP adapter
10688 *
10689 * This function will process the stopping of sap adapter.
10690 *
10691 * Return: None
10692 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010693void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694{
Jeff Johnson87251032017-08-29 13:31:11 -070010695 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010696 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010697 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010698 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699
10700 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010701 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010702 return;
10703 }
10704
10705 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10706 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010707 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010708 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010709
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010710 mutex_lock(&hdd_ctx->sap_lock);
10711 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010712 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010713 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10714 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010715 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010716 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010717 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010718 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010719 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010720 qdf_stop_bss_event,
10721 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010722 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010723 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010724 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010725 return;
10726 }
10727 }
10728 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010729 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10730 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010731 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010732 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010734 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735 }
10736 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010737}
10738
10739/**
10740 * wlan_hdd_start_sap() - this function starts bss of SAP.
10741 * @ap_adapter: SAP adapter
10742 *
10743 * This function will process the starting of sap adapter.
10744 *
10745 * Return: None
10746 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010747void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010748{
Jeff Johnson87251032017-08-29 13:31:11 -070010749 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070010750 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010751 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010752 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753 tsap_Config_t *sap_config;
10754
10755 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010756 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 return;
10758 }
10759
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010760 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010761 hdd_err("SoftAp role has not been enabled");
10762 return;
10763 }
10764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10766 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10767 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10768 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010770 mutex_lock(&hdd_ctx->sap_lock);
10771 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10772 goto end;
10773
10774 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010775 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010776 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10777 goto end;
10778 }
10779
Wei Song2f76f642016-11-18 16:32:53 +080010780 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010781 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10782 &hdd_ap_ctx->sapConfig,
10783 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010784 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785 goto end;
10786
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010787 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010788 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010789 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010790 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010791 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010792 goto end;
10793 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010794 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010796 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010797 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10798 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010799 ap_adapter->sessionId);
10800 hostapd_state->bCommit = true;
10801
10802end:
10803 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010804 /* SAP context and beacon cleanup will happen during driver unload
10805 * in hdd_stop_adapter
10806 */
10807 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010810
10811/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010812 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10813 * mac scan config
10814 * @status: Status of set antenna mode
10815 *
10816 * Callback on setting the dual mac configuration
10817 *
10818 * Return: None
10819 */
10820void wlan_hdd_soc_set_antenna_mode_cb(
10821 enum set_antenna_mode_status status)
10822{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010823 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010824
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010825 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010826
10827 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10828 if (0 != wlan_hdd_validate_context(hdd_ctx))
10829 return;
10830
10831 /* Signal the completion of set dual mac config */
10832 complete(&hdd_ctx->set_antenna_mode_cmpl);
10833}
10834
10835/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010836 * hdd_get_fw_version() - Get FW version
10837 * @hdd_ctx: pointer to HDD context.
10838 * @major_spid: FW version - major spid.
10839 * @minor_spid: FW version - minor spid
10840 * @ssid: FW version - ssid
10841 * @crmid: FW version - crmid
10842 *
10843 * This function is called to get the firmware build version stored
10844 * as part of the HDD context
10845 *
10846 * Return: None
10847 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010848void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 uint32_t *major_spid, uint32_t *minor_spid,
10850 uint32_t *siid, uint32_t *crmid)
10851{
10852 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10853 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10854 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10855 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10856}
10857
10858#ifdef QCA_CONFIG_SMP
10859/**
10860 * wlan_hdd_get_cpu() - get cpu_index
10861 *
10862 * Return: cpu_index
10863 */
10864int wlan_hdd_get_cpu(void)
10865{
10866 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010867
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010868 put_cpu();
10869 return cpu_index;
10870}
10871#endif
10872
10873/**
10874 * hdd_get_fwpath() - get framework path
10875 *
10876 * This function is used to get the string written by
10877 * userspace to start the wlan driver
10878 *
10879 * Return: string
10880 */
10881const char *hdd_get_fwpath(void)
10882{
10883 return fwpath.string;
10884}
10885
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010886static int hdd_qdf_print_init(void)
10887{
10888 int qdf_print_idx;
10889 QDF_STATUS status;
10890
10891 status = qdf_print_setup();
10892 if (status != QDF_STATUS_SUCCESS) {
10893 pr_err("qdf_print_setup failed\n");
10894 return -EINVAL;
10895 }
10896
10897 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10898
10899 if (qdf_print_idx < 0) {
10900 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10901 qdf_print_idx);
10902 return -EINVAL;
10903 }
10904
10905 qdf_set_pidx(qdf_print_idx);
10906
10907 return 0;
10908}
10909
10910static void hdd_qdf_print_deinit(void)
10911{
10912 int qdf_print_idx;
10913
10914 qdf_print_idx = qdf_get_pidx();
10915 qdf_print_ctrl_cleanup(qdf_print_idx);
10916}
10917
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010918/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010919 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010920 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010921 * This function initilizes CDS global context with the help of cds_init. This
10922 * has to be the first function called after probe to get a valid global
10923 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010924 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010925 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010926 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010927int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010928{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010929 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010930 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010931
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010932 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010933
10934 wlan_init_bug_report_lock();
10935
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010936#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10937 wlan_logging_sock_init_svc();
10938#endif
10939
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010940 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010941 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010942 ret = -ENOMEM;
10943 goto err_out;
10944 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010945
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053010946 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
10947 (void *)hdd_drv_ops_inactivity_handler, NULL,
10948 QDF_TIMER_TYPE_SW);
10949
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010950 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010951 hdd_qdf_print_init();
10952
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010953 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010954
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010955err_out:
10956 return ret;
10957}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010958
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010959/**
10960 * hdd_deinit() - Deinitialize Driver
10961 *
10962 * This function frees CDS global context with the help of cds_deinit. This
10963 * has to be the last function call in remove callback to free the global
10964 * context.
10965 */
10966void hdd_deinit(void)
10967{
Dustin Brownedce4a52017-05-10 11:59:15 -070010968 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053010969 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010970
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010971 hdd_qdf_print_deinit();
10972
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010973#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10974 wlan_logging_sock_deinit_svc();
10975#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010976
10977 wlan_destroy_bug_report_lock();
10978 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010979}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010980
Yue Ma6e7b1a02017-04-03 14:17:46 -070010981#ifdef QCA_WIFI_NAPIER_EMULATION
10982#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10983#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010984#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010985#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010986
Sachin Ahujadddd2632017-03-07 19:07:24 +053010987static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10988 struct file *file)
10989{
10990 return 0;
10991}
10992
10993static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10994 const char __user *user_buf,
10995 size_t count,
10996 loff_t *f_pos)
10997{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010998 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010999 static const char wlan_off_str[] = "OFF";
11000 static const char wlan_on_str[] = "ON";
11001 int ret;
11002 unsigned long rc;
11003
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011004 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011005 pr_err("Failed to read buffer\n");
11006 return -EINVAL;
11007 }
11008
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011009 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011010 pr_debug("Wifi turning off from UI\n");
11011 goto exit;
11012 }
11013
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011014 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011015 pr_err("Invalid value received from framework");
11016 goto exit;
11017 }
11018
11019 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011020 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011021 rc = wait_for_completion_timeout(&wlan_start_comp,
11022 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11023 if (!rc) {
11024 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11025 ret = -EINVAL;
11026 hdd_start_complete(ret);
11027 return ret;
11028 }
11029
11030 hdd_start_complete(0);
11031 }
11032
11033exit:
11034 return count;
11035}
11036
11037
11038const struct file_operations wlan_hdd_state_fops = {
11039 .owner = THIS_MODULE,
11040 .open = wlan_hdd_state_ctrl_param_open,
11041 .write = wlan_hdd_state_ctrl_param_write,
11042};
11043
11044static int wlan_hdd_state_ctrl_param_create(void)
11045{
11046 unsigned int wlan_hdd_state_major = 0;
11047 int ret;
11048 struct device *dev;
11049
11050 device = MKDEV(wlan_hdd_state_major, 0);
11051
11052 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11053 if (ret) {
11054 pr_err("Failed to register qcwlanstate");
11055 goto dev_alloc_err;
11056 }
11057 wlan_hdd_state_major = MAJOR(device);
11058
11059 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11060 if (IS_ERR(class)) {
11061 pr_err("wlan_hdd_state class_create error");
11062 goto class_err;
11063 }
11064
11065 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11066 if (IS_ERR(dev)) {
11067 pr_err("wlan_hdd_statedevice_create error");
11068 goto err_class_destroy;
11069 }
11070
11071 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11072 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11073 if (ret) {
11074 pr_err("Failed to add cdev error");
11075 goto cdev_add_err;
11076 }
11077
11078 pr_info("wlan_hdd_state %s major(%d) initialized",
11079 WLAN_MODULE_NAME, wlan_hdd_state_major);
11080
11081 return 0;
11082
11083cdev_add_err:
11084 device_destroy(class, device);
11085err_class_destroy:
11086 class_destroy(class);
11087class_err:
11088 unregister_chrdev_region(device, dev_num);
11089dev_alloc_err:
11090 return -ENODEV;
11091}
11092
11093static void wlan_hdd_state_ctrl_param_destroy(void)
11094{
11095 cdev_del(&wlan_hdd_state_cdev);
11096 device_destroy(class, device);
11097 class_destroy(class);
11098 unregister_chrdev_region(device, dev_num);
11099
11100 pr_info("Device node unregistered");
11101}
11102
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011103/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011104 * component_init - API to init cld component's
11105 *
11106 * Return: None
11107 */
11108static void component_init(void)
11109{
11110 pmo_init();
11111}
11112
11113/**
11114 * component_deinit - API to deinit cld component's
11115 *
11116 * Return: None
11117 */
11118static void component_deinit(void)
11119{
11120 pmo_deinit();
11121}
11122
11123/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011124 * __hdd_module_init - Module init helper
11125 *
11126 * Module init helper function used by both module and static driver.
11127 *
11128 * Return: 0 for success, errno on failure
11129 */
11130static int __hdd_module_init(void)
11131{
11132 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011133
Dustin Brownab482ac2017-06-09 17:00:44 -070011134 pr_err("%s: Loading driver v%s (%s)%s\n",
11135 WLAN_MODULE_NAME,
11136 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011137 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011138 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011139
Sachin Ahujadddd2632017-03-07 19:07:24 +053011140 ret = wlan_hdd_state_ctrl_param_create();
11141 if (ret) {
11142 pr_err("wlan_hdd_state_create:%x\n", ret);
11143 goto err_dev_state;
11144 }
11145
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011146 pld_init();
11147
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011148 ret = hdd_init();
11149 if (ret) {
11150 pr_err("hdd_init failed %x\n", ret);
11151 goto err_hdd_init;
11152 }
11153
Rajeev Kumar97767a02016-11-30 11:20:40 -080011154 dispatcher_init();
11155
Mukul Sharmad75a6672017-06-22 15:40:53 +053011156 /* Ensure to call post objmgr init */
11157 component_init();
11158
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011159 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011160
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011161 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011162
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011163 ret = wlan_hdd_register_driver();
11164 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011165 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11166 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011167 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011168 }
11169
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011170 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011171
11172 return 0;
11173out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011174 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011175 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011176 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011177
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011178err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011179 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011180 wlan_hdd_state_ctrl_param_destroy();
11181err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011182 return ret;
11183}
11184
11185/**
11186 * __hdd_module_exit - Module exit helper
11187 *
11188 * Module exit helper function used by both module and static driver.
11189 */
11190static void __hdd_module_exit(void)
11191{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011192
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011193 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11194 QWLAN_VERSIONSTR);
11195
bings6028ee82017-03-29 07:51:40 +080011196 cds_set_unload_in_progress(true);
11197
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011198 hdd_wait_for_recovery_completion();
11199
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011200 wlan_hdd_unregister_driver();
11201
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011202 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011203
Mukul Sharmad75a6672017-06-22 15:40:53 +053011204 /* Ensure to call prior to objmgr deinit */
11205 component_deinit();
11206
Rajeev Kumar97767a02016-11-30 11:20:40 -080011207 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011208 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011209 pld_deinit();
11210
Sachin Ahujadddd2632017-03-07 19:07:24 +053011211 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011212}
11213
Arun Khandavallifae92942016-08-01 13:31:08 +053011214#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011215/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011216 * wlan_boot_cb() - Wlan boot callback
11217 * @kobj: object whose directory we're creating the link in.
11218 * @attr: attribute the user is interacting with
11219 * @buff: the buffer containing the user data
11220 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011221 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011222 * This callback is invoked when the fs is ready to start the
11223 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011224 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011225 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011226 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011227static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011228 struct kobj_attribute *attr,
11229 const char *buf,
11230 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011231{
Arun Khandavallifae92942016-08-01 13:31:08 +053011232
Arun Khandavallifae92942016-08-01 13:31:08 +053011233 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011234 pr_err("%s: wlan driver already initialized\n", __func__);
11235 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011236 }
11237
Arun Khandavallifae92942016-08-01 13:31:08 +053011238 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011239 pr_err("%s: wlan driver initialization failed\n", __func__);
11240 return -EIO;
11241 }
11242
11243 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011244
11245 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011246}
Arun Khandavallifae92942016-08-01 13:31:08 +053011247
11248/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011249 * hdd_sysfs_cleanup() - cleanup sysfs
11250 *
11251 * Return: None
11252 *
11253 */
11254static void hdd_sysfs_cleanup(void)
11255{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011256 /* remove from group */
11257 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11258 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11259 wlan_loader->attr_group);
11260
11261 /* unlink the object from parent */
11262 kobject_del(wlan_loader->boot_wlan_obj);
11263
11264 /* free the object */
11265 kobject_put(wlan_loader->boot_wlan_obj);
11266
11267 kfree(wlan_loader->attr_group);
11268 kfree(wlan_loader);
11269
11270 wlan_loader = NULL;
11271}
11272
11273/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011274 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11275 * ready
11276 *
11277 * This is creates the syfs entry boot_wlan. Which shall be invoked
11278 * when the filesystem is ready.
11279 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011280 * QDF API cannot be used here since this function is called even before
11281 * initializing WLAN driver.
11282 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011283 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011284 */
11285static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011286{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011287 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011288
11289 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011290 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011291 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011292
11293 wlan_loader->boot_wlan_obj = NULL;
11294 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11295 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011296 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011297 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011298
11299 wlan_loader->loaded_state = 0;
11300 wlan_loader->attr_group->attrs = attrs;
11301
11302 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11303 kernel_kobj);
11304 if (!wlan_loader->boot_wlan_obj) {
11305 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011306 goto error_return;
11307 }
11308
11309 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11310 wlan_loader->attr_group);
11311 if (ret) {
11312 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11313 goto error_return;
11314 }
11315
11316 return 0;
11317
11318error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011319 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011320
11321 return ret;
11322}
11323
11324/**
11325 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11326 *
11327 * Return: 0 on success or errno on failure
11328 */
11329static int wlan_deinit_sysfs(void)
11330{
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011332 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011333 return -EINVAL;
11334 }
11335
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011336 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011337 return 0;
11338}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011339
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011340#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011341
11342#ifdef MODULE
11343/**
11344 * __hdd_module_init - Module init helper
11345 *
11346 * Module init helper function used by both module and static driver.
11347 *
11348 * Return: 0 for success, errno on failure
11349 */
11350static int hdd_module_init(void)
11351{
Arun Khandavallifae92942016-08-01 13:31:08 +053011352 if (__hdd_module_init()) {
11353 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011354 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011355 }
11356
Dustin Brownab482ac2017-06-09 17:00:44 -070011357 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011358}
11359#else
11360static int __init hdd_module_init(void)
11361{
11362 int ret = -EINVAL;
11363
11364 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011365 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011366 pr_err("Failed to create sysfs entry for loading wlan");
11367
11368 return ret;
11369}
11370#endif
11371
11372
11373#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011374/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011375 * hdd_module_exit() - Exit function
11376 *
11377 * This is the driver exit point (invoked when module is unloaded using rmmod)
11378 *
11379 * Return: None
11380 */
11381static void __exit hdd_module_exit(void)
11382{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011383 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011384}
Arun Khandavallifae92942016-08-01 13:31:08 +053011385#else
11386static void __exit hdd_module_exit(void)
11387{
11388 __hdd_module_exit();
11389 wlan_deinit_sysfs();
11390}
11391#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011392
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011393static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11394{
11395 return param_set_copystring(kmessage, kp);
11396}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011397
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011398/**
11399 * is_con_mode_valid() check con mode is valid or not
11400 * @mode: global con mode
11401 *
11402 * Return: TRUE on success FALSE on failure
11403 */
11404static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11405{
11406 switch (mode) {
11407 case QDF_GLOBAL_MONITOR_MODE:
11408 case QDF_GLOBAL_FTM_MODE:
11409 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011410 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011411 return true;
11412 default:
11413 return false;
11414 }
11415}
11416
11417/**
11418 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11419 * @mode: global con mode
11420 *
11421 * Return: adapter mode
11422 */
11423static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11424 enum tQDF_GLOBAL_CON_MODE mode)
11425{
11426
11427 switch (mode) {
11428 case QDF_GLOBAL_MISSION_MODE:
11429 return QDF_STA_MODE;
11430 case QDF_GLOBAL_MONITOR_MODE:
11431 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011432 case QDF_GLOBAL_EPPING_MODE:
11433 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011434 case QDF_GLOBAL_FTM_MODE:
11435 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011436 case QDF_GLOBAL_QVIT_MODE:
11437 return QDF_QVIT_MODE;
11438 default:
11439 return QDF_MAX_NO_OF_MODE;
11440 }
11441}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011442
Dustin Brown27cd9942017-09-27 16:11:44 -070011443static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11444 enum tQDF_GLOBAL_CON_MODE curr_mode)
11445{
11446 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11447 return;
11448
11449 switch (curr_mode) {
11450 case QDF_GLOBAL_MISSION_MODE:
11451 case QDF_GLOBAL_MONITOR_MODE:
11452 case QDF_GLOBAL_FTM_MODE:
11453 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11454 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11455
11456 /* re-use the existing session */
11457 hdd_stop_all_adapters(hdd_ctx, false);
11458 break;
11459 default:
11460 break;
11461 }
11462}
11463
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011464static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011465 enum tQDF_GLOBAL_CON_MODE curr_mode)
11466{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011467 int driver_status;
11468
11469 driver_status = hdd_ctx->driver_status;
11470
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011471 switch (curr_mode) {
11472 case QDF_GLOBAL_MISSION_MODE:
11473 case QDF_GLOBAL_MONITOR_MODE:
11474 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011475 hdd_deinit_all_adapters(hdd_ctx, false);
11476 hdd_close_all_adapters(hdd_ctx, false);
11477 break;
11478 case QDF_GLOBAL_EPPING_MODE:
11479 epping_disable();
11480 epping_close();
11481 break;
11482 default:
11483 return;
11484 }
11485}
11486
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011487static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011488 enum tQDF_GLOBAL_CON_MODE mode)
11489{
Jeff Johnson9d295242017-08-29 14:39:48 -070011490 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011491 int ret = 0;
11492 bool rtnl_held;
11493 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11494 QDF_STATUS status;
11495
11496 if (!qdf_dev) {
11497 hdd_err("qdf device context is Null return!");
11498 return -EINVAL;
11499 }
11500
11501 rtnl_held = hdd_hold_rtnl_lock();
11502 switch (mode) {
11503 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011504 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11505 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011506 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011507 break;
11508 case QDF_GLOBAL_FTM_MODE:
11509 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11510 wlan_hdd_get_intf_addr(hdd_ctx),
11511 NET_NAME_UNKNOWN, rtnl_held);
11512 if (adapter == NULL)
11513 ret = -EINVAL;
11514 break;
11515 case QDF_GLOBAL_MONITOR_MODE:
11516 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11517 wlan_hdd_get_intf_addr(hdd_ctx),
11518 NET_NAME_UNKNOWN, rtnl_held);
11519 if (adapter == NULL)
11520 ret = -EINVAL;
11521 break;
11522 case QDF_GLOBAL_EPPING_MODE:
11523 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011524 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011525 hdd_err("Failed to open in eeping mode: %d", status);
11526 ret = -EINVAL;
11527 break;
11528 }
11529 ret = epping_enable(qdf_dev->dev);
11530 if (ret) {
11531 hdd_err("Failed to enable in epping mode : %d", ret);
11532 epping_close();
11533 }
11534 break;
11535 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011536 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011537 ret = -ENOTSUPP;
11538 break;
11539 }
11540 hdd_release_rtnl_lock();
11541 rtnl_held = false;
11542 return ret;
11543}
11544
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011545/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011546 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011547 * @kmessage: con mode name on which driver to be bring up
11548 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011549 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011550 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011551 * This function is invoked when user updates con mode using sys entry,
11552 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011553 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011554 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011555 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011556static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011557 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011558{
11559 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011560 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011561 enum tQDF_GLOBAL_CON_MODE curr_mode;
11562 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011563
Dustin Brownab6029b2017-05-24 13:04:19 -070011564 hdd_info("con_mode handler: %s", kmessage);
11565
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011566 ret = wlan_hdd_validate_context(hdd_ctx);
11567 if (ret)
11568 return ret;
11569
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011570 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011571
11572 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011573
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011574 if (!(is_con_mode_valid(con_mode))) {
11575 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011576 ret = -EINVAL;
11577 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011578 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011579
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011580 curr_mode = hdd_get_conparam();
11581 if (curr_mode == con_mode) {
11582 hdd_err("curr mode: %d is same as user triggered mode %d",
11583 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011584 ret = 0;
11585 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011586 }
11587
Dustin Brown27cd9942017-09-27 16:11:44 -070011588 /* ensure adapters are stopped */
11589 hdd_stop_present_mode(hdd_ctx, curr_mode);
11590
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011591 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011592 if (ret) {
11593 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011594 goto reset_flags;
11595 }
11596
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011597 /* Cleanup present mode before switching to new mode */
11598 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11599
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011600 hdd_set_conparam(con_mode);
11601
11602 /* Register for new con_mode & then kick_start modules again */
11603 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11604 if (ret) {
11605 hdd_err("Failed to register for new mode");
11606 goto reset_flags;
11607 }
11608
11609 adapter_mode = hdd_get_adpter_mode(con_mode);
11610 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11611 hdd_err("invalid adapter");
11612 ret = -EINVAL;
11613 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011614 }
11615
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011616 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011617 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011618 hdd_err("Failed to get adapter:%d", adapter_mode);
11619 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011620 }
11621
11622 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11623 if (ret) {
11624 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011625 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011626 }
11627
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011628 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011629 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011630 if (hdd_start_adapter(adapter)) {
11631 hdd_err("Failed to start %s adapter", kmessage);
11632 ret = -EINVAL;
11633 goto reset_flags;
11634 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011635 }
11636
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011637 hdd_info("Mode successfully changed to %s", kmessage);
11638 ret = 0;
11639
11640reset_flags:
11641 cds_set_load_in_progress(false);
11642 return ret;
11643}
11644
11645
11646static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11647{
11648 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011649 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011650
11651 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11652 ret = wlan_hdd_validate_context(hdd_ctx);
11653 if (ret)
11654 return ret;
11655
11656 cds_ssr_protect(__func__);
11657 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11658 cds_ssr_unprotect(__func__);
11659
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011660 return ret;
11661}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011662
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011663static int con_mode_handler_ftm(const char *kmessage,
11664 struct kernel_param *kp)
11665{
11666 int ret;
11667
11668 ret = param_set_int(kmessage, kp);
11669
11670 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11671 pr_err("Only FTM mode supported!");
11672 return -ENOTSUPP;
11673 }
11674
11675 hdd_set_conparam(con_mode_ftm);
11676 con_mode = con_mode_ftm;
11677
11678 return ret;
11679}
11680
Ravi Joshia307f632017-07-17 23:41:41 -070011681static int con_mode_handler_monitor(const char *kmessage,
11682 struct kernel_param *kp)
11683{
11684 int ret;
11685
11686 ret = param_set_int(kmessage, kp);
11687
11688 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11689 pr_err("Only Monitor mode supported!");
11690 return -ENOTSUPP;
11691 }
11692
11693 hdd_set_conparam(con_mode_monitor);
11694 con_mode = con_mode_monitor;
11695
11696 return ret;
11697}
11698
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011699/**
11700 * hdd_get_conparam() - driver exit point
11701 *
11702 * This is the driver exit point (invoked when module is unloaded using rmmod)
11703 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011704 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011705 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011706enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011707{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011708 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011709}
11710
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011711void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011712{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011713 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011714}
11715
Komal Seelamc11bb222016-01-27 18:57:10 +053011716/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011717 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11718 * @hdd_ctx: HDD context
11719 *
11720 * Cleans up the pre cac interface, if it exists
11721 *
11722 * Return: None
11723 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011724void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011725{
11726 uint8_t session_id;
11727 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011728 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011729
11730 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11731 if (QDF_IS_STATUS_ERROR(status)) {
11732 hdd_err("failed to get pre cac vdev id");
11733 return;
11734 }
11735
11736 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11737 if (!precac_adapter) {
11738 hdd_err("invalid pre cac adapater");
11739 return;
11740 }
11741
11742 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11743 wlan_hdd_sap_pre_cac_failure,
11744 (void *)precac_adapter);
11745 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11746
11747}
11748
11749/**
Komal Seelamec702b02016-02-24 18:42:16 +053011750 * hdd_update_ol_config - API to update ol configuration parameters
11751 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011752 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011753 * Return: void
11754 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011755static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011756{
Komal Seelamec702b02016-02-24 18:42:16 +053011757 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011758 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011759
Komal Seelamec702b02016-02-24 18:42:16 +053011760 if (!ol_ctx)
11761 return;
11762
11763 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11764 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11765 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11766 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011767 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011768
11769 ol_init_ini_config(ol_ctx, &cfg);
11770}
11771
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011772#ifdef FEATURE_RUNTIME_PM
11773/**
11774 * hdd_populate_runtime_cfg() - populate runtime configuration
11775 * @hdd_ctx: hdd context
11776 * @cfg: pointer to the configuration memory being populated
11777 *
11778 * Return: void
11779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011780static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011781 struct hif_config_info *cfg)
11782{
11783 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11784 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11785}
11786#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011787static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011788 struct hif_config_info *cfg)
11789{
11790}
11791#endif
11792
Komal Seelamec702b02016-02-24 18:42:16 +053011793/**
11794 * hdd_update_hif_config - API to update HIF configuration parameters
11795 * @hdd_ctx: HDD Context
11796 *
11797 * Return: void
11798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011799static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011800{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011801 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011802 struct hif_config_info cfg;
11803
11804 if (!scn)
11805 return;
11806
11807 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011808 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011809 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011810
11811 if (hdd_ctx->config->prevent_link_down)
11812 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011813}
11814
11815/**
11816 * hdd_update_config() - Initialize driver per module ini parameters
11817 * @hdd_ctx: HDD Context
11818 *
11819 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011820 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011821 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011822int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011823{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011824 int ret;
11825
Komal Seelamec702b02016-02-24 18:42:16 +053011826 hdd_update_ol_config(hdd_ctx);
11827 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011828 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11829 ret = hdd_update_cds_config_ftm(hdd_ctx);
11830 else
11831 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011832 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011833
11834 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011835}
11836
Mukul Sharma9d797a02017-01-05 20:26:03 +053011837#ifdef FEATURE_WLAN_RA_FILTERING
11838/**
11839 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11840 * @psoc_cfg: pmo psoc Configuration
11841 * @hdd_ctx: Pointer to hdd context
11842 *
11843 * Return: none
11844 */
11845static inline void hdd_ra_populate_pmo_config(
11846 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011847 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011848{
11849 psoc_cfg->ra_ratelimit_interval =
11850 hdd_ctx->config->RArateLimitInterval;
11851 psoc_cfg->ra_ratelimit_enable =
11852 hdd_ctx->config->IsRArateLimitEnabled;
11853}
11854#else
11855static inline void hdd_ra_populate_pmo_config(
11856 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011857 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011858{
11859}
11860#endif
11861/**
11862 * hdd_update_pmo_config - API to update pmo configuration parameters
11863 * @hdd_ctx: HDD context
11864 *
11865 * Return: void
11866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011867static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011868{
11869 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11870 struct pmo_psoc_cfg psoc_cfg;
11871 QDF_STATUS status;
11872
11873 /*
11874 * Value of hdd_ctx->wowEnable can be,
11875 * 0 - Disable both magic pattern match and pattern byte match.
11876 * 1 - Enable magic pattern match on all interfaces.
11877 * 2 - Enable pattern byte match on all interfaces.
11878 * 3 - Enable both magic patter and pattern byte match on
11879 * all interfaces.
11880 */
11881 psoc_cfg.magic_ptrn_enable =
11882 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11883 psoc_cfg.ptrn_match_enable_all_vdev =
11884 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011885 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11886 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011887 psoc_cfg.bpf_enable =
11888 hdd_ctx->config->bpf_packet_filter_enable;
11889 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011890 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011891 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11892 if (hdd_ctx->config->fhostNSOffload)
11893 psoc_cfg.ns_offload_enable_dynamic = true;
11894 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11895 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11896 psoc_cfg.active_mode_offload =
11897 hdd_ctx->config->active_mode_offload;
11898 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11899 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011900 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11901 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11902 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11903 psoc_cfg.power_save_mode =
11904 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011905 psoc_cfg.auto_power_save_fail_mode =
11906 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011907
11908 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011909 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11910 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011911 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11912 if (status != QDF_STATUS_SUCCESS) {
11913 hdd_err("failed pmo psoc configuration");
11914 return -EINVAL;
11915 }
11916
11917 return 0;
11918}
11919
Abhishek Singhb20db962017-03-03 21:28:46 +053011920#ifdef FEATURE_WLAN_SCAN_PNO
11921static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11922 struct hdd_config *cfg)
11923{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011924 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
11925
Abhishek Singhb20db962017-03-03 21:28:46 +053011926 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11927 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11928 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11929 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11930 pno_cfg->channel_prediction_full_scan =
11931 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011932 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
11933 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
11934 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
11935 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053011936}
11937#else
11938static inline void
11939hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11940 struct hdd_config *cfg)
11941{
11942 return;
11943}
11944#endif
11945
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011946void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11947 struct hdd_config *cfg)
11948{
11949 uint8_t i = 0;
11950
11951 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11952 if (!ie_whitelist->white_list)
11953 return;
11954
11955 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11956 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11957 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11958 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11959 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11960 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11961 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11962 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11963
11964 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11965 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11966 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11967}
11968
Abhishek Singh257a9482017-03-06 16:52:39 +053011969/**
11970 * hdd_update_scan_config - API to update scan configuration parameters
11971 * @hdd_ctx: HDD context
11972 *
11973 * Return: 0 if success else err
11974 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011975static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011976{
11977 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11978 struct scan_user_cfg scan_cfg;
11979 struct hdd_config *cfg = hdd_ctx->config;
11980 QDF_STATUS status;
11981
11982 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11983 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11984 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11985 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11986 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11987 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11988 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011989 /* convert to ms */
11990 scan_cfg.scan_cache_aging_time =
11991 cfg->scanAgingTimeout * 1000;
11992 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11993 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11994 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11995 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011996 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011997 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singhb58164a2017-07-19 18:47:23 +053011998 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Abhishek Singh257a9482017-03-06 16:52:39 +053011999
Abhishek Singhb20db962017-03-03 21:28:46 +053012000 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012001 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012002
Abhishek Singh257a9482017-03-06 16:52:39 +053012003 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12004 if (status != QDF_STATUS_SUCCESS) {
12005 hdd_err("failed pmo psoc configuration");
12006 return -EINVAL;
12007 }
12008
12009 return 0;
12010}
Abhishek Singh257a9482017-03-06 16:52:39 +053012011
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012012static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012013{
12014 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12015 struct tdls_start_params tdls_cfg;
12016 struct tdls_user_config *config = &tdls_cfg.config;
12017 struct hdd_config *cfg = hdd_ctx->config;
12018 QDF_STATUS status;
12019
12020 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12021 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12022 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12023 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12024 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12025 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12026 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12027 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12028 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12029 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12030 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12031 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12032 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12033 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12034 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12035 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12036 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12037 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12038 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12039 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12040 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12041 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12042 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12043 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12044 (cfg->fEnableTDLSImplicitTrigger ?
12045 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12046 (cfg->fTDLSExternalControl ?
12047 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12048
12049 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12050 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12051 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12052 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012053 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012054 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012055 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12056 tdls_cfg.tdls_evt_cb_data = psoc;
12057 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12058 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12059 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012060 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12061 tdls_cfg.tdls_wmm_cb_data = psoc;
12062 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12063 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012064 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012065
12066 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12067 if (status != QDF_STATUS_SUCCESS) {
12068 hdd_err("failed pmo psoc configuration");
12069 return -EINVAL;
12070 }
12071
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012072 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012073 /* enable napier specific tdls data path */
12074 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012075
Frank Liud4b2fa02017-03-29 11:46:48 +080012076 return 0;
12077}
Frank Liud4b2fa02017-03-29 11:46:48 +080012078
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012079int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012080{
12081 int ret;
12082
12083 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012084 if (ret)
12085 return ret;
12086 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012087 if (ret)
12088 return ret;
12089 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012090
12091 return ret;
12092}
12093
Agrawal Ashish65634612016-08-18 13:24:32 +053012094/**
12095 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12096 * @mode : cfg80211 DFS mode
12097 *
12098 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12099 */
12100enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12101{
12102 switch (mode) {
12103 case DFS_MODE_ENABLE:
12104 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012105 case DFS_MODE_DISABLE:
12106 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012107 case DFS_MODE_DEPRIORITIZE:
12108 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012109 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012110 hdd_debug("ACS dfs mode is NONE");
12111 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012112 }
12113}
12114
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012115/**
12116 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12117 * @hddctx: pointer to hdd context
12118 * @set_value: enable/disable
12119 *
12120 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12121 * Host(even though it is duplicate). When Host send vendor command
12122 * disable,FW doesn't perform any action. Whenever any change in
12123 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12124 *
12125 * return - 0 on success, appropriate error values on failure.
12126 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012127int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012128{
12129 QDF_STATUS status;
12130
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012131 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012132 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012133
12134 if (!hddctx->config->goptimize_chan_avoid_event) {
12135 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12136 return -EINVAL;
12137 }
12138
12139 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12140 if (!QDF_IS_STATUS_SUCCESS(status)) {
12141 hdd_err("Failed to send chan avoid command to SME");
12142 return -EINVAL;
12143 }
12144 return 0;
12145}
Agrawal Ashish65634612016-08-18 13:24:32 +053012146
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012147/**
12148 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12149 * @value: value to set
12150 *
12151 * This function will set the passed value to roaming in progress flag.
12152 *
12153 * Return: None
12154 */
12155void hdd_set_roaming_in_progress(bool value)
12156{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012157 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012158
12159 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12160 if (!hdd_ctx) {
12161 hdd_err("HDD context is NULL");
12162 return;
12163 }
12164
12165 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012166 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012167}
12168
12169/**
12170 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012171 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012172 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012173 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012174 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012175bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012176{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012177 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012178 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012179
12180 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12181 if (!hdd_ctx) {
12182 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012183 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012184 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012185 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12186 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012187 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12188 hdd_ctx->roaming_in_progress);
12189
12190 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012191}
12192
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012193/**
12194 * hdd_is_connection_in_progress() - check if connection is in
12195 * progress
12196 * @session_id: session id
12197 * @reason: scan reject reason
12198 *
12199 * Go through each adapter and check if Connection is in progress
12200 *
12201 * Return: true if connection is in progress else false
12202 */
12203bool hdd_is_connection_in_progress(uint8_t *session_id,
12204 enum scan_reject_states *reason)
12205{
12206 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012207 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012208 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012209 QDF_STATUS status = 0;
12210 uint8_t sta_id = 0;
12211 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012212 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012213
12214 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12215 if (!hdd_ctx) {
12216 hdd_err("HDD context is NULL");
12217 return false;
12218 }
12219
12220 if (true == hdd_ctx->btCoexModeSet) {
12221 hdd_info("BTCoex Mode operation in progress");
12222 return true;
12223 }
12224 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12225 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -070012226 adapter = adapter_node->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012227 if (!adapter)
12228 goto end;
12229
12230 hdd_info("Adapter with device mode %s(%d) exists",
12231 hdd_device_mode_to_string(adapter->device_mode),
12232 adapter->device_mode);
12233 if (((QDF_STA_MODE == adapter->device_mode)
12234 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12235 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12236 && (eConnectionState_Connecting ==
12237 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12238 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012239 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012240 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12241 adapter->sessionId);
12242 if (session_id && reason) {
12243 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012244 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012245 }
12246 return true;
12247 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012248 /*
12249 * sme_neighbor_middle_of_roaming is for LFR2
12250 * hdd_is_roaming_in_progress is for LFR3
12251 */
12252 if (((QDF_STA_MODE == adapter->device_mode) &&
12253 sme_neighbor_middle_of_roaming(
12254 WLAN_HDD_GET_HAL_CTX(adapter),
12255 adapter->sessionId)) ||
12256 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012257 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012258 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12259 adapter->sessionId);
12260 if (session_id && reason) {
12261 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012262 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012263 }
12264 return true;
12265 }
12266 if ((QDF_STA_MODE == adapter->device_mode) ||
12267 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12268 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12269 hdd_sta_ctx =
12270 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12271 if ((eConnectionState_Associated ==
12272 hdd_sta_ctx->conn_info.connState)
12273 && (false ==
12274 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12275 sta_mac = (uint8_t *)
12276 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012277 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012278 " is in middle of WPS/EAPOL exchange.",
12279 MAC_ADDR_ARRAY(sta_mac));
12280 if (session_id && reason) {
12281 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012282 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012283 }
12284 return true;
12285 }
12286 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12287 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12288 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12289 sta_id++) {
12290 if (!((adapter->aStaInfo[sta_id].isUsed)
12291 && (OL_TXRX_PEER_STATE_CONN ==
12292 adapter->aStaInfo[sta_id].tlSTAState)))
12293 continue;
12294
12295 sta_mac = (uint8_t *)
12296 &(adapter->aStaInfo[sta_id].
12297 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012298 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012299 " of SAP/GO is in middle of WPS/EAPOL exchange",
12300 MAC_ADDR_ARRAY(sta_mac));
12301 if (session_id && reason) {
12302 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012303 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012304 }
12305 return true;
12306 }
12307 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012308 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012309 return true;
12310 }
12311 }
12312end:
12313 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12314 adapter_node = next;
12315 }
12316 return false;
12317}
12318
12319/**
12320 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012321 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012322 *
12323 * Return: None
12324 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012325void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012326{
Jeff Johnson87251032017-08-29 13:31:11 -070012327 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012328 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012329 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012330 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012331 tsap_Config_t *sap_config;
12332 void *sap_ctx;
12333
12334 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12335 sap_config = &hdd_ap_ctx->sapConfig;
12336 sap_ctx = hdd_ap_ctx->sapContext;
12337
12338 mutex_lock(&hdd_ctx->sap_lock);
12339 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12340 wlan_hdd_del_station(ap_adapter);
12341 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12342 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12343 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12344 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12345 qdf_status =
12346 qdf_wait_single_event(&hostapd_state->
12347 qdf_stop_bss_event,
12348 SME_CMD_TIMEOUT_VALUE);
12349
12350 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012351 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012352 goto end;
12353 }
12354 }
12355 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012356 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012357 ap_adapter->device_mode, ap_adapter->sessionId);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012358 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012359
12360 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012361 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012362 wlansap_reset_sap_config_add_ie(sap_config,
12363 eUPDATE_IE_ALL);
12364 goto end;
12365 }
12366
12367 qdf_event_reset(&hostapd_state->qdf_event);
12368 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12369 sap_config,
12370 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012371 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012372 wlansap_reset_sap_config_add_ie(sap_config,
12373 eUPDATE_IE_ALL);
12374 goto end;
12375 }
12376
Jeff Johnson6867ec32017-09-29 20:30:20 -070012377 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012378 qdf_status =
12379 qdf_wait_single_event(&hostapd_state->qdf_event,
12380 SME_CMD_TIMEOUT_VALUE);
12381 wlansap_reset_sap_config_add_ie(sap_config,
12382 eUPDATE_IE_ALL);
12383 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012384 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012385 goto end;
12386 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012387 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012388 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12389 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012390 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12391 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012392 ap_adapter->sessionId);
12393 hostapd_state->bCommit = true;
12394 }
12395end:
12396 mutex_unlock(&hdd_ctx->sap_lock);
12397 return;
12398}
12399
12400/**
12401 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12402 * with non dfs acs
12403 *
12404 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12405 *
12406 * Return: None
12407 */
12408void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12409{
Jeff Johnson9d295242017-08-29 14:39:48 -070012410 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012411 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412 cds_context_type *cds_ctx;
12413
12414 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12415 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012416 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012417 return;
12418 }
12419
12420 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12421 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012422 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012423 return;
12424 }
12425
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012426 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12427 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012428 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012429 return;
12430 }
12431
12432 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012433 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12434 &ap_adapter->event_flags) &&
12435 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12436 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012437
Jeff Johnson6867ec32017-09-29 20:30:20 -070012438 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012439 ap_adapter->sessionCtx.ap.sapConfig.channel =
12440 AUTO_CHANNEL_SELECT;
12441 ap_adapter->sessionCtx.ap.sapConfig.
12442 acs_cfg.acs_mode = true;
12443
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012444 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012445 }
12446}
12447
12448/**
12449 * hdd_set_connection_in_progress() - to set the connection in
12450 * progress flag
12451 * @value: value to set
12452 *
12453 * This function will set the passed value to connection in progress flag.
12454 * If value is previously being set to true then no need to set it again.
12455 *
12456 * Return: true if value is being set correctly and false otherwise.
12457 */
12458bool hdd_set_connection_in_progress(bool value)
12459{
12460 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012461 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012462
12463 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12464 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012465 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012466 return false;
12467 }
12468
12469 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12470 /*
12471 * if the value is set to true previously and if someone is
12472 * trying to make it true again then it could be some race
12473 * condition being triggered. Avoid this situation by returning
12474 * false
12475 */
12476 if (hdd_ctx->connection_in_progress && value)
12477 status = false;
12478 else
12479 hdd_ctx->connection_in_progress = value;
12480 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12481 return status;
12482}
12483
Jeff Johnson9d295242017-08-29 14:39:48 -070012484int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012485{
12486 if (!adapter) {
12487 hdd_err("Invalid adapter");
12488 return -EINVAL;
12489 }
12490 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012491 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012492 WMA_VDEV_MCC_SET_TIME_QUOTA,
12493 set_value, VDEV_CMD);
12494 return 0;
12495
12496}
12497
Jeff Johnson9d295242017-08-29 14:39:48 -070012498int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012499{
12500 if (!adapter) {
12501 hdd_err("Invalid adapter");
12502 return -EINVAL;
12503 }
12504
12505 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012506 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012507 WMA_VDEV_MCC_SET_TIME_LATENCY,
12508 set_value, VDEV_CMD);
12509 return 0;
12510}
12511
Jeff Johnson9d295242017-08-29 14:39:48 -070012512struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012513 *psoc, uint8_t vdev_id)
12514{
Jeff Johnson9d295242017-08-29 14:39:48 -070012515 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012516 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012517
12518 /*
12519 * Currently PSOC is not being used. But this logic will
12520 * change once we have the converged implementation of
12521 * HDD context per PSOC in place. This would break if
12522 * multiple vdev objects reuse the vdev id.
12523 */
12524 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12525 if (!adapter)
12526 hdd_err("Get adapter by vdev id failed");
12527
12528 return adapter;
12529}
12530
Jeff Johnson9d295242017-08-29 14:39:48 -070012531int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012532 int8_t *rssi, int8_t *snr)
12533{
12534 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070012535 struct hdd_wext_state *wext_state =
12536 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012537 tCsrRoamProfile *profile = &wext_state->roamProfile;
12538
12539 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12540 profile, bssid, rssi, snr);
12541 if (QDF_STATUS_SUCCESS != status) {
12542 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12543 return -EINVAL;
12544 }
12545
12546 return 0;
12547}
12548
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012549/**
12550 * hdd_send_limit_off_chan_cmd() - send limit off-channel command parameters
12551 * @param - pointer to sir_limit_off_chan
12552 *
12553 * Return: 0 on success and non zero value on failure
12554 */
12555static int hdd_send_limit_off_chan_cmd(struct sir_limit_off_chan *param)
12556{
12557 struct scheduler_msg msg = {0};
12558
12559 msg.type = WMA_SET_LIMIT_OFF_CHAN;
12560 msg.reserved = 0;
12561 msg.bodyptr = param;
12562
12563 if (!QDF_IS_STATUS_SUCCESS(scheduler_post_msg(QDF_MODULE_ID_WMA,
12564 &msg))) {
12565 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
12566 FL("Not able to post WMA_SET_LIMIT_OFF_CHAN to WMA"));
12567 return QDF_STATUS_E_FAILURE;
12568 }
12569
12570 return 0;
12571}
12572
12573/**
12574 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12575 * @adapter - HDD adapter
12576 * @tos - type of service
12577 * @status - status of the traffic
12578 *
12579 * Return: 0 on success and non zero value on failure
12580 */
12581
12582int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12583 bool is_tos_active)
12584{
12585 int ac_bit;
12586 struct sir_limit_off_chan *cmd;
12587 struct hdd_context *hdd_ctx;
12588 int ret;
12589
12590 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12591 ret = wlan_hdd_validate_context(hdd_ctx);
12592
12593 if (ret < 0) {
12594 hdd_err("failed to set limit off chan params");
12595 return ret;
12596 }
12597
12598 cmd = qdf_mem_malloc(sizeof(struct sir_limit_off_chan));
12599 if (!cmd) {
12600 hdd_err("qdf_mem_malloc failed for limit off channel");
12601 return -ENOMEM;
12602 }
12603
12604 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12605
12606 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012607 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012608 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012609 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012610
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012611 if (adapter->active_ac) {
12612 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012613 cmd->max_off_chan_time =
12614 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12615 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12616 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053012617 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012618 cmd->max_off_chan_time =
12619 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12620 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12621 PM_LATENCY);
12622 } else {
12623 /*ignore this command if only BE/BK is active */
12624 is_tos_active = false;
12625 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12626 hdd_ctx->config->conc_system_pref);
12627 }
12628 } else {
12629 /* No active tos */
12630 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12631 hdd_ctx->config->conc_system_pref);
12632 }
12633
12634 cmd->vdev_id = adapter->sessionId;
12635 cmd->is_tos_active = is_tos_active;
12636 cmd->rest_time = hdd_ctx->config->nRestTimeConc;
12637 cmd->skip_dfs_chans = true;
12638
12639 ret = hdd_send_limit_off_chan_cmd(cmd);
12640 if (ret)
12641 qdf_mem_free(cmd);
12642
12643 return ret;
12644}
12645
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012646/**
12647 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12648 * @drv_op: Enum indicating driver op
12649 *
12650 * Return: none
12651 */
12652void hdd_start_driver_ops_timer(int drv_op)
12653{
12654 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12655 switch (drv_op) {
12656 case eHDD_DRV_OP_PROBE:
12657 memcpy(drv_ops_string, "probe", sizeof("probe"));
12658 break;
12659 case eHDD_DRV_OP_REMOVE:
12660 memcpy(drv_ops_string, "remove", sizeof("remove"));
12661 break;
12662 case eHDD_DRV_OP_SHUTDOWN:
12663 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12664 break;
12665 case eHDD_DRV_OP_REINIT:
12666 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12667 break;
12668 }
12669
12670 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12671 HDD_OPS_INACTIVITY_TIMEOUT);
12672}
12673
12674/**
12675 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12676 *
12677 * Return: none
12678 */
12679void hdd_stop_driver_ops_timer(void)
12680{
12681 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12682}
12683
12684/**
12685 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12686 * inactivity timer
12687 *
12688 * Return: None
12689 */
12690void hdd_drv_ops_inactivity_handler(void)
12691{
12692 hdd_err("%s: %d Sec timer expired while in .%s",
12693 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12694
12695 /* Driver shutdown is stuck, no recovery possible at this point */
12696 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12697 sizeof("shutdown")))
12698 QDF_BUG(0);
12699
12700 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053012701 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012702 else
12703 QDF_BUG(0);
12704}
12705
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053012706void hdd_pld_ipa_uc_shutdown_pipes(void)
12707{
12708 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12709
12710 if (!hdd_ctx)
12711 return;
12712
12713 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
12714}
12715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012716/* Register the module init/exit functions */
12717module_init(hdd_module_init);
12718module_exit(hdd_module_exit);
12719
12720MODULE_LICENSE("Dual BSD/GPL");
12721MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12722MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12723
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012724module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12725 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012726
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012727module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12728 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12729
Ravi Joshia307f632017-07-17 23:41:41 -070012730module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12731 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12732
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012733module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12734 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12735
12736module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12737
12738module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12739
12740module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);