blob: dfff0d48f2542542e9e7154f66a6bf9921496a89 [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"
96
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530103#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700104#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700105#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530106#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700107#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530108#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800109#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530111#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800112#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800113#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530114#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530115#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800116#include "os_if_wifi_pos.h"
117#include "wifi_pos_api.h"
118#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800119#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700120#include "os_if_nan.h"
121#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700122#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530124#include "sme_power_save_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800125
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530126#ifdef CNSS_GENL
127#include <net/cnss_nl.h>
128#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800129#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800131#ifdef MODULE
132#define WLAN_MODULE_NAME module_name(THIS_MODULE)
133#else
134#define WLAN_MODULE_NAME "wlan"
135#endif
136
137#ifdef TIMER_MANAGER
138#define TIMER_MANAGER_STR " +TIMER_MANAGER"
139#else
140#define TIMER_MANAGER_STR ""
141#endif
142
143#ifdef MEMORY_DEBUG
144#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
145#else
146#define MEMORY_DEBUG_STR ""
147#endif
148
Sachin Ahujadddd2632017-03-07 19:07:24 +0530149int wlan_start_ret_val;
150static DECLARE_COMPLETION(wlan_start_comp);
151static unsigned int dev_num = 1;
152static struct cdev wlan_hdd_state_cdev;
153static struct class *class;
154static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530155#ifndef MODULE
156static struct gwlan_loader *wlan_loader;
157static ssize_t wlan_boot_cb(struct kobject *kobj,
158 struct kobj_attribute *attr,
159 const char *buf, size_t count);
160struct gwlan_loader {
161 bool loaded_state;
162 struct kobject *boot_wlan_obj;
163 struct attribute_group *attr_group;
164};
165
166static struct kobj_attribute wlan_boot_attribute =
167 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
168
169static struct attribute *attrs[] = {
170 &wlan_boot_attribute.attr,
171 NULL,
172};
173
174#define MODULE_INITIALIZED 1
175#endif
176
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530177#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
178#define MAX_OPS_NAME_STRING_SIZE 20
179
180static qdf_timer_t hdd_drv_ops_inactivity_timer;
181static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800183/* the Android framework expects this param even though we don't use it */
184#define BUF_LEN 20
185static char fwpath_buffer[BUF_LEN];
186static struct kparam_string fwpath = {
187 .string = fwpath_buffer,
188 .maxlen = BUF_LEN,
189};
190
191static char *country_code;
192static int enable_11d = -1;
193static int enable_dfs_chan_scan = -1;
194
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800195/*
196 * spinlock for synchronizing asynchronous request/response
197 * (full description of use in wlan_hdd_main.h)
198 */
199DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530200DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800201
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800202#define WLAN_NLINK_CESIUM 30
203
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530204static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800205
206#define WOW_MAX_FILTER_LISTS 1
207#define WOW_MAX_FILTERS_PER_LIST 4
208#define WOW_MIN_PATTERN_SIZE 6
209#define WOW_MAX_PATTERN_SIZE 64
210
211#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
212static const struct wiphy_wowlan_support wowlan_support_reg_init = {
213 .flags = WIPHY_WOWLAN_ANY |
214 WIPHY_WOWLAN_MAGIC_PKT |
215 WIPHY_WOWLAN_DISCONNECT |
216 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
217 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
218 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
219 WIPHY_WOWLAN_4WAY_HANDSHAKE |
220 WIPHY_WOWLAN_RFKILL_RELEASE,
221 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
222 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
223 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
224};
225#endif
226
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700227static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
228 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
229 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
233 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
234 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
235 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
240 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
241 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
242 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
243 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
244 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700262 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700263};
264
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530265int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
266 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
267 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
268 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
269 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
270};
271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800272/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530273struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800274
275struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800276#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700277static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278#endif
279
Sachin Ahujadddd2632017-03-07 19:07:24 +0530280void hdd_start_complete(int ret)
281{
282 wlan_start_ret_val = ret;
283
284 complete(&wlan_start_comp);
285}
286
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800287/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530288 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700289 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530290 *
291 * Return: none
292 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700293static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530294{
Jeff Johnson9d295242017-08-29 14:39:48 -0700295 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530296 hdd_adapter_list_node_t *adapter_node, *next;
297 QDF_STATUS status = QDF_STATUS_SUCCESS;
298
299 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
300 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
301 adapter = adapter_node->pAdapter;
302 if (NULL != adapter)
303 hdd_send_rps_ind(adapter);
304 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
305 adapter_node = next;
306 }
307}
308
309/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800310 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
311 * @vdev_id: vdev_id
312 * @action: action type
313 * @reason: reason type
314 *
315 * Return: none
316 */
317void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
318 enum netif_action_type action, enum netif_reason_type reason)
319{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700320 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700321 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322
323 if (!hdd_ctx) {
324 hdd_err("hdd ctx is NULL");
325 return;
326 }
327 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
328
329 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330}
331
332/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700333 * Store WLAN driver version and timestamp info in global variables such that
334 * crash debugger can extract them from driver debug symbol and crashdump for
335 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336 */
337uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700338
339#ifndef BUILD_TIMESTAMP
340#define BUILD_TIMESTAMP ""
341#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700342uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800343
344/**
345 * hdd_device_mode_to_string() - return string conversion of device mode
346 * @device_mode: device mode
347 *
348 * This utility function helps log string conversion of device mode.
349 *
350 * Return: string conversion of device mode, if match found;
351 * "Unknown" otherwise.
352 */
353const char *hdd_device_mode_to_string(uint8_t device_mode)
354{
355 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800356 CASE_RETURN_STRING(QDF_STA_MODE);
357 CASE_RETURN_STRING(QDF_SAP_MODE);
358 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
359 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
360 CASE_RETURN_STRING(QDF_FTM_MODE);
361 CASE_RETURN_STRING(QDF_IBSS_MODE);
362 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
363 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700364 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365 default:
366 return "Unknown";
367 }
368}
369
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530370/**
371 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
372 * @adapter: HDD adapter
373 * @chan_number: Channel number
374 * @chan_bw: Bandwidth
375 *
376 * Checks if the given bandwidth is valid for the given channel number.
377 *
378 * Return: 0 for success, non-zero for failure
379 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700380int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530381 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800382 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530383{
384 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
385 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
386 bool found = false;
387 tHalHandle hal;
388
389 hal = WLAN_HDD_GET_HAL_CTX(adapter);
390 if (!hal) {
391 hdd_err("Invalid HAL context");
392 return -EINVAL;
393 }
394
395 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
396 hdd_err("No valid channel list");
397 return -EOPNOTSUPP;
398 }
399
400 for (i = 0; i < len; i++) {
401 if (chan[i] == chan_number) {
402 found = true;
403 break;
404 }
405 }
406
407 if (found == false) {
408 hdd_err("Channel not in driver's valid channel list");
409 return -EOPNOTSUPP;
410 }
411
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700412 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
413 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530414 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
415 return -EINVAL;
416 }
417
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700418 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530419 if (chan_bw == CH_WIDTH_80MHZ) {
420 hdd_err("BW80 not possible in 2.4GHz band");
421 return -EINVAL;
422 }
423 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
424 (chan_bw != CH_WIDTH_MAX)) {
425 hdd_err("Only BW20 possible on channel 14");
426 return -EINVAL;
427 }
428 }
429
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700430 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530431 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
432 (chan_bw != CH_WIDTH_MAX)) {
433 hdd_err("Only BW20 possible on channel 165");
434 return -EINVAL;
435 }
436 }
437
438 return 0;
439}
440
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530441/**
442 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
443 *
444 * Block the unloading of the driver (or) interface up until the
445 * cds recovery is completed
446 *
447 * Return: true for recovery completion else false
448 */
449static bool hdd_wait_for_recovery_completion(void)
450{
451 int retry = 0;
452
453 /* Wait for recovery to complete */
454 while (cds_is_driver_recovering()) {
455 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
456 hdd_err("Recovery in progress; wait here!!!");
457 msleep(1000);
458 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
459 hdd_err("SSR never completed, error");
460 /*
461 * Trigger the bug_on in the internal builds, in the
462 * customer builds self-recovery will be enabled
463 * in those cases just return error.
464 */
465 if (cds_is_self_recovery_enabled())
466 return false;
467 QDF_BUG(0);
468 }
469 }
470
471 hdd_info("Recovery completed successfully!");
472 return true;
473}
474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475static int __hdd_netdev_notifier_call(struct notifier_block *nb,
476 unsigned long state, void *data)
477{
478#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
479 struct netdev_notifier_info *dev_notif_info = data;
480 struct net_device *dev = dev_notif_info->dev;
481#else
482 struct net_device *dev = data;
483#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700484 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700485 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800486
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800487 ENTER_DEV(dev);
488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489 /* Make sure that this callback corresponds to our device. */
490 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
491 return NOTIFY_DONE;
492
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530493 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700495 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496 return NOTIFY_DONE;
497 }
498
499 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700500 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 return NOTIFY_DONE;
502 }
503
504 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
505 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800506 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530507 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800508 return NOTIFY_DONE;
509 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530510 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511 return NOTIFY_DONE;
512
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800513 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 dev->name, state);
515
516 switch (state) {
517 case NETDEV_REGISTER:
518 break;
519
520 case NETDEV_UNREGISTER:
521 break;
522
523 case NETDEV_UP:
524 sme_ch_avoid_update_req(hdd_ctx->hHal);
525 break;
526
527 case NETDEV_DOWN:
528 break;
529
530 case NETDEV_CHANGE:
531 if (true == adapter->isLinkUpSvcNeeded)
532 complete(&adapter->linkup_event_var);
533 break;
534
535 case NETDEV_GOING_DOWN:
536 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530537 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
538 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800539 } else {
hqueaa33ee2017-05-04 17:56:35 +0800540 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800541 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542 }
543 break;
544
545 default:
546 break;
547 }
548
549 return NOTIFY_DONE;
550}
551
552/**
553 * hdd_netdev_notifier_call() - netdev notifier callback function
554 * @nb: pointer to notifier block
555 * @state: state
556 * @ndev: ndev pointer
557 *
558 * Return: 0 on success, error number otherwise.
559 */
560static int hdd_netdev_notifier_call(struct notifier_block *nb,
561 unsigned long state,
562 void *ndev)
563{
564 int ret;
565
566 cds_ssr_protect(__func__);
567 ret = __hdd_netdev_notifier_call(nb, state, ndev);
568 cds_ssr_unprotect(__func__);
569
570 return ret;
571}
572
573struct notifier_block hdd_netdev_notifier = {
574 .notifier_call = hdd_netdev_notifier_call,
575};
576
577/* variable to hold the insmod parameters */
578static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800579
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530580static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700581int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530582
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800583/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530586/**
587 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
588 * @ch_width: NL channel width
589 *
590 * Converts the NL channel width to the driver's internal representation
591 *
592 * Return: Converted channel width. In case of non matching NL channel width,
593 * CH_WIDTH_MAX will be returned.
594 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800595enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530596{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800597 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700598
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800599 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530600 switch (ch_width) {
601 case NL80211_CHAN_WIDTH_20_NOHT:
602 case NL80211_CHAN_WIDTH_20:
603 return CH_WIDTH_20MHZ;
604 case NL80211_CHAN_WIDTH_40:
605 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530606 case NL80211_CHAN_WIDTH_80:
607 return CH_WIDTH_80MHZ;
608 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800609 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
610 return CH_WIDTH_80P80MHZ;
611 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
612 return CH_WIDTH_160MHZ;
613 else
614 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530615 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800616 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
617 return CH_WIDTH_160MHZ;
618 else
619 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530620 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800621 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530622 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800623 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530624 default:
625 hdd_err("Invalid channel width %d, setting to default",
626 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800627 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530628 }
629}
630
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530631/* wlan_hdd_find_opclass() - Find operating class for a channel
632 * @hal: handler to HAL
633 * @channel: channel id
634 * @bw_offset: bandwidth offset
635 *
636 * Function invokes sme api to find the operating class
637 *
638 * Return: operating class
639 */
640uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
641 uint8_t bw_offset)
642{
643 uint8_t opclass = 0;
644
645 sme_get_opclass(hal, channel, bw_offset, &opclass);
646 return opclass;
647}
648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800649/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530650 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530651 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652 * @bitmask: Bitmask of log levels to be enabled
653 *
654 * Called immediately after the cfg.ini is read in order to configure
655 * the desired trace levels.
656 *
657 * Return: None
658 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530659int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530661 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530662 int qdf_print_idx = -1;
663 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664 /*
665 * if the bitmask is the default value, then a bitmask was not
666 * specified in cfg.ini, so leave the logging level alone (it
667 * will remain at the "compiled in" default value)
668 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700669 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530670 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800671
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530672 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530674 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530675 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530676 QDF_TRACE_LEVEL_NONE, 0);
677
678 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530679 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530681 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800682 while (0 != bitmask) {
683 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530684 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530685 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530686 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530687 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700689
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690 level++;
691 bitmask >>= 1;
692 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530693 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694}
695
696/**
Chris Guo1751acf2017-07-03 14:09:01 +0800697 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
698 * @hdd_ctx: HDD context pointer
699 *
700 * Return: 0 if the context is valid. Error code otherwise
701 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700702int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800703{
704 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
705 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
706 return -ENODEV;
707 }
708
709 if (cds_is_driver_recovering()) {
710 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
711 (void *)_RET_IP_, cds_get_driver_state());
712 return -EAGAIN;
713 }
714
715 if (hdd_ctx->start_modules_in_progress ||
716 hdd_ctx->stop_modules_in_progress) {
717 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
718 (void *)_RET_IP_);
719 return -EAGAIN;
720 }
721
722 return 0;
723}
724
725
726/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 * wlan_hdd_validate_context() - check the HDD context
728 * @hdd_ctx: HDD context pointer
729 *
730 * Return: 0 if the context is valid. Error code otherwise
731 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700732int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530735 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736 return -ENODEV;
737 }
738
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800739 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800740 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530741 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742 return -EAGAIN;
743 }
744
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700745 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530747
748 if (hdd_ctx->start_modules_in_progress ||
749 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800750 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530751 (void *)_RET_IP_);
752 return -EAGAIN;
753 }
754
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530755 if (cds_is_driver_in_bad_state()) {
756 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
757 (void *)_RET_IP_, cds_get_driver_state());
758 return -ENODEV;
759 }
760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 return 0;
762}
763
Jeff Johnson9d295242017-08-29 14:39:48 -0700764int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700765{
766 if (!adapter) {
767 hdd_err("adapter is null");
768 return -EINVAL;
769 }
770
771 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
772 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
773 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
774 return -EINVAL;
775 }
776
777 if (!adapter->dev) {
778 hdd_err("adapter net_device is null");
779 return -EINVAL;
780 }
781
782 if (!(adapter->dev->flags & IFF_UP)) {
783 hdd_info("adapter net_device is not up");
784 return -EAGAIN;
785 }
786
787 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
788 hdd_info("adapter session is not open");
789 return -EAGAIN;
790 }
791
792 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
793 hdd_err("bad adapter session Id: %u", adapter->sessionId);
794 return -EINVAL;
795 }
796
797 return 0;
798}
799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530801 * wlan_hdd_validate_modules_state() - Check modules status
802 * @hdd_ctx: HDD context pointer
803 *
804 * Check's the driver module's state and returns true if the
805 * modules are enabled returns false if modules are closed.
806 *
807 * Return: True if modules are enabled or false.
808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700809bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530810{
811 mutex_lock(&hdd_ctx->iface_change_lock);
812 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
813 mutex_unlock(&hdd_ctx->iface_change_lock);
814 hdd_notice("Modules not enabled, Present status: %d",
815 hdd_ctx->driver_status);
816 return false;
817 }
818 mutex_unlock(&hdd_ctx->iface_change_lock);
819 return true;
820}
821
822/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700824 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 *
826 * This function sets the IBSS power save config parameters to WMA
827 * which will send it to firmware if FW supports IBSS power save
828 * before vdev start.
829 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530830 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 * on failure.
832 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700833QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834{
835 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700836 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837
838 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700839 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530840 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 }
842
Naveen Rawat247a8682017-06-05 15:00:31 -0700843 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800844 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
845 hdd_ctx->config->ibssATIMWinSize,
846 VDEV_CMD);
847 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700848 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530849 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 }
851
Naveen Rawat247a8682017-06-05 15:00:31 -0700852 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
854 hdd_ctx->config->isIbssPowerSaveAllowed,
855 VDEV_CMD);
856 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700857 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
858 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530859 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 }
861
Naveen Rawat247a8682017-06-05 15:00:31 -0700862 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
864 hdd_ctx->config->
865 isIbssPowerCollapseAllowed, VDEV_CMD);
866 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700867 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
868 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530869 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 }
871
Naveen Rawat247a8682017-06-05 15:00:31 -0700872 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
874 hdd_ctx->config->isIbssAwakeOnTxRx,
875 VDEV_CMD);
876 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700877 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530878 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 }
880
Naveen Rawat247a8682017-06-05 15:00:31 -0700881 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
883 hdd_ctx->config->ibssInactivityCount,
884 VDEV_CMD);
885 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700886 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530887 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888 }
889
Naveen Rawat247a8682017-06-05 15:00:31 -0700890 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
892 hdd_ctx->config->ibssTxSpEndInactivityTime,
893 VDEV_CMD);
894 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700895 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
896 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530897 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898 }
899
Naveen Rawat247a8682017-06-05 15:00:31 -0700900 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
902 hdd_ctx->config->ibssPsWarmupTime,
903 VDEV_CMD);
904 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700905 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
906 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530907 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 }
909
Naveen Rawat247a8682017-06-05 15:00:31 -0700910 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
912 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
913 VDEV_CMD);
914 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700915 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
916 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530917 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 }
919
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530920 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921}
922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923#define INTF_MACADDR_MASK 0x7
924
925/**
926 * hdd_update_macaddr() - update mac address
927 * @config: hdd configuration
928 * @hw_macaddr: mac address
929 *
930 * Mac address for multiple virtual interface is found as following
931 * i) The mac address of the first interface is just the actual hw mac address.
932 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
933 * define the mac address for the remaining interfaces and locally
934 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
935 * supported virtual interfaces, right now this is 0x07 (meaning 8
936 * interface).
937 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
938 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
939 *
940 * Return: None
941 */
942void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530943 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944{
945 int8_t i;
946 uint8_t macaddr_b3, tmp_br3;
947
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530948 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530949 QDF_MAC_ADDR_SIZE);
950 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530951 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530952 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 macaddr_b3 = config->intfMacAddr[i].bytes[3];
954 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
955 INTF_MACADDR_MASK;
956 macaddr_b3 += tmp_br3;
957
958 /* XOR-ing bit-24 of the mac address. This will give enough
959 * mac address range before collision
960 */
961 macaddr_b3 ^= (1 << 7);
962
963 /* Set locally administered bit */
964 config->intfMacAddr[i].bytes[0] |= 0x02;
965 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800966 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 MAC_ADDRESS_STR, i,
968 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
969 }
970}
971
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700972static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 struct wma_tgt_services *cfg)
974{
975 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976
977 /* Set up UAPSD */
978 config->apUapsdEnabled &= cfg->uapsd;
979
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800980 /* 11AX mode support */
981 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
982 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
983 config->dot11Mode = eHDD_DOT11_MODE_11ac;
984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985 /* 11AC mode support */
986 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
987 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
988 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989
990 /* ARP offload: override user setting if invalid */
991 config->fhostArpOffload &= cfg->arp_offload;
992
993#ifdef FEATURE_WLAN_SCAN_PNO
994 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800995 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996 if (cfg->pno_offload)
997 config->PnoOffload = true;
998#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999#ifdef FEATURE_WLAN_TDLS
1000 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301001 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1002 cfg->en_tdls_offchan;
1003 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1004 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001005 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001007 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1011 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1012#endif
Will Huang496b36c2017-07-11 16:38:50 +08001013 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001014 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015
1016}
1017
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001018/**
1019 * hdd_update_vdev_nss() - sets the vdev nss
1020 * @hdd_ctx: HDD context
1021 *
1022 * Sets the Nss per vdev type based on INI
1023 *
1024 * Return: None
1025 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001026static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001027{
1028 struct hdd_config *cfg_ini = hdd_ctx->config;
1029 uint8_t max_supp_nss = 1;
1030
Naveen Rawat10b1c152017-01-18 11:16:06 -08001031 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001032 max_supp_nss = 2;
1033
1034 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1035 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1036
1037 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1038 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1039}
1040
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301041/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301042 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1043 * @hdd_ctx: HDD context
1044 *
1045 * Updates wiphy vhtcap fields
1046 *
1047 * Return: None
1048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001049static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301050{
1051 struct ieee80211_supported_band *band_5g =
1052 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1053 uint32_t val;
1054
1055 if (!band_5g) {
1056 hdd_debug("5GHz band disabled, skipping capability population");
1057 return;
1058 }
1059
1060 val = hdd_ctx->config->txBFCsnValue;
1061 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1062
1063 val = NUM_OF_SOUNDING_DIMENSIONS;
1064 band_5g->vht_cap.cap |=
1065 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1066
1067 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1068 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1069}
1070
1071/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301072 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1073 * @hdd_ctx: HDD context
1074 *
1075 * Sets the DBS capability as per INI and firmware capability
1076 *
1077 * Return: None
1078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001079static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301080{
1081 struct hdd_config *cfg_ini = hdd_ctx->config;
1082 uint8_t hw_dbs_capable = 0;
1083
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001084 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1085 ((cfg_ini->dual_mac_feature_disable ==
1086 ENABLE_DBS_CXN_AND_SCAN) ||
1087 (cfg_ini->dual_mac_feature_disable ==
1088 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301089 hw_dbs_capable = 1;
1090
1091 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1092}
1093
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001094static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 struct wma_tgt_ht_cap *cfg)
1096{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301097 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 uint32_t value, val32;
1099 uint16_t val16;
1100 struct hdd_config *pconfig = hdd_ctx->config;
1101 tSirMacHTCapabilityInfo *phtCapInfo;
1102 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1103 uint8_t enable_tx_stbc;
1104
1105 /* check and update RX STBC */
1106 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1107 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1108
1109 /* get the MPDU density */
1110 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1111
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301112 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001113 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 value = 0;
1115 }
1116
1117 /*
1118 * MPDU density:
1119 * override user's setting if value is larger
1120 * than the one supported by target
1121 */
1122 if (value > cfg->mpdu_density) {
1123 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1124 cfg->mpdu_density);
1125
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301126 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001127 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 }
1129
1130 /* get the HT capability info */
1131 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301132 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001133 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134 return;
1135 }
1136 val16 = (uint16_t) val32;
1137 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1138
1139 /* Set the LDPC capability */
1140 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1141
1142 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1143 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1144
1145 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1146 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1147
1148 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1149 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1150
1151 enable_tx_stbc = pconfig->enableTxSTBC;
1152
1153 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1154 pconfig->enable2x2 = 1;
1155 } else {
1156 pconfig->enable2x2 = 0;
1157 enable_tx_stbc = 0;
1158
1159 /* 1x1 */
1160 /* Update Rx Highest Long GI data Rate */
1161 if (sme_cfg_set_int(hdd_ctx->hHal,
1162 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001163 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301164 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001165 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 }
1167
1168 /* Update Tx Highest Long GI data Rate */
1169 if (sme_cfg_set_int
1170 (hdd_ctx->hHal,
1171 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001172 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301173 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001174 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001175 }
1176 }
1177 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1178 enable_tx_stbc = 0;
1179 phtCapInfo->txSTBC = enable_tx_stbc;
1180
1181 val32 = val16;
1182 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301183 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001184 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1186 value = SIZE_OF_SUPPORTED_MCS_SET;
1187 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301188 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001189 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190
1191 if (pconfig->enable2x2) {
1192 for (value = 0; value < cfg->num_rf_chains; value++)
1193 mcs_set[value] =
1194 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1195
1196 status =
1197 sme_cfg_set_str(hdd_ctx->hHal,
1198 WNI_CFG_SUPPORTED_MCS_SET,
1199 mcs_set,
1200 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301201 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001202 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203 }
1204 }
1205#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1206}
1207
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001208static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209 struct wma_tgt_vht_cap *cfg)
1210{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301211 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 uint32_t value = 0;
1213 struct hdd_config *pconfig = hdd_ctx->config;
1214 struct wiphy *wiphy = hdd_ctx->wiphy;
1215 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001216 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001217 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001218 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001219 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220
Dustin Brown5e06bd32016-10-04 12:49:10 -07001221 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001222 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001223 return;
1224 }
1225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 /* Get the current MPDU length */
1227 status =
1228 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1229 &value);
1230
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301231 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001232 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 value = 0;
1234 }
1235
1236 /*
1237 * VHT max MPDU length:
1238 * override if user configured value is too high
1239 * that the target cannot support
1240 */
1241 if (value > cfg->vht_max_mpdu) {
1242 status = sme_cfg_set_int(hdd_ctx->hHal,
1243 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1244 cfg->vht_max_mpdu);
1245
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001246 if (status == QDF_STATUS_E_FAILURE)
1247 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 }
1249
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001250 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1251 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1252
1253 if (pconfig->enable2x2)
1254 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1255
1256 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1257 QDF_STATUS_E_FAILURE) {
1258 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1259 }
1260
1261 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1262 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1263 if (pconfig->enable2x2)
1264 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1265
1266 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1267 QDF_STATUS_E_FAILURE) {
1268 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1269 }
1270
1271 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1272 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1273 if (pconfig->enable2x2)
1274 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1275
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001276 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001277 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1278
1279 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1280 QDF_STATUS_E_FAILURE) {
1281 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1282 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001283 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001284 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 &value);
1286
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301287 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001288 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001289 value = 0;
1290 }
1291
jiad4a7a33c2017-08-08 15:32:24 +08001292 /* Set HW RX LDPC capability */
1293 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1294 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001295 status = sme_cfg_set_int(hdd_ctx->hHal,
1296 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001297 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001299 if (status == QDF_STATUS_E_FAILURE)
1300 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001301 }
1302
1303 /* Get current GI 80 value */
1304 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1305 &value);
1306
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301307 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001308 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001309 value = 0;
1310 }
1311
1312 /* set the Guard interval 80MHz */
1313 if (value && !cfg->vht_short_gi_80) {
1314 status = sme_cfg_set_int(hdd_ctx->hHal,
1315 WNI_CFG_VHT_SHORT_GI_80MHZ,
1316 cfg->vht_short_gi_80);
1317
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001318 if (status == QDF_STATUS_E_FAILURE)
1319 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320 }
1321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 /* Get VHT TX STBC cap */
1323 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1324
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301325 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001326 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001327 value = 0;
1328 }
1329
1330 /* VHT TX STBC cap */
1331 if (value && !cfg->vht_tx_stbc) {
1332 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1333 cfg->vht_tx_stbc);
1334
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001335 if (status == QDF_STATUS_E_FAILURE)
1336 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 }
1338
1339 /* Get VHT RX STBC cap */
1340 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1341
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001343 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 value = 0;
1345 }
1346
1347 /* VHT RX STBC cap */
1348 if (value && !cfg->vht_rx_stbc) {
1349 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1350 cfg->vht_rx_stbc);
1351
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001352 if (status == QDF_STATUS_E_FAILURE)
1353 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 }
1355
1356 /* Get VHT SU Beamformer cap */
1357 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1358 &value);
1359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301360 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001361 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 value = 0;
1363 }
1364
1365 /* set VHT SU Beamformer cap */
1366 if (value && !cfg->vht_su_bformer) {
1367 status = sme_cfg_set_int(hdd_ctx->hHal,
1368 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1369 cfg->vht_su_bformer);
1370
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001371 if (status == QDF_STATUS_E_FAILURE)
1372 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 }
1374
1375 /* check and update SU BEAMFORMEE capabality */
1376 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1377 pconfig->enableTxBF = cfg->vht_su_bformee;
1378
1379 status = sme_cfg_set_int(hdd_ctx->hHal,
1380 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1381 pconfig->enableTxBF);
1382
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001383 if (status == QDF_STATUS_E_FAILURE)
1384 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385
1386 /* Get VHT MU Beamformer cap */
1387 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1388 &value);
1389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301390 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001391 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 value = 0;
1393 }
1394
1395 /* set VHT MU Beamformer cap */
1396 if (value && !cfg->vht_mu_bformer) {
1397 status = sme_cfg_set_int(hdd_ctx->hHal,
1398 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1399 cfg->vht_mu_bformer);
1400
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001401 if (status == QDF_STATUS_E_FAILURE)
1402 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 }
1404
1405 /* Get VHT MU Beamformee cap */
1406 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1407 &value);
1408
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301409 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001410 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 value = 0;
1412 }
1413
1414 /* set VHT MU Beamformee cap */
1415 if (value && !cfg->vht_mu_bformee) {
1416 status = sme_cfg_set_int(hdd_ctx->hHal,
1417 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1418 cfg->vht_mu_bformee);
1419
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 if (status == QDF_STATUS_E_FAILURE)
1421 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422 }
1423
1424 /* Get VHT MAX AMPDU Len exp */
1425 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1426 &value);
1427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301428 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001429 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 value = 0;
1431 }
1432
1433 /*
1434 * VHT max AMPDU len exp:
1435 * override if user configured value is too high
1436 * that the target cannot support.
1437 * Even though Rome publish ampdu_len=7, it can
1438 * only support 4 because of some h/w bug.
1439 */
1440
1441 if (value > cfg->vht_max_ampdu_len_exp) {
1442 status = sme_cfg_set_int(hdd_ctx->hHal,
1443 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1444 cfg->vht_max_ampdu_len_exp);
1445
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001446 if (status == QDF_STATUS_E_FAILURE)
1447 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 }
1449
1450 /* Get VHT TXOP PS CAP */
1451 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1452
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301453 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001454 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 value = 0;
1456 }
1457
1458 /* set VHT TXOP PS cap */
1459 if (value && !cfg->vht_txop_ps) {
1460 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1461 cfg->vht_txop_ps);
1462
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001463 if (status == QDF_STATUS_E_FAILURE)
1464 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 }
1466
1467 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1468 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1469 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1470 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1471 else
1472 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1473
1474
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001475 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1476 status = sme_cfg_set_int(hdd_ctx->hHal,
1477 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1478 VHT_CAP_160_AND_80P80_SUPP);
1479 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001480 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 band_5g->vht_cap.cap |=
1482 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001483 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1484 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1485 status = sme_cfg_set_int(hdd_ctx->hHal,
1486 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1487 VHT_CAP_160_SUPP);
1488 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001489 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 band_5g->vht_cap.cap |=
1491 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001492 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1493 }
1494 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1495 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301496 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001497 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301498 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001499 &value);
1500 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301501 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001502 value = 0;
1503 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301504 /* set the Guard interval 160MHz */
1505 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001506 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301507 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1508 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001509
1510 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301511 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001512 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513
1514 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1515 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1516
1517 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1518 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1519 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1520 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1521
1522 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1523 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1524
1525 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1526 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1527 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1528 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1529 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1530 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1531
1532 band_5g->vht_cap.cap |=
1533 (cfg->vht_max_ampdu_len_exp <<
1534 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1535
1536 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1537 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1538 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1539 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1540 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1541 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1542 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1543 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1544
1545 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1546 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1547
1548}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001550/**
1551 * hdd_generate_macaddr_auto() - Auto-generate mac address
1552 * @hdd_ctx: Pointer to the HDD context
1553 *
1554 * Auto-generate mac address using device serial number.
1555 * Keep the first 3 bytes of OUI as before and replace
1556 * the last 3 bytes with the lower 3 bytes of serial number.
1557 *
1558 * Return: 0 for success
1559 * Non zero failure code for errors
1560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001561static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001562{
1563 unsigned int serialno = 0;
1564 struct qdf_mac_addr mac_addr = {
1565 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1566 };
1567
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001568 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001569 if (serialno == 0)
1570 return -EINVAL;
1571
1572 serialno &= 0x00ffffff;
1573
1574 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1575 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1576 mac_addr.bytes[5] = serialno & 0xff;
1577
1578 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1579 return 0;
1580}
1581
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301582/**
1583 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1584 * configuration to cfg_ini in HDD
1585 * @hdd_ctx: Pointer to hdd_ctx
1586 * @cfg: target configuration
1587 *
1588 * Return: None
1589 */
1590#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001591static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301592 struct wma_tgt_cfg *cfg)
1593{
1594 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1595}
1596#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001597static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301598 struct wma_tgt_cfg *cfg)
1599{
1600}
1601#endif
1602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603void hdd_update_tgt_cfg(void *context, void *param)
1604{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001605 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001606 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 struct wma_tgt_cfg *cfg = param;
1608 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001609 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301610 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301611
Yue Mae3e86ab2017-05-08 10:48:24 -07001612 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301613 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1614 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1615 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1616 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1617 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001618 /* Restore pdev to MAC/WMA contexts */
1619 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001620 } else {
1621 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1622 if (ret) {
1623 hdd_err("pdev creation fails!");
1624 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301625 } else
1626 hdd_debug("New pdev has been created with pdev_id = %u",
1627 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301628 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001629
Naveen Rawat64e477e2016-05-20 10:34:56 -07001630 if (cds_cfg) {
1631 if (hdd_ctx->config->enable_sub_20_channel_width !=
1632 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1633 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1634 cds_cfg->sub_20_channel_width =
1635 WLAN_SUB_20_CH_WIDTH_NONE;
1636 } else {
1637 cds_cfg->sub_20_channel_width =
1638 hdd_ctx->config->enable_sub_20_channel_width;
1639 }
1640 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641
1642 /* first store the INI band capability */
1643 temp_band_cap = hdd_ctx->config->nBandCapability;
1644
1645 hdd_ctx->config->nBandCapability = cfg->band_cap;
1646
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001647 /*
1648 * now overwrite the target band capability with INI
1649 * setting if INI setting is a subset
1650 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651
1652 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1653 (temp_band_cap != eCSR_BAND_ALL))
1654 hdd_ctx->config->nBandCapability = temp_band_cap;
1655 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1656 (temp_band_cap != eCSR_BAND_ALL) &&
1657 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001658 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 }
1660
Amar Singhal58b45ef2017-08-01 13:43:54 -07001661 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1662
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301663 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1665 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1666 }
1667
1668 /* This can be extended to other configurations like ht, vht cap... */
1669
Anurag Chouhanc5548422016-02-24 18:33:27 +05301670 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001672 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001674 static struct qdf_mac_addr default_mac_addr = {
1675 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1676 };
1677 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1678 &default_mac_addr)) {
1679 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1680 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1681 MAC_ADDRESS_STR,
1682 MAC_ADDR_ARRAY(hdd_ctx->config->
1683 intfMacAddr[0].bytes));
1684 } else {
1685 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1686 MAC_ADDRESS_STR,
1687 MAC_ADDR_ARRAY(hdd_ctx->config->
1688 intfMacAddr[0].bytes));
1689 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001690 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 }
1692
1693 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001694 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695
1696 hdd_ctx->max_intf_count = cfg->max_intf_count;
1697
Jeff Johnsonc875e242016-09-23 18:12:34 -07001698 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001699 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1702 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1703
1704 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1705
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001707 if (cfg->services.en_11ax) {
1708 hdd_info("11AX: 11ax is enabled - update HDD config");
1709 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1710 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001711
1712 hdd_update_vdev_nss(hdd_ctx);
1713
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301714 hdd_update_hw_dbs_capable(hdd_ctx);
1715
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001716 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001717 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001718 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001719 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001720
Nitesh Shahe50711f2017-04-26 16:30:45 +05301721 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1722 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1723 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001724 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001725 hdd_ctx->current_antenna_mode);
1726
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001727 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1728 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301729 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301730
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301731 if ((hdd_ctx->config->txBFCsnValue >
1732 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1733 !cfg->tx_bfee_8ss_enabled)
1734 hdd_ctx->config->txBFCsnValue =
1735 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1736
1737 if (sme_cfg_set_int(hdd_ctx->hHal,
1738 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1739 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1740 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1741
1742
1743 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1744 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1745 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301746
1747 /*
1748 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1749 */
1750 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301751
1752 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1753
Arun Khandavallid454d422016-08-17 12:47:05 +05301754 /*
1755 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1756 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1757 * configure the STA mode wow pattern.
1758 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301759 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301760 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301761
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301762 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1763
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001764 /* Configure NAN datapath features */
1765 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001766 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767}
1768
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001769bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001772 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301773 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001774 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775
Arif Hussaincd151632017-02-11 16:57:19 -08001776 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001777 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001778 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301779 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001780 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001781
Arif Hussaincd151632017-02-11 16:57:19 -08001782 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1783 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1784 adapter = adapterNode->pAdapter;
1785 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1786
1787 if ((QDF_SAP_MODE == adapter->device_mode ||
1788 QDF_P2P_GO_MODE == adapter->device_mode) &&
1789 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1790 ap_ctx->operatingChannel))) {
1791 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1792 true;
1793 hdd_info("tx blocked for session: %d",
1794 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301795 }
Arif Hussaincd151632017-02-11 16:57:19 -08001796 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1797 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301799
1800 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001802
1803/**
1804 * hdd_is_valid_mac_address() - validate MAC address
1805 * @pMacAddr: Pointer to the input MAC address
1806 *
1807 * This function validates whether the given MAC address is valid or not
1808 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1809 * where X is the hexa decimal digit character and separated by ':'
1810 * This algorithm works even if MAC address is not separated by ':'
1811 *
1812 * This code checks given input string mac contains exactly 12 hexadecimal
1813 * digits and a separator colon : appears in the input string only after
1814 * an even number of hex digits.
1815 *
1816 * Return: 1 for valid and 0 for invalid
1817 */
1818bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1819{
1820 int xdigit = 0;
1821 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 while (*pMacAddr) {
1824 if (isxdigit(*pMacAddr)) {
1825 xdigit++;
1826 } else if (':' == *pMacAddr) {
1827 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1828 break;
1829
1830 ++separator;
1831 } else {
1832 /* Invalid MAC found */
1833 return 0;
1834 }
1835 ++pMacAddr;
1836 }
1837 return xdigit == 12 && (separator == 5 || separator == 0);
1838}
1839
1840/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301841 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1842 * @dev: Handle to struct net_device to be updated.
1843 *
1844 * Return: None
1845 */
1846static void hdd_mon_mode_ether_setup(struct net_device *dev)
1847{
1848 dev->header_ops = NULL;
1849 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1850 dev->hard_header_len = ETH_HLEN;
1851 dev->mtu = ETH_DATA_LEN;
1852 dev->addr_len = ETH_ALEN;
1853 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1854 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1855 dev->priv_flags |= IFF_TX_SKB_SHARING;
1856
1857 memset(dev->broadcast, 0xFF, ETH_ALEN);
1858}
1859
1860/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001861 * __hdd__mon_open() - HDD Open function
1862 * @dev: Pointer to net_device structure
1863 *
1864 * This is called in response to ifconfig up
1865 *
1866 * Return: 0 for success; non-zero for failure
1867 */
1868static int __hdd_mon_open(struct net_device *dev)
1869{
1870 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001871 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1872 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001873
1874 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001875
1876 ret = wlan_hdd_validate_context(hdd_ctx);
1877 if (ret)
1878 return ret;
1879
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301880 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001881
1882 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1883 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1884 if (ret) {
1885 hdd_err("Failed to start WLAN modules return");
1886 return ret;
1887 }
1888 hdd_err("hdd_wlan_start_modules() successful !");
1889
1890 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1891 ret = hdd_start_adapter(adapter);
1892 if (ret) {
1893 hdd_err("Failed to start adapter :%d",
1894 adapter->device_mode);
1895 return ret;
1896 }
1897 hdd_err("hdd_start_adapters() successful !");
1898 }
1899 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1900 }
1901
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001902 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001903
1904 if (!ret)
1905 ret = hdd_enable_monitor_mode(dev);
1906
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001907 return ret;
1908}
1909
1910/**
1911 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1912 * @dev: Pointer to net_device structure
1913 *
1914 * This is called in response to ifconfig up
1915 *
1916 * Return: 0 for success; non-zero for failure
1917 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001918static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001919{
1920 int ret;
1921
1922 cds_ssr_protect(__func__);
1923 ret = __hdd_mon_open(dev);
1924 cds_ssr_unprotect(__func__);
1925
1926 return ret;
1927}
1928
1929/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301930 * hdd_start_adapter() - Wrapper function for device specific adapter
1931 * @adapter: pointer to HDD adapter
1932 *
1933 * This function is called to start the device specific adapter for
1934 * the mode passed in the adapter's device_mode.
1935 *
1936 * Return: 0 for success; non-zero for failure
1937 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001938int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301939{
1940
1941 int ret;
1942 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1943
1944 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001945 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301946
1947 switch (device_mode) {
1948 case QDF_P2P_CLIENT_MODE:
1949 case QDF_P2P_DEVICE_MODE:
1950 case QDF_OCB_MODE:
1951 case QDF_STA_MODE:
1952 case QDF_MONITOR_MODE:
1953 ret = hdd_start_station_adapter(adapter);
1954 if (ret)
1955 goto err_start_adapter;
1956 break;
1957 case QDF_P2P_GO_MODE:
1958 case QDF_SAP_MODE:
1959 ret = hdd_start_ap_adapter(adapter);
1960 if (ret)
1961 goto err_start_adapter;
1962 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301963 case QDF_IBSS_MODE:
1964 /*
1965 * For IBSS interface is initialized as part of
1966 * hdd_init_station_mode()
1967 */
1968 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301969 case QDF_FTM_MODE:
1970 ret = hdd_start_ftm_adapter(adapter);
1971 if (ret)
1972 goto err_start_adapter;
1973 break;
1974 default:
1975 hdd_err("Invalid session type %d", device_mode);
1976 QDF_ASSERT(0);
1977 goto err_start_adapter;
1978 }
1979 if (hdd_set_fw_params(adapter))
1980 hdd_err("Failed to set the FW params for the adapter!");
1981
1982 /*
1983 * Action frame registered in one adapter which will
1984 * applicable to all interfaces
1985 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301986 ret = wlan_hdd_cfg80211_register_frames(adapter);
1987 if (ret < 0) {
1988 hdd_err("Failed to register frames - ret %d", ret);
1989 goto err_start_adapter;
1990 }
1991
Arun Khandavallifae92942016-08-01 13:31:08 +05301992 EXIT();
1993 return 0;
1994err_start_adapter:
1995 return -EINVAL;
1996}
1997
1998/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301999 * hdd_enable_power_management() - API to Enable Power Management
2000 *
2001 * API invokes Bus Interface Layer power management functionality
2002 *
2003 * Return: None
2004 */
2005static void hdd_enable_power_management(void)
2006{
2007 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2008
2009 if (!hif_ctx) {
2010 hdd_err("Bus Interface Context is Invalid");
2011 return;
2012 }
2013
2014 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2015}
2016
2017/**
2018 * hdd_disable_power_management() - API to disable Power Management
2019 *
2020 * API disable Bus Interface Layer Power management functionality
2021 *
2022 * Return: None
2023 */
2024static void hdd_disable_power_management(void)
2025{
2026 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2027
2028 if (!hif_ctx) {
2029 hdd_err("Bus Interface Context is Invalid");
2030 return;
2031 }
2032
2033 hif_disable_power_management(hif_ctx);
2034}
2035
2036/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302037 * hdd_update_hw_sw_info() - API to update the HW/SW information
2038 *
2039 * API to update the HW and SW information in the driver
2040 *
2041 * Return: None
2042 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002043static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302044{
2045 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002046 size_t target_hw_name_len;
2047 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302048
2049 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2050 if (!hif_sc) {
2051 hdd_err("HIF context is NULL");
2052 return;
2053 }
2054
2055 /*
2056 * target hw version/revision would only be retrieved after firmware
2057 * download
2058 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002059 hif_get_hw_info(hif_sc,
2060 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302061 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002062 &target_hw_name);
2063
2064 if (hdd_ctx->target_hw_name)
2065 qdf_mem_free(hdd_ctx->target_hw_name);
2066
2067 target_hw_name_len = strlen(target_hw_name) + 1;
2068 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2069 if (hdd_ctx->target_hw_name)
2070 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2071 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302072
2073 /* Get the wlan hw/fw version */
2074 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302075}
2076
2077/**
gbian62edd7e2017-03-07 13:12:13 +08002078 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2079 * @hdd_ctx: Pointer to hdd context
2080 *
2081 * Return: none
2082 */
2083static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002084hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002085{
2086 uint8_t num_entries = 0;
2087 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2088 uint8_t *tx_sched_wrr_ac;
2089 int i;
2090 cds_context_type *cds_ctx;
2091
2092 if (NULL == hdd_ctx)
2093 return;
2094
2095 if (NULL == hdd_ctx->config) {
2096 /* Do nothing if hdd_ctx is invalid */
2097 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2098 return;
2099 }
2100
2101 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2102
2103 if (!cds_ctx) {
2104 hdd_err("Invalid CDS Context");
2105 return;
2106 }
2107
2108 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2109 switch (i) {
2110 case OL_TX_WMM_AC_BE:
2111 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2112 break;
2113 case OL_TX_WMM_AC_BK:
2114 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2115 break;
2116 case OL_TX_WMM_AC_VI:
2117 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2118 break;
2119 case OL_TX_WMM_AC_VO:
2120 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2121 break;
2122 default:
2123 tx_sched_wrr_ac = NULL;
2124 break;
2125 }
2126
2127 hdd_string_to_u8_array(tx_sched_wrr_ac,
2128 tx_sched_wrr_param,
2129 &num_entries,
2130 sizeof(tx_sched_wrr_param));
2131
2132 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2133 cds_ctx->ac_specs[i].wrr_skip_weight =
2134 tx_sched_wrr_param[0];
2135 cds_ctx->ac_specs[i].credit_threshold =
2136 tx_sched_wrr_param[1];
2137 cds_ctx->ac_specs[i].send_limit =
2138 tx_sched_wrr_param[2];
2139 cds_ctx->ac_specs[i].credit_reserve =
2140 tx_sched_wrr_param[3];
2141 cds_ctx->ac_specs[i].discard_weight =
2142 tx_sched_wrr_param[4];
2143 }
2144
2145 num_entries = 0;
2146 }
2147}
2148
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002149#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002150static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2151 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2152{
Jeff Johnson9d295242017-08-29 14:39:48 -07002153 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002154 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002155
2156 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2157 if (!adapter) {
2158 hdd_err("Adapter is NULL");
2159 return PM_MAX_NUM_OF_MODE;
2160 }
2161
2162 return policy_mgr_convert_device_mode_to_qdf_type(
2163 adapter->device_mode);
2164}
2165
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002166static void hdd_register_policy_manager_callback(
2167 struct wlan_objmgr_psoc *psoc)
2168{
2169 struct policy_mgr_hdd_cbacks hdd_cbacks;
2170 hdd_cbacks.sap_restart_chan_switch_cb =
2171 sap_restart_chan_switch_cb;
2172 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2173 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002174 hdd_cbacks.get_mode_for_non_connected_vdev =
2175 wlan_hdd_get_mode_for_non_connected_vdev;
2176
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002177 if (QDF_STATUS_SUCCESS !=
2178 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2179 hdd_err("HDD callback registration with policy manager failed");
2180 }
2181}
2182#else
2183static void hdd_register_policy_manager_callback(
2184 struct wlan_objmgr_psoc *psoc)
2185{
2186}
2187#endif
2188
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002189#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002190static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002191{
2192 struct nan_callbacks cb_obj = {0};
2193
2194 cb_obj.ndi_open = hdd_ndi_open;
2195 cb_obj.ndi_close = hdd_ndi_close;
2196 cb_obj.ndi_start = hdd_ndi_start;
2197 cb_obj.ndi_delete = hdd_ndi_delete;
2198 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2199 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2200
Naveen Rawat37f62c82017-03-26 22:24:43 -07002201 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2202 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002203 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002204
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002205 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2206}
2207#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002208static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002209{
2210}
2211#endif
2212
gbian62edd7e2017-03-07 13:12:13 +08002213/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302214 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2215 * @hdd_ctx: HDD context
2216 * @adapter: HDD adapter
2217 * @reinit: flag to indicate from SSR or normal path
2218 *
2219 * This function maintains the driver state machine it will be invoked from
2220 * startup, reinit and change interface. Depending on the driver state shall
2221 * perform the opening of the modules.
2222 *
2223 * Return: 0 for success; non-zero for failure
2224 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002225int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2226 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302227 bool reinit)
2228{
2229 int ret;
2230 qdf_device_t qdf_dev;
2231 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302232 bool unint = false;
2233 void *hif_ctx;
2234
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002235 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302236
2237 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2238 if (!qdf_dev) {
2239 hdd_err("QDF Device Context is Invalid return");
2240 return -EINVAL;
2241 }
2242
2243 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302244 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302245
2246 if (QDF_TIMER_STATE_RUNNING ==
2247 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2248
2249 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002250 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302251 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2252 }
2253
2254 switch (hdd_ctx->driver_status) {
2255 case DRIVER_MODULES_UNINITIALIZED:
2256 unint = true;
2257 /* Fall through dont add break here */
2258 case DRIVER_MODULES_CLOSED:
2259 if (!reinit && !unint) {
2260 ret = pld_power_on(qdf_dev->dev);
2261 if (ret) {
2262 hdd_err("Failed to Powerup the device: %d", ret);
2263 goto release_lock;
2264 }
2265 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002266
2267 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2268 hdd_ctx->config->enable_fw_log);
2269
Arun Khandavallifae92942016-08-01 13:31:08 +05302270 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2271 qdf_dev->bus_type,
2272 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2273 HIF_ENABLE_TYPE_PROBE);
2274 if (ret) {
2275 hdd_err("Failed to open hif: %d", ret);
2276 goto power_down;
2277 }
2278
2279 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302280 if (!hif_ctx) {
2281 hdd_err("hif context is null!!");
2282 goto power_down;
2283 }
2284
Arun Khandavallifae92942016-08-01 13:31:08 +05302285 status = ol_cds_init(qdf_dev, hif_ctx);
2286 if (status != QDF_STATUS_SUCCESS) {
2287 hdd_err("No Memory to Create BMI Context :%d", status);
2288 goto hif_close;
2289 }
2290
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002291 ret = hdd_update_config(hdd_ctx);
2292 if (ret) {
2293 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302294 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002295 }
2296
gbian62edd7e2017-03-07 13:12:13 +08002297 hdd_update_cds_ac_specs_params(hdd_ctx);
2298
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302299 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302300 if (!QDF_IS_STATUS_SUCCESS(status)) {
2301 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302302 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 }
2304
Mukul Sharma9d797a02017-01-05 20:26:03 +05302305 /* initalize components configurations after psoc open */
2306 ret = hdd_update_components_config(hdd_ctx);
2307 if (ret) {
2308 hdd_err("Failed to update components configs :%d",
2309 ret);
2310 goto close;
2311 }
2312
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002313 /*
2314 * NAN compoenet requires certian operations like, open adapter,
2315 * close adapter, etc. to be initiated by HDD, for those
2316 * register HDD callbacks with UMAC's NAN componenet.
2317 */
2318 hdd_nan_register_callbacks(hdd_ctx);
2319
Arun Khandavallifae92942016-08-01 13:31:08 +05302320 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2321
Jeff Johnson3a280122017-09-13 07:42:00 -07002322 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302323 if (!QDF_IS_STATUS_SUCCESS(status)) {
2324 hdd_err("Failed to pre-enable CDS: %d", status);
2325 goto close;
2326 }
2327
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002328 hdd_register_policy_manager_callback(
2329 hdd_ctx->hdd_psoc);
2330
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302331 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302332 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302333
Arun Khandavallifae92942016-08-01 13:31:08 +05302334 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2335 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2336 hdd_ftm_mc_process_msg);
2337 break;
2338 }
2339 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002340 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302341 break;
2342 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302343
2344 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002345 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2346 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002347 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002348 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302349 }
2350
Arun Khandavallifae92942016-08-01 13:31:08 +05302351 /* Fall through dont add break here */
2352 case DRIVER_MODULES_OPENED:
2353 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002354 hdd_alert("adapter is Null");
2355 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302356 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302357 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2358 hdd_err("in ftm mode, no need to configure cds modules");
2359 break;
2360 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302361 if (hdd_configure_cds(hdd_ctx, adapter)) {
2362 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002363 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302364 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302365 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302366 hdd_info("Driver Modules Successfully Enabled");
2367 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2368 break;
2369 case DRIVER_MODULES_ENABLED:
2370 hdd_info("Driver modules already Enabled");
2371 break;
2372 default:
2373 hdd_err("WLAN start invoked in wrong state! :%d\n",
2374 hdd_ctx->driver_status);
2375 goto release_lock;
2376 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302377 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302378 mutex_unlock(&hdd_ctx->iface_change_lock);
2379 EXIT();
2380 return 0;
2381
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002382post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002383 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002384
Arun Khandavallifae92942016-08-01 13:31:08 +05302385close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002386 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002387 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302388
2389ol_cds_free:
2390 ol_cds_free();
2391
2392hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002393 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2394 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302395power_down:
2396 if (!reinit && !unint)
2397 pld_power_off(qdf_dev->dev);
2398release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302399 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302400 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302401 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002402
Arun Khandavallifae92942016-08-01 13:31:08 +05302403 return -EINVAL;
2404}
2405
Naveen Rawat910726a2017-03-06 11:42:51 -08002406#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002407static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002408{
2409 int ret = os_if_wifi_pos_register_nl();
2410
2411 if (ret)
2412 hdd_err("os_if_wifi_pos_register_nl failed");
2413
2414 return ret;
2415}
2416
2417static int hdd_deactivate_wifi_pos(void)
2418{
2419 int ret = os_if_wifi_pos_deregister_nl();
2420
2421 if (ret)
2422 hdd_err("os_if_wifi_pos_deregister_nl failed");
2423
2424 return ret;
2425}
2426
2427/**
2428 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2429 * @hdd_ctx: hdd context
2430 *
2431 * Return: status of operation
2432 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002433static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002434{
2435 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2436 struct hdd_config *cfg = hdd_ctx->config;
2437
2438 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2439 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2440 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2441 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2442 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2443 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2444 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2445 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2446}
2447#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002448static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002449{
2450 return oem_activate_service(hdd_ctx);
2451}
2452
2453static int hdd_deactivate_wifi_pos(void)
2454{
2455 return 0;
2456}
2457
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002458static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002459{
2460}
2461#endif
2462
Arun Khandavallifae92942016-08-01 13:31:08 +05302463/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002464 * __hdd_open() - HDD Open function
2465 * @dev: Pointer to net_device structure
2466 *
2467 * This is called in response to ifconfig up
2468 *
2469 * Return: 0 for success; non-zero for failure
2470 */
2471static int __hdd_open(struct net_device *dev)
2472{
Jeff Johnson9d295242017-08-29 14:39:48 -07002473 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002474 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002475 int ret;
2476
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002477 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302478 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302479 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002480
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302481 if (!hdd_wait_for_recovery_completion()) {
2482 hdd_err("Recovery failed");
2483 return -EIO;
2484 }
2485
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302486 /* Nothing to be done if device is unloading */
2487 if (cds_is_driver_unloading()) {
2488 hdd_err("Driver is unloading can not open the hdd");
2489 return -EBUSY;
2490 }
2491
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302492 mutex_lock(&hdd_init_deinit_lock);
2493
2494 /*
2495 * This scenario can be hit in cases where in the wlan driver after
2496 * registering the netdevices and there is a failure in driver
2497 * initialization. So return error gracefully because the netdevices
2498 * will be de-registered as part of the load failure.
2499 */
2500
2501 if (!cds_is_driver_loaded()) {
2502 hdd_err("Failed to start the wlan driver!!");
2503 ret = -EIO;
2504 goto err_hdd_hdd_init_deinit_lock;
2505 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002507
Arun Khandavallifae92942016-08-01 13:31:08 +05302508 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2509 if (ret) {
2510 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302511 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302512 }
2513
2514
2515 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2516 ret = hdd_start_adapter(adapter);
2517 if (ret) {
2518 hdd_err("Failed to start adapter :%d",
2519 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302520 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302521 }
2522 }
2523
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002524 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2525 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002526 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 /* Enable TX queues only when we are connected */
2528 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302529 WLAN_START_ALL_NETIF_QUEUE,
2530 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002531 }
2532
Naveen Rawat286def52016-09-23 15:38:02 -07002533 /* Enable carrier and transmit queues for NDI */
2534 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002535 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002536 wlan_hdd_netif_queue_control(adapter,
2537 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2538 WLAN_CONTROL_PATH);
2539 }
2540
Naveen Rawat910726a2017-03-06 11:42:51 -08002541 hdd_populate_wifi_pos_cfg(hdd_ctx);
2542
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302543err_hdd_hdd_init_deinit_lock:
2544 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002545 return ret;
2546}
2547
Arun Khandavallifae92942016-08-01 13:31:08 +05302548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002549/**
2550 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2551 * @dev: Pointer to net_device structure
2552 *
2553 * This is called in response to ifconfig up
2554 *
2555 * Return: 0 for success; non-zero for failure
2556 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002557static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002558{
2559 int ret;
2560
2561 cds_ssr_protect(__func__);
2562 ret = __hdd_open(dev);
2563 cds_ssr_unprotect(__func__);
2564
2565 return ret;
2566}
2567
2568/**
2569 * __hdd_stop() - HDD stop function
2570 * @dev: Pointer to net_device structure
2571 *
2572 * This is called in response to ifconfig down
2573 *
2574 * Return: 0 for success; non-zero for failure
2575 */
2576static int __hdd_stop(struct net_device *dev)
2577{
Jeff Johnson9d295242017-08-29 14:39:48 -07002578 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002579 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 int ret;
2581
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002582 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302584 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002585 adapter->sessionId, adapter->device_mode));
2586
2587 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302588 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590
2591 /* Nothing to be done if the interface is not opened */
2592 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002593 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594 return -ENODEV;
2595 }
2596
2597 /* Make sure the interface is marked as closed */
2598 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302599
2600 hdd_debug("Disabling Auto Power save timer");
2601 sme_ps_disable_auto_ps_timer(
2602 WLAN_HDD_GET_HAL_CTX(adapter),
2603 adapter->sessionId);
2604
2605 /*
2606 * Disable TX on the interface, after this hard_start_xmit() will not
2607 * be called on that interface
2608 */
2609 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302610 wlan_hdd_netif_queue_control(adapter,
2611 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2612 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613
2614 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002615 * NAN data interface is different in some sense. The traffic on NDI is
2616 * bursty in nature and depends on the need to transfer. The service
2617 * layer may down the interface after the usage and up again when
2618 * required. In some sense, the NDI is expected to be available
2619 * (like SAP) iface until NDI delete request is issued by the service
2620 * layer. Skip BSS termination and adapter deletion for NAN Data
2621 * interface (NDI).
2622 */
2623 if (WLAN_HDD_IS_NDI(adapter))
2624 return 0;
2625
2626 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 * The interface is marked as down for outside world (aka kernel)
2628 * But the driver is pretty much alive inside. The driver needs to
2629 * tear down the existing connection on the netdev (session)
2630 * cleanup the data pipes and wait until the control plane is stabilized
2631 * for this interface. The call also needs to wait until the above
2632 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002633 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 * That is intentional to be able to scan if it is a STA/P2P interface
2635 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302636 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637
2638 /* DeInit the adapter. This ensures datapath cleanup as well */
2639 hdd_deinit_adapter(hdd_ctx, adapter, true);
2640
Arun Khandavallifae92942016-08-01 13:31:08 +05302641
2642 /*
2643 * Find if any iface is up. If any iface is up then can't put device to
2644 * sleep/power save mode
2645 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302646 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002647 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302648 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302649 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302650 }
2651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002652 EXIT();
2653 return 0;
2654}
2655
2656/**
2657 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2658 * @dev: pointer to net_device structure
2659 *
2660 * This is called in response to ifconfig down
2661 *
2662 * Return: 0 for success and error number for failure
2663 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002664static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665{
2666 int ret;
2667
2668 cds_ssr_protect(__func__);
2669 ret = __hdd_stop(dev);
2670 cds_ssr_unprotect(__func__);
2671
2672 return ret;
2673}
2674
2675/**
2676 * __hdd_uninit() - HDD uninit function
2677 * @dev: Pointer to net_device structure
2678 *
2679 * This is called during the netdev unregister to uninitialize all data
2680 * associated with the device
2681 *
2682 * Return: None
2683 */
2684static void __hdd_uninit(struct net_device *dev)
2685{
Jeff Johnson9d295242017-08-29 14:39:48 -07002686 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002687 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002689 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002690
2691 do {
2692 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002693 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002694 break;
2695 }
2696
Jeff Johnson399c6272017-08-30 10:51:00 -07002697 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2698 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002699 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 break;
2701 }
2702
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002703 if (dev != adapter->dev)
2704 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705
Jeff Johnson399c6272017-08-30 10:51:00 -07002706 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707
2708 /* after uninit our adapter structure will no longer be valid */
2709 adapter->dev = NULL;
2710 adapter->magic = 0;
2711 } while (0);
2712
2713 EXIT();
2714}
2715
2716/**
2717 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2718 * @dev: pointer to net_device structure
2719 *
2720 * This is called during the netdev unregister to uninitialize all data
2721 * associated with the device
2722 *
2723 * Return: none
2724 */
2725static void hdd_uninit(struct net_device *dev)
2726{
2727 cds_ssr_protect(__func__);
2728 __hdd_uninit(dev);
2729 cds_ssr_unprotect(__func__);
2730}
2731
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002732static int hdd_open_cesium_nl_sock(void)
2733{
2734#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2735 struct netlink_kernel_cfg cfg = {
2736 .groups = WLAN_NLINK_MCAST_GRP_ID,
2737 .input = NULL
2738 };
2739#endif
2740 int ret = 0;
2741
2742#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2743 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2744#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2745 THIS_MODULE,
2746#endif
2747 &cfg);
2748#else
2749 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2750 WLAN_NLINK_MCAST_GRP_ID,
2751 NULL, NULL, THIS_MODULE);
2752#endif
2753
2754 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002755 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002756 ret = -ECONNREFUSED;
2757 }
2758
2759 return ret;
2760}
2761
2762static void hdd_close_cesium_nl_sock(void)
2763{
2764 if (NULL != cesium_nl_srv_sock) {
2765 netlink_kernel_release(cesium_nl_srv_sock);
2766 cesium_nl_srv_sock = NULL;
2767 }
2768}
2769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002770/**
2771 * __hdd_set_mac_address() - set the user specified mac address
2772 * @dev: Pointer to the net device.
2773 * @addr: Pointer to the sockaddr.
2774 *
2775 * This function sets the user specified mac address using
2776 * the command ifconfig wlanX hw ether <mac adress>.
2777 *
2778 * Return: 0 for success, non zero for failure
2779 */
2780static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2781{
Jeff Johnson9d295242017-08-29 14:39:48 -07002782 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002783 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302785 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786 int ret;
2787
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002788 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789
2790 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2791 ret = wlan_hdd_validate_context(hdd_ctx);
2792 if (0 != ret)
2793 return ret;
2794
2795 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2796 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2797
2798 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302799 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002800}
2801
2802/**
2803 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2804 * function from SSR
2805 * @dev: pointer to net_device structure
2806 * @addr: Pointer to the sockaddr
2807 *
2808 * This function sets the user specified mac address using
2809 * the command ifconfig wlanX hw ether <mac adress>.
2810 *
2811 * Return: 0 for success.
2812 */
2813static int hdd_set_mac_address(struct net_device *dev, void *addr)
2814{
2815 int ret;
2816
2817 cds_ssr_protect(__func__);
2818 ret = __hdd_set_mac_address(dev, addr);
2819 cds_ssr_unprotect(__func__);
2820
2821 return ret;
2822}
2823
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002824uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002825{
2826 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002827
Anurag Chouhan6d760662016-02-20 16:05:43 +05302828 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002829 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2830 break;
2831 }
2832
Anurag Chouhan6d760662016-02-20 16:05:43 +05302833 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834 return NULL;
2835
2836 hdd_ctx->config->intfAddrMask |= (1 << i);
2837 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2838}
2839
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002840void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002841{
2842 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002843
Anurag Chouhan6d760662016-02-20 16:05:43 +05302844 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845 if (!memcmp(releaseAddr,
2846 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2847 6)) {
2848 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2849 break;
2850 }
2851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852}
2853
2854#ifdef WLAN_FEATURE_PACKET_FILTERING
2855/**
2856 * __hdd_set_multicast_list() - set the multicast address list
2857 * @dev: Pointer to the WLAN device.
2858 * @skb: Pointer to OS packet (sk_buff).
2859 *
2860 * This funciton sets the multicast address list.
2861 *
2862 * Return: None
2863 */
2864static void __hdd_set_multicast_list(struct net_device *dev)
2865{
Jeff Johnson9d295242017-08-29 14:39:48 -07002866 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867 int i = 0, status;
2868 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002869 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302870 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2871 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2872 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002873
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002874 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302875 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302876 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302879 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302880 goto out;
2881
Dustin Brownc788acb2017-08-01 17:43:51 -07002882 status = hdd_validate_adapter(adapter);
2883 if (status)
2884 goto out;
2885
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302886 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2887 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002888 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302889 goto out;
2890 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302892 /* Delete already configured multicast address list */
2893 if (adapter->mc_addr_list.mc_cnt > 0) {
2894 hdd_info("clear previously configured MC address list");
2895 hdd_disable_and_flush_mc_addr_list(adapter,
2896 pmo_mc_list_change_notify);
2897 }
2898
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002900 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302901 hdd_disable_and_flush_mc_addr_list(adapter,
2902 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 } else {
2904 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302905 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002906 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302907 pmo_ucfg_max_mc_addr_supported(psoc));
2908 hdd_disable_and_flush_mc_addr_list(adapter,
2909 pmo_mc_list_change_notify);
2910 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002912 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002913 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302914 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915 if (i == mc_count)
2916 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302917 memset(&(mc_list_request->mc_addr[i].bytes),
2918 0, ETH_ALEN);
2919 memcpy(&(mc_list_request->mc_addr[i].bytes),
2920 ha->addr, ETH_ALEN);
2921 hdd_info("mlist[%d] = %pM", i,
2922 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002923 i++;
2924 }
2925 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302926
2927 mc_list_request->psoc = psoc;
2928 mc_list_request->vdev_id = adapter->sessionId;
2929 mc_list_request->count = mc_count;
2930 status = hdd_cache_mc_addr_list(mc_list_request);
2931 if (status == 0) {
2932 hdd_enable_mc_addr_filtering(adapter,
2933 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302935 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302937out:
2938 if (mc_list_request)
2939 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302940 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941}
2942
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302943
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944/**
2945 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2946 * @dev: pointer to net_device
2947 *
2948 * Return: none
2949 */
2950static void hdd_set_multicast_list(struct net_device *dev)
2951{
2952 cds_ssr_protect(__func__);
2953 __hdd_set_multicast_list(dev);
2954 cds_ssr_unprotect(__func__);
2955}
2956#endif
2957
2958/**
2959 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2960 * @dev: Pointer to the WLAN device.
2961 * @skb: Pointer to OS packet (sk_buff).
2962 *
2963 * This function is registered with the Linux OS for network
2964 * core to decide which queue to use first.
2965 *
2966 * Return: ac, Queue Index/access category corresponding to UP in IP header
2967 */
2968static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2969#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2970 , void *accel_priv
2971#endif
2972#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2973 , select_queue_fallback_t fallback
2974#endif
2975)
2976{
2977 return hdd_wmm_select_queue(dev, skb);
2978}
2979
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002980static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981 .ndo_open = hdd_open,
2982 .ndo_stop = hdd_stop,
2983 .ndo_uninit = hdd_uninit,
2984 .ndo_start_xmit = hdd_hard_start_xmit,
2985 .ndo_tx_timeout = hdd_tx_timeout,
2986 .ndo_get_stats = hdd_get_stats,
2987 .ndo_do_ioctl = hdd_ioctl,
2988 .ndo_set_mac_address = hdd_set_mac_address,
2989 .ndo_select_queue = hdd_select_queue,
2990#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002991 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992#endif
2993};
2994
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002995/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002996static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002997 .ndo_open = hdd_mon_open,
2998 .ndo_stop = hdd_stop,
2999 .ndo_get_stats = hdd_get_stats,
3000};
3001
3002/**
3003 * hdd_set_station_ops() - update net_device ops for monitor mode
3004 * @pWlanDev: Handle to struct net_device to be updated.
3005 * Return: None
3006 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007void hdd_set_station_ops(struct net_device *pWlanDev)
3008{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003009 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
3010 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
3011 else
3012 pWlanDev->netdev_ops = &wlan_drv_ops;
3013}
3014
Komal Seelama89be8d2016-09-29 11:09:26 +05303015#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05303016/**
3017 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
3018 * @hdd_ctx: HDD context
3019 *
3020 * Return: None
3021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003022static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303023{
3024 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3025
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003026 qdf_runtime_lock_init(&ctx->roc);
3027 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05303028}
3029
3030/**
3031 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
3032 * @hdd_ctx: HDD Context
3033 *
3034 * Return: None
3035 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003036static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303037{
3038 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3039
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003040 qdf_runtime_lock_deinit(&ctx->roc);
3041 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05303042
3043 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05303044}
3045
Jeff Johnson9d295242017-08-29 14:39:48 -07003046static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303047{
3048 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3049
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003050 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303051}
3052
Jeff Johnson9d295242017-08-29 14:39:48 -07003053static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303054{
3055 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3056
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003057 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303058}
3059#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003060static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3061static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003062static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3063static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303064#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003065/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003066 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3067 * @hdd_ctx: global hdd context
3068 * @macAddr: mac address to assign to the interface
3069 * @name: User-visible name of the interface
3070 *
3071 * hdd adapter pointer would point to the netdev->priv space, this function
3072 * would retrive the pointer, and setup the hdd adapter configuration.
3073 *
3074 * Return: the pointer to hdd adapter, otherwise NULL
3075 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003076static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003078 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 const char *name)
3080{
3081 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003082 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003083 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 /*
3085 * cfg80211 initialization and registration....
3086 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003087 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003088#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3089 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003090#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003091 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3092 hdd_mon_mode_ether_setup : ether_setup),
3093 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094
3095 if (pWlanDev != NULL) {
3096
3097 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003098 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003099
Jeff Johnson9d295242017-08-29 14:39:48 -07003100 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303101 sta_ctx = &adapter->sessionCtx.station;
3102 qdf_mem_set(sta_ctx->conn_info.staId,
3103 sizeof(sta_ctx->conn_info.staId),
3104 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003106 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003107 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303108 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109
3110 init_completion(&adapter->session_open_comp_var);
3111 init_completion(&adapter->session_close_comp_var);
3112 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303113 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 init_completion(&adapter->linkup_event_var);
3115 init_completion(&adapter->cancel_rem_on_chan_var);
3116 init_completion(&adapter->rem_on_chan_ready_event);
3117 init_completion(&adapter->sta_authorized_event);
3118 init_completion(&adapter->offchannel_tx_event);
3119 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003120 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 init_completion(&adapter->change_country_code);
3122
3123
3124 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303125 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126
3127 adapter->offloads_configured = false;
3128 adapter->isLinkUpSvcNeeded = false;
3129 adapter->higherDtimTransition = true;
3130 /* Init the net_device structure */
3131 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3132
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303133 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303135 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136 sizeof(tSirMacAddr));
3137 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
3139 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3140 pWlanDev->features |=
3141 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3142 pWlanDev->features |= NETIF_F_RXCSUM;
3143
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003144 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 hdd_set_station_ops(adapter->dev);
3147
Dustin Brownc81dd412017-08-15 16:26:28 -07003148 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003150 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 adapter->wdev.wiphy = hdd_ctx->wiphy;
3152 adapter->wdev.netdev = pWlanDev;
3153 /* set pWlanDev's parent to underlying device */
3154 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3155 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303156 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303158 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159 }
3160
3161 return adapter;
3162}
3163
Jeff Johnson9d295242017-08-29 14:39:48 -07003164static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003166 struct net_device *dev = adapter->dev;
3167 int ret;
3168
3169 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003171 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003172 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3173
3174 ret = dev_alloc_name(dev, dev->name);
3175 if (ret < 0) {
3176 hdd_err(
3177 "unable to get dev name: %s, err = 0x%x",
3178 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303179 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180 }
3181 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003182
3183 ret = register_netdevice(dev);
3184 if (ret) {
3185 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3186 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303187 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 }
3189 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003190 ret = register_netdev(dev);
3191 if (ret) {
3192 hdd_err("register_netdev(%s) failed, err = 0x%x",
3193 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303194 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195 }
3196 }
3197 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3198
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003199 EXIT();
3200
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303201 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202}
3203
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003204QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205{
Jeff Johnson9d295242017-08-29 14:39:48 -07003206 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207
3208 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003209 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303210 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 }
3212
3213 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003214 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303215 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003216 }
3217
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003218 /*
3219 * For NAN Data interface, the close session results in the final
3220 * indication to the userspace
3221 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003222 if (adapter->device_mode == QDF_NDI_MODE)
3223 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 /*
3228 * We can be blocked while waiting for scheduled work to be
3229 * flushed, and the adapter structure can potentially be freed, in
3230 * which case the magic will have been reset. So make sure the
3231 * magic is still good, and hence the adapter structure is still
3232 * valid, before signaling completion
3233 */
3234 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3235 complete(&adapter->session_close_comp_var);
3236
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303237 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238}
3239
Jeff Johnson9d295242017-08-29 14:39:48 -07003240int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241{
Dustin Brownd28772b2017-03-17 14:16:07 -07003242 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243
Dustin Brownd28772b2017-03-17 14:16:07 -07003244 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003245 if (QDF_IS_STATUS_ERROR(status))
3246 return qdf_status_to_os_return(status);
3247
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003248 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003249 if (QDF_IS_STATUS_ERROR(status))
3250 return qdf_status_to_os_return(status);
3251
3252 if (wma_capability_enhanced_mcast_filter())
3253 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3254 else
3255 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003256
3257 return qdf_status_to_os_return(status);
3258}
3259
Jeff Johnson9d295242017-08-29 14:39:48 -07003260int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003261{
3262 QDF_STATUS status;
3263 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003264 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003265 unsigned long rc;
3266
3267 hdd_info("destroying vdev %d", adapter->sessionId);
3268
3269 /* vdev created sanity check */
3270 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3271 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3272 return -EINVAL;
3273 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003274 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003275 /*
3276 * In SSR case, there is no need to destroy vdev in firmware since
3277 * it has already asserted. vdev can be released directly.
3278 */
3279 if (cds_is_driver_recovering())
3280 goto release_vdev;
3281
Dustin Brownd28772b2017-03-17 14:16:07 -07003282 /* close sme session (destroy vdev in firmware via legacy API) */
3283 INIT_COMPLETION(adapter->session_close_comp_var);
3284 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3285 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3286 hdd_sme_close_session_callback, adapter);
3287 if (QDF_IS_STATUS_ERROR(status)) {
3288 hdd_err("failed to close sme session: %d", status);
3289 return qdf_status_to_os_return(status);
3290 }
3291
3292 /* block on a completion variable until sme session is closed */
3293 rc = wait_for_completion_timeout(
3294 &adapter->session_close_comp_var,
3295 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3296 if (!rc) {
3297 hdd_err("timed out waiting for close sme session: %ld", rc);
3298 if (adapter->device_mode == QDF_NDI_MODE)
3299 hdd_ndp_session_end_handler(adapter);
3300 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3301 return -ETIMEDOUT;
3302 }
Yue Maf9782842017-05-08 12:49:49 -07003303release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003304 /* do vdev logical destroy via objmgr */
3305 errno = hdd_objmgr_destroy_vdev(adapter);
3306 if (errno) {
3307 hdd_err("failed to destroy objmgr vdev: %d", errno);
3308 return errno;
3309 }
3310
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003311 /* now that sme session is closed, allow physical vdev destroy */
3312 errno = hdd_objmgr_release_vdev(adapter);
3313 if (errno) {
3314 hdd_err("failed to release objmgr vdev: %d", errno);
3315 return errno;
3316 }
3317
Dustin Brownd28772b2017-03-17 14:16:07 -07003318 hdd_info("vdev destroyed successfully");
3319
3320 return 0;
3321}
3322
Jeff Johnson9d295242017-08-29 14:39:48 -07003323int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003324{
3325 QDF_STATUS status;
3326 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003327 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003328 uint32_t type;
3329 uint32_t sub_type;
3330 unsigned long rc;
3331
3332 hdd_info("creating new vdev");
3333
3334 /* determine vdev (sub)type */
3335 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303336 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003337 hdd_err("failed to get vdev type: %d", status);
3338 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003340
3341 /* do vdev create via objmgr */
3342 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003343 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003344 if (errno) {
3345 hdd_err("failed to create objmgr vdev: %d", errno);
3346 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003347 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003348
3349 /* Open a SME session (prepare vdev in firmware via legacy API) */
3350 INIT_COMPLETION(adapter->session_open_comp_var);
3351 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3352 (uint8_t *)&adapter->macAddressCurrent,
3353 adapter->sessionId, type, sub_type);
3354 if (QDF_IS_STATUS_ERROR(status)) {
3355 hdd_err("failed to open sme session: %d", status);
3356 errno = qdf_status_to_os_return(status);
3357 goto objmgr_vdev_destroy;
3358 }
3359
3360 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 rc = wait_for_completion_timeout(
3362 &adapter->session_open_comp_var,
3363 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3364 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003365 hdd_err("timed out waiting for open sme session: %ld", rc);
3366 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303367 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3368 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003369 }
3370
3371 /* firmware ready for component communication, raise vdev_ready event */
3372 errno = hdd_vdev_ready(adapter);
3373 if (errno) {
3374 hdd_err("failed to dispatch vdev ready event: %d", errno);
3375 goto hdd_vdev_destroy;
3376 }
3377
3378 hdd_info("vdev %d created successfully", adapter->sessionId);
3379
3380 return 0;
3381
3382 /*
3383 * Due to legacy constraints, we need to destroy in the same order as
3384 * create. So, split error handling into 2 cases to accommodate.
3385 */
3386
3387objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003388 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003389
3390 return errno;
3391
3392hdd_vdev_destroy:
3393 QDF_BUG(!hdd_vdev_destroy(adapter));
3394
3395 return errno;
3396}
3397
Jeff Johnson9d295242017-08-29 14:39:48 -07003398QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003399{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003400 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003401 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003402 QDF_STATUS status;
3403 int ret_val;
3404
3405 ret_val = hdd_vdev_create(adapter);
3406 if (ret_val) {
3407 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303408 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 }
3410
Dustin Brownd28772b2017-03-17 14:16:07 -07003411 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3412 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3413 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003414 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003417 status = hdd_register_wext(adapter->dev);
3418 if (QDF_IS_STATUS_ERROR(status)) {
3419 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 goto error_register_wext;
3421 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003422 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303424 qdf_mem_set(pHddStaCtx->conn_info.staId,
3425 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3426
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003427 /* set fast roaming capability in sme session */
3428 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3429 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 /* Set the default operation channel */
3431 pHddStaCtx->conn_info.operationChannel =
3432 hdd_ctx->config->OperatingChannel;
3433
3434 /* Make the default Auth Type as OPEN */
3435 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3436
3437 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303438 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003439 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 status, status);
3441 goto error_init_txrx;
3442 }
3443
3444 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3445
3446 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303447 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003448 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 status, status);
3450 goto error_wmm_init;
3451 }
3452
3453 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3454
Naveen Rawat247a8682017-06-05 15:00:31 -07003455 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456 WMI_PDEV_PARAM_BURST_ENABLE,
3457 hdd_ctx->config->enableSifsBurst,
3458 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003459 if (ret_val)
3460 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003462 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303463 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465error_wmm_init:
3466 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3467 hdd_deinit_tx_rx(adapter);
3468error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003469 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003471 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 return status;
3474}
3475
Jeff Johnson9d295242017-08-29 14:39:48 -07003476void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477{
3478 hdd_cfg80211_state_t *cfgState;
3479
3480 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3481
3482 if (NULL != cfgState->buf) {
3483 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 rc = wait_for_completion_timeout(
3486 &adapter->tx_action_cnf_event,
3487 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3488 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003489 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303490 /*
3491 * Inform tx status as FAILURE to upper layer and free
3492 * cfgState->buf
3493 */
3494 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003495 }
3496 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497}
3498
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303499/**
3500 * hdd_station_adapter_deinit() - De-initialize the station adapter
3501 * @hdd_ctx: global hdd context
3502 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003503 * @rtnl_held: Used to indicate whether or not the caller is holding
3504 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303505 *
3506 * This function De-initializes the STA/P2P/OCB adapter.
3507 *
3508 * Return: None.
3509 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003510static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003511 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003512 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303513{
3514 ENTER_DEV(adapter->dev);
3515
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303516 if (adapter->dev) {
3517 if (rtnl_held)
3518 adapter->dev->wireless_handlers = NULL;
3519 else {
3520 rtnl_lock();
3521 adapter->dev->wireless_handlers = NULL;
3522 rtnl_unlock();
3523 }
3524 }
3525
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303526 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3527 hdd_deinit_tx_rx(adapter);
3528 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3529 }
3530
3531 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3532 hdd_wmm_adapter_close(adapter);
3533 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3534 }
3535
3536 hdd_cleanup_actionframe(hdd_ctx, adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303537
3538 EXIT();
3539}
3540
3541/**
3542 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3543 * @hdd_ctx: global hdd context
3544 * @adapter: HDD adapter
3545 * @rtnl_held: the rtnl lock hold flag
3546 * This function De-initializes the AP/P2PGo adapter.
3547 *
3548 * Return: None.
3549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003550static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003551 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003552 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303553{
3554 ENTER_DEV(adapter->dev);
3555
3556 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3557 hdd_wmm_adapter_close(adapter);
3558 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3559 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003560 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303561
3562 hdd_cleanup_actionframe(hdd_ctx, adapter);
3563
3564 hdd_unregister_hostapd(adapter, rtnl_held);
3565
3566 EXIT();
3567}
3568
Jeff Johnson9d295242017-08-29 14:39:48 -07003569void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570 bool rtnl_held)
3571{
3572 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003575 case QDF_STA_MODE:
3576 case QDF_P2P_CLIENT_MODE:
3577 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303579 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 break;
3581 }
3582
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003583 case QDF_SAP_MODE:
3584 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 {
3586
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303587 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 break;
3589 }
3590
3591 default:
3592 break;
3593 }
3594
3595 EXIT();
3596}
3597
Jeff Johnson9d295242017-08-29 14:39:48 -07003598static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003599 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600{
3601 struct net_device *pWlanDev = NULL;
3602
3603 if (adapter)
3604 pWlanDev = adapter->dev;
3605 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003606 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607 return;
3608 }
3609
Rajeev Kumardca5f812016-02-04 17:28:06 -08003610 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303611
3612 if (adapter->scan_info.default_scan_ies) {
3613 qdf_mem_free(adapter->scan_info.default_scan_ies);
3614 adapter->scan_info.default_scan_ies = NULL;
3615 }
3616
Komal Seelama89be8d2016-09-29 11:09:26 +05303617 hdd_adapter_runtime_suspend_denit(adapter);
3618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 /*
3620 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3621 * the driver is almost closed and cannot handle either control
3622 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003623 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3624 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 * is not right. Setting this flag helps hdd_stop() to recognize that
3626 * the interface is closed and restricts any operations on that
3627 */
3628 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3629
3630 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003631 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003633 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 /*
3636 * Note that the adapter is no longer valid at this point
3637 * since the memory has been reclaimed
3638 */
3639 }
3640}
3641
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003642static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003643 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644{
3645 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003646 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303647 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303650 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 adapter = adapterNode->pAdapter;
3652 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303653 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303655 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 }
3657 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3658 adapterNode = pNext;
3659 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303660 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003662
Arun Khandavalli2358d522016-05-16 18:05:37 +05303663#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3664/**
3665 * hdd_set_fw_log_params() - Set log parameters to FW
3666 * @hdd_ctx: HDD Context
3667 * @adapter: HDD Adapter
3668 *
3669 * This function set the FW Debug log level based on the INI.
3670 *
3671 * Return: None
3672 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003673static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003674 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303675{
3676 uint8_t count = 0, numentries = 0,
3677 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3678 uint32_t value = 0;
3679 int ret;
3680
Arun Khandavallifae92942016-08-01 13:31:08 +05303681 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3682 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003683 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303684 return;
3685 }
3686
Arun Khandavallifae92942016-08-01 13:31:08 +05303687 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303688 hdd_ctx->fw_log_settings.dl_type =
3689 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003690 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303691 WMI_DBGLOG_TYPE,
3692 hdd_ctx->config->enableFwLogType,
3693 DBG_CMD);
3694 if (ret != 0)
3695 hdd_err("Failed to enable FW log type ret %d",
3696 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303697
3698 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303699 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003700 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303701 WMI_DBGLOG_LOG_LEVEL,
3702 hdd_ctx->config->enableFwLogLevel,
3703 DBG_CMD);
3704 if (ret != 0)
3705 hdd_err("Failed to enable FW log level ret %d",
3706 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303707
3708 hdd_string_to_u8_array(
3709 hdd_ctx->config->enableFwModuleLogLevel,
3710 moduleloglevel,
3711 &numentries,
3712 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3713
3714 while (count < numentries) {
3715 /*
3716 * FW module log level input string looks like
3717 * below:
3718 * gFwDebugModuleLoglevel=<FW Module ID>,
3719 * <Log Level>,...
3720 * For example:
3721 * gFwDebugModuleLoglevel=
3722 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3723 * Above input string means :
3724 * For FW module ID 1 enable log level 0
3725 * For FW module ID 2 enable log level 1
3726 * For FW module ID 3 enable log level 2
3727 * For FW module ID 4 enable log level 3
3728 * For FW module ID 5 enable log level 4
3729 * For FW module ID 6 enable log level 5
3730 * For FW module ID 7 enable log level 6
3731 */
3732
Nishank Aggarwale239d962017-03-03 12:26:02 +05303733 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3734 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3735 hdd_err("Module id %d and dbglog level %d input length is more than max",
3736 moduleloglevel[count],
3737 moduleloglevel[count + 1]);
3738 return;
3739 }
3740
3741 value = moduleloglevel[count] << 16;
3742 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003743 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303744 WMI_DBGLOG_MOD_LOG_LEVEL,
3745 value, DBG_CMD);
3746 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303747 hdd_err("Failed to enable FW module log level %d ret %d",
3748 value, ret);
3749
3750 count += 2;
3751 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303752
Arun Khandavalli2358d522016-05-16 18:05:37 +05303753}
3754#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003755static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003756 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303757{
3758}
3759
3760#endif
3761
3762/**
3763 * hdd_set_fw_params() - Set parameters to firmware
3764 * @adapter: HDD adapter
3765 *
3766 * This function Sets various parameters to fw once the
3767 * adapter is started.
3768 *
3769 * Return: 0 on success or errno on failure
3770 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003771int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303772{
3773 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003774 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303775
3776 ENTER_DEV(adapter->dev);
3777
3778 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3779 if (!hdd_ctx)
3780 return -EINVAL;
3781
Dustin Brown732ab9c2017-06-15 13:24:09 -07003782 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3783 hdd_debug("FTM Mode is active; nothing to do");
3784 return 0;
3785 }
3786
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303787 ret = sme_cli_set_command(adapter->sessionId,
3788 WMI_PDEV_PARAM_DTIM_SYNTH,
3789 hdd_ctx->config->enable_lprx, PDEV_CMD);
3790 if (ret) {
3791 hdd_err("Failed to set LPRx");
3792 goto error;
3793 }
3794
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303795 if (adapter->device_mode == QDF_STA_MODE) {
3796 sme_set_smps_cfg(adapter->sessionId,
3797 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3798 hdd_ctx->config->upper_brssi_thresh);
3799
3800 sme_set_smps_cfg(adapter->sessionId,
3801 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3802 hdd_ctx->config->lower_brssi_thresh);
3803
3804 sme_set_smps_cfg(adapter->sessionId,
3805 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3806 hdd_ctx->config->enable_dtim_1chrx);
3807 }
3808
Dustin Brown732ab9c2017-06-15 13:24:09 -07003809 if (hdd_ctx->config->enable2x2) {
3810 hdd_debug("configuring 2x2 mode fw params");
3811
Naveen Rawat247a8682017-06-05 15:00:31 -07003812 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003813 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3814 hdd_ctx->config->enable_cck_tx_fir_override,
3815 PDEV_CMD);
3816 if (ret) {
3817 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3818 ret);
3819 goto error;
3820 }
3821 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303822#define HDD_DTIM_1CHAIN_RX_ID 0x5
3823#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003824 hdd_debug("configuring 1x1 mode fw params");
3825
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003826 /*
3827 * Disable DTIM 1 chain Rx when in 1x1,
3828 * we are passing two value
3829 * as param_id << 29 | param_value.
3830 * Below param_value = 0(disable)
3831 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003832 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003833 WMI_STA_SMPS_PARAM_CMDID,
3834 HDD_DTIM_1CHAIN_RX_ID <<
3835 HDD_SMPS_PARAM_VALUE_S,
3836 VDEV_CMD);
3837 if (ret) {
3838 hdd_err("DTIM 1 chain set failed %d", ret);
3839 goto error;
3840 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303841
Naveen Rawat247a8682017-06-05 15:00:31 -07003842 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003843 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3844 hdd_ctx->config->txchainmask1x1,
3845 PDEV_CMD);
3846 if (ret) {
3847 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3848 ret);
3849 goto error;
3850 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303851
Naveen Rawat247a8682017-06-05 15:00:31 -07003852 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003853 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3854 hdd_ctx->config->rxchainmask1x1,
3855 PDEV_CMD);
3856 if (ret) {
3857 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3858 ret);
3859 goto error;
3860 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303861#undef HDD_DTIM_1CHAIN_RX_ID
3862#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003863 }
3864
Naveen Rawat247a8682017-06-05 15:00:31 -07003865 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003866 WMI_PDEV_PARAM_HYST_EN,
3867 hdd_ctx->config->enableMemDeepSleep,
3868 PDEV_CMD);
3869 if (ret) {
3870 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3871 goto error;
3872 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303873
Naveen Rawat247a8682017-06-05 15:00:31 -07003874 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003875 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3876 hdd_ctx->config->rts_profile,
3877 VDEV_CMD);
3878 if (ret) {
3879 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3880 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303881 }
3882
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003883 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3884
3885 ret = wma_cli_set_command(adapter->sessionId,
3886 GEN_VDEV_PARAM_AMSDU,
3887 hdd_ctx->config->max_amsdu_num,
3888 GEN_CMD);
3889 if (ret != 0) {
3890 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3891 goto error;
3892 }
3893
Arun Khandavalli2358d522016-05-16 18:05:37 +05303894 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303895 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003896
Arun Khandavalli2358d522016-05-16 18:05:37 +05303897 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303898
Arun Khandavalli2358d522016-05-16 18:05:37 +05303899error:
3900 return -EINVAL;
3901}
3902
Ryan Hsu07495ea2016-01-21 15:25:39 -08003903/**
3904 * hdd_open_adapter() - open and setup the hdd adatper
3905 * @hdd_ctx: global hdd context
3906 * @session_type: type of the interface to be created
3907 * @iface_name: User-visible name of the interface
3908 * @macAddr: MAC address to assign to the interface
3909 * @name_assign_type: the name of assign type of the netdev
3910 * @rtnl_held: the rtnl lock hold flag
3911 *
3912 * This function open and setup the hdd adpater according to the device
3913 * type request, assign the name, the mac address assigned, and then prepared
3914 * the hdd related parameters, queue, lock and ready to start.
3915 *
3916 * Return: the pointer of hdd adapter, otherwise NULL.
3917 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003918struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003920 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003921 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922{
Jeff Johnson9d295242017-08-29 14:39:48 -07003923 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303925 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928
3929 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3930 /*
3931 * Max limit reached on the number of vdevs configured by the
3932 * host. Return error
3933 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303934 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3935 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 return NULL;
3937 }
3938
3939 if (macAddr == NULL) {
3940 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303941 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 return NULL;
3943 }
3944 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303945 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303946 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3947 " already exists",
3948 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 return NULL;
3950 }
3951
3952 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003953 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 /* Reset locally administered bit if the device mode is STA */
3955 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303956 hdd_info("locally administered bit reset in sta mode: "
3957 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003959 case QDF_P2P_CLIENT_MODE:
3960 case QDF_P2P_DEVICE_MODE:
3961 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003962 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303963 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003964 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3965 name_assign_type,
3966 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967
3968 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303969 hdd_err("failed to allocate adapter for session %d",
3970 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 return NULL;
3972 }
3973
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003974 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003976 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303978 else if (QDF_MONITOR_MODE == session_type)
3979 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 else
3981 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3982
3983 adapter->device_mode = session_type;
3984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 /*
3987 * Workqueue which gets scheduled in IPv4 notification
3988 * callback
3989 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3991 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992
3993#ifdef WLAN_NS_OFFLOAD
3994 /*
3995 * Workqueue which gets scheduled in IPv6
3996 * notification callback.
3997 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3999 hdd_ipv6_notifier_work_queue);
4000#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304002 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304004 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 }
4006
4007 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004008 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304010 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4011 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304012
Ravi Joshi1a292562017-05-18 16:28:54 -07004013 /* Initialize NAN Data Interface */
4014 if (QDF_NDI_MODE == session_type) {
4015 status = hdd_init_nan_data_mode(adapter);
4016 if (QDF_STATUS_SUCCESS != status)
4017 goto err_free_netdev;
4018 }
4019
4020 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004022 case QDF_P2P_GO_MODE:
4023 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004024 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4025 name_assign_type,
4026 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004028 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304029 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 return NULL;
4031 }
4032
4033 adapter->wdev.iftype =
4034 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004035 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 NL80211_IFTYPE_P2P_GO;
4037 adapter->device_mode = session_type;
4038
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004039 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304040 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4042 goto err_free_netdev;
4043 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004044 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304046 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4047 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304049 case QDF_FTM_MODE:
4050 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4051 name_assign_type,
4052 "wlan0");
4053 if (NULL == adapter) {
4054 hdd_err("Failed to allocate adapter for FTM mode");
4055 return NULL;
4056 }
4057 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4058 adapter->device_mode = session_type;
4059 status = hdd_register_interface(adapter, rtnl_held);
4060 if (QDF_STATUS_SUCCESS != status) {
4061 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4062 goto err_free_netdev;
4063 }
4064 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004065 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304066 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304067 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4068 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304069 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004070 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004071 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304072 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 return NULL;
4074 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075
hqueaa33ee2017-05-04 17:56:35 +08004076 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4079 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4080
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304081 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 /* Add it to the hdd's session list. */
4083 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304084 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304086 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 } else {
4088 pHddAdapterNode->pAdapter = adapter;
4089 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4090 }
4091 }
4092
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304093 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 if (NULL != adapter) {
4095 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4096 adapter = NULL;
4097 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004098 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304099 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101 return NULL;
4102 }
4103
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304104 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004105 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4106 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108 /* Adapter successfully added. Increment the vdev count */
4109 hdd_ctx->current_intf_count++;
4110
Jeff Johnson5880d792016-08-15 13:32:30 -07004111 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 hdd_ctx->current_intf_count);
4113
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004114 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 }
4116
Rajeev Kumardca5f812016-02-04 17:28:06 -08004117 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004118 hdd_err("Interface %s wow debug_fs init failed",
4119 netdev_name(adapter->dev));
4120
4121 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4122 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123
4124 return adapter;
4125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004126err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304128 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129
4130 return NULL;
4131}
4132
Jeff Johnson9d295242017-08-29 14:39:48 -07004133QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004134 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135{
4136 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304137 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138
4139 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304140 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004141 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 status);
4143 return status;
4144 }
4145
4146 while (pCurrent->pAdapter != adapter) {
4147 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304148 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149 break;
4150
4151 pCurrent = pNext;
4152 }
4153 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304154 if (QDF_STATUS_SUCCESS == status) {
Lin Baic5c06882017-09-21 13:58:43 +08004155 /*
4156 * Here we are stopping global bus_bw timer & work per adapter.
4157 *
4158 * The reason is to fix one race condition between
4159 * bus bandwidth work and cleaning up an adapter.
4160 * Under some conditions, it is possible for the bus bandwidth
4161 * work to access a particularly destroyed adapter, leading to
4162 * use-after-free.
4163 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004164 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004165 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Lin Baic5c06882017-09-21 13:58:43 +08004166 hdd_bus_bw_cancel_work(hdd_ctx);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004167
4168 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004169 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4170 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304173 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 adapterNode = NULL;
4175
Dustin Brown5ec6b552017-03-31 12:11:40 -07004176 /* conditionally restart the bw timer */
4177 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4178
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 /* Adapter removed. Decrement vdev count */
4180 if (hdd_ctx->current_intf_count != 0)
4181 hdd_ctx->current_intf_count--;
4182
4183 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304184 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304186
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188}
4189
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004190/**
4191 * hdd_close_all_adapters - Close all open adapters
4192 * @hdd_ctx: Hdd context
4193 * rtnl_held: True if RTNL lock held
4194 *
4195 * Close all open adapters.
4196 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304197 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004198 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004199QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200{
4201 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304202 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203
4204 ENTER();
4205
4206 do {
4207 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304208 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304209 wlan_hdd_release_intf_addr(hdd_ctx,
4210 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004211 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004212 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304213 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304214 /* Adapter removed. Decrement vdev count */
4215 if (hdd_ctx->current_intf_count != 0)
4216 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304218 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219
4220 EXIT();
4221
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304222 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223}
4224
Jeff Johnson9d295242017-08-29 14:39:48 -07004225void wlan_hdd_reset_prob_rspies(struct hdd_adapter *pHostapdAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304227 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004231 case QDF_STA_MODE:
4232 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004234 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004236 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004237 break;
4238 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004239 case QDF_SAP_MODE:
4240 case QDF_P2P_GO_MODE:
4241 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004242 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004243 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 break;
4245 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004246 case QDF_FTM_MODE:
4247 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 default:
4249 /*
4250 * wlan_hdd_reset_prob_rspies should not have been called
4251 * for these kind of devices
4252 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004253 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254 pHostapdAdapter->device_mode);
4255 return;
4256 }
4257
Anurag Chouhanc5548422016-02-24 18:33:27 +05304258 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4260 updateIE.ieBufferlength = 0;
4261 updateIE.pAdditionIEBuffer = NULL;
4262 updateIE.append = true;
4263 updateIE.notify = false;
4264 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4265 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304266 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004267 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 }
4269}
4270
Jeff Johnson9d295242017-08-29 14:39:48 -07004271QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 const bool bCloseSession)
4273{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304274 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4276 union iwreq_data wrqu;
4277 tSirUpdateIE updateIE;
4278 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004279 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280
4281 ENTER();
4282
Sachin Ahuja988fd102016-09-15 17:16:25 +05304283 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004284 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304285 wlan_hdd_netif_queue_control(adapter,
4286 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4287 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004289 case QDF_STA_MODE:
4290 case QDF_P2P_CLIENT_MODE:
4291 case QDF_IBSS_MODE:
4292 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004293 case QDF_NDI_MODE:
4294 if ((QDF_NDI_MODE == adapter->device_mode) ||
4295 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4297 hdd_is_connecting(
4298 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004299 INIT_COMPLETION(adapter->disconnect_comp_var);
4300 /*
4301 * For NDI do not use pWextState from sta_ctx, if needed
4302 * extract from ndi_ctx.
4303 */
4304 if (QDF_NDI_MODE == adapter->device_mode)
4305 qdf_ret_status = sme_roam_disconnect(
4306 hdd_ctx->hHal,
4307 adapter->sessionId,
4308 eCSR_DISCONNECT_REASON_NDI_DELETE);
4309 else if (pWextState->roamProfile.BSSType ==
4310 eCSR_BSS_TYPE_START_IBSS)
4311 qdf_ret_status = sme_roam_disconnect(
4312 hdd_ctx->hHal,
4313 adapter->sessionId,
4314 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004315 else if (QDF_STA_MODE == adapter->device_mode)
4316 qdf_ret_status =
4317 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004319 qdf_ret_status = sme_roam_disconnect(
4320 hdd_ctx->hHal,
4321 adapter->sessionId,
4322 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004323 /* success implies disconnect command got
4324 * queued up successfully
4325 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004326 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4327 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 rc = wait_for_completion_timeout(
4329 &adapter->disconnect_comp_var,
4330 msecs_to_jiffies
4331 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004332 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004333 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004335 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4336 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337 memset(&wrqu, '\0', sizeof(wrqu));
4338 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4339 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4340 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4341 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304342 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004343 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304344 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004345
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304346 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304347 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
4349#ifdef WLAN_OPEN_SOURCE
4350 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4351#endif
4352
4353 hdd_deregister_tx_flow_control(adapter);
4354
4355#ifdef WLAN_NS_OFFLOAD
4356#ifdef WLAN_OPEN_SOURCE
4357 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4358#endif
4359#endif
4360
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304361 if (adapter->device_mode == QDF_STA_MODE)
4362 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4363 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 /*
4365 * It is possible that the caller of this function does not
4366 * wish to close the session
4367 */
Krunal Soni985b8132017-02-10 18:49:08 -08004368 if (true == bCloseSession) {
4369 if (0 != wlan_hdd_try_disconnect(adapter)) {
4370 hdd_err("Error: Can't disconnect adapter");
4371 return QDF_STATUS_E_FAILURE;
4372 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004373 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004374 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 break;
4376
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004377 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304378 /* Flush IPA exception path packets */
4379 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004380 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004382 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4384
4385 hdd_deregister_tx_flow_control(adapter);
4386
Kapil Guptac1224bf2017-06-22 21:22:40 +05304387 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388 mutex_lock(&hdd_ctx->sap_lock);
4389 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304390 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304391 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392
4393 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 status = wlansap_stop_bss(
4395 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304397 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 hdd_hostapd_state_t *hostapd_state =
4399 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304400 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304401 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304402 qdf_status =
4403 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004404 qdf_stop_bss_event,
4405 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406
Anurag Chouhance0dc992016-02-16 18:18:03 +05304407 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004408 hdd_err("failure waiting for wlansap_stop_bss %d",
4409 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 }
4411 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004412 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 }
4414 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004415 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4416 adapter->device_mode,
4417 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418
Anurag Chouhanc5548422016-02-24 18:33:27 +05304419 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004420 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 updateIE.smeSessionId = adapter->sessionId;
4422 updateIE.ieBufferlength = 0;
4423 updateIE.pAdditionIEBuffer = NULL;
4424 updateIE.append = false;
4425 updateIE.notify = false;
4426 /* Probe bcn reset */
4427 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4428 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304429 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004430 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 }
4432 /* Assoc resp reset */
4433 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4434 &updateIE,
4435 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304436 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004437 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438 }
4439 /* Reset WNI_CFG_PROBE_RSP Flags */
4440 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004442 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4443 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304444 /*
4445 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4446 */
4447 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4448 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4449
Peng Xu66162de2016-02-11 17:01:20 -08004450 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004451 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004452 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004454 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004455 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004456 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004457 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458 break;
4459 default:
4460 break;
4461 }
4462
4463 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304464 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465}
4466
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304467/**
4468 * hdd_deinit_all_adapters - deinit all adapters
4469 * @hdd_ctx: HDD context
4470 * @rtnl_held: True if RTNL lock held
4471 *
4472 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004473void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304474{
4475 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4476 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004477 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304478
4479 ENTER();
4480
4481 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4482
4483 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4484 adapter = adapter_node->pAdapter;
4485 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4486 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4487 adapter_node = next;
4488 }
4489
4490 EXIT();
4491}
4492
Dustin Brown27cd9942017-09-27 16:11:44 -07004493QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4494 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495{
4496 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304497 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004498 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004499
4500 ENTER();
4501
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304502 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4505
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304506 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 adapter = adapterNode->pAdapter;
Dustin Brown27cd9942017-09-27 16:11:44 -07004508 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4510 adapterNode = pNext;
4511 }
4512
4513 EXIT();
4514
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304515 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516}
4517
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004518QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519{
4520 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304521 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004522 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004523 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004524 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525
4526 ENTER();
4527
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304528 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4531
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304532 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004534 hdd_notice("Disabling queues for adapter type: %d",
4535 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304536
4537 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004538 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304539 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004540 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304541
Arun Khandavallicc544b32017-01-30 19:52:16 +05304542 if (hdd_ctx->config->sap_internal_restart &&
4543 adapter->device_mode == QDF_SAP_MODE) {
4544 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304545 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304546 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004547 if (test_bit(SOFTAP_BSS_STARTED,
4548 &adapter->event_flags)) {
4549 hdd_sap_indicate_disconnect_for_sta(adapter);
4550 hdd_cleanup_actionframe(hdd_ctx, adapter);
4551 hdd_sap_destroy_events(adapter);
4552 }
4553 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4554 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304555 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304556 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004558 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559
4560 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4561
4562 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004563 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4564 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4566 hdd_wmm_adapter_close(adapter);
4567 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4568 }
4569
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304570 if (adapter->device_mode == QDF_STA_MODE)
4571 hdd_clear_fils_connection_info(adapter);
4572
Wu Gao3545e642017-07-14 19:24:41 +08004573 if (adapter->device_mode == QDF_SAP_MODE) {
4574 /*
4575 * If adapter is SAP, set session ID to invalid
4576 * since SAP session will be cleanup during SSR.
4577 */
Wu Gao36717432016-11-21 15:09:48 +08004578 wlansap_set_invalid_session(
4579 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4580
Wu Gao3545e642017-07-14 19:24:41 +08004581 wlansap_cleanup_cac_timer(
4582 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4583 }
4584
Yue Mad5b4b9f2017-05-26 16:23:40 -07004585 /* Delete peers if any for STA and P2P client modes */
4586 if (adapter->device_mode == QDF_STA_MODE ||
4587 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4588 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4589 qdf_copy_macaddr(&peerMacAddr,
4590 &pHddStaCtx->conn_info.bssId);
4591
4592 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4593 peerMacAddr.bytes);
4594 }
4595
Yue Maf9782842017-05-08 12:49:49 -07004596 /* Destroy vdev which will be recreated during reinit. */
4597 hdd_vdev_destroy(adapter);
4598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4600 adapterNode = pNext;
4601 }
4602
4603 EXIT();
4604
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304605 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004606}
4607
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004608bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304609{
4610 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4611 QDF_STATUS status;
4612 bool close_modules = true;
4613
Arun Khandavalliba479c42017-07-26 21:29:40 +05304614 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4615 hdd_info("FTM mode, don't close the module");
4616 return false;
4617 }
4618
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304619 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4620 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4621 if (test_bit(DEVICE_IFACE_OPENED,
4622 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004623 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304624 close_modules = false;
4625 break;
4626 }
4627 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4628 adapter_node = next;
4629 }
4630
4631 return close_modules;
4632}
4633
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304634bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304635{
4636 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4637 return true;
4638 else
4639 return false;
4640}
4641
Anurag Chouhanc4092922016-09-08 15:56:11 +05304642#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004643 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304644struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4645 struct ieee80211_channel *channel,
4646 const u8 *bssid, const u8 *ssid,
4647 size_t ssid_len)
4648{
4649 return cfg80211_get_bss(wiphy, channel, bssid,
4650 ssid, ssid_len,
4651 WLAN_CAPABILITY_ESS,
4652 WLAN_CAPABILITY_ESS);
4653}
4654#else
4655struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4656 struct ieee80211_channel *channel,
4657 const u8 *bssid, const u8 *ssid,
4658 size_t ssid_len)
4659{
4660 return cfg80211_get_bss(wiphy, channel, bssid,
4661 ssid, ssid_len,
4662 IEEE80211_BSS_TYPE_ESS,
4663 IEEE80211_PRIVACY_ANY);
4664}
4665#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304666
Abhishek Singha84d3952016-09-13 13:45:05 +05304667#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304668#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4669 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4670/**
4671 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4672 * @timeout_reason: reason for connect timeout
4673 *
4674 * This function is used to convert host timeout
4675 * reason enum to kernel specific enum.
4676 *
4677 * Return: nl timeout enum
4678 */
4679static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4680 tSirResultCodes timeout_reason)
4681{
4682 switch (timeout_reason) {
4683 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4684 return NL80211_TIMEOUT_SCAN;
4685 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4686 return NL80211_TIMEOUT_AUTH;
4687 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4688 return NL80211_TIMEOUT_ASSOC;
4689 default:
4690 return NL80211_TIMEOUT_UNSPECIFIED;
4691 }
4692}
4693
4694/**
4695 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4696 * @dev: network device
4697 * @bssid: bssid to which we want to associate
4698 * @timeout_reason: reason for connect timeout
4699 *
4700 * This API is used to send connection timeout reason to supplicant
4701 *
4702 * Return: void
4703 */
4704static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4705 const u8 *bssid,
4706 tSirResultCodes timeout_reason)
4707{
4708 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004709
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304710 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4711
4712 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4713 nl_timeout_reason);
4714}
4715
4716/**
4717 * __hdd_connect_bss() - API to send connection status to supplicant
4718 * @dev: network device
4719 * @bssid: bssid to which we want to associate
4720 * @req_ie: Request Information Element
4721 * @req_ie_len: len of the req IE
4722 * @resp_ie: Response IE
4723 * @resp_ie_len: len of ht response IE
4724 * @status: status
4725 * @gfp: Kernel Flag
4726 * @timeout_reason: reason for connect timeout
4727 *
4728 * Return: void
4729 */
4730static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4731 struct cfg80211_bss *bss, const u8 *req_ie,
4732 size_t req_ie_len, const u8 *resp_ie,
4733 size_t resp_ie_len, int status, gfp_t gfp,
4734 tSirResultCodes timeout_reason)
4735{
4736 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004737
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304738 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4739
4740 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4741 resp_ie, resp_ie_len, status, gfp,
4742 nl_timeout_reason);
4743}
4744#else
4745#if defined CFG80211_CONNECT_TIMEOUT
4746static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4747 const u8 *bssid,
4748 tSirResultCodes timeout_reason)
4749{
4750 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4751}
4752#endif
4753
4754static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4755 struct cfg80211_bss *bss, const u8 *req_ie,
4756 size_t req_ie_len, const u8 *resp_ie,
4757 size_t resp_ie_len, int status, gfp_t gfp,
4758 tSirResultCodes timeout_reason)
4759{
4760 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4761 resp_ie, resp_ie_len, status, gfp);
4762}
4763#endif
4764
Abhishek Singha84d3952016-09-13 13:45:05 +05304765/**
4766 * hdd_connect_bss() - API to send connection status to supplicant
4767 * @dev: network device
4768 * @bssid: bssid to which we want to associate
4769 * @req_ie: Request Information Element
4770 * @req_ie_len: len of the req IE
4771 * @resp_ie: Response IE
4772 * @resp_ie_len: len of ht response IE
4773 * @status: status
4774 * @gfp: Kernel Flag
4775 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304776 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304777 *
4778 * The API is a wrapper to send connection status to supplicant
4779 *
4780 * Return: Void
4781 */
4782#if defined CFG80211_CONNECT_TIMEOUT
4783static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4784 struct cfg80211_bss *bss, const u8 *req_ie,
4785 size_t req_ie_len, const u8 *resp_ie,
4786 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304787 bool connect_timeout,
4788 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304789{
4790 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304791 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304792 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304793 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4794 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304795}
4796#else
4797static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4798 struct cfg80211_bss *bss, const u8 *req_ie,
4799 size_t req_ie_len, const u8 *resp_ie,
4800 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304801 bool connect_timeout,
4802 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304803{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304804 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4805 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304806}
4807#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304808
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304809#ifdef WLAN_FEATURE_FILS_SK
4810#ifdef CFG80211_CONNECT_DONE
4811#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4812/**
4813 * hdd_populate_fils_params() - Populate FILS keys to connect response
4814 * @fils_params: connect response to supplicant
4815 * @fils_kek: FILS kek
4816 * @fils_kek_len: FILS kek length
4817 * @pmk: FILS PMK
4818 * @pmk_len: FILS PMK length
4819 * @pmkid: PMKID
4820 * @fils_seq_num: FILS Seq number
4821 *
4822 * Return: None
4823 */
4824static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4825 *fils_params, const uint8_t *fils_kek,
4826 size_t fils_kek_len, const uint8_t *pmk,
4827 size_t pmk_len, const uint8_t *pmkid,
4828 uint16_t fils_seq_num)
4829{
4830 /* Increament seq number to be used for next FILS */
4831 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4832 fils_params->update_erp_next_seq_num = true;
4833 fils_params->fils_kek = fils_kek;
4834 fils_params->fils_kek_len = fils_kek_len;
4835 fils_params->pmk = pmk;
4836 fils_params->pmk_len = pmk_len;
4837 fils_params->pmkid = pmkid;
4838}
4839#else
4840static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4841 *fils_params, const uint8_t
4842 *fils_kek, size_t fils_kek_len,
4843 const uint8_t *pmk, size_t pmk_len,
4844 const uint8_t *pmkid,
4845 uint16_t fils_seq_num)
4846{ }
4847#endif
4848
4849/**
4850 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4851 * @dev: network device
4852 * @bssid: bssid to which we want to associate
4853 * @bss: cfg80211 bss info
4854 * @roam_info: information about connected bss
4855 * @req_ie: Request Information Element
4856 * @req_ie_len: len of the req IE
4857 * @resp_ie: Response IE
4858 * @resp_ie_len: len of ht response IE
4859 * @status: status
4860 * @gfp: allocation flags
4861 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4862 * @timeout_reason: reason for connect timeout
4863 * @roam_fils_params: FILS join response params
4864 *
4865 * This API is used as wrapper to send FILS key/sequence number
4866 * params etc. to supplicant in case of FILS connection
4867 *
4868 * Return: None
4869 */
4870static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4871 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4872 const u8 *req_ie, size_t req_ie_len,
4873 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4874 gfp_t gfp, bool connect_timeout, tSirResultCodes
4875 timeout_reason, struct fils_join_rsp_params
4876 *roam_fils_params)
4877{
4878 struct cfg80211_connect_resp_params fils_params;
4879 qdf_mem_zero(&fils_params, sizeof(fils_params));
4880
4881 if (!roam_fils_params) {
4882 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4883 } else {
4884 fils_params.status = status;
4885 fils_params.bssid = bssid;
4886 fils_params.timeout_reason = timeout_reason;
4887 fils_params.req_ie = req_ie;
4888 fils_params.req_ie_len = req_ie_len;
4889 fils_params.resp_ie = resp_ie;
4890 fils_params.resp_ie_len = resp_ie_len;
4891 fils_params.bss = bss;
4892 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4893 roam_fils_params->kek_len,
4894 roam_fils_params->fils_pmk,
4895 roam_fils_params->fils_pmk_len,
4896 roam_fils_params->fils_pmkid,
4897 roam_info->fils_seq_num);
4898 }
4899 hdd_debug("FILS indicate connect status %d seq no %d",
4900 fils_params.status,
4901 fils_params.fils_erp_next_seq_num);
4902
4903 cfg80211_connect_done(dev, &fils_params, gfp);
4904
4905 /* Clear all the FILS key info */
4906 if (roam_fils_params && roam_fils_params->fils_pmk)
4907 qdf_mem_free(roam_fils_params->fils_pmk);
4908 if (roam_fils_params)
4909 qdf_mem_free(roam_fils_params);
4910 roam_info->fils_join_rsp = NULL;
4911}
4912#else
4913static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4914 struct cfg80211_bss *bss, tCsrRoamInfo
4915 *roam_info, const u8 *req_ie,
4916 size_t req_ie_len, const u8 *resp_ie,
4917 size_t resp_ie_len, u16 status, gfp_t gfp,
4918 bool connect_timeout, tSirResultCodes
4919 timeout_reason, struct fils_join_rsp_params
4920 *roam_fils_params)
4921{ }
4922#endif
4923#endif
4924
4925#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4926/**
4927 * hdd_fils_update_connect_results() - API to send fils connection status to
4928 * supplicant.
4929 * @dev: network device
4930 * @bssid: bssid to which we want to associate
4931 * @bss: cfg80211 bss info
4932 * @roam_info: information about connected bss
4933 * @req_ie: Request Information Element
4934 * @req_ie_len: len of the req IE
4935 * @resp_ie: Response IE
4936 * @resp_ie_len: len of ht response IE
4937 * @status: status
4938 * @gfp: allocation flags
4939 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4940 * @timeout_reason: reason for connect timeout
4941 *
4942 * The API is a wrapper to send connection status to supplicant
4943 *
4944 * Return: 0 if success else failure
4945 */
4946static int hdd_fils_update_connect_results(struct net_device *dev,
4947 const u8 *bssid,
4948 struct cfg80211_bss *bss,
4949 tCsrRoamInfo *roam_info, const u8 *req_ie,
4950 size_t req_ie_len, const u8 *resp_ie,
4951 size_t resp_ie_len, u16 status, gfp_t gfp,
4952 bool connect_timeout,
4953 tSirResultCodes timeout_reason)
4954{
4955 ENTER();
4956 if (!roam_info || !roam_info->is_fils_connection)
4957 return -EINVAL;
4958
4959 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4960 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4961 timeout_reason, roam_info->fils_join_rsp);
4962 return 0;
4963}
4964#else
4965static inline int hdd_fils_update_connect_results(struct net_device *dev,
4966 const u8 *bssid,
4967 struct cfg80211_bss *bss,
4968 tCsrRoamInfo *roam_info, const u8 *req_ie,
4969 size_t req_ie_len, const u8 *resp_ie,
4970 size_t resp_ie_len, u16 status, gfp_t gfp,
4971 bool connect_timeout,
4972 tSirResultCodes timeout_reason)
4973{
4974 return -EINVAL;
4975}
4976#endif
4977
Anurag Chouhanc4092922016-09-08 15:56:11 +05304978/**
4979 * hdd_connect_result() - API to send connection status to supplicant
4980 * @dev: network device
4981 * @bssid: bssid to which we want to associate
4982 * @roam_info: information about connected bss
4983 * @req_ie: Request Information Element
4984 * @req_ie_len: len of the req IE
4985 * @resp_ie: Response IE
4986 * @resp_ie_len: len of ht response IE
4987 * @status: status
4988 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304989 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304990 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304991 *
4992 * The API is a wrapper to send connection status to supplicant
4993 * and allow runtime suspend
4994 *
4995 * Return: Void
4996 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304997void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4998 tCsrRoamInfo *roam_info, const u8 *req_ie,
4999 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305000 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305001 bool connect_timeout,
5002 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305003{
Jeff Johnson9d295242017-08-29 14:39:48 -07005004 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305005 struct cfg80211_bss *bss = NULL;
5006
5007 if (WLAN_STATUS_SUCCESS == status) {
5008 struct ieee80211_channel *chan;
5009 int freq;
5010 int chan_no = roam_info->pBssDesc->channelId;
5011
5012 if (chan_no <= 14)
5013 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005014 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305015 else
5016 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005017 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305018
5019 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5020 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5021 roam_info->u.pConnectedProfile->SSID.ssId,
5022 roam_info->u.pConnectedProfile->SSID.length);
5023 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305024
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305025 if (hdd_fils_update_connect_results(dev, bssid, bss,
5026 roam_info, req_ie, req_ie_len, resp_ie,
5027 resp_ie_len, status, gfp, connect_timeout,
5028 timeout_reason) != 0) {
5029 hdd_connect_bss(dev, bssid, bss, req_ie,
5030 req_ie_len, resp_ie, resp_ie_len,
5031 status, gfp, connect_timeout, timeout_reason);
5032 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305033
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005034 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005035 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305036}
5037#else
5038void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5039 tCsrRoamInfo *roam_info, const u8 *req_ie,
5040 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305041 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305042 bool connect_timeout,
5043 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305044{
Jeff Johnson9d295242017-08-29 14:39:48 -07005045 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305046
Anurag Chouhanc4092922016-09-08 15:56:11 +05305047 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5048 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005049
5050 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005051 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305052}
5053#endif
5054
5055
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005056QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005057{
5058 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305059 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005060 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305062 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063#endif
5064 eConnectionState connState;
5065
5066 ENTER();
5067
5068 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305069 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070 adapter = adapterNode->pAdapter;
5071
Arun Khandavallifae92942016-08-01 13:31:08 +05305072 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305073 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305074
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075 hdd_wmm_init(adapter);
5076
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005077 adapter->scan_info.mScanPending = false;
5078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005080 case QDF_STA_MODE:
5081 case QDF_P2P_CLIENT_MODE:
5082 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083
5084 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5085 ->conn_info.connState;
5086
5087 hdd_init_station_mode(adapter);
5088 /* Open the gates for HDD to receive Wext commands */
5089 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005091 /* Indicate disconnect event to supplicant
5092 * if associated previously
5093 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005095 eConnectionState_IbssConnected == connState ||
5096 eConnectionState_NotConnected == connState ||
5097 eConnectionState_IbssDisconnected == connState ||
5098 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 memset(&wrqu, '\0', sizeof(wrqu));
5102 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5103 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5104 wireless_send_event(adapter->dev, SIOCGIWAP,
5105 &wrqu, NULL);
5106 adapter->sessionCtx.station.
5107 hdd_ReassocScenario = false;
5108
5109 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305110 wlan_hdd_cfg80211_indicate_disconnect(
5111 adapter->dev, false,
5112 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 } else if (eConnectionState_Connecting == connState) {
5114 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005115 * Indicate connect failure to supplicant if we
5116 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305118 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305119 NULL, 0, NULL, 0,
5120 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005121 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122 }
5123
5124 hdd_register_tx_flow_control(adapter,
5125 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005126 hdd_tx_resume_cb,
5127 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128
5129 break;
5130
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005131 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005132 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305133 hdd_init_ap_mode(adapter, true);
5134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 break;
5136
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005137 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005139 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5141#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005142 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 /* event supplicant to restart */
5144 cfg80211_del_sta(adapter->dev,
5145 (const u8 *)&bcastMac.bytes[0],
5146 GFP_KERNEL);
5147#endif
5148 break;
5149
5150 default:
5151 break;
5152 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005153 /*
5154 * Action frame registered in one adapter which will
5155 * applicable to all interfaces
5156 */
5157 wlan_hdd_cfg80211_register_frames(adapter);
5158
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305159get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5161 adapterNode = pNext;
5162 }
5163
5164 EXIT();
5165
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305166 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167}
5168
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005169QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 hdd_adapter_list_node_t **padapterNode)
5171{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305172 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005173
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005174 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305175 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5176 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005177 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 return status;
5179}
5180
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005181QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005182 hdd_adapter_list_node_t *adapterNode,
5183 hdd_adapter_list_node_t **pNextAdapterNode)
5184{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305185 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005186
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005187 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305188 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5189 (qdf_list_node_t *) adapterNode,
5190 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005192 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 return status;
5194}
5195
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005196QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 hdd_adapter_list_node_t *adapterNode)
5198{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305199 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005200
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005201 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305202 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005204 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 return status;
5206}
5207
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005208QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 hdd_adapter_list_node_t **padapterNode)
5210{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305211 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005212
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005213 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305214 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5215 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005216 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 return status;
5218}
5219
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005220QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221 hdd_adapter_list_node_t *adapterNode)
5222{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305223 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005224
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005225 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305226 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5227 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005228 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229 return status;
5230}
5231
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005232QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 hdd_adapter_list_node_t *adapterNode)
5234{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305235 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005236
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005237 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305238 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5239 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005240 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 return status;
5242}
5243
Jeff Johnson9d295242017-08-29 14:39:48 -07005244struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245 tSirMacAddr macAddr)
5246{
5247 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005248 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305249 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250
5251 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5252
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305253 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 adapter = adapterNode->pAdapter;
5255
5256 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305257 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005258 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005259 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005260
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5262 adapterNode = pNext;
5263 }
5264
5265 return NULL;
5266
5267}
5268
Jeff Johnson9d295242017-08-29 14:39:48 -07005269struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270 uint32_t vdev_id)
5271{
5272 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005273 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305274 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305276 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305278 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279 adapter = adapterNode->pAdapter;
5280
5281 if (adapter->sessionId == vdev_id)
5282 return adapter;
5283
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305284 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5286 adapterNode = pNext;
5287 }
5288
Jeff Johnson5880d792016-08-15 13:32:30 -07005289 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005290
5291 return NULL;
5292}
5293
Abhishek Singh7996eb72015-12-30 17:24:02 +05305294/**
5295 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5296 * the sessionid
5297 * @hdd_ctx: hdd context.
5298 * @sme_session_id: sme session is for the adapter to get.
5299 *
5300 * This function is used to get the adapter with provided session id
5301 *
5302 * Return: adapter pointer if found
5303 *
5304 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005305struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305306 uint32_t sme_session_id)
5307{
5308 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005309 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305310 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305311
5312
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305313 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305314
5315 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305316 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305317 adapter = adapter_node->pAdapter;
5318
5319 if (adapter &&
5320 adapter->sessionId == sme_session_id)
5321 return adapter;
5322
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305323 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305324 hdd_get_next_adapter(hdd_ctx,
5325 adapter_node, &next);
5326 adapter_node = next;
5327 }
5328 return NULL;
5329}
5330
Jeff Johnson9d295242017-08-29 14:39:48 -07005331struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005332 const char *iface_name)
5333{
5334 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005335 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005336 QDF_STATUS qdf_status;
5337
5338 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5339
5340 while ((NULL != adapter_node) &&
5341 (QDF_STATUS_SUCCESS == qdf_status)) {
5342 adapter = adapter_node->pAdapter;
5343
5344 if (adapter &&
5345 !qdf_str_cmp(adapter->dev->name, iface_name))
5346 return adapter;
5347
5348 qdf_status =
5349 hdd_get_next_adapter(hdd_ctx,
5350 adapter_node, &next);
5351 adapter_node = next;
5352 }
5353 return NULL;
5354}
5355
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005356/**
5357 * hdd_get_adapter() - to get adapter matching the mode
5358 * @hdd_ctx: hdd context
5359 * @mode: adapter mode
5360 *
5361 * This routine will return the pointer to adapter matching
5362 * with the passed mode.
5363 *
5364 * Return: pointer to adapter or null
5365 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005366struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005367 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005368{
5369 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005370 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305371 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372
5373 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5374
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305375 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 adapter = adapterNode->pAdapter;
5377
5378 if (adapter && (mode == adapter->device_mode))
5379 return adapter;
5380
5381 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5382 adapterNode = pNext;
5383 }
5384
5385 return NULL;
5386
5387}
5388
5389/**
5390 * hdd_get_operating_channel() - return operating channel of the device mode
5391 * @hdd_ctx: Pointer to the HDD context.
5392 * @mode: Device mode for which operating channel is required.
5393 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005394 * QDF_STA_MODE,
5395 * QDF_P2P_CLIENT_MODE,
5396 * QDF_SAP_MODE,
5397 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398 *
5399 * This API returns the operating channel of the requested device mode
5400 *
5401 * Return: channel number. "0" id the requested device is not found OR it is
5402 * not connected.
5403 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005404uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005405 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406{
5407 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305408 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005409 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410 uint8_t operatingChannel = 0;
5411
5412 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5413
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305414 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415 adapter = adapterNode->pAdapter;
5416
5417 if (mode == adapter->device_mode) {
5418 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005419 case QDF_STA_MODE:
5420 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421 if (hdd_conn_is_connected
5422 (WLAN_HDD_GET_STATION_CTX_PTR
5423 (adapter))) {
5424 operatingChannel =
5425 (WLAN_HDD_GET_STATION_CTX_PTR
5426 (adapter))->conn_info.
5427 operationChannel;
5428 }
5429 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005430 case QDF_SAP_MODE:
5431 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 /* softap connection info */
5433 if (test_bit
5434 (SOFTAP_BSS_STARTED,
5435 &adapter->event_flags))
5436 operatingChannel =
5437 (WLAN_HDD_GET_AP_CTX_PTR
5438 (adapter))->operatingChannel;
5439 break;
5440 default:
5441 break;
5442 }
5443
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005444 /* Found the device of interest. break the loop */
5445 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446 }
5447
5448 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5449 adapterNode = pNext;
5450 }
5451 return operatingChannel;
5452}
5453
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005454static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005455 hdd_ctx)
5456{
5457 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305458 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005459 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460
5461 ENTER();
5462
5463 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5464
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305465 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005466 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005467 if ((adapter->device_mode == QDF_STA_MODE) ||
5468 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5469 (adapter->device_mode == QDF_IBSS_MODE) ||
5470 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5471 (adapter->device_mode == QDF_SAP_MODE) ||
5472 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005473 wlan_hdd_cfg80211_deregister_frames(adapter);
5474 hdd_unregister_wext(adapter->dev);
5475 }
5476 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5477 adapterNode = pNext;
5478 }
5479
5480 EXIT();
5481
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305482 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483}
5484
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005485QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005486{
5487 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305488 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005489 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490
5491 ENTER();
5492
5493 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5494
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305495 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005497 if ((adapter->device_mode == QDF_STA_MODE) ||
5498 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5499 (adapter->device_mode == QDF_IBSS_MODE) ||
5500 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5501 (adapter->device_mode == QDF_SAP_MODE) ||
5502 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305503 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5504 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505 }
5506 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5507 adapterNode = pNext;
5508 }
5509
5510 EXIT();
5511
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305512 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513}
5514
Dustin Brownf27bce82016-11-03 12:52:27 -07005515/**
5516 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5517 * adapters
5518 * @hdd_ctx: The HDD context containing the adapters to operate on
5519 *
5520 * return: QDF_STATUS_SUCCESS
5521 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005522static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005523{
5524 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5525 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005526 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005527 int err;
5528
5529 ENTER();
5530
5531 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5532
5533 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5534 adapter = adapter_node->pAdapter;
5535 if ((adapter->device_mode == QDF_STA_MODE) ||
5536 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5537 (adapter->device_mode == QDF_IBSS_MODE) ||
5538 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5539 (adapter->device_mode == QDF_SAP_MODE) ||
5540 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5541 err = wlan_hdd_sched_scan_stop(adapter->dev);
5542 if (err)
5543 hdd_err("Unable to stop scheduled scan");
5544 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005545 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5546 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005547 adapter_node = next_node;
5548 }
5549
5550 EXIT();
5551
5552 return QDF_STATUS_SUCCESS;
5553}
5554
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555#ifdef WLAN_NS_OFFLOAD
5556/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005557 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558 * @hdd_ctx: Pointer to hdd context
5559 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005560 * Unregister for IPv6 address change notifications.
5561 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562 * Return: None
5563 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005564static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565{
5566 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005567}
5568
5569/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005570 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005571 * @hdd_ctx: Pointer to hdd context
5572 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005573 * Register for IPv6 address change notifications.
5574 *
5575 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005576 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005577static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578{
5579 int ret;
5580
5581 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5582 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005583 if (ret) {
5584 hdd_err("Failed to register IPv6 notifier: %d", ret);
5585 goto out;
5586 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005588 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005589out:
5590 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005591}
5592#else
5593/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005594 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595 * @hdd_ctx: Pointer to hdd context
5596 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005597 * Unregister for IPv6 address change notifications.
5598 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005599 * Return: None
5600 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005601static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602{
5603}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005604
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005605/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005606 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607 * @hdd_ctx: Pointer to hdd context
5608 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005609 * Register for IPv6 address change notifications.
5610 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 * Return: None
5612 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005613static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005615 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616}
5617#endif
5618
5619/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005620 * hdd_register_notifiers - Register netdev notifiers.
5621 * @hdd_ctx: HDD context
5622 *
5623 * Register netdev notifiers like IPv4 and IPv6.
5624 *
5625 * Return: 0 on success and errno on failure
5626 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005627static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005628{
5629 int ret;
5630
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005631 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5632 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305633 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005634
5635 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5636 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5637 if (ret) {
5638 hdd_err("Failed to register IPv4 notifier: %d", ret);
5639 goto unregister_ip6_notifier;
5640 }
5641
5642 return 0;
5643
5644unregister_ip6_notifier:
5645 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005646out:
5647 return ret;
5648
5649}
5650
5651/**
5652 * hdd_unregister_notifiers - Unregister netdev notifiers.
5653 * @hdd_ctx: HDD context
5654 *
5655 * Unregister netdev notifiers like IPv4 and IPv6.
5656 *
5657 * Return: None.
5658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005659void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005660{
5661 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5662
5663 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005664}
5665
5666/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005667 * hdd_exit_netlink_services - Exit netlink services
5668 * @hdd_ctx: HDD context
5669 *
5670 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5671 * nl service.
5672 *
5673 * Return: None.
5674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005675static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005676{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005677 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005678 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005679 ptt_sock_deactivate_svc();
5680
5681 nl_srv_exit();
5682}
5683
5684/**
5685 * hdd_init_netlink_services- Init netlink services
5686 * @hdd_ctx: HDD context
5687 *
5688 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5689 * nl service.
5690 *
5691 * Return: 0 on success and errno on failure.
5692 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005693static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005694{
5695 int ret;
5696
Ryan Hsuceddceb2016-04-28 10:20:14 -07005697 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005698 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005699 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005700 goto out;
5701 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005702 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005703
Naveen Rawat910726a2017-03-06 11:42:51 -08005704 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005705 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005706 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005707 goto err_nl_srv;
5708 }
5709
5710 ret = ptt_sock_activate_svc();
5711 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005712 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005713 goto err_nl_srv;
5714 }
5715
5716 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005717 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005718 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005719
5720 ret = cnss_diag_activate_service();
5721 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005722 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005723 goto err_close_cesium;
5724 }
5725
5726 return 0;
5727
5728err_close_cesium:
5729 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005730 ptt_sock_deactivate_svc();
5731err_nl_srv:
5732 nl_srv_exit();
5733out:
5734 return ret;
5735}
5736
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005737/**
5738 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5739 * @hdd_ctx: HDD context.
5740 *
5741 * Destroy RX wakelock.
5742 *
5743 * Return: None.
5744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005745static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005746{
5747 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5748}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005749
5750/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005751 * hdd_rx_wake_lock_create() - Create RX wakelock
5752 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005753 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005754 * Create RX wakelock.
5755 *
5756 * Return: None.
5757 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005758static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005759{
5760 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5761}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005762
5763/**
5764 * hdd_roc_context_init() - Init ROC context
5765 * @hdd_ctx: HDD context.
5766 *
5767 * Initialize ROC context.
5768 *
5769 * Return: 0 on success and errno on failure.
5770 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005771static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005772{
5773 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5774 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5775
5776 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5777
5778 return 0;
5779}
5780
5781/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305782 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5783 * @hdd_ctx: HDD context.
5784 *
5785 * Free memory allocations made in ROC Req Queue nodes.
5786 *
5787 * Return: None.
5788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005789static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305790{
5791 hdd_roc_req_t *hdd_roc_req;
5792 QDF_STATUS status;
5793
5794 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5795
5796 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5797 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5798 (qdf_list_node_t **) &hdd_roc_req);
5799
5800 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305801 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5802 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305803 QDF_ASSERT(0);
5804 return;
5805 }
5806
5807 if (hdd_roc_req->pRemainChanCtx)
5808 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5809
5810 qdf_mem_free(hdd_roc_req);
5811 }
5812
5813 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5814}
5815
5816/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005817 * hdd_roc_context_destroy() - Destroy ROC context
5818 * @hdd_ctx: HDD context.
5819 *
5820 * Destroy roc list and flush the pending roc work.
5821 *
5822 * Return: None.
5823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005824static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005825{
5826 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305827 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005828 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005829}
5830
5831/**
Houston Hoffman160db392016-10-10 17:37:51 -07005832 * hdd_context_deinit() - Deinitialize HDD context
5833 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005834 *
Houston Hoffman160db392016-10-10 17:37:51 -07005835 * Deinitialize HDD context along with all the feature specific contexts but
5836 * do not free hdd context itself. Caller of this API is supposed to free
5837 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005838 *
Houston Hoffman160db392016-10-10 17:37:51 -07005839 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005841static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005842{
Houston Hoffman160db392016-10-10 17:37:51 -07005843 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005844
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005845 hdd_roc_context_destroy(hdd_ctx);
5846
5847 hdd_sap_context_destroy(hdd_ctx);
5848
5849 hdd_rx_wake_lock_destroy(hdd_ctx);
5850
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005851 hdd_scan_context_destroy(hdd_ctx);
5852
5853 qdf_list_destroy(&hdd_ctx->hddAdapters);
5854
Houston Hoffman160db392016-10-10 17:37:51 -07005855 return 0;
5856}
5857
5858/**
5859 * hdd_context_destroy() - Destroy HDD context
5860 * @hdd_ctx: HDD context to be destroyed.
5861 *
5862 * Free config and HDD context as well as destroy all the resources.
5863 *
5864 * Return: None
5865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005866static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005867{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305868
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305869 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5870
Houston Hoffman160db392016-10-10 17:37:51 -07005871 hdd_context_deinit(hdd_ctx);
5872
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305873 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005874 hdd_ctx->config = NULL;
5875
5876 wiphy_free(hdd_ctx->wiphy);
5877}
5878
5879/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305880 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5881 *
5882 * This function is used to destroy bug report lock
5883 *
5884 * Return: None
5885 */
5886static void wlan_destroy_bug_report_lock(void)
5887{
5888 p_cds_contextType p_cds_context;
5889
5890 p_cds_context = cds_get_global_context();
5891 if (!p_cds_context) {
5892 hdd_err("cds context is NULL");
5893 return;
5894 }
5895
5896 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5897}
5898
5899/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005900 * hdd_wlan_exit() - HDD WLAN exit function
5901 * @hdd_ctx: Pointer to the HDD Context
5902 *
5903 * This is the driver exit point (invoked during rmmod)
5904 *
5905 * Return: None
5906 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005907static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305909 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005910 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305911 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005912
5913 ENTER();
5914
Arun Khandavallifae92942016-08-01 13:31:08 +05305915 if (QDF_TIMER_STATE_RUNNING ==
5916 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005917 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305918 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919 }
5920
Arun Khandavallifae92942016-08-01 13:31:08 +05305921 if (!QDF_IS_STATUS_SUCCESS
5922 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5923 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005924
Arun Khandavallifae92942016-08-01 13:31:08 +05305925
5926 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927
Prashanth Bhattaab004382016-10-11 16:08:11 -07005928 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005929
5930#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305931 if (QDF_TIMER_STATE_RUNNING ==
5932 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5933 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 }
5935
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305936 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305937 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005938 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005939 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005940 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5941 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5942 hdd_ctx->last_acs_channel_list = NULL;
5943 hdd_ctx->num_of_channels = 0;
5944 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946
Arun Khandavallifae92942016-08-01 13:31:08 +05305947 mutex_lock(&hdd_ctx->iface_change_lock);
5948 driver_status = hdd_ctx->driver_status;
5949 mutex_unlock(&hdd_ctx->iface_change_lock);
5950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005951 /*
5952 * Powersave Offload Case
5953 * Disable Idle Power Save Mode
5954 */
5955 hdd_set_idle_ps_config(hdd_ctx, false);
5956
Arun Khandavallifae92942016-08-01 13:31:08 +05305957 if (driver_status != DRIVER_MODULES_CLOSED) {
5958 hdd_unregister_wext_all_adapters(hdd_ctx);
5959 /*
5960 * Cancel any outstanding scan requests. We are about to close
5961 * all of our adapters, but an adapter structure is what SME
5962 * passes back to our callback function. Hence if there
5963 * are any outstanding scan requests then there is a
5964 * race condition between when the adapter is closed and
5965 * when the callback is invoked. We try to resolve that
5966 * race condition here by canceling any outstanding scans
5967 * before we close the adapters.
5968 * Note that the scans may be cancelled in an asynchronous
5969 * manner, so ideally there needs to be some kind of
5970 * synchronization. Rather than introduce a new
5971 * synchronization here, we will utilize the fact that we are
5972 * about to Request Full Power, and since that is synchronized,
5973 * the expectation is that by the time Request Full Power has
5974 * completed, all scans will be cancelled
5975 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005976 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305977 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005978 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07005979 hdd_stop_all_adapters(hdd_ctx, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980 }
5981
5982 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305983 * Close the scheduler before calling cds_close to make sure
5984 * no thread is scheduled after the each module close is
5985 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986 */
Jeff Johnson7d562272017-09-13 15:12:54 -07005987 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305988 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305989 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305990 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005991 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305993 unregister_netdevice_notifier(&hdd_netdev_notifier);
5994
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005995 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305996
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305997 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5998 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5999 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006001 /*
6002 * Close CDS
6003 * This frees pMac(HAL) context. There should not be any call
6004 * that requires pMac access after this.
6005 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006006
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006007 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006008 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006010 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006011
6012 hdd_ipa_cleanup(hdd_ctx);
6013
6014 /* Free up RoC request queue and flush workqueue */
6015 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306017 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306018 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306019 /*
6020 * If there is re_init failure wiphy would have already de-registered
6021 * check the wiphy status before un-registering again
6022 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306023 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306024 wiphy_unregister(wiphy);
6025 wlan_hdd_cfg80211_deinit(wiphy);
6026 hdd_lpass_notify_stop(hdd_ctx);
6027 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006028
Arun Khandavallifae92942016-08-01 13:31:08 +05306029 hdd_exit_netlink_services(hdd_ctx);
6030 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306031#ifdef FEATURE_WLAN_CH_AVOID
6032 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6033#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306034
6035 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6036 if (driver_status)
6037 hdd_err("Pdev delete failed");
6038
6039 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6040 if (driver_status)
6041 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006042
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006043 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044}
6045
6046void __hdd_wlan_exit(void)
6047{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006048 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049
6050 ENTER();
6051
Anurag Chouhan6d760662016-02-20 16:05:43 +05306052 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006054 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055 EXIT();
6056 return;
6057 }
6058
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006059 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306060 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062 /* Do all the cleanup before deregistering the driver */
6063 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065 EXIT();
6066}
6067
6068#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006069/**
6070 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006071 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006072 *
6073 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6074 * Then new ACS request will do a fresh scan without reusing the cached
6075 * scan information.
6076 *
6077 * Return: void
6078 */
Tang Yingying523322d2017-01-17 23:28:43 +08006079static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006081 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006082
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006083 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006084 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006085 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6086 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6087 hdd_ctx->last_acs_channel_list = NULL;
6088 hdd_ctx->num_of_channels = 0;
6089 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090
6091 if (!hdd_ctx->hHal)
6092 return;
6093 sme_scan_flush_result(hdd_ctx->hHal);
6094}
6095#endif
6096
6097#ifdef QCA_HT_2040_COEX
6098/**
6099 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6100 * @adapter: pointer to adapter
6101 * @staId: station id
6102 * @macAddrSTA: station MAC address
6103 * @channel_type: channel type
6104 *
6105 * This function notifies FW with HT20/HT40 mode
6106 *
6107 * Return: 0 if successful, error number otherwise
6108 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006109int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306110 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111{
6112 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306113 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006114 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115
6116 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6117
6118 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306119 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006120 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 if (!hdd_ctx->hHal)
6123 return -EINVAL;
6124
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306125 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006126 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306127 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006128 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129 return -EINVAL;
6130 }
6131
6132 return 0;
6133}
6134#endif
6135
6136/**
6137 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6138 * @state: state
6139 *
6140 * This function notifies FW with modem power status
6141 *
6142 * Return: 0 if successful, error number otherwise
6143 */
6144int hdd_wlan_notify_modem_power_state(int state)
6145{
6146 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306147 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006148 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149
Anurag Chouhan6d760662016-02-20 16:05:43 +05306150 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306152 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306154
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155 if (!hdd_ctx->hHal)
6156 return -EINVAL;
6157
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306158 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6159 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006160 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161 state);
6162 return -EINVAL;
6163 }
6164 return 0;
6165}
6166
6167/**
6168 *
6169 * hdd_post_cds_enable_config() - HDD post cds start config helper
6170 * @adapter - Pointer to the HDD
6171 *
6172 * Return: None
6173 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006174QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306176 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177
6178 /*
6179 * Send ready indication to the HDD. This will kick off the MAC
6180 * into a 'running' state and should kick off an initial scan.
6181 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306182 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6183 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006184 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6185 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306186 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006187 }
6188
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306189 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190}
6191
6192/* wake lock APIs for HDD */
6193void hdd_prevent_suspend(uint32_t reason)
6194{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306195 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006196}
6197
6198void hdd_allow_suspend(uint32_t reason)
6199{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306200 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201}
6202
6203void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6204{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306205 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6206 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207}
6208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006210QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006212
Amar Singhal6f8592b2017-04-26 14:31:58 -07006213 return sme_init_chan_list(hdd_ctx->hHal,
6214 hdd_ctx->reg.alpha2,
6215 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216}
6217
6218/**
6219 * hdd_is_5g_supported() - check if hardware supports 5GHz
6220 * @hdd_ctx: Pointer to the hdd context
6221 *
6222 * HDD function to know if hardware supports 5GHz
6223 *
6224 * Return: true if hardware supports 5GHz
6225 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006226bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006228 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006229 return true;
6230
Amar Singhal58b45ef2017-08-01 13:43:54 -07006231 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006232 return true;
6233 else
6234 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235}
6236
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006237static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006238{
6239 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006240 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241
6242 wiphy = hdd_ctx->wiphy;
6243
6244 /*
6245 * The channel information in
6246 * wiphy needs to be initialized before wiphy registration
6247 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006248 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6249 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006250 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006251 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 }
6253
6254#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6255 wiphy->wowlan = &wowlan_support_reg_init;
6256#else
6257 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6258 WIPHY_WOWLAN_MAGIC_PKT |
6259 WIPHY_WOWLAN_DISCONNECT |
6260 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6261 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6262 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6263 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6264 WIPHY_WOWLAN_RFKILL_RELEASE;
6265
6266 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6267 WOW_MAX_FILTERS_PER_LIST);
6268 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6269 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6270#endif
6271
6272 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006273 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306274 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006275 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306276 return ret_val;
6277 }
6278
Amar Singhal5cccafe2017-02-15 12:42:58 -08006279 if (!hdd_ctx->reg_offload)
6280 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281
Amar Singhale4f28ee2015-10-21 14:36:56 -07006282 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283}
6284
Ravi Joshie2331e82015-07-01 18:18:54 -07006285/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006286 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006287 * @hdd_ctx - handle to hdd context
6288 * @tx_packets - transmit packet count
6289 * @rx_packets - receive packet count
6290 *
6291 * The function controls the bus bandwidth and dynamic control of
6292 * tcp delayed ack configuration
6293 *
6294 * Returns: None
6295 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006297static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006298 const uint64_t tx_packets,
6299 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006302 uint64_t temp_rx = 0;
6303 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006304 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006305 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006306 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006307 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006308 uint16_t index = 0;
6309 bool vote_level_change = false;
6310 bool rx_level_change = false;
6311 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006313 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006314 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006316 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006317 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006318 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006319 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006320 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006323 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6324 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006326 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006327 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306328 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306329 if (hdd_ctx->hbw_requested) {
6330 pld_remove_pm_qos(hdd_ctx->parent_dev);
6331 hdd_ctx->hbw_requested = false;
6332 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306333 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006334 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306335 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306336 if (!hdd_ctx->hbw_requested) {
6337 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6338 hdd_ctx->hbw_requested = true;
6339 }
6340
Nirav Shah3bbfa512016-05-12 16:43:49 +05306341 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006342 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306343 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006344 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006345 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006346
Mohit Khannaf8f96822017-05-17 17:11:59 -07006347 qdf_dp_trace_throttle_live_mode(
6348 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6349
Mohit Khannae71e2262015-11-10 09:37:24 -08006350 /* fine-tuning parameters for RX Flows */
6351 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6352
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006354
Ravi Joshifed83572016-10-07 16:20:37 -07006355 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6356 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6357 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6358 next_rx_level = WLAN_SVC_TP_HIGH;
6359 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006360 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006361 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006362 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006363 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006365 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006366 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367 next_rx_level, temp_rx);
6368 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006369 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006370 /* Send throughput indication only if it is enabled.
6371 * Disabling tcp_del_ack will revert the tcp stack behavior
6372 * to default delayed ack. Note that this will disable the
6373 * dynamic delayed ack mechanism across the system
6374 */
6375 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306376 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6377 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 &next_rx_level,
6379 sizeof(next_rx_level));
6380 }
6381
Mohit Khannae71e2262015-11-10 09:37:24 -08006382 /* fine-tuning parameters for TX Flows */
6383 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6384 hdd_ctx->prev_tx = tx_packets;
6385 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6386 next_tx_level = WLAN_SVC_TP_HIGH;
6387 else
6388 next_tx_level = WLAN_SVC_TP_LOW;
6389
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006390 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006391 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6392 next_tx_level, temp_tx);
6393 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006394 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306395 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6396 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006397 &next_tx_level,
6398 sizeof(next_tx_level));
6399 }
6400
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006401 index = hdd_ctx->hdd_txrx_hist_idx;
6402
6403 if (vote_level_change || tx_level_change || rx_level_change) {
6404 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6405 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6406 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6407 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6408 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6409 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6410 hdd_ctx->hdd_txrx_hist_idx++;
6411 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6412 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413}
6414
6415#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306416static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006418 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306419 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006420 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306421 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306422 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6423 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 uint64_t total_tx = 0, total_rx = 0;
6425 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306426 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306427 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428 bool connected = false;
6429 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6430
Prashanth Bhattaab004382016-10-11 16:08:11 -07006431 if (wlan_hdd_validate_context(hdd_ctx))
6432 return;
6433
Jingxiang Gec64e1932017-08-22 14:38:59 +08006434 if (hdd_ctx->isWiphySuspended)
6435 goto restart_timer;
6436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306438 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006439 status =
6440 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6441
6442 if (adapterNode->pAdapter == NULL)
6443 continue;
6444 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306445 /*
6446 * Validate magic so we don't end up accessing
6447 * an invalid adapter.
6448 */
6449 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6450 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006452 if ((adapter->device_mode == QDF_STA_MODE ||
6453 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6455 != eConnectionState_Associated) {
6456
6457 continue;
6458 }
6459
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006460 if ((adapter->device_mode == QDF_SAP_MODE ||
6461 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6463
6464 continue;
6465 }
6466
6467 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6468 adapter->prev_tx_packets);
6469 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6470 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306471
6472 if (adapter->device_mode == QDF_SAP_MODE ||
6473 adapter->device_mode == QDF_P2P_GO_MODE ||
6474 adapter->device_mode == QDF_IBSS_MODE) {
6475
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006476 ret = cdp_get_intra_bss_fwd_pkts_count(
6477 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306478 adapter->sessionId,
6479 &fwd_tx_packets, &fwd_rx_packets);
6480 if (ret == A_OK) {
6481 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6482 fwd_tx_packets,
6483 adapter->prev_fwd_tx_packets);
6484 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6485 fwd_tx_packets,
6486 adapter->prev_fwd_rx_packets);
6487 }
6488 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489
6490 total_rx += adapter->stats.rx_packets;
6491 total_tx += adapter->stats.tx_packets;
6492
6493 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6494 adapter->prev_tx_packets = adapter->stats.tx_packets;
6495 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306496 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6497 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6499 connected = true;
6500 }
6501
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306502 /* add intra bss forwarded tx and rx packets */
6503 tx_packets += fwd_tx_packets_diff;
6504 rx_packets += fwd_rx_packets_diff;
6505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6507 tx_packets += (uint64_t)ipa_tx_packets;
6508 rx_packets += (uint64_t)ipa_rx_packets;
6509
6510 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006511 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006512 return;
6513 }
6514
Yuanyuan Liu13738502016-04-06 17:41:37 -07006515 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516
6517 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6518 hdd_ipa_uc_stat_request(adapter, 2);
6519
Jingxiang Gec64e1932017-08-22 14:38:59 +08006520restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006521 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006522 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006523 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306524 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006525 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006526 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006527}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006528
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306529/**
6530 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6531 * @arg: Argument of timer function
6532 *
6533 * Schedule a workqueue in this function where all the processing is done.
6534 *
6535 * Return: None.
6536 */
6537static void __hdd_bus_bw_cbk(void *arg)
6538{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006539 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306540
6541 if (wlan_hdd_validate_context(hdd_ctx))
6542 return;
6543
6544 schedule_work(&hdd_ctx->bus_bw_work);
6545}
6546
6547/**
6548 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6549 * @arg: Argument of timer function
6550 *
6551 * Return: None.
6552 */
6553static void hdd_bus_bw_cbk(void *arg)
6554{
6555 cds_ssr_protect(__func__);
6556 __hdd_bus_bw_cbk(arg);
6557 cds_ssr_unprotect(__func__);
6558}
6559
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006560int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006561{
6562 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306563 INIT_WORK(&hdd_ctx->bus_bw_work,
6564 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006565 hdd_ctx->bus_bw_timer_running = false;
6566 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306567 qdf_timer_init(NULL,
6568 &hdd_ctx->bus_bw_timer,
6569 hdd_bus_bw_cbk, (void *)hdd_ctx,
6570 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006571
6572 return 0;
6573}
6574
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006575void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006576{
Dustin Brownfce08d12017-01-17 16:29:38 -08006577 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006578 hdd_reset_tcp_delack(hdd_ctx);
6579
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006580 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306581 cancel_work_sync(&hdd_ctx->bus_bw_work);
6582 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006583 hdd_ctx->bus_bw_timer_running = false;
6584 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006585}
Lin Baic5c06882017-09-21 13:58:43 +08006586
6587void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6588{
6589 if (hdd_ctx)
6590 cancel_work_sync(&hdd_ctx->bus_bw_work);
6591}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592#endif
6593
6594/**
Nirav Shahed34b212016-04-25 10:59:16 +05306595 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6596 * @hdd_ctx: hdd context
6597 *
6598 * Return: 0 for success or error code
6599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006600static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306601{
6602 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6603 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6604 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006605 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306606 return -ENOMEM;
6607 }
6608 return 0;
6609}
6610
6611/**
6612 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6613 * @hdd_ctx: hdd context
6614 *
6615 * Return: none
6616 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006617void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306618{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306619 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6620 return;
6621
6622 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6623 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306624}
6625
Nirav Shahda008342016-05-17 18:50:40 +05306626static uint8_t *convert_level_to_string(uint32_t level)
6627{
6628 switch (level) {
6629 /* initialize the wlan sub system */
6630 case WLAN_SVC_TP_NONE:
6631 return "NONE";
6632 case WLAN_SVC_TP_LOW:
6633 return "LOW";
6634 case WLAN_SVC_TP_MEDIUM:
6635 return "MED";
6636 case WLAN_SVC_TP_HIGH:
6637 return "HIGH";
6638 default:
6639 return "INVAL";
6640 }
6641}
6642
Nirav Shahed34b212016-04-25 10:59:16 +05306643
6644/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6646 * @hdd_ctx: hdd context
6647 *
6648 * Return: none
6649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006650void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006651{
6652 int i;
6653
6654#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006655 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306656 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006657 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658 hdd_ctx->config->busBandwidthHighThreshold,
6659 hdd_ctx->config->busBandwidthMediumThreshold,
6660 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006661 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306662 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006663 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006664 hdd_ctx->config->tcpDelackThresholdHigh,
6665 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006666 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306667 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668#endif
6669
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006670 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306671 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6672
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006673 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006674
6675 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006676 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006677 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006678 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006679 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6680 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006681 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006682 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6683 convert_level_to_string(
6684 hdd_ctx->hdd_txrx_hist[i].
6685 next_vote_level),
6686 convert_level_to_string(
6687 hdd_ctx->hdd_txrx_hist[i].
6688 next_rx_level),
6689 convert_level_to_string(
6690 hdd_ctx->hdd_txrx_hist[i].
6691 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006693
6694 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695}
6696
6697/**
6698 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6699 * @hdd_ctx: hdd context
6700 *
6701 * Return: none
6702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006703void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704{
6705 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306706 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6707 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006708}
6709
6710/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006711 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006712 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713 *
6714 * Return: none
6715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006716void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717{
6718
Jeff Johnson9d295242017-08-29 14:39:48 -07006719 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006720 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306721 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306723 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006724
6725 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306726 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006727 adapter = adapter_node->pAdapter;
6728
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006729 hdd_debug("Netif queue operation statistics:");
6730 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306731 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006732 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306733 curr_time = qdf_system_ticks();
6734 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306735 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306736 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306737 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306738 unpause = adapter->total_unpause_time;
6739 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306740 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306741 pause = adapter->total_pause_time;
6742 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006743 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306744 qdf_system_ticks_to_msecs(total),
6745 qdf_system_ticks_to_msecs(pause),
6746 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006747 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006748
Nirav Shahda008342016-05-17 18:50:40 +05306749 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6750 qdf_time_t pause_delta = 0;
6751
6752 if (adapter->pause_map & (1 << i))
6753 pause_delta = delta;
6754
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006755 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006756 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006757 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006758 hdd_reason_type_to_string(i),
6759 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306760 adapter->queue_oper_stats[i].unpause_count,
6761 qdf_system_ticks_to_msecs(
6762 adapter->queue_oper_stats[i].total_pause_time +
6763 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764 }
6765
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006766 hdd_debug("Netif queue operation history:");
6767 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306768 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6769
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006770 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006771
6772 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006773 /* using hdd_log to avoid printing function name */
6774 if (adapter->queue_oper_history[i].time == 0)
6775 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006776 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006777 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306778 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779 adapter->queue_oper_history[i].time),
6780 hdd_action_type_to_string(
6781 adapter->queue_oper_history[i].netif_action),
6782 hdd_reason_type_to_string(
6783 adapter->queue_oper_history[i].netif_reason),
6784 adapter->queue_oper_history[i].pause_map);
6785 }
6786
6787 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6788 adapter_node = next;
6789 }
6790
6791
6792}
6793
6794/**
6795 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6796 * @hdd_ctx: hdd context
6797 *
6798 * Return: none
6799 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006800void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006801{
Jeff Johnson9d295242017-08-29 14:39:48 -07006802 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006803 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306804 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805
6806 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306807 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006808 adapter = adapter_node->pAdapter;
6809
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306810 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306812 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306814 adapter->history_index = 0;
6815 adapter->start_time = adapter->last_time = qdf_system_ticks();
6816 adapter->total_pause_time = 0;
6817 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006818 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6819 adapter_node = next;
6820 }
6821}
6822
6823/**
6824 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6825 * @halHandle: Hal handle
6826 * @pContext: Pointer to the context
6827 * @sessionId: Session ID
6828 * @scanId: Scan ID
6829 * @status: Status
6830 *
6831 * This is the callback to be executed when 11d scan is completed to flush out
6832 * the scan results
6833 *
6834 * 11d scan is done during driver load and is a passive scan on all
6835 * channels supported by the device, 11d scans may find some APs on
6836 * frequencies which are forbidden to be used in the regulatory domain
6837 * the device is operating in. If these APs are notified to the supplicant
6838 * it may try to connect to these APs, thus flush out all the scan results
6839 * which are present in SME after 11d scan is done.
6840 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306841 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006842 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306843static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844 uint8_t sessionId, uint32_t scanId,
6845 eCsrScanStatus status)
6846{
6847 ENTER();
6848
6849 sme_scan_flush_result(halHandle);
6850
6851 EXIT();
6852
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306853 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854}
6855
6856#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6857/**
6858 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6859 * @hdd_ctx: hdd global context
6860 *
6861 * Return: none
6862 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006863static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864{
6865 uint8_t i;
6866
6867 mutex_init(&hdd_ctx->op_ctx.op_lock);
6868 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6869 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6870 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6871 }
6872}
6873#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006874static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875{
6876}
6877#endif
6878
Yingying Tang95409972016-10-20 15:16:15 +08006879#ifdef WLAN_FEATURE_WOW_PULSE
6880/**
6881 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006882 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006883 * @enable: enable or disable this behaviour
6884 *
6885 * Return: int
6886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006887static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006888{
6889 struct hdd_config *pcfg_ini = phddctx->config;
6890 struct wow_pulse_mode wow_pulse_set_info;
6891 QDF_STATUS status;
6892
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006893 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006894
6895 if (false == phddctx->config->wow_pulse_support)
6896 return 0;
6897
6898 /* prepare the request to send to SME */
6899 if (enable == true) {
6900 wow_pulse_set_info.wow_pulse_enable = true;
6901 wow_pulse_set_info.wow_pulse_pin =
6902 pcfg_ini->wow_pulse_pin;
6903 wow_pulse_set_info.wow_pulse_interval_low =
6904 pcfg_ini->wow_pulse_interval_low;
6905 wow_pulse_set_info.wow_pulse_interval_high =
6906 pcfg_ini->wow_pulse_interval_high;
6907 } else {
6908 wow_pulse_set_info.wow_pulse_enable = false;
6909 wow_pulse_set_info.wow_pulse_pin = 0;
6910 wow_pulse_set_info.wow_pulse_interval_low = 0;
6911 wow_pulse_set_info.wow_pulse_interval_high = 0;
6912 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006913 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006914 wow_pulse_set_info.wow_pulse_enable,
6915 wow_pulse_set_info.wow_pulse_pin,
6916 wow_pulse_set_info.wow_pulse_interval_low,
6917 wow_pulse_set_info.wow_pulse_interval_high);
6918
6919 status = sme_set_wow_pulse(&wow_pulse_set_info);
6920 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006921 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006922 return -EIO;
6923 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006924 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006925 return 0;
6926}
6927#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006928static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006929{
6930 return 0;
6931}
6932#endif
6933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934#ifdef WLAN_FEATURE_FASTPATH
6935/**
6936 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6937 * @hdd_cfg: hdd config
6938 * @context: lower layer context
6939 *
6940 * Return: none
6941 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306942void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006943 void *context)
6944{
6945 if (hdd_cfg->fastpath_enable)
6946 hif_enable_fastpath(context);
6947}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006948#endif
6949
Yuanyuan Liu13738502016-04-06 17:41:37 -07006950#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951/**
6952 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006953 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954 * @level: thermal level
6955 *
6956 * Change IPA data path to SW path when the thermal throttle level greater
6957 * than 0, and restore the original data path when throttle level is 0
6958 *
6959 * Return: none
6960 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006961static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006963 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965 /* Change IPA to SW path when throttle level greater than 0 */
6966 if (level > THROTTLE_LEVEL_0)
6967 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6968 else
6969 /* restore original concurrency mode */
6970 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6971}
6972
6973/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306974 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6975 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306976 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006977 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306978 * Get a safe channel to restart SAP. PCL already takes into account the
6979 * unsafe channels. So, the PCL is validated with the ACS range to provide
6980 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306982 * Return: Channel number to restart SAP in case of success. In case of any
6983 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306985static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07006986 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306988 struct sir_pcl_list pcl;
6989 QDF_STATUS status;
6990 uint32_t i, j;
6991 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006992 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306993 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306995 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6996 if (!hdd_ctx) {
6997 hdd_err("invalid HDD context");
6998 return INVALID_CHANNEL_ID;
6999 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307001 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7002 if (!hal_handle) {
7003 hdd_err("invalid HAL handle");
7004 return INVALID_CHANNEL_ID;
7005 }
7006
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007007 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7008 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007009 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7010 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307011 if (QDF_IS_STATUS_ERROR(status)) {
7012 hdd_err("Get PCL failed");
7013 return INVALID_CHANNEL_ID;
7014 }
7015
Frank Liudc2cefb2017-06-21 15:38:18 +08007016 /*
7017 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7018 * channel is unsafe channel, the pcl may be empty, instead of return,
7019 * try to choose a safe channel from acs range.
7020 */
7021 if (!pcl.pcl_len)
7022 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307023
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007024 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307025 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7026 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7027
7028 /* PCL already takes unsafe channel into account */
7029 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007030 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307031 if ((pcl.pcl_list[i] >=
7032 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7033 (pcl.pcl_list[i] <=
7034 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007035 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307036 return pcl.pcl_list[i];
7037 }
7038 }
7039
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007040 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307041
7042 /* Try for safe channel from all valid channel */
7043 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007044 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307045 &pcl.pcl_len);
7046 if (QDF_IS_STATUS_ERROR(status)) {
7047 hdd_err("error in getting valid channel list");
7048 return INVALID_CHANNEL_ID;
7049 }
7050
7051 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007052 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307053 found = false;
7054 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007055 if (pcl.pcl_list[i] ==
7056 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007057 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307058 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007059 break;
7060 }
7061 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307062
7063 if (found)
7064 continue;
7065
7066 if ((pcl.pcl_list[i] >=
7067 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7068 (pcl.pcl_list[i] <=
7069 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007070 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307071 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007072 }
7073 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307074
7075 return INVALID_CHANNEL_ID;
7076}
7077
7078/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007079 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307080 * @adapter: AP adapter
7081 * @channel: Channel
7082 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007083 * Moves the SAP interface by invoking the function which
7084 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307085 *
7086 * Return: None
7087 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007088void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307089{
Jeff Johnson87251032017-08-29 13:31:11 -07007090 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007092 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307093
7094 if (!adapter) {
7095 hdd_err("invalid adapter");
7096 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007097 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307098
7099 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7100
7101 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7102 if (!hal_handle) {
7103 hdd_err("invalid HAL handle");
7104 return;
7105 }
7106
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007107 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7108
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307109 hdd_ap_ctx->sapConfig.channel = channel;
7110 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7111 hdd_ap_ctx->sapConfig.ch_width_orig;
7112
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007113 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307114 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7115
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007116 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7117 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307118 hdd_ap_ctx->sapConfig.sec_ch,
7119 &hdd_ap_ctx->sapConfig.ch_params);
7120
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007121 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7122 adapter->sessionId, channel,
7123 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307125
Jeff Johnson9d295242017-08-29 14:39:48 -07007126int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307127{
7128 struct hdd_external_acs_timer_context *timer_context;
7129
7130 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7131
7132 if (QDF_TIMER_STATE_RUNNING ==
7133 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7134 ap.vendor_acs_timer)) {
7135 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7136 }
7137 timer_context = (struct hdd_external_acs_timer_context *)
7138 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7139 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307140 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307141 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307142 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7143 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307144 hdd_notice("Updated ACS config to nl with reason %d", reason);
7145
7146 return 0;
7147}
7148
Agrawal Ashish467dde42016-09-08 18:44:22 +05307149/**
7150 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7151 * @hdd_ctx: hdd context pointer
7152 *
7153 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7154 * and if ACS is enabled, driver will ask userspace to restart the
7155 * sap. User space on LTE coex indication restart driver.
7156 *
7157 * Return - none
7158 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007159void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307160{
7161 QDF_STATUS status;
7162 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007163 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307164 uint32_t i;
7165 bool found = false;
7166 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007167
Agrawal Ashish467dde42016-09-08 18:44:22 +05307168 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7169 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7170 adapter_temp = adapter_node->pAdapter;
7171
7172 if (!adapter_temp) {
7173 hdd_err("adapter is NULL, moving to next one");
7174 goto next_adapater;
7175 }
7176
7177 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7178 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007179 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307180 adapter_temp->device_mode,
7181 adapter_temp->sessionCtx.ap.sapConfig.
7182 acs_cfg.acs_mode);
7183 goto next_adapater;
7184 }
7185
7186 found = false;
7187 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007188 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307189 hdd_ctxt->unsafe_channel_list[i]) {
7190 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007191 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307192 adapter_temp->sessionCtx.ap.operatingChannel);
7193 break;
7194 }
7195 }
7196
7197 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007198 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307199 adapter_temp->sessionCtx.ap.operatingChannel);
7200 goto next_adapater;
7201 }
7202
Kapil Gupta8878ad92017-02-13 11:56:04 +05307203 if (hdd_ctxt->config->vendor_acs_support &&
7204 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7205 hdd_update_acs_timer_reason(adapter_temp,
7206 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7207 goto next_adapater;
7208 } else
7209 restart_chan =
7210 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307211 adapter_temp);
7212 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007213 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307214 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007215 /*
7216 * SAP restart due to unsafe channel. While
7217 * restarting the SAP, make sure to clear
7218 * acs_channel, channel to reset to
7219 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307220 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007221 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307222 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7223 adapter_temp->sessionCtx.ap.sapConfig.channel =
7224 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007225 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307226 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7227 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007228 hdd_debug("driver to start sap: %d",
7229 hdd_ctxt->config->sap_internal_restart);
7230 if (hdd_ctxt->config->sap_internal_restart)
7231 hdd_switch_sap_channel(adapter_temp, restart_chan);
7232 else
7233 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307234 }
7235
7236next_adapater:
7237 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7238 adapter_node = next;
7239 }
7240}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307241
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007242/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007243 * hdd_init_channel_avoidance() - Initialize channel avoidance
7244 * @hdd_ctx: HDD global context
7245 *
7246 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007247 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248 * down to the lower layers. Then subscribe to subsequent channel
7249 * avoidance events.
7250 *
7251 * Return: None
7252 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007253static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007254{
7255 uint16_t unsafe_channel_count;
7256 int index;
7257
Yuanyuan Liu13738502016-04-06 17:41:37 -07007258 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7259 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007260 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007261 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007263 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007264 hdd_ctx->unsafe_channel_count);
7265
Anurag Chouhan6d760662016-02-20 16:05:43 +05307266 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007267 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268
7269 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007270 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271 hdd_ctx->unsafe_channel_list[index]);
7272
7273 }
7274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007275}
Dustin Brown676a2322017-08-15 13:16:13 -07007276
Jeff Johnson9d295242017-08-29 14:39:48 -07007277static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007278 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007279{
7280 uint8_t restart_chan;
7281
7282 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7283 if (!restart_chan) {
7284 hdd_alert("fail to restart SAP");
7285 return;
7286 }
7287
7288 /* SAP restart due to unsafe channel. While restarting
7289 * the SAP, make sure to clear acs_channel, channel to
7290 * reset to 0. Otherwise these settings will override
7291 * the ACS while restart.
7292 */
7293 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7294 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7295
7296 hdd_debug("sending coex indication");
7297
7298 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7299 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7300 hdd_switch_sap_channel(adapter, restart_chan);
7301}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007302
7303int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7304 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7305{
7306 uint32_t size;
7307 uint16_t *unsafe_list;
7308 uint16_t chan_count;
7309
7310 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7311 return -EINVAL;
7312
7313 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7314 NUM_CHANNELS);
7315 if (chan_count) {
7316 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7317 unsafe_list = qdf_mem_malloc(size);
7318 if (!unsafe_list) {
7319 hdd_err("No memory for unsafe chan list size%d",
7320 size);
7321 return -ENOMEM;
7322 }
7323 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7324 } else {
7325 unsafe_list = NULL;
7326 }
7327
7328 *local_unsafe_list = unsafe_list;
7329 *local_unsafe_list_count = chan_count;
7330
7331 return 0;
7332}
7333
7334bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7335 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7336{
7337 int i, j;
7338
7339 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7340 return true;
7341 if (local_unsafe_list_count == 0)
7342 return false;
7343 for (i = 0; i < local_unsafe_list_count; i++) {
7344 for (j = 0; j < local_unsafe_list_count; j++)
7345 if (local_unsafe_list[i] ==
7346 hdd_ctx->unsafe_channel_list[j])
7347 break;
7348 if (j >= local_unsafe_list_count)
7349 break;
7350 }
7351 if (i >= local_unsafe_list_count) {
7352 hdd_info("unsafe chan list same");
7353 return false;
7354 }
7355
7356 return true;
7357}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007358#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007359static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007360{
7361}
Dustin Brown676a2322017-08-15 13:16:13 -07007362
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007363static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007364{
7365}
Dustin Brown676a2322017-08-15 13:16:13 -07007366
Jeff Johnson9d295242017-08-29 14:39:48 -07007367static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007368 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007369{
7370 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7371}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007372#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007373
7374/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007375 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7376 * user space
7377 * @frame_ind: Management frame data to be informed.
7378 *
7379 * This function is used to indicate management frame to
7380 * user space
7381 *
7382 * Return: None
7383 *
7384 */
7385void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7386{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007387 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007388 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007389 int i;
7390
Rajeev Kumard004abc2016-02-17 12:09:56 -08007391 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007392 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007393
7394 if (0 != wlan_hdd_validate_context(hdd_ctx))
7395 return;
7396
7397 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7398 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7399 adapter =
7400 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7401 if (adapter)
7402 break;
7403 }
7404 } else {
7405 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7406 frame_ind->sessionId);
7407 }
7408
7409 if ((NULL != adapter) &&
7410 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7411 __hdd_indicate_mgmt_frame(adapter,
7412 frame_ind->frame_len,
7413 frame_ind->frameBuf,
7414 frame_ind->frameType,
7415 frame_ind->rxChan,
7416 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007417}
7418
Kapil Gupta8878ad92017-02-13 11:56:04 +05307419void hdd_acs_response_timeout_handler(void *context)
7420{
7421 struct hdd_external_acs_timer_context *timer_context =
7422 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007423 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007424 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307425 uint8_t reason;
7426
7427 ENTER();
7428 if (!timer_context) {
7429 hdd_err("invlaid timer context");
7430 return;
7431 }
7432 adapter = timer_context->adapter;
7433 reason = timer_context->reason;
7434
7435
7436 if ((!adapter) ||
7437 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7438 hdd_err("invalid adapter or adapter has invalid magic");
7439 return;
7440 }
7441 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7442 if (wlan_hdd_validate_context(hdd_ctx))
7443 return;
7444
7445 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7446 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7447 else
7448 return;
7449
7450 hdd_err("ACS timeout happened for %s reason %d",
7451 adapter->dev->name, reason);
7452 switch (reason) {
7453 /* SAP init case */
7454 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7455 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7456 false);
7457 wlan_hdd_cfg80211_start_acs(adapter);
7458 break;
7459 /* DFS detected on current channel */
7460 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7461 wlan_sap_update_next_channel(
7462 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7463 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7464 adapter->sessionId);
7465 break;
7466 /* LTE coex event on current channel */
7467 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7468 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7469 break;
7470 default:
7471 hdd_info("invalid reason for timer invoke");
7472
7473 }
7474}
7475
Rajeev Kumard004abc2016-02-17 12:09:56 -08007476/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7478 * @hdd_ctx: HDD context
7479 *
7480 * Disables all the dual mac features like DBS, Agile DFS etc.
7481 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307482 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007484static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007485{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007486 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307487 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007488
7489 if (!hdd_ctx) {
7490 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307491 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492 }
7493
7494 cfg.scan_config = 0;
7495 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007496 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497
7498 hdd_debug("Disabling all dual mac features...");
7499
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007500 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307501 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007502 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7503 return status;
7504 }
7505
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307506 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007507}
7508
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007509static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007510wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007511{
7512 struct policy_mgr_dual_mac_config cfg = {0};
7513 QDF_STATUS status;
7514
7515 if (!hdd_ctx) {
7516 hdd_err("HDD context is NULL");
7517 return QDF_STATUS_E_FAILURE;
7518 }
7519
7520 cfg.scan_config = 0;
7521 cfg.fw_mode_config = 0;
7522 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7523 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7524 hdd_ctx->hdd_psoc, &cfg.scan_config,
7525 &cfg.fw_mode_config,
7526 hdd_ctx->config->dual_mac_feature_disable);
7527
7528 if (status != QDF_STATUS_SUCCESS) {
7529 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7530 status);
7531 return status;
7532 }
7533
7534 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7535 cfg.scan_config, cfg.fw_mode_config);
7536
7537 status = sme_soc_set_dual_mac_config(cfg);
7538 if (status != QDF_STATUS_SUCCESS) {
7539 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7540 return status;
7541 }
7542
7543 return QDF_STATUS_SUCCESS;
7544}
7545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007547 * hdd_override_ini_config - Override INI config
7548 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007549 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007550 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007552 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007554static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007555{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007556
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007557 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7558 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007559 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007560 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007562 if (0 == enable_11d || 1 == enable_11d) {
7563 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007564 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565 }
Leo Chang11545d62016-10-17 14:53:50 -07007566
7567 if (!hdd_ipa_is_present(hdd_ctx))
7568 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007569}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007571/**
7572 * hdd_set_trace_level_for_each - Set trace level for each INI config
7573 * @hdd_ctx - HDD context
7574 *
7575 * Set trace level for each module based on INI config.
7576 *
7577 * Return: None
7578 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007579static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007580{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307581 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7582 hdd_ctx->config->qdf_trace_enable_wdi);
7583 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7584 hdd_ctx->config->qdf_trace_enable_hdd);
7585 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7586 hdd_ctx->config->qdf_trace_enable_sme);
7587 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7588 hdd_ctx->config->qdf_trace_enable_pe);
7589 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7590 hdd_ctx->config->qdf_trace_enable_wma);
7591 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7592 hdd_ctx->config->qdf_trace_enable_sys);
7593 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7594 hdd_ctx->config->qdf_trace_enable_qdf);
7595 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7596 hdd_ctx->config->qdf_trace_enable_sap);
7597 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7598 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7599 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7600 hdd_ctx->config->qdf_trace_enable_bmi);
7601 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7602 hdd_ctx->config->qdf_trace_enable_cfg);
7603 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7604 hdd_ctx->config->qdf_trace_enable_epping);
7605 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7606 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7607 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007608 hdd_ctx->config->qdf_trace_enable_txrx);
7609 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7610 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307611 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7612 hdd_ctx->config->qdf_trace_enable_htc);
7613 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7614 hdd_ctx->config->qdf_trace_enable_hif);
7615 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7616 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7617 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7618 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007619 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7620 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007621 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7622 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007623 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7624 hdd_ctx->config->qdf_trace_enable_regulatory);
7625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007627}
7628
7629/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007630 * hdd_context_init() - Initialize HDD context
7631 * @hdd_ctx: HDD context.
7632 *
7633 * Initialize HDD context along with all the feature specific contexts.
7634 *
7635 * return: 0 on success and errno on failure.
7636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007637static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007638{
7639 int ret;
7640
7641 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7642 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7643
7644 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307645 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007646
7647 init_completion(&hdd_ctx->mc_sus_event_var);
7648 init_completion(&hdd_ctx->ready_to_suspend);
7649
7650 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307651 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007652 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307653
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007654 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7655
7656 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7657
7658 ret = hdd_scan_context_init(hdd_ctx);
7659 if (ret)
7660 goto list_destroy;
7661
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007662 hdd_rx_wake_lock_create(hdd_ctx);
7663
7664 ret = hdd_sap_context_init(hdd_ctx);
7665 if (ret)
7666 goto scan_destroy;
7667
7668 ret = hdd_roc_context_init(hdd_ctx);
7669 if (ret)
7670 goto sap_destroy;
7671
7672 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7673
7674 hdd_init_offloaded_packets_ctx(hdd_ctx);
7675
7676 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7677 hdd_ctx->config);
7678 if (ret)
7679 goto roc_destroy;
7680
7681 return 0;
7682
7683roc_destroy:
7684 hdd_roc_context_destroy(hdd_ctx);
7685
7686sap_destroy:
7687 hdd_sap_context_destroy(hdd_ctx);
7688
7689scan_destroy:
7690 hdd_scan_context_destroy(hdd_ctx);
7691 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007692list_destroy:
7693 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007694
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007695 return ret;
7696}
7697
7698/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307699 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7700 * @hdd_ctx: pointer to hdd context
7701 *
7702 * Return: status of initialization
7703 * 0 - success
7704 * negative value - failure
7705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007706static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307707{
7708 int ret;
7709
7710 if (!hdd_ctx->config->probe_req_ie_whitelist)
7711 return 0;
7712
7713 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7714 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7715 hdd_ctx->config->probe_req_ie_whitelist = false;
7716 return -EINVAL;
7717 }
7718
7719 /* parse ini string probe req oui */
7720 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7721 if (ret) {
7722 hdd_err("parsing error: disable ie whitelisting");
7723 hdd_ctx->config->probe_req_ie_whitelist = false;
7724 }
7725
7726 return ret;
7727}
7728
7729/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007730 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307731 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007732 *
7733 * Allocate and initialize HDD context. HDD context is allocated as part of
7734 * wiphy allocation and then context is initialized.
7735 *
7736 * Return: HDD context on success and ERR_PTR on failure
7737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007738static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007739{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307740 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007741 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007742 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007743
7744 ENTER();
7745
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007746 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007747 if (hdd_ctx == NULL) {
7748 ret = -ENOMEM;
7749 goto err_out;
7750 }
7751
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007752 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307753 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007754
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307755 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007756 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007757 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007758 ret = -ENOMEM;
7759 goto err_free_hdd_context;
7760 }
7761
7762 /* Read and parse the qcom_cfg.ini file */
7763 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307764 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307765 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007766 WLAN_INI_FILE);
7767 ret = -EINVAL;
7768 goto err_free_config;
7769 }
7770
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307771 ie_whitelist_attrs_init(hdd_ctx);
7772
Dustin Brown7f939932017-05-18 15:02:17 -07007773 hdd_debug("setting timer multiplier: %u",
7774 hdd_ctx->config->timer_multiplier);
7775 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7776
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007777
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307778 if (hdd_ctx->config->fhostNSOffload)
7779 hdd_ctx->ns_offload_enable = true;
7780
Abhishek Singh5ea86532016-04-27 14:10:53 +05307781 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7782
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007783 hdd_override_ini_config(hdd_ctx);
7784
Jeff Johnson3543fb22017-09-24 13:44:13 -07007785 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007786
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007787 ret = hdd_context_init(hdd_ctx);
7788
7789 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007790 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007791
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007792 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307793 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007794
Anurag Chouhan6d760662016-02-20 16:05:43 +05307795 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007796 goto skip_multicast_logging;
7797
7798 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7799
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007800 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7801 if (ret)
7802 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307803
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007804 ret = hdd_init_netlink_services(hdd_ctx);
7805 if (ret)
7806 goto err_deinit_txrx_histogram;
7807
Dustin Brown7b3dea22017-07-10 13:02:47 -07007808 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7809 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307810
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007811skip_multicast_logging:
7812 hdd_set_trace_level_for_each(hdd_ctx);
7813
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007814 EXIT();
7815
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007816 return hdd_ctx;
7817
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007818err_deinit_txrx_histogram:
7819 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7820
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007821err_deinit_hdd_context:
7822 hdd_context_deinit(hdd_ctx);
7823
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007824err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307825 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826
7827err_free_hdd_context:
7828 wiphy_free(hdd_ctx->wiphy);
7829
7830err_out:
7831 return ERR_PTR(ret);
7832}
7833
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007834#ifdef WLAN_OPEN_P2P_INTERFACE
7835/**
7836 * hdd_open_p2p_interface - Open P2P interface
7837 * @hdd_ctx: HDD context
7838 * @rtnl_held: True if RTNL lock held
7839 *
7840 * Open P2P interface during probe. This function called to open the P2P
7841 * interface at probe along with STA interface.
7842 *
7843 * Return: 0 on success and errno on failure
7844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007845static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007846{
Jeff Johnson9d295242017-08-29 14:39:48 -07007847 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007848 uint8_t *p2p_dev_addr;
7849
7850 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7851 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307852 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007853 hdd_ctx->config->intfMacAddr[0].bytes,
7854 sizeof(tSirMacAddr));
7855
7856 /*
7857 * Generate the P2P Device Address. This consists of
7858 * the device's primary MAC address with the locally
7859 * administered bit set.
7860 */
7861 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7862 } else {
7863 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7864 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007865 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007866 return -ENOSPC;
7867 }
7868
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307869 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307870 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007871 }
7872
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007873 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007874 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007875 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007876
7877 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007878 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007879 return -ENOSPC;
7880 }
7881
7882 return 0;
7883}
7884#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007885static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007886 bool rtnl_held)
7887{
7888 return 0;
7889}
7890#endif
7891
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007892static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007893{
Jeff Johnson9d295242017-08-29 14:39:48 -07007894 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007895 int ret = 0;
7896
7897 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7898 wlan_hdd_get_intf_addr(hdd_ctx),
7899 NET_NAME_UNKNOWN, rtnl_held);
7900 if (adapter == NULL) {
7901 hdd_err("Failed to open 802.11p interface");
7902 ret = -ENOSPC;
7903 }
7904
7905 return ret;
7906}
7907
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007908/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307909 * hdd_start_station_adapter()- Start the Station Adapter
7910 * @adapter: HDD adapter
7911 *
7912 * This function initializes the adapter for the station mode.
7913 *
7914 * Return: 0 on success or errno on failure.
7915 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007916int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307917{
7918 QDF_STATUS status;
7919
7920 ENTER_DEV(adapter->dev);
7921
7922 status = hdd_init_station_mode(adapter);
7923
7924 if (QDF_STATUS_SUCCESS != status) {
7925 hdd_err("Error Initializing station mode: %d", status);
7926 return qdf_status_to_os_return(status);
7927 }
7928
Arun Khandavallifae92942016-08-01 13:31:08 +05307929 hdd_register_tx_flow_control(adapter,
7930 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007931 hdd_tx_resume_cb,
7932 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307933
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307934 EXIT();
7935 return 0;
7936}
7937
7938/**
7939 * hdd_start_ap_adapter()- Start AP Adapter
7940 * @adapter: HDD adapter
7941 *
7942 * This function initializes the adapter for the AP mode.
7943 *
7944 * Return: 0 on success errno on failure.
7945 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007946int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307947{
7948 QDF_STATUS status;
7949
7950 ENTER();
7951
Arun Khandavallicc544b32017-01-30 19:52:16 +05307952 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307953
7954 if (QDF_STATUS_SUCCESS != status) {
7955 hdd_err("Error Initializing the AP mode: %d", status);
7956 return qdf_status_to_os_return(status);
7957 }
7958
Arun Khandavallifae92942016-08-01 13:31:08 +05307959 hdd_register_tx_flow_control(adapter,
7960 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007961 hdd_softap_tx_resume_cb,
7962 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307963
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307964 EXIT();
7965 return 0;
7966}
7967
7968/**
7969 * hdd_start_ftm_adapter()- Start FTM adapter
7970 * @adapter: HDD adapter
7971 *
7972 * This function initializes the adapter for the FTM mode.
7973 *
7974 * Return: 0 on success or errno on failure.
7975 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007976int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307977{
7978 QDF_STATUS qdf_status;
7979
7980 ENTER_DEV(adapter->dev);
7981
7982 qdf_status = hdd_init_tx_rx(adapter);
7983
7984 if (QDF_STATUS_SUCCESS != qdf_status) {
7985 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7986 return qdf_status_to_os_return(qdf_status);
7987 }
7988
7989 return 0;
7990 EXIT();
7991}
7992
7993/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007994 * hdd_open_interfaces - Open all required interfaces
7995 * hdd_ctx: HDD context
7996 * rtnl_held: True if RTNL lock is held
7997 *
7998 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7999 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008000 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008001 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008002static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008003{
Jeff Johnson9d295242017-08-29 14:39:48 -07008004 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008005 int ret;
8006
Ravi Joshia307f632017-07-17 23:41:41 -07008007 /* open monitor mode adapter if con_mode is monitor mode */
8008 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8009 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8010 wlan_hdd_get_intf_addr(hdd_ctx),
8011 NET_NAME_UNKNOWN, rtnl_held);
8012 if (!adapter) {
8013 hdd_err("open adapter failed");
8014 return -ENOSPC;
8015 }
8016 return 0;
8017 }
8018
Jeff Johnson957bc272017-02-02 08:54:48 -08008019 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308020 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008021 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008022
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008023 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008024 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008025 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008026
8027 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008028 return -ENOSPC;
8029
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008030 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8031 adapter->fast_roaming_allowed = true;
8032
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008033 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8034 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008035 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008036
8037 /* Open 802.11p Interface */
8038 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008039 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8040 if (ret)
8041 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008042 }
8043
Jeff Johnson957bc272017-02-02 08:54:48 -08008044 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008045
Jeff Johnson957bc272017-02-02 08:54:48 -08008046err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008047 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008048 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008049}
8050
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008051/**
8052 * hdd_update_country_code - Update country code
8053 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008054 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008055 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008056 *
8057 * Return: 0 on success and errno on failure
8058 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008059static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008060{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008061 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008062 return 0;
8063
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008064 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008065}
8066
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308067#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8068/**
8069 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8070 * @cds_cfg: CDS Configuration
8071 * @hdd_ctx: Pointer to hdd context
8072 *
8073 * Return: none
8074 */
8075static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8076 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008077 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308078{
8079 cds_cfg->tx_flow_stop_queue_th =
8080 hdd_ctx->config->TxFlowStopQueueThreshold;
8081 cds_cfg->tx_flow_start_queue_offset =
8082 hdd_ctx->config->TxFlowStartQueueOffset;
8083}
8084#else
8085static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8086 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008087 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308088{
8089}
8090#endif
8091
8092#ifdef FEATURE_WLAN_RA_FILTERING
8093/**
8094 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8095 * @cds_cfg: CDS Configuration
8096 * @hdd_ctx: Pointer to hdd context
8097 *
8098 * Return: none
8099 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308100static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008101 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308102{
8103 cds_cfg->ra_ratelimit_interval =
8104 hdd_ctx->config->RArateLimitInterval;
8105 cds_cfg->is_ra_ratelimit_enabled =
8106 hdd_ctx->config->IsRArateLimitEnabled;
8107}
8108#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308109static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008110 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308111{
8112}
8113#endif
8114
8115/**
8116 * hdd_update_cds_config() - API to update cds configuration parameters
8117 * @hdd_ctx: HDD Context
8118 *
8119 * Return: 0 for Success, errno on failure
8120 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008121static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308122{
8123 struct cds_config_info *cds_cfg;
8124
8125 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8126 if (!cds_cfg) {
8127 hdd_err("failed to allocate cds config");
8128 return -ENOMEM;
8129 }
8130
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008131 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008132 if (!hdd_ctx->config->nMaxPsPoll ||
8133 !hdd_ctx->config->enablePowersaveOffload) {
8134 cds_cfg->powersave_offload_enabled =
8135 hdd_ctx->config->enablePowersaveOffload;
8136 } else {
8137 if ((hdd_ctx->config->enablePowersaveOffload ==
8138 PS_QPOWER_NODEEPSLEEP) ||
8139 (hdd_ctx->config->enablePowersaveOffload ==
8140 PS_LEGACY_NODEEPSLEEP))
8141 cds_cfg->powersave_offload_enabled =
8142 PS_LEGACY_NODEEPSLEEP;
8143 else
8144 cds_cfg->powersave_offload_enabled =
8145 PS_LEGACY_DEEPSLEEP;
8146 hdd_info("Qpower disabled in cds config, %d",
8147 cds_cfg->powersave_offload_enabled);
8148 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308149 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8150 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8151 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8152 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8153 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8154
8155 /* Here ol_ini_info is used to store ini status of arp offload
8156 * ns offload and others. Currently 1st bit is used for arp
8157 * off load and 2nd bit for ns offload currently, rest bits are unused
8158 */
8159 if (hdd_ctx->config->fhostArpOffload)
8160 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8161 if (hdd_ctx->config->fhostNSOffload)
8162 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8163
8164 /*
8165 * Copy the DFS Phyerr Filtering Offload status.
8166 * This parameter reflects the value of the
8167 * dfs_phyerr_filter_offload flag as set in the ini.
8168 */
8169 cds_cfg->dfs_phyerr_filter_offload =
8170 hdd_ctx->config->fDfsPhyerrFilterOffload;
8171 if (hdd_ctx->config->ssdp)
8172 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8173
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308174 cds_cfg->force_target_assert_enabled =
8175 hdd_ctx->config->crash_inject_enabled;
8176
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308177 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8178 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8179
8180 cds_cfg->ap_maxoffload_reorderbuffs =
8181 hdd_ctx->config->apMaxOffloadReorderBuffs;
8182
8183 cds_cfg->ap_disable_intrabss_fwd =
8184 hdd_ctx->config->apDisableIntraBssFwd;
8185
8186 cds_cfg->dfs_pri_multiplier =
8187 hdd_ctx->config->dfsRadarPriMultiplier;
8188 cds_cfg->reorder_offload =
8189 hdd_ctx->config->reorderOffloadSupport;
8190
8191 /* IPA micro controller data path offload resource config item */
8192 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008193 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8194 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008195 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008196 hdd_ctx->config->IpaUcTxBufCount);
8197 hdd_ctx->config->IpaUcTxBufCount =
8198 rounddown_pow_of_two(
8199 hdd_ctx->config->IpaUcTxBufCount);
8200 if (!hdd_ctx->config->IpaUcTxBufCount) {
8201 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308202 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008203 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008204 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008205 hdd_ctx->config->IpaUcTxBufCount);
8206 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308207 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8208 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008209 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8210 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008211 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008212 hdd_ctx->config->IpaUcRxIndRingCount);
8213 hdd_ctx->config->IpaUcRxIndRingCount =
8214 rounddown_pow_of_two(
8215 hdd_ctx->config->IpaUcRxIndRingCount);
8216 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8217 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308218 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008219 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008220 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008221 hdd_ctx->config->IpaUcRxIndRingCount);
8222 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308223 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008224 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308225 cds_cfg->uc_tx_partition_base =
8226 hdd_ctx->config->IpaUcTxPartitionBase;
8227 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8228
8229 cds_cfg->ip_tcp_udp_checksum_offload =
8230 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308231 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308232 cds_cfg->ce_classify_enabled =
8233 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008234 cds_cfg->bpf_packet_filter_enable =
8235 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308236 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8237 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8238 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008239 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008240 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008241 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008242 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308243 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8244 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308245 cds_cfg->auto_power_save_fail_mode =
8246 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308247
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308248 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8249
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308250 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8251 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8252 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008253 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308254 cds_init_ini_config(cds_cfg);
8255 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308256
8257exit:
8258 qdf_mem_free(cds_cfg);
8259 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308260}
8261
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008262/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008263 * hdd_update_user_config() - API to update user configuration
8264 * parameters to obj mgr which are used by multiple components
8265 * @hdd_ctx: HDD Context
8266 *
8267 * Return: 0 for Success, errno on failure
8268 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008269static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008270{
8271 struct wlan_objmgr_psoc_user_config *user_config;
8272
8273 user_config = qdf_mem_malloc(sizeof(*user_config));
8274 if (user_config == NULL) {
8275 hdd_alert("Failed to alloc memory for user_config!");
8276 return -ENOMEM;
8277 }
8278
8279 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8280 user_config->dual_mac_feature_disable =
8281 hdd_ctx->config->dual_mac_feature_disable;
8282 user_config->indoor_channel_support =
8283 hdd_ctx->config->indoor_channel_support;
8284 user_config->is_11d_support_enabled =
8285 hdd_ctx->config->Is11dSupportEnabled;
8286 user_config->is_11h_support_enabled =
8287 hdd_ctx->config->Is11hSupportEnabled;
8288 user_config->optimize_chan_avoid_event =
8289 hdd_ctx->config->goptimize_chan_avoid_event;
8290 user_config->skip_dfs_chnl_in_p2p_search =
8291 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008292 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008293 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8294
8295 qdf_mem_free(user_config);
8296 return 0;
8297}
8298
8299/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008300 * hdd_init_thermal_info - Initialize thermal level
8301 * @hdd_ctx: HDD context
8302 *
8303 * Initialize thermal level at SME layer and set the thermal level callback
8304 * which would be called when a configured thermal threshold is hit.
8305 *
8306 * Return: 0 on success and errno on failure
8307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008308static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008309{
8310 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308311 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008312
8313 thermal_param.smeThermalMgmtEnabled =
8314 hdd_ctx->config->thermalMitigationEnable;
8315 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8316
Poddar, Siddarth83905022016-04-16 17:56:08 -07008317 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8318 hdd_ctx->config->throttle_dutycycle_level0;
8319 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8320 hdd_ctx->config->throttle_dutycycle_level1;
8321 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8322 hdd_ctx->config->throttle_dutycycle_level2;
8323 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8324 hdd_ctx->config->throttle_dutycycle_level3;
8325
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008326 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8327 hdd_ctx->config->thermalTempMinLevel0;
8328 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8329 hdd_ctx->config->thermalTempMaxLevel0;
8330 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8331 hdd_ctx->config->thermalTempMinLevel1;
8332 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8333 hdd_ctx->config->thermalTempMaxLevel1;
8334 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8335 hdd_ctx->config->thermalTempMinLevel2;
8336 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8337 hdd_ctx->config->thermalTempMaxLevel2;
8338 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8339 hdd_ctx->config->thermalTempMinLevel3;
8340 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8341 hdd_ctx->config->thermalTempMaxLevel3;
8342
8343 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8344
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308345 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308346 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008347
8348 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8349 hdd_set_thermal_level_cb);
8350
8351 return 0;
8352
8353}
8354
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008355#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8356/**
8357 * hdd_hold_rtnl_lock - Hold RTNL lock
8358 *
8359 * Hold RTNL lock
8360 *
8361 * Return: True if held and false otherwise
8362 */
8363static inline bool hdd_hold_rtnl_lock(void)
8364{
8365 rtnl_lock();
8366 return true;
8367}
8368
8369/**
8370 * hdd_release_rtnl_lock - Release RTNL lock
8371 *
8372 * Release RTNL lock
8373 *
8374 * Return: None
8375 */
8376static inline void hdd_release_rtnl_lock(void)
8377{
8378 rtnl_unlock();
8379}
8380#else
8381static inline bool hdd_hold_rtnl_lock(void) { return false; }
8382static inline void hdd_release_rtnl_lock(void) { }
8383#endif
8384
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008385#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008386
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308387/* MAX iwpriv command support */
8388#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308389#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308390#define MAX_PKTLOG_SIZE 16
8391
8392/**
8393 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8394 * @hdd_ctx: hdd context
8395 * @set_value2: pktlog buffer size value
8396 *
8397 *
8398 * Return: 0 for success or error.
8399 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008400static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308401{
8402 struct sir_wifi_start_log start_log = { 0 };
8403 QDF_STATUS status;
8404
8405 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8406 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8407 start_log.ini_triggered = cds_is_packet_log_enabled();
8408 start_log.user_triggered = 1;
8409 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308410 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308411
8412 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8413 if (!QDF_IS_STATUS_SUCCESS(status)) {
8414 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8415 EXIT();
8416 return -EINVAL;
8417 }
8418
8419 return 0;
8420}
8421
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008422/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308423 * hdd_pktlog_clear_buff() - clear pktlog buffer
8424 * @hdd_ctx: hdd context
8425 *
8426 * Return: 0 for success or error.
8427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008428static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308429{
8430 struct sir_wifi_start_log start_log;
8431 QDF_STATUS status;
8432
8433 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8434 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8435 start_log.ini_triggered = cds_is_packet_log_enabled();
8436 start_log.user_triggered = 1;
8437 start_log.size = 0;
8438 start_log.is_pktlog_buff_clear = true;
8439
8440 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8441 if (!QDF_IS_STATUS_SUCCESS(status)) {
8442 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8443 EXIT();
8444 return -EINVAL;
8445 }
8446
8447 return 0;
8448}
8449
8450
8451/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008452 * hdd_process_pktlog_command() - process pktlog command
8453 * @hdd_ctx: hdd context
8454 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308455 * @set_value2: pktlog buffer size value
8456 *
8457 * This function process pktlog command.
8458 * set_value2 only matters when set_value is 3 (set buff size)
8459 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008460 *
8461 * Return: 0 for success or error.
8462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008463int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308464 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008465{
8466 int ret;
8467 bool enable;
8468 uint8_t user_triggered = 0;
8469
8470 ret = wlan_hdd_validate_context(hdd_ctx);
8471 if (0 != ret)
8472 return ret;
8473
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008474 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008475
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308476 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008477 hdd_err("invalid pktlog value %d", set_value);
8478 return -EINVAL;
8479 }
8480
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308481 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8482 if (set_value2 <= 0) {
8483 hdd_err("invalid pktlog size %d", set_value2);
8484 return -EINVAL;
8485 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8486 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8487 return -EINVAL;
8488 }
8489 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308490 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8491 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308492 }
8493
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008494 /*
8495 * set_value = 0 then disable packetlog
8496 * set_value = 1 enable packetlog forcefully
8497 * set_vlaue = 2 then disable packetlog if disabled through ini or
8498 * enable packetlog with AUTO type.
8499 */
8500 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8501 true : false;
8502
8503 if (1 == set_value) {
8504 enable = true;
8505 user_triggered = 1;
8506 }
8507
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308508 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008509}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008510/**
8511 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8512 * @hdd_ctx: HDD context
8513 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308514 * @user_triggered: triggered through iwpriv
8515 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008516 *
8517 * Return: 0 on success; error number otherwise
8518 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008519int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308520 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008521{
8522 struct sir_wifi_start_log start_log;
8523 QDF_STATUS status;
8524
8525 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8526 start_log.verbose_level =
8527 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008528 start_log.ini_triggered = cds_is_packet_log_enabled();
8529 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308530 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308531 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308532 /*
8533 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8534 * commands. Host uses this flag to decide whether to send pktlog
8535 * disable command to fw without sending pktlog enable command
8536 * previously. For eg, If vendor sends pktlog disable command without
8537 * sending pktlog enable command, then host discards the packet
8538 * but for iwpriv command, host will send it to fw.
8539 */
8540 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008541 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8542 if (!QDF_IS_STATUS_SUCCESS(status)) {
8543 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8544 EXIT();
8545 return -EINVAL;
8546 }
8547
8548 return 0;
8549}
8550#endif /* REMOVE_PKT_LOG */
8551
Komal Seelam92fff912016-03-24 11:51:41 +05308552/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008553 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8554 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308555 * @dev: Device Pointer
8556 * @num: Number of Valid Mac address
8557 *
8558 * Return: Pointer to MAC address buffer
8559 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008560static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8561 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308562{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008563 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308564}
Komal Seelam92fff912016-03-24 11:51:41 +05308565
8566/**
8567 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8568 * @hdd_ctx: HDD Context
8569 * @num: Number of random mac addresses needed
8570 *
8571 * Generate random addresses using bit manipulation on the base mac address
8572 *
8573 * Return: None
8574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008575void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308576{
8577 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8578 uint32_t iter;
8579 struct hdd_config *ini = hdd_ctx->config;
8580 uint8_t *buf = NULL;
8581 uint8_t macaddr_b3, tmp_br3;
8582 uint8_t *src = ini->intfMacAddr[0].bytes;
8583
8584 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8585 buf = ini->intfMacAddr[iter].bytes;
8586 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8587 macaddr_b3 = buf[3];
8588 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8589 INTF_MACADDR_MASK;
8590 macaddr_b3 += tmp_br3;
8591 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8592 buf[0] |= 0x02;
8593 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008594 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308595 }
8596}
8597
8598/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008599 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308600 * @hdd_ctx: HDD Context
8601 *
8602 * API to get mac addresses from platform driver and update the driver
8603 * structures and configure FW with the base mac address.
8604 * Return: int
8605 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008606static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308607{
8608 uint32_t no_of_mac_addr, iter;
8609 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8610 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8611 uint8_t *addr, *buf;
8612 struct device *dev = hdd_ctx->parent_dev;
8613 struct hdd_config *ini = hdd_ctx->config;
8614 tSirMacAddr mac_addr;
8615 QDF_STATUS status;
8616
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008617 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308618
8619 if (no_of_mac_addr == 0 || !addr) {
8620 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8621 return -EINVAL;
8622 }
8623
8624 if (no_of_mac_addr > max_mac_addr)
8625 no_of_mac_addr = max_mac_addr;
8626
8627 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8628
8629 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8630 buf = ini->intfMacAddr[iter].bytes;
8631 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008632 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308633 }
8634
8635 status = sme_set_custom_mac_addr(mac_addr);
8636
8637 if (!QDF_IS_STATUS_SUCCESS(status))
8638 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008639
Komal Seelam92fff912016-03-24 11:51:41 +05308640 if (no_of_mac_addr < max_mac_addr)
8641 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8642 no_of_mac_addr);
8643 return 0;
8644}
8645
8646/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008647 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8648 * @hdd_ctx: HDD Context
8649 *
8650 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8651 * will generate its own MAC and update it to FW.
8652 *
8653 * Return: 0 for success
8654 * Non-zero error code for failure
8655 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008656static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008657{
8658 tSirMacAddr customMacAddr;
8659 QDF_STATUS status;
8660
8661 qdf_mem_copy(&customMacAddr,
8662 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8663 sizeof(tSirMacAddr));
8664 status = sme_set_custom_mac_addr(customMacAddr);
8665 if (!QDF_IS_STATUS_SUCCESS(status))
8666 return -EAGAIN;
8667 return 0;
8668}
8669
8670/**
Komal Seelam92fff912016-03-24 11:51:41 +05308671 * hdd_initialize_mac_address() - API to get wlan mac addresses
8672 * @hdd_ctx: HDD Context
8673 *
8674 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8675 * is provisioned with mac addresses, driver uses it, else it will use
8676 * wlan_mac.bin to update HW MAC addresses.
8677 *
8678 * Return: None
8679 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008680static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308681{
8682 QDF_STATUS status;
8683 int ret;
8684
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008685 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308686 if (ret == 0)
8687 return;
8688
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008689 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8690 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308691
8692 status = hdd_update_mac_config(hdd_ctx);
8693
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008694 if (QDF_IS_STATUS_SUCCESS(status))
8695 return;
8696
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008697 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8698 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008699
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008700 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008701 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008702 if (ret != 0) {
8703 hdd_err("MAC address out-of-sync, ret:%d", ret);
8704 QDF_ASSERT(ret);
8705 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008706 }
Komal Seelam92fff912016-03-24 11:51:41 +05308707}
8708
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008709static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008710{
8711 int vdev_id = 0;
8712 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8713 int value = hdd_ctx->config->smart_chainmask_enabled;
8714 int vpdev = PDEV_CMD;
8715 int ret;
8716
Naveen Rawat247a8682017-06-05 15:00:31 -07008717 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008718 if (ret)
8719 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8720
8721 return ret;
8722}
8723
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008724static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008725{
8726 int vdev_id = 0;
8727 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8728 int value = hdd_ctx->config->alternative_chainmask_enabled;
8729 int vpdev = PDEV_CMD;
8730 int ret;
8731
Naveen Rawat247a8682017-06-05 15:00:31 -07008732 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008733 if (ret)
8734 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8735 ret);
8736
8737 return ret;
8738}
8739
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008740static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008741{
8742 int vdev_id = 0;
8743 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8744 int value = hdd_ctx->config->ani_enabled;
8745 int vpdev = PDEV_CMD;
8746 int ret;
8747
Naveen Rawat247a8682017-06-05 15:00:31 -07008748 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008749 if (ret)
8750 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8751
8752 return ret;
8753}
8754
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008755/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008756 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8757 * @hdd_ctx: HDD context
8758 *
8759 * Pre configurations to be done at lower layer before calling cds enable.
8760 *
8761 * Return: 0 on success and errno on failure.
8762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008763static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008764{
8765 int ret;
8766 QDF_STATUS status;
8767 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008768 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008769
Leo Changfdb45c32016-10-28 11:09:23 -07008770 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008771 /*
8772 * Set 802.11p config
8773 * TODO-OCB: This has been temporarily added here to ensure this
8774 * parameter is set in CSR when we init the channel list. This should
8775 * be removed once the 5.9 GHz channels are added to the regulatory
8776 * domain.
8777 */
8778 hdd_set_dot11p_config(hdd_ctx);
8779
8780 /*
8781 * Note that the cds_pre_enable() sequence triggers the cfg download.
8782 * The cfg download must occur before we update the SME config
8783 * since the SME config operation must access the cfg database
8784 */
8785 status = hdd_set_sme_config(hdd_ctx);
8786
8787 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008788 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008789 ret = qdf_status_to_os_return(status);
8790 goto out;
8791 }
8792
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008793 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8794 if (QDF_STATUS_SUCCESS != status) {
8795 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8796 ret = qdf_status_to_os_return(status);
8797 goto out;
8798 }
8799
Naveen Rawat247a8682017-06-05 15:00:31 -07008800 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008801 hdd_ctx->config->tx_chain_mask_1ss,
8802 PDEV_CMD);
8803 if (0 != ret) {
8804 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8805 goto out;
8806 }
8807
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008808 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8809 if (ret)
8810 goto out;
8811
8812 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8813 if (ret)
8814 goto out;
8815
Jeff Johnson12a744b2017-04-04 08:19:37 -07008816 ret = hdd_set_ani_enabled(hdd_ctx);
8817 if (ret)
8818 goto out;
8819
Naveen Rawat247a8682017-06-05 15:00:31 -07008820 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008821 hdd_ctx->config->arp_ac_category,
8822 PDEV_CMD);
8823 if (0 != ret) {
8824 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8825 hdd_ctx->config->arp_ac_category, ret);
8826 goto out;
8827 }
8828
8829
Prashanth Bhatta07998752016-04-28 12:35:33 -07008830 status = hdd_set_sme_chan_list(hdd_ctx);
8831 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008832 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008833 ret = qdf_status_to_os_return(status);
8834 goto out;
8835 }
8836
8837 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008838 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008839 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008840 ret = -EINVAL;
8841 goto out;
8842 }
8843
Prashanth Bhatta07998752016-04-28 12:35:33 -07008844 /*
8845 * Set the MAC Address Currently this is used by HAL to add self sta.
8846 * Remove this once self sta is added as part of session open.
8847 */
8848 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8849 hdd_ctx->config->intfMacAddr[0].bytes,
8850 sizeof(hdd_ctx->config->intfMacAddr[0]));
8851
8852 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8853 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8854 hal_status, hal_status);
8855 ret = -EINVAL;
8856 goto out;
8857 }
8858
8859 hdd_init_channel_avoidance(hdd_ctx);
8860
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308861 /* update enable sap mandatory chan list */
8862 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8863 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008864out:
8865 return ret;
8866}
8867
8868/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008869 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8870 * @context_ptr - hdd context pointer
8871 * @event_ptr - event structure pointer
8872 *
8873 * This is the p2p listen offload stop event handler, it sends vendor
8874 * event back to supplicant to notify the stop reason.
8875 *
8876 * Return: None
8877 */
8878static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8879 void *event_ptr)
8880{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008881 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008882 struct sir_p2p_lo_event *evt = event_ptr;
8883 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008884 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008885
8886 ENTER();
8887
8888 if (hdd_ctx == NULL) {
8889 hdd_err("Invalid HDD context pointer");
8890 return;
8891 }
8892
Peng Xu5c682812017-08-06 07:39:13 -07008893 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8894 if (!adapter) {
8895 hdd_err("Cannot find adapter by vdev_id = %d",
8896 evt->vdev_id);
8897 return;
8898 }
8899
Peng Xu8fdaa492016-06-22 10:20:47 -07008900 vendor_event =
8901 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008902 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008903 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8904 GFP_KERNEL);
8905
8906 if (!vendor_event) {
8907 hdd_err("cfg80211_vendor_event_alloc failed");
8908 return;
8909 }
8910
8911 if (nla_put_u32(vendor_event,
8912 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8913 evt->reason_code)) {
8914 hdd_err("nla put failed");
8915 kfree_skb(vendor_event);
8916 return;
8917 }
8918
8919 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008920 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8921 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008922}
8923
8924/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308925 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8926 * @hdd_ctx: HDD context
8927 *
8928 * This function sends the adaptive dwell time config configuration to the
8929 * firmware via WMA
8930 *
8931 * Return: 0 - success, < 0 - failure
8932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008933static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308934{
8935 QDF_STATUS status;
8936 struct adaptive_dwelltime_params dwelltime_params;
8937
8938 dwelltime_params.is_enabled =
8939 hdd_ctx->config->adaptive_dwell_mode_enabled;
8940 dwelltime_params.dwelltime_mode =
8941 hdd_ctx->config->global_adapt_dwelltime_mode;
8942 dwelltime_params.lpf_weight =
8943 hdd_ctx->config->adapt_dwell_lpf_weight;
8944 dwelltime_params.passive_mon_intval =
8945 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8946 dwelltime_params.wifi_act_threshold =
8947 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8948
8949 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8950 &dwelltime_params);
8951
8952 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8953 if (!QDF_IS_STATUS_SUCCESS(status)) {
8954 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8955 return -EAGAIN;
8956 }
8957 return 0;
8958}
8959
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008960int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308961{
8962 QDF_STATUS status;
8963 struct wmi_dbs_scan_sel_params dbs_scan_params;
8964 uint32_t i = 0;
8965 uint8_t count = 0, numentries = 0;
8966 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8967 * CDS_DBS_SCAN_CLIENTS_MAX];
8968
8969 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008970 if (hdd_ctx->config->dual_mac_feature_disable ==
8971 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308972 return -EINVAL;
8973
8974 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8975 dbs_scan_config, &numentries,
8976 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8977 * CDS_DBS_SCAN_CLIENTS_MAX));
8978
8979 hdd_info("numentries %hu", numentries);
8980 if (!numentries) {
8981 hdd_info("Donot send scan_selection_config");
8982 return 0;
8983 }
8984
8985 /* hdd_set_fw_log_params */
8986 dbs_scan_params.num_clients = 0;
8987 while (count < (numentries - 2)) {
8988 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8989 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8990 dbs_scan_params.num_non_dbs_scans[i] =
8991 dbs_scan_config[count + 2];
8992 dbs_scan_params.num_clients++;
8993 hdd_debug("module:%d NDS:%d NNDS:%d",
8994 dbs_scan_params.module_id[i],
8995 dbs_scan_params.num_dbs_scans[i],
8996 dbs_scan_params.num_non_dbs_scans[i]);
8997 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8998 i++;
8999 }
9000
9001 dbs_scan_params.pdev_id = 0;
9002
9003 hdd_debug("clients:%d pdev:%d",
9004 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9005
9006 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9007 &dbs_scan_params);
9008 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9009 if (!QDF_IS_STATUS_SUCCESS(status)) {
9010 hdd_err("Failed to send DBS Scan selection configuration!");
9011 return -EAGAIN;
9012 }
9013 return 0;
9014}
9015
Arun Khandavallid4349a92016-07-25 11:10:43 +05309016#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9017/**
9018 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9019 * @hdd_ctx: HDD context
9020 *
9021 * Set auto shutdown callback to get indications from firmware to indicate
9022 * userspace to shutdown WLAN after a configured amount of inactivity.
9023 *
9024 * Return: 0 on success and errno on failure.
9025 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009026static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309027{
9028 QDF_STATUS status;
9029
9030 if (!hdd_ctx->config->WlanAutoShutdown)
9031 return 0;
9032
9033 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9034 wlan_hdd_auto_shutdown_cb);
9035 if (status != QDF_STATUS_SUCCESS)
9036 hdd_err("Auto shutdown feature could not be enabled: %d",
9037 status);
9038
9039 return qdf_status_to_os_return(status);
9040}
9041#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009042static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309043{
9044 return 0;
9045}
9046#endif
9047
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009048static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009049{
9050 QDF_STATUS status = QDF_STATUS_SUCCESS;
9051
9052 switch (hdd_ctx->config->dual_mac_feature_disable) {
9053 case DISABLE_DBS_CXN_AND_SCAN:
9054 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9055 if (status != QDF_STATUS_SUCCESS)
9056 hdd_err("Failed to disable dual mac features");
9057 break;
9058 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9059 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9060 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9061 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9062 if (status != QDF_STATUS_SUCCESS)
9063 hdd_err("Failed to set dbs scan and fw mode config");
9064 break;
9065 default:
9066 break;
9067 }
9068
9069 return status;
9070}
9071
Arun Khandavallid4349a92016-07-25 11:10:43 +05309072/**
9073 * hdd_features_init() - Init features
9074 * @hdd_ctx: HDD context
9075 * @adapter: Primary adapter context
9076 *
9077 * Initialize features and their feature context after WLAN firmware is up.
9078 *
9079 * Return: 0 on success and errno on failure.
9080 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009081static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309082{
9083 tSirTxPowerLimit hddtxlimit;
9084 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309085 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309086 int ret;
9087
9088 ENTER();
9089
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009090 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309091 if (ret) {
9092 hdd_err("Failed to update country code: %d", ret);
9093 goto out;
9094 }
9095
9096 /* FW capabilities received, Set the Dot11 mode */
9097 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009098 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9099 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309100
Arun Khandavallid4349a92016-07-25 11:10:43 +05309101
9102 if (hdd_ctx->config->fIsImpsEnabled)
9103 hdd_set_idle_ps_config(hdd_ctx, true);
9104 else
9105 hdd_set_idle_ps_config(hdd_ctx, false);
9106
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309107 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009108 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309109
Arun Khandavallid4349a92016-07-25 11:10:43 +05309110 if (hdd_lro_init(hdd_ctx))
9111 hdd_err("Unable to initialize LRO in fw");
9112
9113 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9114 hdd_err("Unable to send adaptive dwelltime setting to FW");
9115
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309116 if (hdd_dbs_scan_selection_init(hdd_ctx))
9117 hdd_err("Unable to send DBS scan selection setting to FW");
9118
Arun Khandavallid4349a92016-07-25 11:10:43 +05309119 ret = hdd_init_thermal_info(hdd_ctx);
9120 if (ret) {
9121 hdd_err("Error while initializing thermal information");
9122 goto deregister_frames;
9123 }
9124
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309125 if (cds_is_packet_log_enabled())
9126 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9127
Arun Khandavallid4349a92016-07-25 11:10:43 +05309128 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9129 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9130 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9131 if (!QDF_IS_STATUS_SUCCESS(status))
9132 hdd_err("Error setting txlimit in sme: %d", status);
9133
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009134 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309135
Arun Khandavallid4349a92016-07-25 11:10:43 +05309136 ret = hdd_register_cb(hdd_ctx);
9137 if (ret) {
9138 hdd_err("Failed to register HDD callbacks!");
9139 goto deregister_frames;
9140 }
9141
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009142 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9143 if (!QDF_IS_STATUS_SUCCESS(status)) {
9144 hdd_err("Failed to set dbs scan and fw mode cfg");
9145 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309146 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009147
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309148 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9149 status = sme_enable_disable_chanavoidind_event(
9150 hdd_ctx->hHal, 0);
9151 if (!QDF_IS_STATUS_SUCCESS(status)) {
9152 hdd_err("Failed to disable Chan Avoidance Indication");
9153 goto deregister_cb;
9154 }
9155 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309156
Manjeet Singha9cae432017-02-28 11:58:22 +05309157 if (hdd_ctx->config->enable_5g_band_pref) {
9158 band_pref_params.rssi_boost_threshold_5g =
9159 hdd_ctx->config->rssi_boost_threshold_5g;
9160 band_pref_params.rssi_boost_factor_5g =
9161 hdd_ctx->config->rssi_boost_factor_5g;
9162 band_pref_params.max_rssi_boost_5g =
9163 hdd_ctx->config->max_rssi_boost_5g;
9164 band_pref_params.rssi_penalize_threshold_5g =
9165 hdd_ctx->config->rssi_penalize_threshold_5g;
9166 band_pref_params.rssi_penalize_factor_5g =
9167 hdd_ctx->config->rssi_penalize_factor_5g;
9168 band_pref_params.max_rssi_penalize_5g =
9169 hdd_ctx->config->max_rssi_penalize_5g;
9170 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9171 }
9172
Arun Khandavallid4349a92016-07-25 11:10:43 +05309173 /* register P2P Listen Offload event callback */
9174 if (wma_is_p2p_lo_capable())
9175 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9176 wlan_hdd_p2p_lo_event_callback);
9177
9178 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9179
9180 if (ret)
9181 goto deregister_cb;
9182
9183 EXIT();
9184 return 0;
9185
9186deregister_cb:
9187 hdd_deregister_cb(hdd_ctx);
9188deregister_frames:
9189 wlan_hdd_cfg80211_deregister_frames(adapter);
9190out:
9191 return -EINVAL;
9192
9193}
9194
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009195/**
9196 * hdd_features_deinit() - Deinit features
9197 * @hdd_ctx: HDD context
9198 *
9199 * De-Initialize features and their feature context.
9200 *
9201 * Return: none.
9202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009203static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009204{
9205 wlan_hdd_tsf_deinit(hdd_ctx);
9206}
9207
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309208/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009209 * hdd_register_bcn_cb() - register scan beacon callback
9210 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309211 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009212 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309213 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009214static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309215{
9216 QDF_STATUS status;
9217
9218 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9219 wlan_cfg80211_inform_bss_frame,
9220 SCAN_CB_TYPE_INFORM_BCN);
9221 if (!QDF_IS_STATUS_SUCCESS(status)) {
9222 hdd_err("failed with status code %08d [x%08x]",
9223 status, status);
9224 return status;
9225 }
9226
9227 return QDF_STATUS_SUCCESS;
9228}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309229
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309230/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309231 * hdd_configure_cds() - Configure cds modules
9232 * @hdd_ctx: HDD context
9233 * @adapter: Primary adapter context
9234 *
9235 * Enable Cds modules after WLAN firmware is up.
9236 *
9237 * Return: 0 on success and errno on failure.
9238 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009239int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309240{
9241 int ret;
9242 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309243
9244 ret = hdd_pre_enable_configure(hdd_ctx);
9245 if (ret) {
9246 hdd_err("Failed to pre-configure cds");
9247 goto out;
9248 }
9249
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009250 /* Always get latest IPA resources allocated from cds_open and configure
9251 * IPA module before configuring them to FW. Sequence required as crash
9252 * observed otherwise.
9253 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009254 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9255 hdd_err("Failed to setup pipes");
9256 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009257 }
9258
Arun Khandavallifae92942016-08-01 13:31:08 +05309259 /*
9260 * Start CDS which starts up the SME/MAC/HAL modules and everything
9261 * else
9262 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009263 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309264
9265 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009266 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309267 goto out;
9268 }
9269
9270 status = hdd_post_cds_enable_config(hdd_ctx);
9271 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009272 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009273 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309274 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309275 status = hdd_register_bcn_cb(hdd_ctx);
9276 if (!QDF_IS_STATUS_SUCCESS(status)) {
9277 hdd_alert("hdd_post_cds_enable_config failed");
9278 goto cds_disable;
9279 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309280
9281 ret = hdd_features_init(hdd_ctx, adapter);
9282 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009283 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309284
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309285 if (hdd_enable_egap(hdd_ctx))
9286 hdd_debug("enhance green ap is not enabled");
9287
Nachiket Kukadedd302662017-07-13 17:31:44 +05309288 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9289 hdd_debug("Failed to set wow pulse");
9290
Arun Khandavallifae92942016-08-01 13:31:08 +05309291 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009292
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009293cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009294 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009295
Arun Khandavallifae92942016-08-01 13:31:08 +05309296out:
9297 return -EINVAL;
9298}
9299
9300/**
9301 * hdd_deconfigure_cds() -De-Configure cds
9302 * @hdd_ctx: HDD context
9303 *
9304 * Deconfigure Cds modules before WLAN firmware is down.
9305 *
9306 * Return: 0 on success and errno on failure.
9307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009308static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309309{
9310 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009311 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309312
9313 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009314
9315 /* De-init features */
9316 hdd_features_deinit(hdd_ctx);
9317
Arun Khandavallifae92942016-08-01 13:31:08 +05309318 /* De-register the SME callbacks */
9319 hdd_deregister_cb(hdd_ctx);
9320
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009321 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309322 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9323 hdd_err("Failed to Disable the CDS Modules! :%d",
9324 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009325 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309326 }
9327
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309328 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9329 hdd_err("Failed to disconnect pipes");
9330 ret = -EINVAL;
9331 }
9332
Arun Khandavallifae92942016-08-01 13:31:08 +05309333 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009334 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309335}
9336
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009337#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9338static void hdd_deregister_policy_manager_callback(
9339 struct wlan_objmgr_psoc *psoc)
9340{
9341 if (QDF_STATUS_SUCCESS !=
9342 policy_mgr_deregister_hdd_cb(psoc)) {
9343 hdd_err("HDD callback deregister with policy manager failed");
9344 }
9345}
9346#else
9347static void hdd_deregister_policy_manager_callback(
9348 struct wlan_objmgr_psoc *psoc)
9349{
9350}
9351#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309352
9353/**
9354 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9355 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009356 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309357 *
9358 * This function maintains the driver state machine it will be invoked from
9359 * exit, shutdown and con_mode change handler. Depending on the driver state
9360 * shall perform the stopping/closing of the modules.
9361 *
9362 * Return: 0 for success; non-zero for failure
9363 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009364int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309365{
9366 void *hif_ctx;
9367 qdf_device_t qdf_ctx;
9368 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309369 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009370 bool is_idle_stop = !cds_is_driver_unloading() &&
9371 !cds_is_driver_recovering();
9372 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309373
9374 ENTER();
9375
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009376 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9377
Arun Khandavallifae92942016-08-01 13:31:08 +05309378 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9379 if (!qdf_ctx) {
9380 hdd_err("QDF device context NULL");
9381 return -EINVAL;
9382 }
9383
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309384 mutex_lock(&hdd_ctx->iface_change_lock);
9385 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309386
Dustin Brown70111822017-03-30 15:31:40 -07009387 active_threads = cds_return_external_threads_count();
9388 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009389 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009390 active_threads, hdd_ctx->isWiphySuspended);
9391
9392 cds_print_external_threads();
9393
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009394 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009395 mutex_unlock(&hdd_ctx->iface_change_lock);
9396 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009397 hdd_ctx->config->iface_change_wait_time);
9398 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009399 return 0;
9400 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009401 }
9402
Arun Khandavallifae92942016-08-01 13:31:08 +05309403 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9404
9405 switch (hdd_ctx->driver_status) {
9406 case DRIVER_MODULES_UNINITIALIZED:
9407 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309408 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309409 case DRIVER_MODULES_CLOSED:
9410 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309411 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309412 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309413 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309414 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009415 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309416 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309417 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309418 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009419 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309420 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9421 break;
9422 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009423 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309424 break;
9425 default:
9426 hdd_err("Trying to stop wlan in a wrong state: %d",
9427 hdd_ctx->driver_status);
9428 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309429 ret = -EINVAL;
9430 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309431 }
9432
Rajeev Kumarbe021242017-02-16 16:12:23 -08009433 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309434 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9435 hdd_err("Failed to process post CDS disable Modules! :%d",
9436 qdf_status);
9437 ret = -EINVAL;
9438 QDF_ASSERT(0);
9439 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009440 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309441 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009442 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309443 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309444 QDF_ASSERT(0);
9445 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009446
Arun Khandavallifae92942016-08-01 13:31:08 +05309447 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9448 if (!hif_ctx) {
9449 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309450 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309451 }
9452
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309453 hdd_runtime_suspend_context_deinit(hdd_ctx);
9454
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309455 if (hdd_ctx->target_hw_name) {
9456 qdf_mem_free(hdd_ctx->target_hw_name);
9457 hdd_ctx->target_hw_name = NULL;
9458 }
9459
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309460 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309461
9462 ol_cds_free();
9463
Dustin Brown70111822017-03-30 15:31:40 -07009464 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309465 ret = pld_power_off(qdf_ctx->dev);
9466 if (ret)
9467 hdd_err("CNSS power down failed put device into Low power mode:%d",
9468 ret);
9469 }
9470 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009471 /*
9472 * Reset total mac phy during module stop such that during
9473 * next module start same psoc is used to populate new service
9474 * ready data
9475 */
9476 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309477
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309478done:
9479 hdd_ctx->stop_modules_in_progress = false;
9480 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309481 EXIT();
9482
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309483 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309484
9485}
9486
9487/**
9488 * hdd_iface_change_callback() - Function invoked when stop modules expires
9489 * @priv: pointer to hdd context
9490 *
9491 * This function is invoked when the timer waiting for the interface change
9492 * expires, it shall cut-down the power to wlan and stop all the modules.
9493 *
9494 * Return: void
9495 */
9496static void hdd_iface_change_callback(void *priv)
9497{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009498 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309499 int ret;
9500 int status = wlan_hdd_validate_context(hdd_ctx);
9501
9502 if (status)
9503 return;
9504
9505 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009506 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009507 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309508 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009509 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309510 EXIT();
9511}
9512
9513/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309514 * hdd_state_info_dump() - prints state information of hdd layer
9515 * @buf: buffer pointer
9516 * @size: size of buffer to be filled
9517 *
9518 * This function is used to dump state information of hdd layer
9519 *
9520 * Return: None
9521 */
9522static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9523{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009524 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309525 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9526 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009527 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009528 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309529 uint16_t len = 0;
9530 char *buf = *buf_ptr;
9531
9532 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9533 if (!hdd_ctx) {
9534 hdd_err("Failed to get hdd context ");
9535 return;
9536 }
9537
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009538 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309539
9540 len += scnprintf(buf + len, *size - len,
9541 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9542 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009543 "\n is_scheduler_suspended %d",
9544 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309545
9546 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9547
9548 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9549 adapter = adapter_node->pAdapter;
9550 if (adapter->dev)
9551 len += scnprintf(buf + len, *size - len,
9552 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009553 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309554 "\n device_mode: %d", adapter->device_mode);
9555 switch (adapter->device_mode) {
9556 case QDF_STA_MODE:
9557 case QDF_P2P_CLIENT_MODE:
9558 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9559 len += scnprintf(buf + len, *size - len,
9560 "\n connState: %d",
9561 hdd_sta_ctx->conn_info.connState);
9562 break;
9563
9564 default:
9565 break;
9566 }
9567 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9568 adapter_node = next;
9569 }
9570
9571 *size -= len;
9572 *buf_ptr += len;
9573}
9574
9575/**
9576 * hdd_register_debug_callback() - registration function for hdd layer
9577 * to print hdd state information
9578 *
9579 * Return: None
9580 */
9581static void hdd_register_debug_callback(void)
9582{
9583 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9584}
9585
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309586/*
9587 * wlan_init_bug_report_lock() - Initialize bug report lock
9588 *
9589 * This function is used to create bug report lock
9590 *
9591 * Return: None
9592 */
9593static void wlan_init_bug_report_lock(void)
9594{
9595 p_cds_contextType p_cds_context;
9596
9597 p_cds_context = cds_get_global_context();
9598 if (!p_cds_context) {
9599 hdd_err("cds context is NULL");
9600 return;
9601 }
9602
9603 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9604}
9605
Mohit Khannaf8f96822017-05-17 17:11:59 -07009606void hdd_dp_trace_init(struct hdd_config *config)
9607{
9608
9609 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9610 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9611 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9612 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9613 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9614 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9615 uint8_t num_entries = 0;
9616
9617 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9618 &num_entries, sizeof(config_params));
9619
9620 /* calculating, num bw timer intervals in a second (1000ms) */
9621 if (config->busBandwidthComputeInterval)
9622 thresh_time_limit =
9623 (1000 / config->busBandwidthComputeInterval);
9624 else
9625 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9626
9627 switch (num_entries) {
9628 case 4:
9629 proto_bitmap = config_params[3];
9630 case 3:
9631 verbosity = config_params[2];
9632 case 2:
9633 thresh = config_params[1];
9634 case 1:
9635 live_mode = config_params[0];
9636 default:
9637 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9638 live_mode, thresh, thresh_time_limit,
9639 verbosity, proto_bitmap);
9640 };
9641
9642 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9643 verbosity, proto_bitmap);
9644
9645}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309646/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009647 * hdd_wlan_startup() - HDD init function
9648 * @dev: Pointer to the underlying device
9649 *
9650 * This is the driver startup code executed once a WLAN device has been detected
9651 *
9652 * Return: 0 for success, < 0 for failure
9653 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309654int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009655{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309656 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009657 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009658 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009659 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309660 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009661 uint32_t num_abg_tx_chains = 0;
9662 uint32_t num_11b_tx_chains = 0;
9663 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009664
9665 ENTER();
9666
Arun Khandavallifae92942016-08-01 13:31:08 +05309667 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009668
9669 if (IS_ERR(hdd_ctx))
9670 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009671
Abhishek Singhe9068f12017-03-31 14:14:52 +05309672 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9673 DEFAULT_PSOC_ID);
9674 if (ret) {
9675 hdd_err("Psoc creation fails!");
9676 QDF_BUG(0);
9677 goto err_hdd_free_context;
9678 }
9679
Arun Khandavallifae92942016-08-01 13:31:08 +05309680 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9681 hdd_iface_change_callback, (void *)hdd_ctx);
9682
9683 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309684#ifdef FEATURE_WLAN_CH_AVOID
9685 mutex_init(&hdd_ctx->avoid_freq_lock);
9686#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309687
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009688 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009689 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309690
Jeff Johnson957bc272017-02-02 08:54:48 -08009691 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309692 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009693 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009694 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009695 }
9696
Yingying Tang80e15f32016-09-27 18:23:01 +08009697 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009698
Anurag Chouhan6d760662016-02-20 16:05:43 +05309699 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009700
9701 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009702 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309703 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009704 }
9705
Prashanth Bhatta07998752016-04-28 12:35:33 -07009706 ret = hdd_wiphy_init(hdd_ctx);
9707 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009708 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309709 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009710 }
9711
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309712 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009713 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309714
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309715 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009716 goto err_wiphy_unregister;
9717
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309718 wlan_hdd_init_chan_info(hdd_ctx);
9719
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009720 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009721
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309722 ret = hdd_register_notifiers(hdd_ctx);
9723 if (ret)
9724 goto err_ipa_cleanup;
9725
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009726 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009727
Jeff Johnson957bc272017-02-02 08:54:48 -08009728 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9729 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009730 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009731 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009732 }
9733
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009734 hdd_release_rtnl_lock();
9735 rtnl_held = false;
9736
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009737 wlan_hdd_update_11n_mode(hdd_ctx->config);
9738
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009739#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309740 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309741 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009742 hdd_skip_acs_scan_timer_handler,
9743 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309744 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009745 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009746 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009747#endif
9748
Prashanth Bhattaab004382016-10-11 16:08:11 -07009749 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009750
Jeff Johnson9afc5012016-09-23 13:56:27 -07009751 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009752
Nirav Shahbd36b062016-07-18 11:12:59 +05309753 if (hdd_ctx->rps)
9754 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009755
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309756 status = wlansap_global_init();
9757 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009758 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009759
Komal Seelam8634b772016-09-29 12:12:24 +05309760 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009761 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309762 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009763
Arun Khandavallifae92942016-08-01 13:31:08 +05309764 if (hdd_ctx->config->fIsImpsEnabled)
9765 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309766
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309767 if (hdd_ctx->config->sifs_burst_duration) {
9768 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9769 hdd_ctx->config->sifs_burst_duration;
9770
9771 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009772 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309773 set_value, PDEV_CMD);
9774 }
9775
Paul Zhang42dade02017-05-12 19:20:37 +08009776 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009777 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009778 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309779 /* set chip power save failure detected callback */
9780 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9781 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009782
lifeng959a04c2017-05-10 14:21:28 +08009783 if (hdd_ctx->config->max_mpdus_inampdu) {
9784 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009785 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009786 set_value, PDEV_CMD);
9787 }
9788
9789 if (hdd_ctx->config->enable_rts_sifsbursting) {
9790 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009791 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009792 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9793 set_value, PDEV_CMD);
9794 }
9795
Will Huang496b36c2017-07-11 16:38:50 +08009796 if (hdd_ctx->config->sap_get_peer_info) {
9797 set_value = hdd_ctx->config->sap_get_peer_info;
9798 sme_cli_set_command(0,
9799 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9800 set_value, PDEV_CMD);
9801 }
9802
Naveen Rawat247a8682017-06-05 15:00:31 -07009803 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9804 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9805 if (!hdd_ctx->config->enable2x2) {
9806 if (num_11b_tx_chains > 1)
9807 num_11b_tx_chains = 1;
9808 if (num_11ag_tx_chains > 1)
9809 num_11ag_tx_chains = 1;
9810 }
9811 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9812 num_11b_tx_chains);
9813 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9814 num_11ag_tx_chains);
9815 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9816 num_abg_tx_chains, PDEV_CMD);
9817
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309818 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9819 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309820 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309821
Sachin Ahujadddd2632017-03-07 19:07:24 +05309822 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009823 goto success;
9824
Jeff Johnson957bc272017-02-02 08:54:48 -08009825err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009826 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009827
Jeff Johnson46bde382017-02-01 15:31:16 -08009828err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309829 if (rtnl_held)
9830 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009831
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309832err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309833 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009835err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009836 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009837
Arun Khandavallifae92942016-08-01 13:31:08 +05309838err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009839 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309840
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009841err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309842 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009843 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309844 if (!QDF_IS_STATUS_SUCCESS(status)) {
9845 hdd_err("Failed to close CDS Scheduler");
9846 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9847 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009848 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009849
Houston Hoffman47a4a052016-11-14 23:22:44 -08009850 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009851 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009852 hdd_exit_netlink_services(hdd_ctx);
9853
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309854 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009855
Dustin Brown20912462017-06-07 13:48:25 -07009856 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9857
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009858err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309859 if (cds_is_fw_down())
9860 hdd_err("Not setting the complete event as fw is down");
9861 else
9862 hdd_start_complete(ret);
9863
Arun Khandavallifae92942016-08-01 13:31:08 +05309864 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9865 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009866 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867 return -EIO;
9868
9869success:
9870 EXIT();
9871 return 0;
9872}
9873
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009874/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309875 * hdd_wlan_update_target_info() - update target type info
9876 * @hdd_ctx: HDD context
9877 * @context: hif context
9878 *
9879 * Update target info received from firmware in hdd context
9880 * Return:None
9881 */
9882
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009883void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309884{
9885 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9886
9887 if (!tgt_info) {
9888 hdd_err("Target info is Null");
9889 return;
9890 }
9891
9892 hdd_ctx->target_type = tgt_info->target_type;
9893}
9894
9895/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309896 * hdd_get_nud_stats_cb() - callback api to update the stats
9897 * received from the firmware
9898 * @data: pointer to adapter.
9899 * @rsp: pointer to data received from FW.
9900 *
9901 * This is called when wlan driver received response event for
9902 * get arp stats to firmware.
9903 *
9904 * Return: None
9905 */
9906static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9907{
9908 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
9909 struct hdd_nud_stats_context *context;
9910 int status;
9911 struct hdd_adapter *adapter = NULL;
9912
9913 ENTER();
9914
9915 if (!rsp) {
9916 hdd_err("data is null");
9917 return;
9918 }
9919
9920 status = wlan_hdd_validate_context(hdd_ctx);
9921 if (0 != status)
9922 return;
9923
9924 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
9925 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
9926 hdd_err("Invalid adapter or adapter has invalid magic");
9927 return;
9928 }
9929
9930 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
9931 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
9932 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
9933 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
9934 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
9935 rsp->out_of_order_arp_rsp_drop_cnt);
9936 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
9937 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
9938 hdd_notice("rsp->ba_session_establishment_status :%x",
9939 rsp->ba_session_establishment_status);
9940
9941 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
9942 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
9943 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
9944 adapter->dad |= rsp->dad_detected;
9945 adapter->con_status = rsp->connect_status;
9946
9947 spin_lock(&hdd_context_lock);
9948 context = &hdd_ctx->nud_stats_context;
9949 complete(&context->response_event);
9950 spin_unlock(&hdd_context_lock);
9951
9952 EXIT();
9953
9954 return;
9955}
9956
9957/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309958 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309959 * @hdd_ctx: HDD context
9960 *
9961 * Register the HDD callbacks to CDS/SME.
9962 *
9963 * Return: 0 for success or Error code for failure
9964 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009965int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309966{
9967 QDF_STATUS status;
9968 int ret = 0;
9969
9970 ENTER();
9971
9972 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9973
9974 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9975 hdd_send_oem_data_rsp_msg);
9976
9977 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9978 wlan_hdd_cfg80211_fw_mem_dump_cb);
9979 if (!QDF_IS_STATUS_SUCCESS(status)) {
9980 hdd_err("Failed to register memdump callback");
9981 ret = -EINVAL;
9982 return ret;
9983 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309984 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9985 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309986 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9987 sme_nan_register_callback(hdd_ctx->hHal,
9988 wlan_hdd_cfg80211_nan_callback);
9989 sme_stats_ext_register_callback(hdd_ctx->hHal,
9990 wlan_hdd_cfg80211_stats_ext_callback);
9991
9992 sme_ext_scan_register_callback(hdd_ctx->hHal,
9993 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009994 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9995 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309996
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309997 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9998 hdd_rssi_threshold_breached);
9999
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010000 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10001
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010002 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10003 wlan_hdd_cfg80211_link_layer_stats_callback);
10004
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010005 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10006
Zhang Qianca38fb12016-12-23 11:10:48 +080010007 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10008 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10009
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010010 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10011 hdd_lost_link_info_cb);
10012 /* print error and not block the startup process */
10013 if (!QDF_IS_STATUS_SUCCESS(status))
10014 hdd_err("set lost link info callback failed");
10015
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010016 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10017
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010018 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010019 hdd_set_connection_in_progress,
10020 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010021
10022 status = sme_congestion_register_callback(hdd_ctx->hHal,
10023 hdd_update_cca_info_cb);
10024 if (!QDF_IS_STATUS_SUCCESS(status))
10025 hdd_err("set congestion callback failed");
10026
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010027 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10028 hdd_bt_activity_cb);
10029 if (!QDF_IS_STATUS_SUCCESS(status))
10030 hdd_err("set bt activity info callback failed");
10031
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010032 EXIT();
10033
10034 return ret;
10035}
10036
10037/**
10038 * hdd_deregister_cb() - De-Register HDD callbacks.
10039 * @hdd_ctx: HDD context
10040 *
10041 * De-Register the HDD callbacks to CDS/SME.
10042 *
10043 * Return: void
10044 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010045void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010046{
10047 QDF_STATUS status;
10048
10049 ENTER();
10050
10051 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10052 if (!QDF_IS_STATUS_SUCCESS(status))
10053 hdd_err("De-register of dcc stats callback failed: %d",
10054 status);
10055
10056 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010057 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10058
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010059 sme_stats_ext_register_callback(hdd_ctx->hHal,
10060 wlan_hdd_cfg80211_stats_ext_callback);
10061
10062 sme_nan_deregister_callback(hdd_ctx->hHal);
10063 status = sme_reset_tsfcb(hdd_ctx->hHal);
10064 if (!QDF_IS_STATUS_SUCCESS(status))
10065 hdd_err("Failed to de-register tsfcb the callback:%d",
10066 status);
10067 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10068 if (!QDF_IS_STATUS_SUCCESS(status))
10069 hdd_err("Failed to de-register the fw mem dump callback: %d",
10070 status);
10071
10072 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10073 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10074
10075 EXIT();
10076}
10077
10078/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010079 * hdd_softap_sta_deauth() - handle deauth req from HDD
10080 * @adapter: Pointer to the HDD
10081 * @enable: bool value
10082 *
10083 * This to take counter measure to handle deauth req from HDD
10084 *
10085 * Return: None
10086 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010087QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010088 struct tagCsrDelStaParams *pDelStaParams)
10089{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010090 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010091
10092 ENTER();
10093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010094 /* Ignore request to deauth bcmc station */
10095 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010096 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010097
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010098 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010099 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10100 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010101
10102 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010103 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010104}
10105
10106/**
10107 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10108 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010109 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010110 *
10111 * This to take counter measure to handle deauth req from HDD
10112 *
10113 * Return: None
10114 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010115void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010116 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010117{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010118 ENTER();
10119
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010120 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010121 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010122 return;
10123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010124 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010125 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010126}
10127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010128/**
10129 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10130 * @hdd_ctx: HDD Context
10131 *
10132 * API to find if there is any STA or P2P-Client is connected
10133 *
10134 * Return: true if connected; false otherwise
10135 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010136QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010137{
10138 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10139}
10140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010141/**
10142 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10143 * @adapter: HDD adapter pointer
10144 *
10145 * This function loop through each adapter and disable roaming on each STA
10146 * device mode except the input adapter.
10147 *
10148 * Note: On the input adapter roaming is not enabled yet hence no need to
10149 * disable.
10150 *
10151 * Return: None
10152 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010153void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010154{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010155 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010156 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010157 hdd_adapter_list_node_t *adapterNode = NULL;
10158 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010159 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010160
10161 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010162 hdd_ctx->config->isRoamOffloadScanEnabled &&
10163 QDF_STA_MODE == adapter->device_mode &&
10164 policy_mgr_is_sta_active_connection_exists(
10165 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010166 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010167 adapter->sessionId);
10168 /*
10169 * Loop through adapter and disable roaming for each STA device
10170 * mode except the input adapter.
10171 */
10172 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10173
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010174 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010175 adapterIdx = adapterNode->pAdapter;
10176
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010177 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010179 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010180 adapterIdx->sessionId);
10181 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10182 (adapterIdx),
10183 adapterIdx->sessionId, 0);
10184 }
10185
10186 status = hdd_get_next_adapter(hdd_ctx,
10187 adapterNode,
10188 &pNext);
10189 adapterNode = pNext;
10190 }
10191 }
10192}
10193
10194/**
10195 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10196 * @adapter: HDD adapter pointer
10197 *
10198 * This function loop through each adapter and enable roaming on each STA
10199 * device mode except the input adapter.
10200 * Note: On the input adapter no need to enable roaming because link got
10201 * disconnected on this.
10202 *
10203 * Return: None
10204 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010205void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010207 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010208 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010209 hdd_adapter_list_node_t *adapterNode = NULL;
10210 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010211 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010212
10213 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010214 hdd_ctx->config->isRoamOffloadScanEnabled &&
10215 QDF_STA_MODE == adapter->device_mode &&
10216 policy_mgr_is_sta_active_connection_exists(
10217 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010218 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010219 adapter->sessionId);
10220 /*
10221 * Loop through adapter and enable roaming for each STA device
10222 * mode except the input adapter.
10223 */
10224 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010226 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010227 adapterIdx = adapterNode->pAdapter;
10228
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010229 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010230 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010231 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232 adapterIdx->sessionId);
10233 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10234 (adapterIdx),
10235 adapterIdx->sessionId,
10236 REASON_CONNECT);
10237 }
10238
10239 status = hdd_get_next_adapter(hdd_ctx,
10240 adapterNode,
10241 &pNext);
10242 adapterNode = pNext;
10243 }
10244 }
10245}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010246
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010247/**
10248 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10249 * @skb: sk buffer pointer
10250 *
10251 * Sends the bcast message to SVC multicast group with generic nl socket
10252 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10253 *
10254 * Return: None
10255 */
10256static void nl_srv_bcast_svc(struct sk_buff *skb)
10257{
10258#ifdef CNSS_GENL
10259 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10260#else
10261 nl_srv_bcast(skb);
10262#endif
10263}
10264
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010265void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010266{
10267 struct sk_buff *skb;
10268 struct nlmsghdr *nlh;
10269 tAniMsgHdr *ani_hdr;
10270 void *nl_data = NULL;
10271 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010272 struct radio_index_tlv *radio_info;
10273 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010274
10275 if (in_interrupt() || irqs_disabled() || in_atomic())
10276 flags = GFP_ATOMIC;
10277
10278 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10279
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010280 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010282
10283 nlh = (struct nlmsghdr *)skb->data;
10284 nlh->nlmsg_pid = 0; /* from kernel */
10285 nlh->nlmsg_flags = 0;
10286 nlh->nlmsg_seq = 0;
10287 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10288
10289 ani_hdr = NLMSG_DATA(nlh);
10290 ani_hdr->type = type;
10291
10292 switch (type) {
10293 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010294 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010295 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010296 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010297 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010298 ani_hdr->length = 0;
10299 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010300 break;
10301 case WLAN_SVC_WLAN_STATUS_IND:
10302 case WLAN_SVC_WLAN_VERSION_IND:
10303 case WLAN_SVC_DFS_CAC_START_IND:
10304 case WLAN_SVC_DFS_CAC_END_IND:
10305 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10306 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10307 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010308 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010309 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010310 ani_hdr->length = len;
10311 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10312 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10313 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010314 break;
10315
10316 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010317 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010318 type);
10319 kfree_skb(skb);
10320 return;
10321 }
10322
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010323 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010324 * Add radio index at the end of the svc event in TLV format
10325 * to maintain the backward compatibility with userspace
10326 * applications.
10327 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010328
10329 tlv_len = 0;
10330
10331 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10332 < WLAN_NL_MAX_PAYLOAD) {
10333 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10334 sizeof(*ani_hdr) + len);
10335 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10336 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10337 radio_info->radio = radio;
10338 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010339 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010340 "Added radio index tlv - radio index %d",
10341 radio_info->radio);
10342 }
10343
10344 nlh->nlmsg_len += tlv_len;
10345 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10346
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010347 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010348}
10349
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010350#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10351void wlan_hdd_auto_shutdown_cb(void)
10352{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010353 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010354
10355 if (!hdd_ctx)
10356 return;
10357
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010358 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010359 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10360 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361}
10362
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010363void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010364{
10365 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010366 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010367 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010368 bool ap_connected = false, sta_connected = false;
10369 tHalHandle hal_handle;
10370
10371 hal_handle = hdd_ctx->hHal;
10372 if (hal_handle == NULL)
10373 return;
10374
10375 if (hdd_ctx->config->WlanAutoShutdown == 0)
10376 return;
10377
10378 if (enable == false) {
10379 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010380 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010381 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010382 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010383 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010384 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010385 return;
10386 }
10387
10388 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010389 if (policy_mgr_concurrent_open_sessions_running(
10390 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010391 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10392
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010393 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010394 adapter = adapterNode->pAdapter;
10395 if (adapter
10396 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010397 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010398 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10399 conn_info.connState ==
10400 eConnectionState_Associated) {
10401 sta_connected = true;
10402 break;
10403 }
10404 }
10405 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010406 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10408 bApActive == true) {
10409 ap_connected = true;
10410 break;
10411 }
10412 }
10413 status = hdd_get_next_adapter(hdd_ctx,
10414 adapterNode,
10415 &pNext);
10416 adapterNode = pNext;
10417 }
10418 }
10419
10420 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010421 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010422 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423 }
Jeff Johnson68755312017-02-10 11:46:55 -080010424
10425 if (sme_set_auto_shutdown_timer(hal_handle,
10426 hdd_ctx->config->WlanAutoShutdown)
10427 != QDF_STATUS_SUCCESS)
10428 hdd_err("Failed to start wlan auto shutdown timer");
10429 else
10430 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10431 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010432}
10433#endif
10434
Jeff Johnson9d295242017-08-29 14:39:48 -070010435struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010436 bool check_start_bss)
10437{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010438 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010439 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010440 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010441 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10442
10443 con_sap_adapter = NULL;
10444
10445 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010446 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010448 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10449 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010450 adapter != this_sap_adapter) {
10451 if (check_start_bss) {
10452 if (test_bit(SOFTAP_BSS_STARTED,
10453 &adapter->event_flags)) {
10454 con_sap_adapter = adapter;
10455 break;
10456 }
10457 } else {
10458 con_sap_adapter = adapter;
10459 break;
10460 }
10461 }
10462 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10463 adapterNode = pNext;
10464 }
10465
10466 return con_sap_adapter;
10467}
10468
10469#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010470static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010472 return adapter->device_mode == QDF_STA_MODE ||
10473 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474}
10475
Jeff Johnson9d295242017-08-29 14:39:48 -070010476static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010478 return adapter->device_mode == QDF_SAP_MODE ||
10479 adapter->device_mode == QDF_P2P_GO_MODE;
10480}
10481
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010482static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010483{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010484 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010485 hdd_adapter_list_node_t *node;
10486
10487 status = hdd_get_front_adapter(hdd_ctx, &node);
10488 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson9d295242017-08-29 14:39:48 -070010489 struct hdd_adapter *adapter = node->pAdapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010490
10491 if (adapter &&
10492 hdd_adapter_is_sta(adapter) &&
10493 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10494 conn_info.connState == eConnectionState_Associated) {
10495 return true;
10496 }
10497
10498 if (adapter &&
10499 hdd_adapter_is_ap(adapter) &&
10500 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10501 return true;
10502 }
10503
10504 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10505 }
10506
10507 return false;
10508}
10509
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010510static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010511{
10512 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010513
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010514 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010515 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010516 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517
Dustin Brown5ec6b552017-03-31 12:11:40 -070010518 return is_running;
10519}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010520
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010521static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010522{
10523 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10524 hdd_ctx->bus_bw_timer_running = true;
10525 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10526 hdd_ctx->config->busBandwidthComputeInterval);
10527 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10528}
10529
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010530void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010531{
10532 ENTER();
10533
10534 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10535 hdd_debug("Bandwidth compute timer already started");
10536 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537 }
10538
Dustin Brown5ec6b552017-03-31 12:11:40 -070010539 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10540
10541 EXIT();
10542}
10543
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010544void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010545{
10546 ENTER();
10547
10548 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10549 hdd_debug("Bandwidth compute timer already started");
10550 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010551 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010552
10553 if (hdd_any_adapter_is_assoc(hdd_ctx))
10554 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10555
10556 EXIT();
10557}
10558
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010559static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010560{
10561 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10562
10563 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10564 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10565 hdd_ctx->bus_bw_timer_running = false;
10566 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10567
10568 hdd_reset_tcp_delack(hdd_ctx);
10569}
10570
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010571void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010572{
10573 ENTER();
10574
10575 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10576 hdd_debug("Bandwidth compute timer already stopped");
10577 return;
10578 }
10579
10580 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10581
10582 EXIT();
10583}
10584
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010585void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010586{
10587 ENTER();
10588
10589 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10590 hdd_debug("Bandwidth compute timer already stopped");
10591 return;
10592 }
10593
10594 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10595 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10596
10597 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010598}
10599#endif
10600
10601/**
10602 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10603 * and sta's operating channel.
10604 * @sta_adapter: Describe the first argument to foobar.
10605 * @ap_adapter: Describe the second argument to foobar.
10606 * @roam_profile: Roam profile of AP to which STA wants to connect.
10607 * @concurrent_chnl_same: If both SAP and STA channels are same then
10608 * set this flag to true else false.
10609 *
10610 * This function checks the sap's operating channel and sta's operating channel.
10611 * if both are same then it will return false else it will restart the sap in
10612 * sta's channel and return true.
10613 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010614 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010616QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10617 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010618 tCsrRoamProfile *roam_profile,
10619 tScanResultHandle *scan_cache,
10620 bool *concurrent_chnl_same)
10621{
Jeff Johnson87251032017-08-29 13:31:11 -070010622 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010623 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010624 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010625 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010626 *concurrent_chnl_same = true;
10627
10628 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10629 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010630 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010631 scan_cache,
10632 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010633 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010634 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010635 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10636 if (hdd_ap_ctx->operatingChannel != channel_id) {
10637 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010638 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010640 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010641 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10642 if (hdd_ap_ctx->operatingChannel != channel_id) {
10643 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010644 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010645 }
10646 }
10647 } else {
10648 /*
10649 * Lets handle worst case scenario here, Scan cache lookup is
10650 * failed so we have to stop the SAP to avoid any channel
10651 * discrepancy between SAP's channel and STA's channel.
10652 * Return the status as failure so caller function could know
10653 * that scan look up is failed.
10654 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010655 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010656 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010657 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010658 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659}
10660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010661/**
10662 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10663 * @ap_adapter: SAP adapter
10664 *
10665 * This function will process the stopping of sap adapter.
10666 *
10667 * Return: None
10668 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010669void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010670{
Jeff Johnson87251032017-08-29 13:31:11 -070010671 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010672 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010673 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010674 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010675
10676 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010677 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010678 return;
10679 }
10680
10681 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10682 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010683 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010684 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010685
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010686 mutex_lock(&hdd_ctx->sap_lock);
10687 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010688 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010689 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10690 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010691 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010692 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010693 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010694 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010695 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010696 qdf_stop_bss_event,
10697 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010698 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010700 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010701 return;
10702 }
10703 }
10704 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010705 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10706 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010708 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010709 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010710 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010711 }
10712 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010713}
10714
10715/**
10716 * wlan_hdd_start_sap() - this function starts bss of SAP.
10717 * @ap_adapter: SAP adapter
10718 *
10719 * This function will process the starting of sap adapter.
10720 *
10721 * Return: None
10722 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010723void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010724{
Jeff Johnson87251032017-08-29 13:31:11 -070010725 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010726 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010727 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010728 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010729 tsap_Config_t *sap_config;
10730
10731 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010732 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733 return;
10734 }
10735
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010736 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010737 hdd_err("SoftAp role has not been enabled");
10738 return;
10739 }
10740
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010741 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10742 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10743 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10744 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 mutex_lock(&hdd_ctx->sap_lock);
10747 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10748 goto end;
10749
10750 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010751 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010752 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10753 goto end;
10754 }
10755
Wei Song2f76f642016-11-18 16:32:53 +080010756 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10758 &hdd_ap_ctx->sapConfig,
10759 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010760 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 goto end;
10762
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010763 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010764 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010765 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010766 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010767 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010768 goto end;
10769 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010770 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010771 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010772 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010773 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10774 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010775 ap_adapter->sessionId);
10776 hostapd_state->bCommit = true;
10777
10778end:
10779 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010780 /* SAP context and beacon cleanup will happen during driver unload
10781 * in hdd_stop_adapter
10782 */
10783 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010785}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010786
10787/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010788 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10789 * mac scan config
10790 * @status: Status of set antenna mode
10791 *
10792 * Callback on setting the dual mac configuration
10793 *
10794 * Return: None
10795 */
10796void wlan_hdd_soc_set_antenna_mode_cb(
10797 enum set_antenna_mode_status status)
10798{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010799 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010800
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010801 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010802
10803 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10804 if (0 != wlan_hdd_validate_context(hdd_ctx))
10805 return;
10806
10807 /* Signal the completion of set dual mac config */
10808 complete(&hdd_ctx->set_antenna_mode_cmpl);
10809}
10810
10811/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010812 * hdd_get_fw_version() - Get FW version
10813 * @hdd_ctx: pointer to HDD context.
10814 * @major_spid: FW version - major spid.
10815 * @minor_spid: FW version - minor spid
10816 * @ssid: FW version - ssid
10817 * @crmid: FW version - crmid
10818 *
10819 * This function is called to get the firmware build version stored
10820 * as part of the HDD context
10821 *
10822 * Return: None
10823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010824void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010825 uint32_t *major_spid, uint32_t *minor_spid,
10826 uint32_t *siid, uint32_t *crmid)
10827{
10828 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10829 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10830 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10831 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10832}
10833
10834#ifdef QCA_CONFIG_SMP
10835/**
10836 * wlan_hdd_get_cpu() - get cpu_index
10837 *
10838 * Return: cpu_index
10839 */
10840int wlan_hdd_get_cpu(void)
10841{
10842 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010843
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010844 put_cpu();
10845 return cpu_index;
10846}
10847#endif
10848
10849/**
10850 * hdd_get_fwpath() - get framework path
10851 *
10852 * This function is used to get the string written by
10853 * userspace to start the wlan driver
10854 *
10855 * Return: string
10856 */
10857const char *hdd_get_fwpath(void)
10858{
10859 return fwpath.string;
10860}
10861
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010862static int hdd_qdf_print_init(void)
10863{
10864 int qdf_print_idx;
10865 QDF_STATUS status;
10866
10867 status = qdf_print_setup();
10868 if (status != QDF_STATUS_SUCCESS) {
10869 pr_err("qdf_print_setup failed\n");
10870 return -EINVAL;
10871 }
10872
10873 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10874
10875 if (qdf_print_idx < 0) {
10876 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10877 qdf_print_idx);
10878 return -EINVAL;
10879 }
10880
10881 qdf_set_pidx(qdf_print_idx);
10882
10883 return 0;
10884}
10885
10886static void hdd_qdf_print_deinit(void)
10887{
10888 int qdf_print_idx;
10889
10890 qdf_print_idx = qdf_get_pidx();
10891 qdf_print_ctrl_cleanup(qdf_print_idx);
10892}
10893
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010894/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010895 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010896 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010897 * This function initilizes CDS global context with the help of cds_init. This
10898 * has to be the first function called after probe to get a valid global
10899 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010900 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010901 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010902 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010903int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010904{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010905 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010906 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010907
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010908 status = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010909
10910 wlan_init_bug_report_lock();
10911
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010912#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10913 wlan_logging_sock_init_svc();
10914#endif
10915
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070010916 if (QDF_IS_STATUS_ERROR(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010917 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010918 ret = -ENOMEM;
10919 goto err_out;
10920 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010921
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053010922 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
10923 (void *)hdd_drv_ops_inactivity_handler, NULL,
10924 QDF_TIMER_TYPE_SW);
10925
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010926 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010927 hdd_qdf_print_init();
10928
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010929 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010930
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010931err_out:
10932 return ret;
10933}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010934
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010935/**
10936 * hdd_deinit() - Deinitialize Driver
10937 *
10938 * This function frees CDS global context with the help of cds_deinit. This
10939 * has to be the last function call in remove callback to free the global
10940 * context.
10941 */
10942void hdd_deinit(void)
10943{
Dustin Brownedce4a52017-05-10 11:59:15 -070010944 hdd_deinit_wowl();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053010945 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010946
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010947 hdd_qdf_print_deinit();
10948
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010949#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10950 wlan_logging_sock_deinit_svc();
10951#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010952
10953 wlan_destroy_bug_report_lock();
10954 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010955}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010956
Yue Ma6e7b1a02017-04-03 14:17:46 -070010957#ifdef QCA_WIFI_NAPIER_EMULATION
10958#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10959#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010960#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010961#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010962
Sachin Ahujadddd2632017-03-07 19:07:24 +053010963static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10964 struct file *file)
10965{
10966 return 0;
10967}
10968
10969static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10970 const char __user *user_buf,
10971 size_t count,
10972 loff_t *f_pos)
10973{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010974 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010975 static const char wlan_off_str[] = "OFF";
10976 static const char wlan_on_str[] = "ON";
10977 int ret;
10978 unsigned long rc;
10979
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010980 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010981 pr_err("Failed to read buffer\n");
10982 return -EINVAL;
10983 }
10984
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010985 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010986 pr_debug("Wifi turning off from UI\n");
10987 goto exit;
10988 }
10989
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010990 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010991 pr_err("Invalid value received from framework");
10992 goto exit;
10993 }
10994
10995 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010996 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010997 rc = wait_for_completion_timeout(&wlan_start_comp,
10998 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10999 if (!rc) {
11000 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11001 ret = -EINVAL;
11002 hdd_start_complete(ret);
11003 return ret;
11004 }
11005
11006 hdd_start_complete(0);
11007 }
11008
11009exit:
11010 return count;
11011}
11012
11013
11014const struct file_operations wlan_hdd_state_fops = {
11015 .owner = THIS_MODULE,
11016 .open = wlan_hdd_state_ctrl_param_open,
11017 .write = wlan_hdd_state_ctrl_param_write,
11018};
11019
11020static int wlan_hdd_state_ctrl_param_create(void)
11021{
11022 unsigned int wlan_hdd_state_major = 0;
11023 int ret;
11024 struct device *dev;
11025
11026 device = MKDEV(wlan_hdd_state_major, 0);
11027
11028 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11029 if (ret) {
11030 pr_err("Failed to register qcwlanstate");
11031 goto dev_alloc_err;
11032 }
11033 wlan_hdd_state_major = MAJOR(device);
11034
11035 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11036 if (IS_ERR(class)) {
11037 pr_err("wlan_hdd_state class_create error");
11038 goto class_err;
11039 }
11040
11041 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11042 if (IS_ERR(dev)) {
11043 pr_err("wlan_hdd_statedevice_create error");
11044 goto err_class_destroy;
11045 }
11046
11047 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11048 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11049 if (ret) {
11050 pr_err("Failed to add cdev error");
11051 goto cdev_add_err;
11052 }
11053
11054 pr_info("wlan_hdd_state %s major(%d) initialized",
11055 WLAN_MODULE_NAME, wlan_hdd_state_major);
11056
11057 return 0;
11058
11059cdev_add_err:
11060 device_destroy(class, device);
11061err_class_destroy:
11062 class_destroy(class);
11063class_err:
11064 unregister_chrdev_region(device, dev_num);
11065dev_alloc_err:
11066 return -ENODEV;
11067}
11068
11069static void wlan_hdd_state_ctrl_param_destroy(void)
11070{
11071 cdev_del(&wlan_hdd_state_cdev);
11072 device_destroy(class, device);
11073 class_destroy(class);
11074 unregister_chrdev_region(device, dev_num);
11075
11076 pr_info("Device node unregistered");
11077}
11078
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011079/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011080 * component_init - API to init cld component's
11081 *
11082 * Return: None
11083 */
11084static void component_init(void)
11085{
11086 pmo_init();
11087}
11088
11089/**
11090 * component_deinit - API to deinit cld component's
11091 *
11092 * Return: None
11093 */
11094static void component_deinit(void)
11095{
11096 pmo_deinit();
11097}
11098
11099/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011100 * __hdd_module_init - Module init helper
11101 *
11102 * Module init helper function used by both module and static driver.
11103 *
11104 * Return: 0 for success, errno on failure
11105 */
11106static int __hdd_module_init(void)
11107{
11108 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011109
Dustin Brownab482ac2017-06-09 17:00:44 -070011110 pr_err("%s: Loading driver v%s (%s)%s\n",
11111 WLAN_MODULE_NAME,
11112 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011113 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011114 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011115
Sachin Ahujadddd2632017-03-07 19:07:24 +053011116 ret = wlan_hdd_state_ctrl_param_create();
11117 if (ret) {
11118 pr_err("wlan_hdd_state_create:%x\n", ret);
11119 goto err_dev_state;
11120 }
11121
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011122 pld_init();
11123
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011124 ret = hdd_init();
11125 if (ret) {
11126 pr_err("hdd_init failed %x\n", ret);
11127 goto err_hdd_init;
11128 }
11129
Rajeev Kumar97767a02016-11-30 11:20:40 -080011130 dispatcher_init();
11131
Mukul Sharmad75a6672017-06-22 15:40:53 +053011132 /* Ensure to call post objmgr init */
11133 component_init();
11134
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011135 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011136
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011137 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011138
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011139 ret = wlan_hdd_register_driver();
11140 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011141 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11142 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011143 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011144 }
11145
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011146 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011147
11148 return 0;
11149out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011150 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011151 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011152 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011153
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011154err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011155 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011156 wlan_hdd_state_ctrl_param_destroy();
11157err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011158 return ret;
11159}
11160
11161/**
11162 * __hdd_module_exit - Module exit helper
11163 *
11164 * Module exit helper function used by both module and static driver.
11165 */
11166static void __hdd_module_exit(void)
11167{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011168
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011169 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11170 QWLAN_VERSIONSTR);
11171
bings6028ee82017-03-29 07:51:40 +080011172 cds_set_unload_in_progress(true);
11173
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011174 hdd_wait_for_recovery_completion();
11175
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011176 wlan_hdd_unregister_driver();
11177
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011178 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011179
Mukul Sharmad75a6672017-06-22 15:40:53 +053011180 /* Ensure to call prior to objmgr deinit */
11181 component_deinit();
11182
Rajeev Kumar97767a02016-11-30 11:20:40 -080011183 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011184 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011185 pld_deinit();
11186
Sachin Ahujadddd2632017-03-07 19:07:24 +053011187 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011188}
11189
Arun Khandavallifae92942016-08-01 13:31:08 +053011190#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011191/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011192 * wlan_boot_cb() - Wlan boot callback
11193 * @kobj: object whose directory we're creating the link in.
11194 * @attr: attribute the user is interacting with
11195 * @buff: the buffer containing the user data
11196 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011197 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011198 * This callback is invoked when the fs is ready to start the
11199 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011200 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011201 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011202 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011203static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011204 struct kobj_attribute *attr,
11205 const char *buf,
11206 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011207{
Arun Khandavallifae92942016-08-01 13:31:08 +053011208
Arun Khandavallifae92942016-08-01 13:31:08 +053011209 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011210 pr_err("%s: wlan driver already initialized\n", __func__);
11211 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011212 }
11213
Arun Khandavallifae92942016-08-01 13:31:08 +053011214 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011215 pr_err("%s: wlan driver initialization failed\n", __func__);
11216 return -EIO;
11217 }
11218
11219 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011220
11221 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011222}
Arun Khandavallifae92942016-08-01 13:31:08 +053011223
11224/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011225 * hdd_sysfs_cleanup() - cleanup sysfs
11226 *
11227 * Return: None
11228 *
11229 */
11230static void hdd_sysfs_cleanup(void)
11231{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011232 /* remove from group */
11233 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11234 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11235 wlan_loader->attr_group);
11236
11237 /* unlink the object from parent */
11238 kobject_del(wlan_loader->boot_wlan_obj);
11239
11240 /* free the object */
11241 kobject_put(wlan_loader->boot_wlan_obj);
11242
11243 kfree(wlan_loader->attr_group);
11244 kfree(wlan_loader);
11245
11246 wlan_loader = NULL;
11247}
11248
11249/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011250 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11251 * ready
11252 *
11253 * This is creates the syfs entry boot_wlan. Which shall be invoked
11254 * when the filesystem is ready.
11255 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011256 * QDF API cannot be used here since this function is called even before
11257 * initializing WLAN driver.
11258 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011259 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011260 */
11261static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011262{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011263 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011264
11265 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011266 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011267 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011268
11269 wlan_loader->boot_wlan_obj = NULL;
11270 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11271 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011272 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011273 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011274
11275 wlan_loader->loaded_state = 0;
11276 wlan_loader->attr_group->attrs = attrs;
11277
11278 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11279 kernel_kobj);
11280 if (!wlan_loader->boot_wlan_obj) {
11281 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011282 goto error_return;
11283 }
11284
11285 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11286 wlan_loader->attr_group);
11287 if (ret) {
11288 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11289 goto error_return;
11290 }
11291
11292 return 0;
11293
11294error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011295 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011296
11297 return ret;
11298}
11299
11300/**
11301 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11302 *
11303 * Return: 0 on success or errno on failure
11304 */
11305static int wlan_deinit_sysfs(void)
11306{
Arun Khandavallifae92942016-08-01 13:31:08 +053011307 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011308 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011309 return -EINVAL;
11310 }
11311
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011312 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011313 return 0;
11314}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011315
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011316#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011317
11318#ifdef MODULE
11319/**
11320 * __hdd_module_init - Module init helper
11321 *
11322 * Module init helper function used by both module and static driver.
11323 *
11324 * Return: 0 for success, errno on failure
11325 */
11326static int hdd_module_init(void)
11327{
Arun Khandavallifae92942016-08-01 13:31:08 +053011328 if (__hdd_module_init()) {
11329 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011330 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 }
11332
Dustin Brownab482ac2017-06-09 17:00:44 -070011333 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011334}
11335#else
11336static int __init hdd_module_init(void)
11337{
11338 int ret = -EINVAL;
11339
11340 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011341 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011342 pr_err("Failed to create sysfs entry for loading wlan");
11343
11344 return ret;
11345}
11346#endif
11347
11348
11349#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011350/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011351 * hdd_module_exit() - Exit function
11352 *
11353 * This is the driver exit point (invoked when module is unloaded using rmmod)
11354 *
11355 * Return: None
11356 */
11357static void __exit hdd_module_exit(void)
11358{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011359 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011360}
Arun Khandavallifae92942016-08-01 13:31:08 +053011361#else
11362static void __exit hdd_module_exit(void)
11363{
11364 __hdd_module_exit();
11365 wlan_deinit_sysfs();
11366}
11367#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011368
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011369static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11370{
11371 return param_set_copystring(kmessage, kp);
11372}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011373
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011374/**
11375 * is_con_mode_valid() check con mode is valid or not
11376 * @mode: global con mode
11377 *
11378 * Return: TRUE on success FALSE on failure
11379 */
11380static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11381{
11382 switch (mode) {
11383 case QDF_GLOBAL_MONITOR_MODE:
11384 case QDF_GLOBAL_FTM_MODE:
11385 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011386 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011387 return true;
11388 default:
11389 return false;
11390 }
11391}
11392
11393/**
11394 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11395 * @mode: global con mode
11396 *
11397 * Return: adapter mode
11398 */
11399static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11400 enum tQDF_GLOBAL_CON_MODE mode)
11401{
11402
11403 switch (mode) {
11404 case QDF_GLOBAL_MISSION_MODE:
11405 return QDF_STA_MODE;
11406 case QDF_GLOBAL_MONITOR_MODE:
11407 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011408 case QDF_GLOBAL_EPPING_MODE:
11409 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011410 case QDF_GLOBAL_FTM_MODE:
11411 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011412 case QDF_GLOBAL_QVIT_MODE:
11413 return QDF_QVIT_MODE;
11414 default:
11415 return QDF_MAX_NO_OF_MODE;
11416 }
11417}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011418
Dustin Brown27cd9942017-09-27 16:11:44 -070011419static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
11420 enum tQDF_GLOBAL_CON_MODE curr_mode)
11421{
11422 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11423 return;
11424
11425 switch (curr_mode) {
11426 case QDF_GLOBAL_MISSION_MODE:
11427 case QDF_GLOBAL_MONITOR_MODE:
11428 case QDF_GLOBAL_FTM_MODE:
11429 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11430 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11431
11432 /* re-use the existing session */
11433 hdd_stop_all_adapters(hdd_ctx, false);
11434 break;
11435 default:
11436 break;
11437 }
11438}
11439
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011440static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011441 enum tQDF_GLOBAL_CON_MODE curr_mode)
11442{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011443 int driver_status;
11444
11445 driver_status = hdd_ctx->driver_status;
11446
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011447 switch (curr_mode) {
11448 case QDF_GLOBAL_MISSION_MODE:
11449 case QDF_GLOBAL_MONITOR_MODE:
11450 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011451 hdd_deinit_all_adapters(hdd_ctx, false);
11452 hdd_close_all_adapters(hdd_ctx, false);
11453 break;
11454 case QDF_GLOBAL_EPPING_MODE:
11455 epping_disable();
11456 epping_close();
11457 break;
11458 default:
11459 return;
11460 }
11461}
11462
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011463static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011464 enum tQDF_GLOBAL_CON_MODE mode)
11465{
Jeff Johnson9d295242017-08-29 14:39:48 -070011466 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011467 int ret = 0;
11468 bool rtnl_held;
11469 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11470 QDF_STATUS status;
11471
11472 if (!qdf_dev) {
11473 hdd_err("qdf device context is Null return!");
11474 return -EINVAL;
11475 }
11476
11477 rtnl_held = hdd_hold_rtnl_lock();
11478 switch (mode) {
11479 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011480 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11481 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011482 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011483 break;
11484 case QDF_GLOBAL_FTM_MODE:
11485 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11486 wlan_hdd_get_intf_addr(hdd_ctx),
11487 NET_NAME_UNKNOWN, rtnl_held);
11488 if (adapter == NULL)
11489 ret = -EINVAL;
11490 break;
11491 case QDF_GLOBAL_MONITOR_MODE:
11492 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11493 wlan_hdd_get_intf_addr(hdd_ctx),
11494 NET_NAME_UNKNOWN, rtnl_held);
11495 if (adapter == NULL)
11496 ret = -EINVAL;
11497 break;
11498 case QDF_GLOBAL_EPPING_MODE:
11499 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011500 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011501 hdd_err("Failed to open in eeping mode: %d", status);
11502 ret = -EINVAL;
11503 break;
11504 }
11505 ret = epping_enable(qdf_dev->dev);
11506 if (ret) {
11507 hdd_err("Failed to enable in epping mode : %d", ret);
11508 epping_close();
11509 }
11510 break;
11511 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011512 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011513 ret = -ENOTSUPP;
11514 break;
11515 }
11516 hdd_release_rtnl_lock();
11517 rtnl_held = false;
11518 return ret;
11519}
11520
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011521/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011522 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011523 * @kmessage: con mode name on which driver to be bring up
11524 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011525 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011526 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011527 * This function is invoked when user updates con mode using sys entry,
11528 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011529 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011530 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011531 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011532static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011533 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011534{
11535 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011536 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011537 enum tQDF_GLOBAL_CON_MODE curr_mode;
11538 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011539
Dustin Brownab6029b2017-05-24 13:04:19 -070011540 hdd_info("con_mode handler: %s", kmessage);
11541
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011542 ret = wlan_hdd_validate_context(hdd_ctx);
11543 if (ret)
11544 return ret;
11545
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011546 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011547
11548 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011549
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011550 if (!(is_con_mode_valid(con_mode))) {
11551 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011552 ret = -EINVAL;
11553 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011554 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011555
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011556 curr_mode = hdd_get_conparam();
11557 if (curr_mode == con_mode) {
11558 hdd_err("curr mode: %d is same as user triggered mode %d",
11559 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011560 ret = 0;
11561 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011562 }
11563
Dustin Brown27cd9942017-09-27 16:11:44 -070011564 /* ensure adapters are stopped */
11565 hdd_stop_present_mode(hdd_ctx, curr_mode);
11566
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011567 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011568 if (ret) {
11569 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011570 goto reset_flags;
11571 }
11572
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011573 /* Cleanup present mode before switching to new mode */
11574 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11575
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011576 hdd_set_conparam(con_mode);
11577
11578 /* Register for new con_mode & then kick_start modules again */
11579 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11580 if (ret) {
11581 hdd_err("Failed to register for new mode");
11582 goto reset_flags;
11583 }
11584
11585 adapter_mode = hdd_get_adpter_mode(con_mode);
11586 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11587 hdd_err("invalid adapter");
11588 ret = -EINVAL;
11589 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011590 }
11591
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011592 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011593 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011594 hdd_err("Failed to get adapter:%d", adapter_mode);
11595 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011596 }
11597
11598 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11599 if (ret) {
11600 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011601 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011602 }
11603
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011604 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070011605 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011606 if (hdd_start_adapter(adapter)) {
11607 hdd_err("Failed to start %s adapter", kmessage);
11608 ret = -EINVAL;
11609 goto reset_flags;
11610 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011611 }
11612
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011613 hdd_info("Mode successfully changed to %s", kmessage);
11614 ret = 0;
11615
11616reset_flags:
11617 cds_set_load_in_progress(false);
11618 return ret;
11619}
11620
11621
11622static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11623{
11624 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011625 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011626
11627 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11628 ret = wlan_hdd_validate_context(hdd_ctx);
11629 if (ret)
11630 return ret;
11631
11632 cds_ssr_protect(__func__);
11633 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11634 cds_ssr_unprotect(__func__);
11635
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011636 return ret;
11637}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011638
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011639static int con_mode_handler_ftm(const char *kmessage,
11640 struct kernel_param *kp)
11641{
11642 int ret;
11643
11644 ret = param_set_int(kmessage, kp);
11645
11646 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11647 pr_err("Only FTM mode supported!");
11648 return -ENOTSUPP;
11649 }
11650
11651 hdd_set_conparam(con_mode_ftm);
11652 con_mode = con_mode_ftm;
11653
11654 return ret;
11655}
11656
Ravi Joshia307f632017-07-17 23:41:41 -070011657static int con_mode_handler_monitor(const char *kmessage,
11658 struct kernel_param *kp)
11659{
11660 int ret;
11661
11662 ret = param_set_int(kmessage, kp);
11663
11664 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11665 pr_err("Only Monitor mode supported!");
11666 return -ENOTSUPP;
11667 }
11668
11669 hdd_set_conparam(con_mode_monitor);
11670 con_mode = con_mode_monitor;
11671
11672 return ret;
11673}
11674
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011675/**
11676 * hdd_get_conparam() - driver exit point
11677 *
11678 * This is the driver exit point (invoked when module is unloaded using rmmod)
11679 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011680 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011681 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011682enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011683{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011684 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011685}
11686
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011687void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011688{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011689 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011690}
11691
Komal Seelamc11bb222016-01-27 18:57:10 +053011692/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011693 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11694 * @hdd_ctx: HDD context
11695 *
11696 * Cleans up the pre cac interface, if it exists
11697 *
11698 * Return: None
11699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011700void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011701{
11702 uint8_t session_id;
11703 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011704 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011705
11706 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11707 if (QDF_IS_STATUS_ERROR(status)) {
11708 hdd_err("failed to get pre cac vdev id");
11709 return;
11710 }
11711
11712 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11713 if (!precac_adapter) {
11714 hdd_err("invalid pre cac adapater");
11715 return;
11716 }
11717
11718 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11719 wlan_hdd_sap_pre_cac_failure,
11720 (void *)precac_adapter);
11721 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11722
11723}
11724
11725/**
Komal Seelamec702b02016-02-24 18:42:16 +053011726 * hdd_update_ol_config - API to update ol configuration parameters
11727 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011728 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011729 * Return: void
11730 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011731static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011732{
Komal Seelamec702b02016-02-24 18:42:16 +053011733 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011734 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011735
Komal Seelamec702b02016-02-24 18:42:16 +053011736 if (!ol_ctx)
11737 return;
11738
11739 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11740 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11741 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11742 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011743 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011744
11745 ol_init_ini_config(ol_ctx, &cfg);
11746}
11747
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011748#ifdef FEATURE_RUNTIME_PM
11749/**
11750 * hdd_populate_runtime_cfg() - populate runtime configuration
11751 * @hdd_ctx: hdd context
11752 * @cfg: pointer to the configuration memory being populated
11753 *
11754 * Return: void
11755 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011756static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011757 struct hif_config_info *cfg)
11758{
11759 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11760 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11761}
11762#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011763static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011764 struct hif_config_info *cfg)
11765{
11766}
11767#endif
11768
Komal Seelamec702b02016-02-24 18:42:16 +053011769/**
11770 * hdd_update_hif_config - API to update HIF configuration parameters
11771 * @hdd_ctx: HDD Context
11772 *
11773 * Return: void
11774 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011775static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011776{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011777 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011778 struct hif_config_info cfg;
11779
11780 if (!scn)
11781 return;
11782
11783 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011784 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011785 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011786
11787 if (hdd_ctx->config->prevent_link_down)
11788 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011789}
11790
11791/**
11792 * hdd_update_config() - Initialize driver per module ini parameters
11793 * @hdd_ctx: HDD Context
11794 *
11795 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011796 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011797 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011798int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011799{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011800 int ret;
11801
Komal Seelamec702b02016-02-24 18:42:16 +053011802 hdd_update_ol_config(hdd_ctx);
11803 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011804 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11805 ret = hdd_update_cds_config_ftm(hdd_ctx);
11806 else
11807 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011808 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011809
11810 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011811}
11812
Mukul Sharma9d797a02017-01-05 20:26:03 +053011813#ifdef FEATURE_WLAN_RA_FILTERING
11814/**
11815 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11816 * @psoc_cfg: pmo psoc Configuration
11817 * @hdd_ctx: Pointer to hdd context
11818 *
11819 * Return: none
11820 */
11821static inline void hdd_ra_populate_pmo_config(
11822 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011823 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011824{
11825 psoc_cfg->ra_ratelimit_interval =
11826 hdd_ctx->config->RArateLimitInterval;
11827 psoc_cfg->ra_ratelimit_enable =
11828 hdd_ctx->config->IsRArateLimitEnabled;
11829}
11830#else
11831static inline void hdd_ra_populate_pmo_config(
11832 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011833 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011834{
11835}
11836#endif
11837/**
11838 * hdd_update_pmo_config - API to update pmo configuration parameters
11839 * @hdd_ctx: HDD context
11840 *
11841 * Return: void
11842 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011843static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011844{
11845 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11846 struct pmo_psoc_cfg psoc_cfg;
11847 QDF_STATUS status;
11848
11849 /*
11850 * Value of hdd_ctx->wowEnable can be,
11851 * 0 - Disable both magic pattern match and pattern byte match.
11852 * 1 - Enable magic pattern match on all interfaces.
11853 * 2 - Enable pattern byte match on all interfaces.
11854 * 3 - Enable both magic patter and pattern byte match on
11855 * all interfaces.
11856 */
11857 psoc_cfg.magic_ptrn_enable =
11858 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11859 psoc_cfg.ptrn_match_enable_all_vdev =
11860 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080011861 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
11862 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011863 psoc_cfg.bpf_enable =
11864 hdd_ctx->config->bpf_packet_filter_enable;
11865 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011866 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011867 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11868 if (hdd_ctx->config->fhostNSOffload)
11869 psoc_cfg.ns_offload_enable_dynamic = true;
11870 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11871 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11872 psoc_cfg.active_mode_offload =
11873 hdd_ctx->config->active_mode_offload;
11874 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11875 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011876 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11877 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11878 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11879 psoc_cfg.power_save_mode =
11880 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011881 psoc_cfg.auto_power_save_fail_mode =
11882 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011883
11884 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011885 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11886 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011887 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11888 if (status != QDF_STATUS_SUCCESS) {
11889 hdd_err("failed pmo psoc configuration");
11890 return -EINVAL;
11891 }
11892
11893 return 0;
11894}
11895
Abhishek Singhb20db962017-03-03 21:28:46 +053011896#ifdef FEATURE_WLAN_SCAN_PNO
11897static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11898 struct hdd_config *cfg)
11899{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011900 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
11901
Abhishek Singhb20db962017-03-03 21:28:46 +053011902 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11903 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11904 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11905 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11906 pno_cfg->channel_prediction_full_scan =
11907 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011908 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
11909 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
11910 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
11911 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053011912}
11913#else
11914static inline void
11915hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11916 struct hdd_config *cfg)
11917{
11918 return;
11919}
11920#endif
11921
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011922void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11923 struct hdd_config *cfg)
11924{
11925 uint8_t i = 0;
11926
11927 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11928 if (!ie_whitelist->white_list)
11929 return;
11930
11931 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11932 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11933 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11934 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11935 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11936 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11937 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11938 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11939
11940 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11941 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11942 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11943}
11944
Abhishek Singh257a9482017-03-06 16:52:39 +053011945/**
11946 * hdd_update_scan_config - API to update scan configuration parameters
11947 * @hdd_ctx: HDD context
11948 *
11949 * Return: 0 if success else err
11950 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011951static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011952{
11953 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11954 struct scan_user_cfg scan_cfg;
11955 struct hdd_config *cfg = hdd_ctx->config;
11956 QDF_STATUS status;
11957
11958 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11959 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11960 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11961 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11962 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11963 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11964 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011965 /* convert to ms */
11966 scan_cfg.scan_cache_aging_time =
11967 cfg->scanAgingTimeout * 1000;
11968 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11969 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11970 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11971 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011972 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011973 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011974
Abhishek Singhb20db962017-03-03 21:28:46 +053011975 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011976 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011977
Abhishek Singh257a9482017-03-06 16:52:39 +053011978 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11979 if (status != QDF_STATUS_SUCCESS) {
11980 hdd_err("failed pmo psoc configuration");
11981 return -EINVAL;
11982 }
11983
11984 return 0;
11985}
Abhishek Singh257a9482017-03-06 16:52:39 +053011986
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011987static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080011988{
11989 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11990 struct tdls_start_params tdls_cfg;
11991 struct tdls_user_config *config = &tdls_cfg.config;
11992 struct hdd_config *cfg = hdd_ctx->config;
11993 QDF_STATUS status;
11994
11995 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11996 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11997 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11998 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11999 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12000 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12001 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12002 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12003 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12004 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12005 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12006 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12007 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12008 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12009 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12010 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12011 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12012 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12013 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12014 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12015 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12016 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12017 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12018 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12019 (cfg->fEnableTDLSImplicitTrigger ?
12020 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12021 (cfg->fTDLSExternalControl ?
12022 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12023
12024 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12025 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12026 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12027 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012028 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012029 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012030 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12031 tdls_cfg.tdls_evt_cb_data = psoc;
12032 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12033 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12034 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012035 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12036 tdls_cfg.tdls_wmm_cb_data = psoc;
12037 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12038 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012039 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012040
12041 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12042 if (status != QDF_STATUS_SUCCESS) {
12043 hdd_err("failed pmo psoc configuration");
12044 return -EINVAL;
12045 }
12046
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012047 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012048 /* enable napier specific tdls data path */
12049 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012050
Frank Liud4b2fa02017-03-29 11:46:48 +080012051 return 0;
12052}
Frank Liud4b2fa02017-03-29 11:46:48 +080012053
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012054int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012055{
12056 int ret;
12057
12058 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012059 if (ret)
12060 return ret;
12061 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012062 if (ret)
12063 return ret;
12064 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012065
12066 return ret;
12067}
12068
Agrawal Ashish65634612016-08-18 13:24:32 +053012069/**
12070 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12071 * @mode : cfg80211 DFS mode
12072 *
12073 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12074 */
12075enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12076{
12077 switch (mode) {
12078 case DFS_MODE_ENABLE:
12079 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012080 case DFS_MODE_DISABLE:
12081 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012082 case DFS_MODE_DEPRIORITIZE:
12083 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012084 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012085 hdd_debug("ACS dfs mode is NONE");
12086 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012087 }
12088}
12089
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012090/**
12091 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12092 * @hddctx: pointer to hdd context
12093 * @set_value: enable/disable
12094 *
12095 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12096 * Host(even though it is duplicate). When Host send vendor command
12097 * disable,FW doesn't perform any action. Whenever any change in
12098 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12099 *
12100 * return - 0 on success, appropriate error values on failure.
12101 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012102int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012103{
12104 QDF_STATUS status;
12105
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012106 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012107 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012108
12109 if (!hddctx->config->goptimize_chan_avoid_event) {
12110 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12111 return -EINVAL;
12112 }
12113
12114 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12115 if (!QDF_IS_STATUS_SUCCESS(status)) {
12116 hdd_err("Failed to send chan avoid command to SME");
12117 return -EINVAL;
12118 }
12119 return 0;
12120}
Agrawal Ashish65634612016-08-18 13:24:32 +053012121
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012122/**
12123 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12124 * @value: value to set
12125 *
12126 * This function will set the passed value to roaming in progress flag.
12127 *
12128 * Return: None
12129 */
12130void hdd_set_roaming_in_progress(bool value)
12131{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012132 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012133
12134 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12135 if (!hdd_ctx) {
12136 hdd_err("HDD context is NULL");
12137 return;
12138 }
12139
12140 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012141 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012142}
12143
12144/**
12145 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012146 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012147 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012148 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012149 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012150bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012151{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012152 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012153 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012154
12155 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12156 if (!hdd_ctx) {
12157 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012158 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012159 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012160 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12161 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012162 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12163 hdd_ctx->roaming_in_progress);
12164
12165 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012166}
12167
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012168/**
12169 * hdd_is_connection_in_progress() - check if connection is in
12170 * progress
12171 * @session_id: session id
12172 * @reason: scan reject reason
12173 *
12174 * Go through each adapter and check if Connection is in progress
12175 *
12176 * Return: true if connection is in progress else false
12177 */
12178bool hdd_is_connection_in_progress(uint8_t *session_id,
12179 enum scan_reject_states *reason)
12180{
12181 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012182 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012183 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012184 QDF_STATUS status = 0;
12185 uint8_t sta_id = 0;
12186 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012187 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012188
12189 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12190 if (!hdd_ctx) {
12191 hdd_err("HDD context is NULL");
12192 return false;
12193 }
12194
12195 if (true == hdd_ctx->btCoexModeSet) {
12196 hdd_info("BTCoex Mode operation in progress");
12197 return true;
12198 }
12199 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12200 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
12201 adapter = adapter_node->pAdapter;
12202 if (!adapter)
12203 goto end;
12204
12205 hdd_info("Adapter with device mode %s(%d) exists",
12206 hdd_device_mode_to_string(adapter->device_mode),
12207 adapter->device_mode);
12208 if (((QDF_STA_MODE == adapter->device_mode)
12209 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12210 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12211 && (eConnectionState_Connecting ==
12212 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12213 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012214 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012215 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12216 adapter->sessionId);
12217 if (session_id && reason) {
12218 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012219 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012220 }
12221 return true;
12222 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012223 /*
12224 * sme_neighbor_middle_of_roaming is for LFR2
12225 * hdd_is_roaming_in_progress is for LFR3
12226 */
12227 if (((QDF_STA_MODE == adapter->device_mode) &&
12228 sme_neighbor_middle_of_roaming(
12229 WLAN_HDD_GET_HAL_CTX(adapter),
12230 adapter->sessionId)) ||
12231 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012232 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012233 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12234 adapter->sessionId);
12235 if (session_id && reason) {
12236 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012237 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012238 }
12239 return true;
12240 }
12241 if ((QDF_STA_MODE == adapter->device_mode) ||
12242 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12243 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12244 hdd_sta_ctx =
12245 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12246 if ((eConnectionState_Associated ==
12247 hdd_sta_ctx->conn_info.connState)
12248 && (false ==
12249 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12250 sta_mac = (uint8_t *)
12251 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012252 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012253 " is in middle of WPS/EAPOL exchange.",
12254 MAC_ADDR_ARRAY(sta_mac));
12255 if (session_id && reason) {
12256 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012257 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012258 }
12259 return true;
12260 }
12261 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12262 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12263 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12264 sta_id++) {
12265 if (!((adapter->aStaInfo[sta_id].isUsed)
12266 && (OL_TXRX_PEER_STATE_CONN ==
12267 adapter->aStaInfo[sta_id].tlSTAState)))
12268 continue;
12269
12270 sta_mac = (uint8_t *)
12271 &(adapter->aStaInfo[sta_id].
12272 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012273 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012274 " of SAP/GO is in middle of WPS/EAPOL exchange",
12275 MAC_ADDR_ARRAY(sta_mac));
12276 if (session_id && reason) {
12277 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012278 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012279 }
12280 return true;
12281 }
12282 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012283 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012284 return true;
12285 }
12286 }
12287end:
12288 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12289 adapter_node = next;
12290 }
12291 return false;
12292}
12293
12294/**
12295 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012296 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012297 *
12298 * Return: None
12299 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012300void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012301{
Jeff Johnson87251032017-08-29 13:31:11 -070012302 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012303 hdd_hostapd_state_t *hostapd_state;
12304 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012305 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012306 tsap_Config_t *sap_config;
12307 void *sap_ctx;
12308
12309 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12310 sap_config = &hdd_ap_ctx->sapConfig;
12311 sap_ctx = hdd_ap_ctx->sapContext;
12312
12313 mutex_lock(&hdd_ctx->sap_lock);
12314 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12315 wlan_hdd_del_station(ap_adapter);
12316 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12317 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12318 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12319 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12320 qdf_status =
12321 qdf_wait_single_event(&hostapd_state->
12322 qdf_stop_bss_event,
12323 SME_CMD_TIMEOUT_VALUE);
12324
12325 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12326 cds_err("SAP Stop Failed");
12327 goto end;
12328 }
12329 }
12330 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012331 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012332 ap_adapter->device_mode, ap_adapter->sessionId);
12333 cds_err("SAP Stop Success");
12334
12335 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12336 cds_err("SAP Not able to set AP IEs");
12337 wlansap_reset_sap_config_add_ie(sap_config,
12338 eUPDATE_IE_ALL);
12339 goto end;
12340 }
12341
12342 qdf_event_reset(&hostapd_state->qdf_event);
12343 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12344 sap_config,
12345 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12346 cds_err("SAP Start Bss fail");
12347 wlansap_reset_sap_config_add_ie(sap_config,
12348 eUPDATE_IE_ALL);
12349 goto end;
12350 }
12351
12352 cds_info("Waiting for SAP to start");
12353 qdf_status =
12354 qdf_wait_single_event(&hostapd_state->qdf_event,
12355 SME_CMD_TIMEOUT_VALUE);
12356 wlansap_reset_sap_config_add_ie(sap_config,
12357 eUPDATE_IE_ALL);
12358 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12359 cds_err("SAP Start failed");
12360 goto end;
12361 }
12362 cds_err("SAP Start Success");
12363 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12364 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012365 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12366 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012367 ap_adapter->sessionId);
12368 hostapd_state->bCommit = true;
12369 }
12370end:
12371 mutex_unlock(&hdd_ctx->sap_lock);
12372 return;
12373}
12374
12375/**
12376 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12377 * with non dfs acs
12378 *
12379 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12380 *
12381 * Return: None
12382 */
12383void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12384{
Jeff Johnson9d295242017-08-29 14:39:48 -070012385 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012386 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012387 cds_context_type *cds_ctx;
12388
12389 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12390 if (!hdd_ctx) {
12391 cds_err("HDD context is NULL");
12392 return;
12393 }
12394
12395 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12396 if (!cds_ctx) {
12397 cds_err("Invalid CDS Context");
12398 return;
12399 }
12400
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012401 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12402 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012403 cds_info("Concurrency mode is not SAP");
12404 return;
12405 }
12406
12407 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012408 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12409 &ap_adapter->event_flags) &&
12410 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12411 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012412
12413 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12414 ap_adapter->sessionCtx.ap.sapConfig.channel =
12415 AUTO_CHANNEL_SELECT;
12416 ap_adapter->sessionCtx.ap.sapConfig.
12417 acs_cfg.acs_mode = true;
12418
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012419 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012420 }
12421}
12422
12423/**
12424 * hdd_set_connection_in_progress() - to set the connection in
12425 * progress flag
12426 * @value: value to set
12427 *
12428 * This function will set the passed value to connection in progress flag.
12429 * If value is previously being set to true then no need to set it again.
12430 *
12431 * Return: true if value is being set correctly and false otherwise.
12432 */
12433bool hdd_set_connection_in_progress(bool value)
12434{
12435 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012436 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012437
12438 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12439 if (!hdd_ctx) {
12440 cds_err("HDD context is NULL");
12441 return false;
12442 }
12443
12444 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12445 /*
12446 * if the value is set to true previously and if someone is
12447 * trying to make it true again then it could be some race
12448 * condition being triggered. Avoid this situation by returning
12449 * false
12450 */
12451 if (hdd_ctx->connection_in_progress && value)
12452 status = false;
12453 else
12454 hdd_ctx->connection_in_progress = value;
12455 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12456 return status;
12457}
12458
Jeff Johnson9d295242017-08-29 14:39:48 -070012459int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012460{
12461 if (!adapter) {
12462 hdd_err("Invalid adapter");
12463 return -EINVAL;
12464 }
12465 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012466 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012467 WMA_VDEV_MCC_SET_TIME_QUOTA,
12468 set_value, VDEV_CMD);
12469 return 0;
12470
12471}
12472
Jeff Johnson9d295242017-08-29 14:39:48 -070012473int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012474{
12475 if (!adapter) {
12476 hdd_err("Invalid adapter");
12477 return -EINVAL;
12478 }
12479
12480 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012481 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012482 WMA_VDEV_MCC_SET_TIME_LATENCY,
12483 set_value, VDEV_CMD);
12484 return 0;
12485}
12486
Jeff Johnson9d295242017-08-29 14:39:48 -070012487struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012488 *psoc, uint8_t vdev_id)
12489{
Jeff Johnson9d295242017-08-29 14:39:48 -070012490 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012491 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012492
12493 /*
12494 * Currently PSOC is not being used. But this logic will
12495 * change once we have the converged implementation of
12496 * HDD context per PSOC in place. This would break if
12497 * multiple vdev objects reuse the vdev id.
12498 */
12499 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12500 if (!adapter)
12501 hdd_err("Get adapter by vdev id failed");
12502
12503 return adapter;
12504}
12505
Jeff Johnson9d295242017-08-29 14:39:48 -070012506int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012507 int8_t *rssi, int8_t *snr)
12508{
12509 QDF_STATUS status;
12510 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12511 tCsrRoamProfile *profile = &wext_state->roamProfile;
12512
12513 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12514 profile, bssid, rssi, snr);
12515 if (QDF_STATUS_SUCCESS != status) {
12516 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12517 return -EINVAL;
12518 }
12519
12520 return 0;
12521}
12522
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012523/**
12524 * hdd_send_limit_off_chan_cmd() - send limit off-channel command parameters
12525 * @param - pointer to sir_limit_off_chan
12526 *
12527 * Return: 0 on success and non zero value on failure
12528 */
12529static int hdd_send_limit_off_chan_cmd(struct sir_limit_off_chan *param)
12530{
12531 struct scheduler_msg msg = {0};
12532
12533 msg.type = WMA_SET_LIMIT_OFF_CHAN;
12534 msg.reserved = 0;
12535 msg.bodyptr = param;
12536
12537 if (!QDF_IS_STATUS_SUCCESS(scheduler_post_msg(QDF_MODULE_ID_WMA,
12538 &msg))) {
12539 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
12540 FL("Not able to post WMA_SET_LIMIT_OFF_CHAN to WMA"));
12541 return QDF_STATUS_E_FAILURE;
12542 }
12543
12544 return 0;
12545}
12546
12547/**
12548 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12549 * @adapter - HDD adapter
12550 * @tos - type of service
12551 * @status - status of the traffic
12552 *
12553 * Return: 0 on success and non zero value on failure
12554 */
12555
12556int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12557 bool is_tos_active)
12558{
12559 int ac_bit;
12560 struct sir_limit_off_chan *cmd;
12561 struct hdd_context *hdd_ctx;
12562 int ret;
12563
12564 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12565 ret = wlan_hdd_validate_context(hdd_ctx);
12566
12567 if (ret < 0) {
12568 hdd_err("failed to set limit off chan params");
12569 return ret;
12570 }
12571
12572 cmd = qdf_mem_malloc(sizeof(struct sir_limit_off_chan));
12573 if (!cmd) {
12574 hdd_err("qdf_mem_malloc failed for limit off channel");
12575 return -ENOMEM;
12576 }
12577
12578 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12579
12580 if (is_tos_active)
12581 hdd_ctx->active_ac |= ac_bit;
12582 else
12583 hdd_ctx->active_ac &= ~ac_bit;
12584
12585 if (hdd_ctx->active_ac) {
12586 if (hdd_ctx->active_ac & HDD_AC_VO_BIT) {
12587 cmd->max_off_chan_time =
12588 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12589 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12590 PM_LATENCY);
12591 } else if (hdd_ctx->active_ac & HDD_AC_VI_BIT) {
12592 cmd->max_off_chan_time =
12593 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12594 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12595 PM_LATENCY);
12596 } else {
12597 /*ignore this command if only BE/BK is active */
12598 is_tos_active = false;
12599 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12600 hdd_ctx->config->conc_system_pref);
12601 }
12602 } else {
12603 /* No active tos */
12604 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12605 hdd_ctx->config->conc_system_pref);
12606 }
12607
12608 cmd->vdev_id = adapter->sessionId;
12609 cmd->is_tos_active = is_tos_active;
12610 cmd->rest_time = hdd_ctx->config->nRestTimeConc;
12611 cmd->skip_dfs_chans = true;
12612
12613 ret = hdd_send_limit_off_chan_cmd(cmd);
12614 if (ret)
12615 qdf_mem_free(cmd);
12616
12617 return ret;
12618}
12619
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012620/**
12621 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
12622 * @drv_op: Enum indicating driver op
12623 *
12624 * Return: none
12625 */
12626void hdd_start_driver_ops_timer(int drv_op)
12627{
12628 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
12629 switch (drv_op) {
12630 case eHDD_DRV_OP_PROBE:
12631 memcpy(drv_ops_string, "probe", sizeof("probe"));
12632 break;
12633 case eHDD_DRV_OP_REMOVE:
12634 memcpy(drv_ops_string, "remove", sizeof("remove"));
12635 break;
12636 case eHDD_DRV_OP_SHUTDOWN:
12637 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
12638 break;
12639 case eHDD_DRV_OP_REINIT:
12640 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
12641 break;
12642 }
12643
12644 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
12645 HDD_OPS_INACTIVITY_TIMEOUT);
12646}
12647
12648/**
12649 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
12650 *
12651 * Return: none
12652 */
12653void hdd_stop_driver_ops_timer(void)
12654{
12655 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
12656}
12657
12658/**
12659 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
12660 * inactivity timer
12661 *
12662 * Return: None
12663 */
12664void hdd_drv_ops_inactivity_handler(void)
12665{
12666 hdd_err("%s: %d Sec timer expired while in .%s",
12667 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
12668
12669 /* Driver shutdown is stuck, no recovery possible at this point */
12670 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
12671 sizeof("shutdown")))
12672 QDF_BUG(0);
12673
12674 if (cds_is_self_recovery_enabled())
12675 cds_trigger_recovery();
12676 else
12677 QDF_BUG(0);
12678}
12679
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012680/* Register the module init/exit functions */
12681module_init(hdd_module_init);
12682module_exit(hdd_module_exit);
12683
12684MODULE_LICENSE("Dual BSD/GPL");
12685MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12686MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012688module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12689 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012690
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012691module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12692 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12693
Ravi Joshia307f632017-07-17 23:41:41 -070012694module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12695 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012697module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12698 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12699
12700module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12701
12702module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12703
12704module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);