blob: 081d0cfbd46395d89514a64d763cb0d4ec64719b [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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800177/* the Android framework expects this param even though we don't use it */
178#define BUF_LEN 20
179static char fwpath_buffer[BUF_LEN];
180static struct kparam_string fwpath = {
181 .string = fwpath_buffer,
182 .maxlen = BUF_LEN,
183};
184
185static char *country_code;
186static int enable_11d = -1;
187static int enable_dfs_chan_scan = -1;
188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189/*
190 * spinlock for synchronizing asynchronous request/response
191 * (full description of use in wlan_hdd_main.h)
192 */
193DEFINE_SPINLOCK(hdd_context_lock);
194
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800195#define WLAN_NLINK_CESIUM 30
196
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530197static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198
199#define WOW_MAX_FILTER_LISTS 1
200#define WOW_MAX_FILTERS_PER_LIST 4
201#define WOW_MIN_PATTERN_SIZE 6
202#define WOW_MAX_PATTERN_SIZE 64
203
204#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
205static const struct wiphy_wowlan_support wowlan_support_reg_init = {
206 .flags = WIPHY_WOWLAN_ANY |
207 WIPHY_WOWLAN_MAGIC_PKT |
208 WIPHY_WOWLAN_DISCONNECT |
209 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
210 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
211 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
212 WIPHY_WOWLAN_4WAY_HANDSHAKE |
213 WIPHY_WOWLAN_RFKILL_RELEASE,
214 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
215 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
216 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
217};
218#endif
219
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700220static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
221 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
222 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
223 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
224 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
225 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
226 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
227 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
228 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
229 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
233 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
234 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
235 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
236 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
237 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700255 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700256};
257
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530258int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
259 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
260 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
261 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
262 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
263};
264
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800265/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530266struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800267
268struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800269#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700270static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271#endif
272
Sachin Ahujadddd2632017-03-07 19:07:24 +0530273void hdd_start_complete(int ret)
274{
275 wlan_start_ret_val = ret;
276
277 complete(&wlan_start_comp);
278}
279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800280/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530281 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700282 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530283 *
284 * Return: none
285 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700286static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530287{
Jeff Johnson9d295242017-08-29 14:39:48 -0700288 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530289 hdd_adapter_list_node_t *adapter_node, *next;
290 QDF_STATUS status = QDF_STATUS_SUCCESS;
291
292 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
293 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
294 adapter = adapter_node->pAdapter;
295 if (NULL != adapter)
296 hdd_send_rps_ind(adapter);
297 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
298 adapter_node = next;
299 }
300}
301
302/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800303 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
304 * @vdev_id: vdev_id
305 * @action: action type
306 * @reason: reason type
307 *
308 * Return: none
309 */
310void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
311 enum netif_action_type action, enum netif_reason_type reason)
312{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700313 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700314 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315
316 if (!hdd_ctx) {
317 hdd_err("hdd ctx is NULL");
318 return;
319 }
320 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
321
322 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323}
324
325/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700326 * Store WLAN driver version and timestamp info in global variables such that
327 * crash debugger can extract them from driver debug symbol and crashdump for
328 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329 */
330uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700331
332#ifndef BUILD_TIMESTAMP
333#define BUILD_TIMESTAMP ""
334#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700335uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336
337/**
338 * hdd_device_mode_to_string() - return string conversion of device mode
339 * @device_mode: device mode
340 *
341 * This utility function helps log string conversion of device mode.
342 *
343 * Return: string conversion of device mode, if match found;
344 * "Unknown" otherwise.
345 */
346const char *hdd_device_mode_to_string(uint8_t device_mode)
347{
348 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800349 CASE_RETURN_STRING(QDF_STA_MODE);
350 CASE_RETURN_STRING(QDF_SAP_MODE);
351 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
352 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
353 CASE_RETURN_STRING(QDF_FTM_MODE);
354 CASE_RETURN_STRING(QDF_IBSS_MODE);
355 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
356 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700357 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800358 default:
359 return "Unknown";
360 }
361}
362
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530363/**
364 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
365 * @adapter: HDD adapter
366 * @chan_number: Channel number
367 * @chan_bw: Bandwidth
368 *
369 * Checks if the given bandwidth is valid for the given channel number.
370 *
371 * Return: 0 for success, non-zero for failure
372 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700373int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530374 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800375 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530376{
377 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
378 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
379 bool found = false;
380 tHalHandle hal;
381
382 hal = WLAN_HDD_GET_HAL_CTX(adapter);
383 if (!hal) {
384 hdd_err("Invalid HAL context");
385 return -EINVAL;
386 }
387
388 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
389 hdd_err("No valid channel list");
390 return -EOPNOTSUPP;
391 }
392
393 for (i = 0; i < len; i++) {
394 if (chan[i] == chan_number) {
395 found = true;
396 break;
397 }
398 }
399
400 if (found == false) {
401 hdd_err("Channel not in driver's valid channel list");
402 return -EOPNOTSUPP;
403 }
404
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700405 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
406 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530407 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
408 return -EINVAL;
409 }
410
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700411 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530412 if (chan_bw == CH_WIDTH_80MHZ) {
413 hdd_err("BW80 not possible in 2.4GHz band");
414 return -EINVAL;
415 }
416 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
417 (chan_bw != CH_WIDTH_MAX)) {
418 hdd_err("Only BW20 possible on channel 14");
419 return -EINVAL;
420 }
421 }
422
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700423 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530424 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
425 (chan_bw != CH_WIDTH_MAX)) {
426 hdd_err("Only BW20 possible on channel 165");
427 return -EINVAL;
428 }
429 }
430
431 return 0;
432}
433
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530434/**
435 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
436 *
437 * Block the unloading of the driver (or) interface up until the
438 * cds recovery is completed
439 *
440 * Return: true for recovery completion else false
441 */
442static bool hdd_wait_for_recovery_completion(void)
443{
444 int retry = 0;
445
446 /* Wait for recovery to complete */
447 while (cds_is_driver_recovering()) {
448 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
449 hdd_err("Recovery in progress; wait here!!!");
450 msleep(1000);
451 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
452 hdd_err("SSR never completed, error");
453 /*
454 * Trigger the bug_on in the internal builds, in the
455 * customer builds self-recovery will be enabled
456 * in those cases just return error.
457 */
458 if (cds_is_self_recovery_enabled())
459 return false;
460 QDF_BUG(0);
461 }
462 }
463
464 hdd_info("Recovery completed successfully!");
465 return true;
466}
467
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800468static int __hdd_netdev_notifier_call(struct notifier_block *nb,
469 unsigned long state, void *data)
470{
471#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
472 struct netdev_notifier_info *dev_notif_info = data;
473 struct net_device *dev = dev_notif_info->dev;
474#else
475 struct net_device *dev = data;
476#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700477 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700478 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800480 ENTER_DEV(dev);
481
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800482 /* Make sure that this callback corresponds to our device. */
483 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
484 return NOTIFY_DONE;
485
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530486 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800487 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700488 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489 return NOTIFY_DONE;
490 }
491
492 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700493 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 return NOTIFY_DONE;
495 }
496
497 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
498 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800499 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530500 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 return NOTIFY_DONE;
502 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530503 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 return NOTIFY_DONE;
505
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800506 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507 dev->name, state);
508
509 switch (state) {
510 case NETDEV_REGISTER:
511 break;
512
513 case NETDEV_UNREGISTER:
514 break;
515
516 case NETDEV_UP:
517 sme_ch_avoid_update_req(hdd_ctx->hHal);
518 break;
519
520 case NETDEV_DOWN:
521 break;
522
523 case NETDEV_CHANGE:
524 if (true == adapter->isLinkUpSvcNeeded)
525 complete(&adapter->linkup_event_var);
526 break;
527
528 case NETDEV_GOING_DOWN:
529 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530530 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
531 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532 } else {
hqueaa33ee2017-05-04 17:56:35 +0800533 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800534 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800535 }
536 break;
537
538 default:
539 break;
540 }
541
542 return NOTIFY_DONE;
543}
544
545/**
546 * hdd_netdev_notifier_call() - netdev notifier callback function
547 * @nb: pointer to notifier block
548 * @state: state
549 * @ndev: ndev pointer
550 *
551 * Return: 0 on success, error number otherwise.
552 */
553static int hdd_netdev_notifier_call(struct notifier_block *nb,
554 unsigned long state,
555 void *ndev)
556{
557 int ret;
558
559 cds_ssr_protect(__func__);
560 ret = __hdd_netdev_notifier_call(nb, state, ndev);
561 cds_ssr_unprotect(__func__);
562
563 return ret;
564}
565
566struct notifier_block hdd_netdev_notifier = {
567 .notifier_call = hdd_netdev_notifier_call,
568};
569
570/* variable to hold the insmod parameters */
571static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800572
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530573static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700574int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530575
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800576/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800577static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800578
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530579/**
580 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
581 * @ch_width: NL channel width
582 *
583 * Converts the NL channel width to the driver's internal representation
584 *
585 * Return: Converted channel width. In case of non matching NL channel width,
586 * CH_WIDTH_MAX will be returned.
587 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800588enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530589{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800590 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700591
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800592 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530593 switch (ch_width) {
594 case NL80211_CHAN_WIDTH_20_NOHT:
595 case NL80211_CHAN_WIDTH_20:
596 return CH_WIDTH_20MHZ;
597 case NL80211_CHAN_WIDTH_40:
598 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530599 case NL80211_CHAN_WIDTH_80:
600 return CH_WIDTH_80MHZ;
601 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800602 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
603 return CH_WIDTH_80P80MHZ;
604 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
605 return CH_WIDTH_160MHZ;
606 else
607 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530608 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800609 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
610 return CH_WIDTH_160MHZ;
611 else
612 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530613 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800614 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530615 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800616 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530617 default:
618 hdd_err("Invalid channel width %d, setting to default",
619 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800620 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530621 }
622}
623
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530624/* wlan_hdd_find_opclass() - Find operating class for a channel
625 * @hal: handler to HAL
626 * @channel: channel id
627 * @bw_offset: bandwidth offset
628 *
629 * Function invokes sme api to find the operating class
630 *
631 * Return: operating class
632 */
633uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
634 uint8_t bw_offset)
635{
636 uint8_t opclass = 0;
637
638 sme_get_opclass(hal, channel, bw_offset, &opclass);
639 return opclass;
640}
641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530643 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530644 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800645 * @bitmask: Bitmask of log levels to be enabled
646 *
647 * Called immediately after the cfg.ini is read in order to configure
648 * the desired trace levels.
649 *
650 * Return: None
651 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530652int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530654 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530655 int qdf_print_idx = -1;
656 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800657 /*
658 * if the bitmask is the default value, then a bitmask was not
659 * specified in cfg.ini, so leave the logging level alone (it
660 * will remain at the "compiled in" default value)
661 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700662 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530663 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800664
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530665 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530667 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530668 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530669 QDF_TRACE_LEVEL_NONE, 0);
670
671 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530672 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800673 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530674 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800675 while (0 != bitmask) {
676 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530677 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530678 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530679 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530680 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700682
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 level++;
684 bitmask >>= 1;
685 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530686 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687}
688
689/**
Chris Guo1751acf2017-07-03 14:09:01 +0800690 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
691 * @hdd_ctx: HDD context pointer
692 *
693 * Return: 0 if the context is valid. Error code otherwise
694 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700695int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800696{
697 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
698 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
699 return -ENODEV;
700 }
701
702 if (cds_is_driver_recovering()) {
703 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
704 (void *)_RET_IP_, cds_get_driver_state());
705 return -EAGAIN;
706 }
707
708 if (hdd_ctx->start_modules_in_progress ||
709 hdd_ctx->stop_modules_in_progress) {
710 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
711 (void *)_RET_IP_);
712 return -EAGAIN;
713 }
714
715 return 0;
716}
717
718
719/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800720 * wlan_hdd_validate_context() - check the HDD context
721 * @hdd_ctx: HDD context pointer
722 *
723 * Return: 0 if the context is valid. Error code otherwise
724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700725int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530728 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729 return -ENODEV;
730 }
731
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800732 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800733 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530734 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735 return -EAGAIN;
736 }
737
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700738 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530740
741 if (hdd_ctx->start_modules_in_progress ||
742 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800743 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530744 (void *)_RET_IP_);
745 return -EAGAIN;
746 }
747
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530748 if (cds_is_driver_in_bad_state()) {
749 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
750 (void *)_RET_IP_, cds_get_driver_state());
751 return -ENODEV;
752 }
753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754 return 0;
755}
756
Jeff Johnson9d295242017-08-29 14:39:48 -0700757int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700758{
759 if (!adapter) {
760 hdd_err("adapter is null");
761 return -EINVAL;
762 }
763
764 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
765 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
766 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
767 return -EINVAL;
768 }
769
770 if (!adapter->dev) {
771 hdd_err("adapter net_device is null");
772 return -EINVAL;
773 }
774
775 if (!(adapter->dev->flags & IFF_UP)) {
776 hdd_info("adapter net_device is not up");
777 return -EAGAIN;
778 }
779
780 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
781 hdd_info("adapter session is not open");
782 return -EAGAIN;
783 }
784
785 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
786 hdd_err("bad adapter session Id: %u", adapter->sessionId);
787 return -EINVAL;
788 }
789
790 return 0;
791}
792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530794 * wlan_hdd_validate_modules_state() - Check modules status
795 * @hdd_ctx: HDD context pointer
796 *
797 * Check's the driver module's state and returns true if the
798 * modules are enabled returns false if modules are closed.
799 *
800 * Return: True if modules are enabled or false.
801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700802bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530803{
804 mutex_lock(&hdd_ctx->iface_change_lock);
805 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
806 mutex_unlock(&hdd_ctx->iface_change_lock);
807 hdd_notice("Modules not enabled, Present status: %d",
808 hdd_ctx->driver_status);
809 return false;
810 }
811 mutex_unlock(&hdd_ctx->iface_change_lock);
812 return true;
813}
814
815/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700817 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 *
819 * This function sets the IBSS power save config parameters to WMA
820 * which will send it to firmware if FW supports IBSS power save
821 * before vdev start.
822 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530823 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 * on failure.
825 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700826QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800827{
828 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700829 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830
831 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700832 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530833 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 }
835
Naveen Rawat247a8682017-06-05 15:00:31 -0700836 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
838 hdd_ctx->config->ibssATIMWinSize,
839 VDEV_CMD);
840 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700841 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530842 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843 }
844
Naveen Rawat247a8682017-06-05 15:00:31 -0700845 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800846 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
847 hdd_ctx->config->isIbssPowerSaveAllowed,
848 VDEV_CMD);
849 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700850 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
851 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530852 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 }
854
Naveen Rawat247a8682017-06-05 15:00:31 -0700855 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
857 hdd_ctx->config->
858 isIbssPowerCollapseAllowed, VDEV_CMD);
859 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700860 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
861 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 }
864
Naveen Rawat247a8682017-06-05 15:00:31 -0700865 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
867 hdd_ctx->config->isIbssAwakeOnTxRx,
868 VDEV_CMD);
869 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700870 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530871 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 }
873
Naveen Rawat247a8682017-06-05 15:00:31 -0700874 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
876 hdd_ctx->config->ibssInactivityCount,
877 VDEV_CMD);
878 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700879 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530880 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881 }
882
Naveen Rawat247a8682017-06-05 15:00:31 -0700883 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
885 hdd_ctx->config->ibssTxSpEndInactivityTime,
886 VDEV_CMD);
887 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700888 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
889 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530890 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 }
892
Naveen Rawat247a8682017-06-05 15:00:31 -0700893 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
895 hdd_ctx->config->ibssPsWarmupTime,
896 VDEV_CMD);
897 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700898 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
899 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 }
902
Naveen Rawat247a8682017-06-05 15:00:31 -0700903 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
905 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
906 VDEV_CMD);
907 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700908 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
909 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530910 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 }
912
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530913 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914}
915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916#define INTF_MACADDR_MASK 0x7
917
918/**
919 * hdd_update_macaddr() - update mac address
920 * @config: hdd configuration
921 * @hw_macaddr: mac address
922 *
923 * Mac address for multiple virtual interface is found as following
924 * i) The mac address of the first interface is just the actual hw mac address.
925 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
926 * define the mac address for the remaining interfaces and locally
927 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
928 * supported virtual interfaces, right now this is 0x07 (meaning 8
929 * interface).
930 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
931 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
932 *
933 * Return: None
934 */
935void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530936 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937{
938 int8_t i;
939 uint8_t macaddr_b3, tmp_br3;
940
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530941 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530942 QDF_MAC_ADDR_SIZE);
943 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530944 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530945 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 macaddr_b3 = config->intfMacAddr[i].bytes[3];
947 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
948 INTF_MACADDR_MASK;
949 macaddr_b3 += tmp_br3;
950
951 /* XOR-ing bit-24 of the mac address. This will give enough
952 * mac address range before collision
953 */
954 macaddr_b3 ^= (1 << 7);
955
956 /* Set locally administered bit */
957 config->intfMacAddr[i].bytes[0] |= 0x02;
958 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800959 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 MAC_ADDRESS_STR, i,
961 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
962 }
963}
964
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700965static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966 struct wma_tgt_services *cfg)
967{
968 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969
970 /* Set up UAPSD */
971 config->apUapsdEnabled &= cfg->uapsd;
972
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800973 /* 11AX mode support */
974 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
975 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
976 config->dot11Mode = eHDD_DOT11_MODE_11ac;
977
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 /* 11AC mode support */
979 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
980 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
981 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982
983 /* ARP offload: override user setting if invalid */
984 config->fhostArpOffload &= cfg->arp_offload;
985
986#ifdef FEATURE_WLAN_SCAN_PNO
987 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800988 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 if (cfg->pno_offload)
990 config->PnoOffload = true;
991#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992#ifdef FEATURE_WLAN_TDLS
993 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530994 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
995 cfg->en_tdls_offchan;
996 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
997 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700998 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001000 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1004 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1005#endif
Will Huang496b36c2017-07-11 16:38:50 +08001006 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001007 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008
1009}
1010
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001011/**
1012 * hdd_update_vdev_nss() - sets the vdev nss
1013 * @hdd_ctx: HDD context
1014 *
1015 * Sets the Nss per vdev type based on INI
1016 *
1017 * Return: None
1018 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001019static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001020{
1021 struct hdd_config *cfg_ini = hdd_ctx->config;
1022 uint8_t max_supp_nss = 1;
1023
Naveen Rawat10b1c152017-01-18 11:16:06 -08001024 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001025 max_supp_nss = 2;
1026
1027 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1028 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
1029
1030 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
1031 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
1032}
1033
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301034/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301035 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1036 * @hdd_ctx: HDD context
1037 *
1038 * Updates wiphy vhtcap fields
1039 *
1040 * Return: None
1041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001042static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301043{
1044 struct ieee80211_supported_band *band_5g =
1045 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1046 uint32_t val;
1047
1048 if (!band_5g) {
1049 hdd_debug("5GHz band disabled, skipping capability population");
1050 return;
1051 }
1052
1053 val = hdd_ctx->config->txBFCsnValue;
1054 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1055
1056 val = NUM_OF_SOUNDING_DIMENSIONS;
1057 band_5g->vht_cap.cap |=
1058 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1059
1060 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1061 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1062}
1063
1064/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301065 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1066 * @hdd_ctx: HDD context
1067 *
1068 * Sets the DBS capability as per INI and firmware capability
1069 *
1070 * Return: None
1071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001072static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301073{
1074 struct hdd_config *cfg_ini = hdd_ctx->config;
1075 uint8_t hw_dbs_capable = 0;
1076
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001077 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1078 ((cfg_ini->dual_mac_feature_disable ==
1079 ENABLE_DBS_CXN_AND_SCAN) ||
1080 (cfg_ini->dual_mac_feature_disable ==
1081 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301082 hw_dbs_capable = 1;
1083
1084 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1085}
1086
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001087static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088 struct wma_tgt_ht_cap *cfg)
1089{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301090 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 uint32_t value, val32;
1092 uint16_t val16;
1093 struct hdd_config *pconfig = hdd_ctx->config;
1094 tSirMacHTCapabilityInfo *phtCapInfo;
1095 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1096 uint8_t enable_tx_stbc;
1097
1098 /* check and update RX STBC */
1099 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1100 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1101
1102 /* get the MPDU density */
1103 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1104
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301105 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001106 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107 value = 0;
1108 }
1109
1110 /*
1111 * MPDU density:
1112 * override user's setting if value is larger
1113 * than the one supported by target
1114 */
1115 if (value > cfg->mpdu_density) {
1116 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1117 cfg->mpdu_density);
1118
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301119 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001120 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001121 }
1122
1123 /* get the HT capability info */
1124 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301125 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001126 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 return;
1128 }
1129 val16 = (uint16_t) val32;
1130 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1131
1132 /* Set the LDPC capability */
1133 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1134
1135 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1136 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1137
1138 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1139 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1140
1141 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1142 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1143
1144 enable_tx_stbc = pconfig->enableTxSTBC;
1145
1146 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1147 pconfig->enable2x2 = 1;
1148 } else {
1149 pconfig->enable2x2 = 0;
1150 enable_tx_stbc = 0;
1151
1152 /* 1x1 */
1153 /* Update Rx Highest Long GI data Rate */
1154 if (sme_cfg_set_int(hdd_ctx->hHal,
1155 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001156 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301157 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001158 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159 }
1160
1161 /* Update Tx Highest Long GI data Rate */
1162 if (sme_cfg_set_int
1163 (hdd_ctx->hHal,
1164 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001165 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301166 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001167 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168 }
1169 }
1170 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1171 enable_tx_stbc = 0;
1172 phtCapInfo->txSTBC = enable_tx_stbc;
1173
1174 val32 = val16;
1175 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301176 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001177 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1179 value = SIZE_OF_SUPPORTED_MCS_SET;
1180 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301181 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001182 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001183
1184 if (pconfig->enable2x2) {
1185 for (value = 0; value < cfg->num_rf_chains; value++)
1186 mcs_set[value] =
1187 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1188
1189 status =
1190 sme_cfg_set_str(hdd_ctx->hHal,
1191 WNI_CFG_SUPPORTED_MCS_SET,
1192 mcs_set,
1193 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301194 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001195 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196 }
1197 }
1198#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1199}
1200
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001201static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 struct wma_tgt_vht_cap *cfg)
1203{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301204 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 uint32_t value = 0;
1206 struct hdd_config *pconfig = hdd_ctx->config;
1207 struct wiphy *wiphy = hdd_ctx->wiphy;
1208 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001209 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001210 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001211 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001212 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213
Dustin Brown5e06bd32016-10-04 12:49:10 -07001214 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001215 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001216 return;
1217 }
1218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 /* Get the current MPDU length */
1220 status =
1221 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1222 &value);
1223
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301224 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001225 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 value = 0;
1227 }
1228
1229 /*
1230 * VHT max MPDU length:
1231 * override if user configured value is too high
1232 * that the target cannot support
1233 */
1234 if (value > cfg->vht_max_mpdu) {
1235 status = sme_cfg_set_int(hdd_ctx->hHal,
1236 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1237 cfg->vht_max_mpdu);
1238
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001239 if (status == QDF_STATUS_E_FAILURE)
1240 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 }
1242
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001243 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1244 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1245
1246 if (pconfig->enable2x2)
1247 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1248
1249 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1250 QDF_STATUS_E_FAILURE) {
1251 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1252 }
1253
1254 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1255 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1256 if (pconfig->enable2x2)
1257 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1258
1259 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1260 QDF_STATUS_E_FAILURE) {
1261 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1262 }
1263
1264 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1265 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1266 if (pconfig->enable2x2)
1267 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1268
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001269 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001270 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1271
1272 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1273 QDF_STATUS_E_FAILURE) {
1274 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1275 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001276 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001277 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 &value);
1279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301280 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001281 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001282 value = 0;
1283 }
1284
jiad4a7a33c2017-08-08 15:32:24 +08001285 /* Set HW RX LDPC capability */
1286 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1287 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 status = sme_cfg_set_int(hdd_ctx->hHal,
1289 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001290 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001292 if (status == QDF_STATUS_E_FAILURE)
1293 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001294 }
1295
1296 /* Get current GI 80 value */
1297 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1298 &value);
1299
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301300 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001301 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 value = 0;
1303 }
1304
1305 /* set the Guard interval 80MHz */
1306 if (value && !cfg->vht_short_gi_80) {
1307 status = sme_cfg_set_int(hdd_ctx->hHal,
1308 WNI_CFG_VHT_SHORT_GI_80MHZ,
1309 cfg->vht_short_gi_80);
1310
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001311 if (status == QDF_STATUS_E_FAILURE)
1312 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
1314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 /* Get VHT TX STBC cap */
1316 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1317
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301318 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001319 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320 value = 0;
1321 }
1322
1323 /* VHT TX STBC cap */
1324 if (value && !cfg->vht_tx_stbc) {
1325 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1326 cfg->vht_tx_stbc);
1327
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001328 if (status == QDF_STATUS_E_FAILURE)
1329 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 }
1331
1332 /* Get VHT RX STBC cap */
1333 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1334
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301335 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001336 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 value = 0;
1338 }
1339
1340 /* VHT RX STBC cap */
1341 if (value && !cfg->vht_rx_stbc) {
1342 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1343 cfg->vht_rx_stbc);
1344
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001345 if (status == QDF_STATUS_E_FAILURE)
1346 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 }
1348
1349 /* Get VHT SU Beamformer cap */
1350 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1351 &value);
1352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301353 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001354 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 value = 0;
1356 }
1357
1358 /* set VHT SU Beamformer cap */
1359 if (value && !cfg->vht_su_bformer) {
1360 status = sme_cfg_set_int(hdd_ctx->hHal,
1361 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1362 cfg->vht_su_bformer);
1363
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 if (status == QDF_STATUS_E_FAILURE)
1365 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 }
1367
1368 /* check and update SU BEAMFORMEE capabality */
1369 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1370 pconfig->enableTxBF = cfg->vht_su_bformee;
1371
1372 status = sme_cfg_set_int(hdd_ctx->hHal,
1373 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1374 pconfig->enableTxBF);
1375
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001376 if (status == QDF_STATUS_E_FAILURE)
1377 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378
1379 /* Get VHT MU Beamformer cap */
1380 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1381 &value);
1382
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301383 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001384 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 value = 0;
1386 }
1387
1388 /* set VHT MU Beamformer cap */
1389 if (value && !cfg->vht_mu_bformer) {
1390 status = sme_cfg_set_int(hdd_ctx->hHal,
1391 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1392 cfg->vht_mu_bformer);
1393
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001394 if (status == QDF_STATUS_E_FAILURE)
1395 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 }
1397
1398 /* Get VHT MU Beamformee cap */
1399 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1400 &value);
1401
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301402 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001403 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 value = 0;
1405 }
1406
1407 /* set VHT MU Beamformee cap */
1408 if (value && !cfg->vht_mu_bformee) {
1409 status = sme_cfg_set_int(hdd_ctx->hHal,
1410 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1411 cfg->vht_mu_bformee);
1412
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001413 if (status == QDF_STATUS_E_FAILURE)
1414 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 }
1416
1417 /* Get VHT MAX AMPDU Len exp */
1418 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1419 &value);
1420
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301421 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001422 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001423 value = 0;
1424 }
1425
1426 /*
1427 * VHT max AMPDU len exp:
1428 * override if user configured value is too high
1429 * that the target cannot support.
1430 * Even though Rome publish ampdu_len=7, it can
1431 * only support 4 because of some h/w bug.
1432 */
1433
1434 if (value > cfg->vht_max_ampdu_len_exp) {
1435 status = sme_cfg_set_int(hdd_ctx->hHal,
1436 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1437 cfg->vht_max_ampdu_len_exp);
1438
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001439 if (status == QDF_STATUS_E_FAILURE)
1440 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 }
1442
1443 /* Get VHT TXOP PS CAP */
1444 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1445
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301446 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001447 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 value = 0;
1449 }
1450
1451 /* set VHT TXOP PS cap */
1452 if (value && !cfg->vht_txop_ps) {
1453 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1454 cfg->vht_txop_ps);
1455
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001456 if (status == QDF_STATUS_E_FAILURE)
1457 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 }
1459
1460 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1461 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1462 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1463 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1464 else
1465 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1466
1467
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001468 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1469 status = sme_cfg_set_int(hdd_ctx->hHal,
1470 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1471 VHT_CAP_160_AND_80P80_SUPP);
1472 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001473 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474 band_5g->vht_cap.cap |=
1475 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001476 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1477 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1478 status = sme_cfg_set_int(hdd_ctx->hHal,
1479 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1480 VHT_CAP_160_SUPP);
1481 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001482 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 band_5g->vht_cap.cap |=
1484 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001485 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1486 }
1487 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1488 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301489 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001490 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301491 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001492 &value);
1493 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301494 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001495 value = 0;
1496 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301497 /* set the Guard interval 160MHz */
1498 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001499 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301500 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1501 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001502
1503 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301504 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001505 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001506
1507 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1508 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1509
1510 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1511 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1512 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1513 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1514
1515 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1516 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1517
1518 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1519 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1520 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1521 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1522 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1523 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1524
1525 band_5g->vht_cap.cap |=
1526 (cfg->vht_max_ampdu_len_exp <<
1527 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1528
1529 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1530 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1531 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1532 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1533 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1534 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1535 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1536 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1537
1538 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1539 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1540
1541}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001543/**
1544 * hdd_generate_macaddr_auto() - Auto-generate mac address
1545 * @hdd_ctx: Pointer to the HDD context
1546 *
1547 * Auto-generate mac address using device serial number.
1548 * Keep the first 3 bytes of OUI as before and replace
1549 * the last 3 bytes with the lower 3 bytes of serial number.
1550 *
1551 * Return: 0 for success
1552 * Non zero failure code for errors
1553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001554static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001555{
1556 unsigned int serialno = 0;
1557 struct qdf_mac_addr mac_addr = {
1558 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1559 };
1560
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001561 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001562 if (serialno == 0)
1563 return -EINVAL;
1564
1565 serialno &= 0x00ffffff;
1566
1567 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1568 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1569 mac_addr.bytes[5] = serialno & 0xff;
1570
1571 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1572 return 0;
1573}
1574
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301575/**
1576 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1577 * configuration to cfg_ini in HDD
1578 * @hdd_ctx: Pointer to hdd_ctx
1579 * @cfg: target configuration
1580 *
1581 * Return: None
1582 */
1583#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001584static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301585 struct wma_tgt_cfg *cfg)
1586{
1587 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1588}
1589#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001590static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301591 struct wma_tgt_cfg *cfg)
1592{
1593}
1594#endif
1595
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596void hdd_update_tgt_cfg(void *context, void *param)
1597{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001598 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001599 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 struct wma_tgt_cfg *cfg = param;
1601 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001602 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301603 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301604
Yue Mae3e86ab2017-05-08 10:48:24 -07001605 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301606 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1607 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1608 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1609 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1610 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001611 /* Restore pdev to MAC/WMA contexts */
1612 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001613 } else {
1614 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1615 if (ret) {
1616 hdd_err("pdev creation fails!");
1617 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301618 } else
1619 hdd_debug("New pdev has been created with pdev_id = %u",
1620 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301621 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001622
Naveen Rawat64e477e2016-05-20 10:34:56 -07001623 if (cds_cfg) {
1624 if (hdd_ctx->config->enable_sub_20_channel_width !=
1625 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1626 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1627 cds_cfg->sub_20_channel_width =
1628 WLAN_SUB_20_CH_WIDTH_NONE;
1629 } else {
1630 cds_cfg->sub_20_channel_width =
1631 hdd_ctx->config->enable_sub_20_channel_width;
1632 }
1633 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634
1635 /* first store the INI band capability */
1636 temp_band_cap = hdd_ctx->config->nBandCapability;
1637
1638 hdd_ctx->config->nBandCapability = cfg->band_cap;
1639
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001640 /*
1641 * now overwrite the target band capability with INI
1642 * setting if INI setting is a subset
1643 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644
1645 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1646 (temp_band_cap != eCSR_BAND_ALL))
1647 hdd_ctx->config->nBandCapability = temp_band_cap;
1648 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1649 (temp_band_cap != eCSR_BAND_ALL) &&
1650 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001651 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 }
1653
Amar Singhal58b45ef2017-08-01 13:43:54 -07001654 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1655
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301656 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1658 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1659 }
1660
1661 /* This can be extended to other configurations like ht, vht cap... */
1662
Anurag Chouhanc5548422016-02-24 18:33:27 +05301663 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001665 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001667 static struct qdf_mac_addr default_mac_addr = {
1668 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1669 };
1670 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1671 &default_mac_addr)) {
1672 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1673 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1674 MAC_ADDRESS_STR,
1675 MAC_ADDR_ARRAY(hdd_ctx->config->
1676 intfMacAddr[0].bytes));
1677 } else {
1678 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1679 MAC_ADDRESS_STR,
1680 MAC_ADDR_ARRAY(hdd_ctx->config->
1681 intfMacAddr[0].bytes));
1682 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001683 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 }
1685
1686 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001687 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688
1689 hdd_ctx->max_intf_count = cfg->max_intf_count;
1690
Jeff Johnsonc875e242016-09-23 18:12:34 -07001691 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001692 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1695 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1696
1697 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1698
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001700 if (cfg->services.en_11ax) {
1701 hdd_info("11AX: 11ax is enabled - update HDD config");
1702 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1703 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001704
1705 hdd_update_vdev_nss(hdd_ctx);
1706
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301707 hdd_update_hw_dbs_capable(hdd_ctx);
1708
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001709 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001710 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001711 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001712 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001713
Nitesh Shahe50711f2017-04-26 16:30:45 +05301714 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1715 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1716 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001717 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001718 hdd_ctx->current_antenna_mode);
1719
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001720 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1721 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301722 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301723
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301724 if ((hdd_ctx->config->txBFCsnValue >
1725 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1726 !cfg->tx_bfee_8ss_enabled)
1727 hdd_ctx->config->txBFCsnValue =
1728 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1729
1730 if (sme_cfg_set_int(hdd_ctx->hHal,
1731 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1732 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1733 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1734
1735
1736 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1737 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1738 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301739
1740 /*
1741 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1742 */
1743 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301744 /*
1745 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1746 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1747 * configure the STA mode wow pattern.
1748 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301749 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301750 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301751
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301752 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1753
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001754 /* Configure NAN datapath features */
1755 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001756 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757}
1758
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001759bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001762 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301763 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001764 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765
Arif Hussaincd151632017-02-11 16:57:19 -08001766 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001767 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001768 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301769 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001770 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
Arif Hussaincd151632017-02-11 16:57:19 -08001772 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1773 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1774 adapter = adapterNode->pAdapter;
1775 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1776
1777 if ((QDF_SAP_MODE == adapter->device_mode ||
1778 QDF_P2P_GO_MODE == adapter->device_mode) &&
1779 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1780 ap_ctx->operatingChannel))) {
1781 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1782 true;
1783 hdd_info("tx blocked for session: %d",
1784 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301785 }
Arif Hussaincd151632017-02-11 16:57:19 -08001786 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1787 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301789
1790 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792
1793/**
1794 * hdd_is_valid_mac_address() - validate MAC address
1795 * @pMacAddr: Pointer to the input MAC address
1796 *
1797 * This function validates whether the given MAC address is valid or not
1798 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1799 * where X is the hexa decimal digit character and separated by ':'
1800 * This algorithm works even if MAC address is not separated by ':'
1801 *
1802 * This code checks given input string mac contains exactly 12 hexadecimal
1803 * digits and a separator colon : appears in the input string only after
1804 * an even number of hex digits.
1805 *
1806 * Return: 1 for valid and 0 for invalid
1807 */
1808bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1809{
1810 int xdigit = 0;
1811 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001813 while (*pMacAddr) {
1814 if (isxdigit(*pMacAddr)) {
1815 xdigit++;
1816 } else if (':' == *pMacAddr) {
1817 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1818 break;
1819
1820 ++separator;
1821 } else {
1822 /* Invalid MAC found */
1823 return 0;
1824 }
1825 ++pMacAddr;
1826 }
1827 return xdigit == 12 && (separator == 5 || separator == 0);
1828}
1829
1830/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301831 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1832 * @dev: Handle to struct net_device to be updated.
1833 *
1834 * Return: None
1835 */
1836static void hdd_mon_mode_ether_setup(struct net_device *dev)
1837{
1838 dev->header_ops = NULL;
1839 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1840 dev->hard_header_len = ETH_HLEN;
1841 dev->mtu = ETH_DATA_LEN;
1842 dev->addr_len = ETH_ALEN;
1843 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1844 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1845 dev->priv_flags |= IFF_TX_SKB_SHARING;
1846
1847 memset(dev->broadcast, 0xFF, ETH_ALEN);
1848}
1849
1850/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001851 * __hdd__mon_open() - HDD Open function
1852 * @dev: Pointer to net_device structure
1853 *
1854 * This is called in response to ifconfig up
1855 *
1856 * Return: 0 for success; non-zero for failure
1857 */
1858static int __hdd_mon_open(struct net_device *dev)
1859{
1860 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001861 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1862 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001863
1864 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001865
1866 ret = wlan_hdd_validate_context(hdd_ctx);
1867 if (ret)
1868 return ret;
1869
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301870 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001871
1872 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1873 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1874 if (ret) {
1875 hdd_err("Failed to start WLAN modules return");
1876 return ret;
1877 }
1878 hdd_err("hdd_wlan_start_modules() successful !");
1879
1880 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1881 ret = hdd_start_adapter(adapter);
1882 if (ret) {
1883 hdd_err("Failed to start adapter :%d",
1884 adapter->device_mode);
1885 return ret;
1886 }
1887 hdd_err("hdd_start_adapters() successful !");
1888 }
1889 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1890 }
1891
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001892 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001893
1894 if (!ret)
1895 ret = hdd_enable_monitor_mode(dev);
1896
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001897 return ret;
1898}
1899
1900/**
1901 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1902 * @dev: Pointer to net_device structure
1903 *
1904 * This is called in response to ifconfig up
1905 *
1906 * Return: 0 for success; non-zero for failure
1907 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001908static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001909{
1910 int ret;
1911
1912 cds_ssr_protect(__func__);
1913 ret = __hdd_mon_open(dev);
1914 cds_ssr_unprotect(__func__);
1915
1916 return ret;
1917}
1918
1919/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301920 * hdd_start_adapter() - Wrapper function for device specific adapter
1921 * @adapter: pointer to HDD adapter
1922 *
1923 * This function is called to start the device specific adapter for
1924 * the mode passed in the adapter's device_mode.
1925 *
1926 * Return: 0 for success; non-zero for failure
1927 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001928int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301929{
1930
1931 int ret;
1932 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1933
1934 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001935 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301936
1937 switch (device_mode) {
1938 case QDF_P2P_CLIENT_MODE:
1939 case QDF_P2P_DEVICE_MODE:
1940 case QDF_OCB_MODE:
1941 case QDF_STA_MODE:
1942 case QDF_MONITOR_MODE:
1943 ret = hdd_start_station_adapter(adapter);
1944 if (ret)
1945 goto err_start_adapter;
1946 break;
1947 case QDF_P2P_GO_MODE:
1948 case QDF_SAP_MODE:
1949 ret = hdd_start_ap_adapter(adapter);
1950 if (ret)
1951 goto err_start_adapter;
1952 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301953 case QDF_IBSS_MODE:
1954 /*
1955 * For IBSS interface is initialized as part of
1956 * hdd_init_station_mode()
1957 */
1958 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301959 case QDF_FTM_MODE:
1960 ret = hdd_start_ftm_adapter(adapter);
1961 if (ret)
1962 goto err_start_adapter;
1963 break;
1964 default:
1965 hdd_err("Invalid session type %d", device_mode);
1966 QDF_ASSERT(0);
1967 goto err_start_adapter;
1968 }
1969 if (hdd_set_fw_params(adapter))
1970 hdd_err("Failed to set the FW params for the adapter!");
1971
1972 /*
1973 * Action frame registered in one adapter which will
1974 * applicable to all interfaces
1975 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301976 ret = wlan_hdd_cfg80211_register_frames(adapter);
1977 if (ret < 0) {
1978 hdd_err("Failed to register frames - ret %d", ret);
1979 goto err_start_adapter;
1980 }
1981
Arun Khandavallifae92942016-08-01 13:31:08 +05301982 EXIT();
1983 return 0;
1984err_start_adapter:
1985 return -EINVAL;
1986}
1987
1988/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301989 * hdd_enable_power_management() - API to Enable Power Management
1990 *
1991 * API invokes Bus Interface Layer power management functionality
1992 *
1993 * Return: None
1994 */
1995static void hdd_enable_power_management(void)
1996{
1997 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1998
1999 if (!hif_ctx) {
2000 hdd_err("Bus Interface Context is Invalid");
2001 return;
2002 }
2003
2004 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2005}
2006
2007/**
2008 * hdd_disable_power_management() - API to disable Power Management
2009 *
2010 * API disable Bus Interface Layer Power management functionality
2011 *
2012 * Return: None
2013 */
2014static void hdd_disable_power_management(void)
2015{
2016 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2017
2018 if (!hif_ctx) {
2019 hdd_err("Bus Interface Context is Invalid");
2020 return;
2021 }
2022
2023 hif_disable_power_management(hif_ctx);
2024}
2025
2026/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302027 * hdd_update_hw_sw_info() - API to update the HW/SW information
2028 *
2029 * API to update the HW and SW information in the driver
2030 *
2031 * Return: None
2032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002033static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302034{
2035 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002036 size_t target_hw_name_len;
2037 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302038
2039 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2040 if (!hif_sc) {
2041 hdd_err("HIF context is NULL");
2042 return;
2043 }
2044
2045 /*
2046 * target hw version/revision would only be retrieved after firmware
2047 * download
2048 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002049 hif_get_hw_info(hif_sc,
2050 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302051 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002052 &target_hw_name);
2053
2054 if (hdd_ctx->target_hw_name)
2055 qdf_mem_free(hdd_ctx->target_hw_name);
2056
2057 target_hw_name_len = strlen(target_hw_name) + 1;
2058 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2059 if (hdd_ctx->target_hw_name)
2060 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2061 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302062
2063 /* Get the wlan hw/fw version */
2064 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302065}
2066
2067/**
gbian62edd7e2017-03-07 13:12:13 +08002068 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2069 * @hdd_ctx: Pointer to hdd context
2070 *
2071 * Return: none
2072 */
2073static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002074hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002075{
2076 uint8_t num_entries = 0;
2077 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2078 uint8_t *tx_sched_wrr_ac;
2079 int i;
2080 cds_context_type *cds_ctx;
2081
2082 if (NULL == hdd_ctx)
2083 return;
2084
2085 if (NULL == hdd_ctx->config) {
2086 /* Do nothing if hdd_ctx is invalid */
2087 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2088 return;
2089 }
2090
2091 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2092
2093 if (!cds_ctx) {
2094 hdd_err("Invalid CDS Context");
2095 return;
2096 }
2097
2098 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2099 switch (i) {
2100 case OL_TX_WMM_AC_BE:
2101 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2102 break;
2103 case OL_TX_WMM_AC_BK:
2104 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2105 break;
2106 case OL_TX_WMM_AC_VI:
2107 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2108 break;
2109 case OL_TX_WMM_AC_VO:
2110 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2111 break;
2112 default:
2113 tx_sched_wrr_ac = NULL;
2114 break;
2115 }
2116
2117 hdd_string_to_u8_array(tx_sched_wrr_ac,
2118 tx_sched_wrr_param,
2119 &num_entries,
2120 sizeof(tx_sched_wrr_param));
2121
2122 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2123 cds_ctx->ac_specs[i].wrr_skip_weight =
2124 tx_sched_wrr_param[0];
2125 cds_ctx->ac_specs[i].credit_threshold =
2126 tx_sched_wrr_param[1];
2127 cds_ctx->ac_specs[i].send_limit =
2128 tx_sched_wrr_param[2];
2129 cds_ctx->ac_specs[i].credit_reserve =
2130 tx_sched_wrr_param[3];
2131 cds_ctx->ac_specs[i].discard_weight =
2132 tx_sched_wrr_param[4];
2133 }
2134
2135 num_entries = 0;
2136 }
2137}
2138
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002139#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002140static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2141 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2142{
Jeff Johnson9d295242017-08-29 14:39:48 -07002143 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002144 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002145
2146 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2147 if (!adapter) {
2148 hdd_err("Adapter is NULL");
2149 return PM_MAX_NUM_OF_MODE;
2150 }
2151
2152 return policy_mgr_convert_device_mode_to_qdf_type(
2153 adapter->device_mode);
2154}
2155
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002156static void hdd_register_policy_manager_callback(
2157 struct wlan_objmgr_psoc *psoc)
2158{
2159 struct policy_mgr_hdd_cbacks hdd_cbacks;
2160 hdd_cbacks.sap_restart_chan_switch_cb =
2161 sap_restart_chan_switch_cb;
2162 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2163 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002164 hdd_cbacks.get_mode_for_non_connected_vdev =
2165 wlan_hdd_get_mode_for_non_connected_vdev;
2166
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002167 if (QDF_STATUS_SUCCESS !=
2168 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2169 hdd_err("HDD callback registration with policy manager failed");
2170 }
2171}
2172#else
2173static void hdd_register_policy_manager_callback(
2174 struct wlan_objmgr_psoc *psoc)
2175{
2176}
2177#endif
2178
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002179#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002180static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002181{
2182 struct nan_callbacks cb_obj = {0};
2183
2184 cb_obj.ndi_open = hdd_ndi_open;
2185 cb_obj.ndi_close = hdd_ndi_close;
2186 cb_obj.ndi_start = hdd_ndi_start;
2187 cb_obj.ndi_delete = hdd_ndi_delete;
2188 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2189 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2190
Naveen Rawat37f62c82017-03-26 22:24:43 -07002191 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2192 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002193 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002194
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002195 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2196}
2197#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002198static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002199{
2200}
2201#endif
2202
gbian62edd7e2017-03-07 13:12:13 +08002203/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302204 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2205 * @hdd_ctx: HDD context
2206 * @adapter: HDD adapter
2207 * @reinit: flag to indicate from SSR or normal path
2208 *
2209 * This function maintains the driver state machine it will be invoked from
2210 * startup, reinit and change interface. Depending on the driver state shall
2211 * perform the opening of the modules.
2212 *
2213 * Return: 0 for success; non-zero for failure
2214 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002215int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302216 bool reinit)
2217{
2218 int ret;
2219 qdf_device_t qdf_dev;
2220 QDF_STATUS status;
2221 p_cds_contextType p_cds_context;
2222 bool unint = false;
2223 void *hif_ctx;
2224
2225 ENTER();
2226
2227 p_cds_context = cds_get_global_context();
2228 if (!p_cds_context) {
2229 hdd_err("Global Context is NULL");
2230 QDF_ASSERT(0);
2231 return -EINVAL;
2232 }
2233
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002234 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302235 hdd_ctx->driver_status, reinit);
2236
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:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302393 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302394power_down:
2395 if (!reinit && !unint)
2396 pld_power_off(qdf_dev->dev);
2397release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302398 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302399 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302400 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002401
Arun Khandavallifae92942016-08-01 13:31:08 +05302402 return -EINVAL;
2403}
2404
Naveen Rawat910726a2017-03-06 11:42:51 -08002405#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002406static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002407{
2408 int ret = os_if_wifi_pos_register_nl();
2409
2410 if (ret)
2411 hdd_err("os_if_wifi_pos_register_nl failed");
2412
2413 return ret;
2414}
2415
2416static int hdd_deactivate_wifi_pos(void)
2417{
2418 int ret = os_if_wifi_pos_deregister_nl();
2419
2420 if (ret)
2421 hdd_err("os_if_wifi_pos_deregister_nl failed");
2422
2423 return ret;
2424}
2425
2426/**
2427 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2428 * @hdd_ctx: hdd context
2429 *
2430 * Return: status of operation
2431 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002432static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002433{
2434 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2435 struct hdd_config *cfg = hdd_ctx->config;
2436
2437 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2438 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2439 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2440 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2441 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2442 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2443 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2444 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2445}
2446#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002447static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002448{
2449 return oem_activate_service(hdd_ctx);
2450}
2451
2452static int hdd_deactivate_wifi_pos(void)
2453{
2454 return 0;
2455}
2456
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002457static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002458{
2459}
2460#endif
2461
Arun Khandavallifae92942016-08-01 13:31:08 +05302462/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002463 * __hdd_open() - HDD Open function
2464 * @dev: Pointer to net_device structure
2465 *
2466 * This is called in response to ifconfig up
2467 *
2468 * Return: 0 for success; non-zero for failure
2469 */
2470static int __hdd_open(struct net_device *dev)
2471{
Jeff Johnson9d295242017-08-29 14:39:48 -07002472 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002473 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002474 int ret;
2475
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002476 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302477 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302478 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479
Arunk Khandavallie1b3a382017-09-26 12:01:26 +05302480 if (!hdd_wait_for_recovery_completion()) {
2481 hdd_err("Recovery failed");
2482 return -EIO;
2483 }
2484
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302485 /* Nothing to be done if device is unloading */
2486 if (cds_is_driver_unloading()) {
2487 hdd_err("Driver is unloading can not open the hdd");
2488 return -EBUSY;
2489 }
2490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302492 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302494
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002495
Arun Khandavallifae92942016-08-01 13:31:08 +05302496 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2497 if (ret) {
2498 hdd_err("Failed to start WLAN modules return");
2499 return -ret;
2500 }
2501
2502
2503 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2504 ret = hdd_start_adapter(adapter);
2505 if (ret) {
2506 hdd_err("Failed to start adapter :%d",
2507 adapter->device_mode);
2508 return ret;
2509 }
2510 }
2511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002512 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2513 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002514 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002515 /* Enable TX queues only when we are connected */
2516 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302517 WLAN_START_ALL_NETIF_QUEUE,
2518 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002519 }
2520
Naveen Rawat286def52016-09-23 15:38:02 -07002521 /* Enable carrier and transmit queues for NDI */
2522 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002523 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002524 wlan_hdd_netif_queue_control(adapter,
2525 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2526 WLAN_CONTROL_PATH);
2527 }
2528
Naveen Rawat910726a2017-03-06 11:42:51 -08002529 hdd_populate_wifi_pos_cfg(hdd_ctx);
2530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002531 return ret;
2532}
2533
Arun Khandavallifae92942016-08-01 13:31:08 +05302534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002535/**
2536 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2537 * @dev: Pointer to net_device structure
2538 *
2539 * This is called in response to ifconfig up
2540 *
2541 * Return: 0 for success; non-zero for failure
2542 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002543static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002544{
2545 int ret;
2546
2547 cds_ssr_protect(__func__);
2548 ret = __hdd_open(dev);
2549 cds_ssr_unprotect(__func__);
2550
2551 return ret;
2552}
2553
2554/**
2555 * __hdd_stop() - HDD stop function
2556 * @dev: Pointer to net_device structure
2557 *
2558 * This is called in response to ifconfig down
2559 *
2560 * Return: 0 for success; non-zero for failure
2561 */
2562static int __hdd_stop(struct net_device *dev)
2563{
Jeff Johnson9d295242017-08-29 14:39:48 -07002564 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002565 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566 int ret;
2567
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002568 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302570 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002571 adapter->sessionId, adapter->device_mode));
2572
2573 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302574 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002576
2577 /* Nothing to be done if the interface is not opened */
2578 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002579 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 return -ENODEV;
2581 }
2582
2583 /* Make sure the interface is marked as closed */
2584 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302585
2586 hdd_debug("Disabling Auto Power save timer");
2587 sme_ps_disable_auto_ps_timer(
2588 WLAN_HDD_GET_HAL_CTX(adapter),
2589 adapter->sessionId);
2590
2591 /*
2592 * Disable TX on the interface, after this hard_start_xmit() will not
2593 * be called on that interface
2594 */
2595 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302596 wlan_hdd_netif_queue_control(adapter,
2597 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2598 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599
2600 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002601 * NAN data interface is different in some sense. The traffic on NDI is
2602 * bursty in nature and depends on the need to transfer. The service
2603 * layer may down the interface after the usage and up again when
2604 * required. In some sense, the NDI is expected to be available
2605 * (like SAP) iface until NDI delete request is issued by the service
2606 * layer. Skip BSS termination and adapter deletion for NAN Data
2607 * interface (NDI).
2608 */
2609 if (WLAN_HDD_IS_NDI(adapter))
2610 return 0;
2611
2612 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613 * The interface is marked as down for outside world (aka kernel)
2614 * But the driver is pretty much alive inside. The driver needs to
2615 * tear down the existing connection on the netdev (session)
2616 * cleanup the data pipes and wait until the control plane is stabilized
2617 * for this interface. The call also needs to wait until the above
2618 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002619 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002620 * That is intentional to be able to scan if it is a STA/P2P interface
2621 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302622 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623
2624 /* DeInit the adapter. This ensures datapath cleanup as well */
2625 hdd_deinit_adapter(hdd_ctx, adapter, true);
2626
Arun Khandavallifae92942016-08-01 13:31:08 +05302627
2628 /*
2629 * Find if any iface is up. If any iface is up then can't put device to
2630 * sleep/power save mode
2631 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302632 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002633 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302634 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302635 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302636 }
2637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638 EXIT();
2639 return 0;
2640}
2641
2642/**
2643 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2644 * @dev: pointer to net_device structure
2645 *
2646 * This is called in response to ifconfig down
2647 *
2648 * Return: 0 for success and error number for failure
2649 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002650static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002651{
2652 int ret;
2653
2654 cds_ssr_protect(__func__);
2655 ret = __hdd_stop(dev);
2656 cds_ssr_unprotect(__func__);
2657
2658 return ret;
2659}
2660
2661/**
2662 * __hdd_uninit() - HDD uninit function
2663 * @dev: Pointer to net_device structure
2664 *
2665 * This is called during the netdev unregister to uninitialize all data
2666 * associated with the device
2667 *
2668 * Return: None
2669 */
2670static void __hdd_uninit(struct net_device *dev)
2671{
Jeff Johnson9d295242017-08-29 14:39:48 -07002672 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002673 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002675 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002676
2677 do {
2678 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002679 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680 break;
2681 }
2682
Jeff Johnson399c6272017-08-30 10:51:00 -07002683 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2684 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002685 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686 break;
2687 }
2688
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002689 if (dev != adapter->dev)
2690 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691
Jeff Johnson399c6272017-08-30 10:51:00 -07002692 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693
2694 /* after uninit our adapter structure will no longer be valid */
2695 adapter->dev = NULL;
2696 adapter->magic = 0;
2697 } while (0);
2698
2699 EXIT();
2700}
2701
2702/**
2703 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2704 * @dev: pointer to net_device structure
2705 *
2706 * This is called during the netdev unregister to uninitialize all data
2707 * associated with the device
2708 *
2709 * Return: none
2710 */
2711static void hdd_uninit(struct net_device *dev)
2712{
2713 cds_ssr_protect(__func__);
2714 __hdd_uninit(dev);
2715 cds_ssr_unprotect(__func__);
2716}
2717
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002718static int hdd_open_cesium_nl_sock(void)
2719{
2720#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2721 struct netlink_kernel_cfg cfg = {
2722 .groups = WLAN_NLINK_MCAST_GRP_ID,
2723 .input = NULL
2724 };
2725#endif
2726 int ret = 0;
2727
2728#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2729 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2730#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2731 THIS_MODULE,
2732#endif
2733 &cfg);
2734#else
2735 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2736 WLAN_NLINK_MCAST_GRP_ID,
2737 NULL, NULL, THIS_MODULE);
2738#endif
2739
2740 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002741 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002742 ret = -ECONNREFUSED;
2743 }
2744
2745 return ret;
2746}
2747
2748static void hdd_close_cesium_nl_sock(void)
2749{
2750 if (NULL != cesium_nl_srv_sock) {
2751 netlink_kernel_release(cesium_nl_srv_sock);
2752 cesium_nl_srv_sock = NULL;
2753 }
2754}
2755
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756/**
2757 * __hdd_set_mac_address() - set the user specified mac address
2758 * @dev: Pointer to the net device.
2759 * @addr: Pointer to the sockaddr.
2760 *
2761 * This function sets the user specified mac address using
2762 * the command ifconfig wlanX hw ether <mac adress>.
2763 *
2764 * Return: 0 for success, non zero for failure
2765 */
2766static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2767{
Jeff Johnson9d295242017-08-29 14:39:48 -07002768 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002769 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002770 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302771 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002772 int ret;
2773
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002774 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002775
2776 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2777 ret = wlan_hdd_validate_context(hdd_ctx);
2778 if (0 != ret)
2779 return ret;
2780
2781 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2782 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2783
2784 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302785 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786}
2787
2788/**
2789 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2790 * function from SSR
2791 * @dev: pointer to net_device structure
2792 * @addr: Pointer to the sockaddr
2793 *
2794 * This function sets the user specified mac address using
2795 * the command ifconfig wlanX hw ether <mac adress>.
2796 *
2797 * Return: 0 for success.
2798 */
2799static int hdd_set_mac_address(struct net_device *dev, void *addr)
2800{
2801 int ret;
2802
2803 cds_ssr_protect(__func__);
2804 ret = __hdd_set_mac_address(dev, addr);
2805 cds_ssr_unprotect(__func__);
2806
2807 return ret;
2808}
2809
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002810uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811{
2812 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002813
Anurag Chouhan6d760662016-02-20 16:05:43 +05302814 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002815 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2816 break;
2817 }
2818
Anurag Chouhan6d760662016-02-20 16:05:43 +05302819 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820 return NULL;
2821
2822 hdd_ctx->config->intfAddrMask |= (1 << i);
2823 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2824}
2825
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002826void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827{
2828 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002829
Anurag Chouhan6d760662016-02-20 16:05:43 +05302830 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831 if (!memcmp(releaseAddr,
2832 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2833 6)) {
2834 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2835 break;
2836 }
2837 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002838}
2839
2840#ifdef WLAN_FEATURE_PACKET_FILTERING
2841/**
2842 * __hdd_set_multicast_list() - set the multicast address list
2843 * @dev: Pointer to the WLAN device.
2844 * @skb: Pointer to OS packet (sk_buff).
2845 *
2846 * This funciton sets the multicast address list.
2847 *
2848 * Return: None
2849 */
2850static void __hdd_set_multicast_list(struct net_device *dev)
2851{
Jeff Johnson9d295242017-08-29 14:39:48 -07002852 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853 int i = 0, status;
2854 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002855 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302856 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2857 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2858 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002859
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002860 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302861 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302862 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302865 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302866 goto out;
2867
Dustin Brownc788acb2017-08-01 17:43:51 -07002868 status = hdd_validate_adapter(adapter);
2869 if (status)
2870 goto out;
2871
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302872 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2873 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002874 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302875 goto out;
2876 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302878 /* Delete already configured multicast address list */
2879 if (adapter->mc_addr_list.mc_cnt > 0) {
2880 hdd_info("clear previously configured MC address list");
2881 hdd_disable_and_flush_mc_addr_list(adapter,
2882 pmo_mc_list_change_notify);
2883 }
2884
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002885 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002886 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302887 hdd_disable_and_flush_mc_addr_list(adapter,
2888 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002889 } else {
2890 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302891 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002892 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302893 pmo_ucfg_max_mc_addr_supported(psoc));
2894 hdd_disable_and_flush_mc_addr_list(adapter,
2895 pmo_mc_list_change_notify);
2896 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002898 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002899 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302900 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901 if (i == mc_count)
2902 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302903 memset(&(mc_list_request->mc_addr[i].bytes),
2904 0, ETH_ALEN);
2905 memcpy(&(mc_list_request->mc_addr[i].bytes),
2906 ha->addr, ETH_ALEN);
2907 hdd_info("mlist[%d] = %pM", i,
2908 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002909 i++;
2910 }
2911 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302912
2913 mc_list_request->psoc = psoc;
2914 mc_list_request->vdev_id = adapter->sessionId;
2915 mc_list_request->count = mc_count;
2916 status = hdd_cache_mc_addr_list(mc_list_request);
2917 if (status == 0) {
2918 hdd_enable_mc_addr_filtering(adapter,
2919 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002920 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302921 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302923out:
2924 if (mc_list_request)
2925 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302926 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927}
2928
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930/**
2931 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2932 * @dev: pointer to net_device
2933 *
2934 * Return: none
2935 */
2936static void hdd_set_multicast_list(struct net_device *dev)
2937{
2938 cds_ssr_protect(__func__);
2939 __hdd_set_multicast_list(dev);
2940 cds_ssr_unprotect(__func__);
2941}
2942#endif
2943
2944/**
2945 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2946 * @dev: Pointer to the WLAN device.
2947 * @skb: Pointer to OS packet (sk_buff).
2948 *
2949 * This function is registered with the Linux OS for network
2950 * core to decide which queue to use first.
2951 *
2952 * Return: ac, Queue Index/access category corresponding to UP in IP header
2953 */
2954static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2955#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2956 , void *accel_priv
2957#endif
2958#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2959 , select_queue_fallback_t fallback
2960#endif
2961)
2962{
2963 return hdd_wmm_select_queue(dev, skb);
2964}
2965
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002966static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 .ndo_open = hdd_open,
2968 .ndo_stop = hdd_stop,
2969 .ndo_uninit = hdd_uninit,
2970 .ndo_start_xmit = hdd_hard_start_xmit,
2971 .ndo_tx_timeout = hdd_tx_timeout,
2972 .ndo_get_stats = hdd_get_stats,
2973 .ndo_do_ioctl = hdd_ioctl,
2974 .ndo_set_mac_address = hdd_set_mac_address,
2975 .ndo_select_queue = hdd_select_queue,
2976#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002978#endif
2979};
2980
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002981/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002982static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002983 .ndo_open = hdd_mon_open,
2984 .ndo_stop = hdd_stop,
2985 .ndo_get_stats = hdd_get_stats,
2986};
2987
2988/**
2989 * hdd_set_station_ops() - update net_device ops for monitor mode
2990 * @pWlanDev: Handle to struct net_device to be updated.
2991 * Return: None
2992 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993void hdd_set_station_ops(struct net_device *pWlanDev)
2994{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002995 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2996 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2997 else
2998 pWlanDev->netdev_ops = &wlan_drv_ops;
2999}
3000
Komal Seelama89be8d2016-09-29 11:09:26 +05303001#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05303002/**
3003 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
3004 * @hdd_ctx: HDD context
3005 *
3006 * Return: None
3007 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003008static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05303009{
3010 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
3011
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003012 qdf_runtime_lock_init(&ctx->roc);
3013 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05303014}
3015
3016/**
3017 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
3018 * @hdd_ctx: HDD Context
3019 *
3020 * Return: None
3021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003022static void hdd_runtime_suspend_context_deinit(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_deinit(&ctx->roc);
3027 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05303028
3029 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05303030}
3031
Jeff Johnson9d295242017-08-29 14:39:48 -07003032static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303033{
3034 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3035
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003036 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303037}
3038
Jeff Johnson9d295242017-08-29 14:39:48 -07003039static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05303040{
3041 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
3042
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08003043 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05303044}
3045#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003046static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3047static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003048static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3049static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303050#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003051/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003052 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3053 * @hdd_ctx: global hdd context
3054 * @macAddr: mac address to assign to the interface
3055 * @name: User-visible name of the interface
3056 *
3057 * hdd adapter pointer would point to the netdev->priv space, this function
3058 * would retrive the pointer, and setup the hdd adapter configuration.
3059 *
3060 * Return: the pointer to hdd adapter, otherwise NULL
3061 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003062static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003064 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065 const char *name)
3066{
3067 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003068 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003069 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 /*
3071 * cfg80211 initialization and registration....
3072 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003073 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003074#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3075 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003077 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3078 hdd_mon_mode_ether_setup : ether_setup),
3079 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080
3081 if (pWlanDev != NULL) {
3082
3083 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003084 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085
Jeff Johnson9d295242017-08-29 14:39:48 -07003086 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303087 sta_ctx = &adapter->sessionCtx.station;
3088 qdf_mem_set(sta_ctx->conn_info.staId,
3089 sizeof(sta_ctx->conn_info.staId),
3090 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003092 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003093 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303094 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095
3096 init_completion(&adapter->session_open_comp_var);
3097 init_completion(&adapter->session_close_comp_var);
3098 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303099 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100 init_completion(&adapter->linkup_event_var);
3101 init_completion(&adapter->cancel_rem_on_chan_var);
3102 init_completion(&adapter->rem_on_chan_ready_event);
3103 init_completion(&adapter->sta_authorized_event);
3104 init_completion(&adapter->offchannel_tx_event);
3105 init_completion(&adapter->tx_action_cnf_event);
3106#ifdef FEATURE_WLAN_TDLS
3107 init_completion(&adapter->tdls_add_station_comp);
3108 init_completion(&adapter->tdls_del_station_comp);
3109 init_completion(&adapter->tdls_mgmt_comp);
3110 init_completion(&adapter->tdls_link_establish_req_comp);
3111#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003112 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113 init_completion(&adapter->change_country_code);
3114
3115
3116 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303117 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118
3119 adapter->offloads_configured = false;
3120 adapter->isLinkUpSvcNeeded = false;
3121 adapter->higherDtimTransition = true;
3122 /* Init the net_device structure */
3123 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3124
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303125 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303127 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 sizeof(tSirMacAddr));
3129 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130
3131 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3132 pWlanDev->features |=
3133 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3134 pWlanDev->features |= NETIF_F_RXCSUM;
3135
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003136 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138 hdd_set_station_ops(adapter->dev);
3139
Dustin Brownc81dd412017-08-15 16:26:28 -07003140 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003142 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 adapter->wdev.wiphy = hdd_ctx->wiphy;
3144 adapter->wdev.netdev = pWlanDev;
3145 /* set pWlanDev's parent to underlying device */
3146 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3147 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303148 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303150 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 }
3152
3153 return adapter;
3154}
3155
Jeff Johnson9d295242017-08-29 14:39:48 -07003156static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003158 struct net_device *dev = adapter->dev;
3159 int ret;
3160
3161 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003163 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003164 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3165
3166 ret = dev_alloc_name(dev, dev->name);
3167 if (ret < 0) {
3168 hdd_err(
3169 "unable to get dev name: %s, err = 0x%x",
3170 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303171 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172 }
3173 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003174
3175 ret = register_netdevice(dev);
3176 if (ret) {
3177 hdd_err("register_netdevice(%s) failed, 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 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003182 ret = register_netdev(dev);
3183 if (ret) {
3184 hdd_err("register_netdev(%s) failed, err = 0x%x",
3185 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303186 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003187 }
3188 }
3189 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3190
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003191 EXIT();
3192
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303193 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194}
3195
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003196QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197{
Jeff Johnson9d295242017-08-29 14:39:48 -07003198 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
3200 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003201 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303202 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203 }
3204
3205 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003206 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303207 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208 }
3209
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003210 /*
3211 * For NAN Data interface, the close session results in the final
3212 * indication to the userspace
3213 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003214 if (adapter->device_mode == QDF_NDI_MODE)
3215 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219 /*
3220 * We can be blocked while waiting for scheduled work to be
3221 * flushed, and the adapter structure can potentially be freed, in
3222 * which case the magic will have been reset. So make sure the
3223 * magic is still good, and hence the adapter structure is still
3224 * valid, before signaling completion
3225 */
3226 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3227 complete(&adapter->session_close_comp_var);
3228
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303229 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230}
3231
Krunal Soni8c37e322016-02-03 16:08:37 -08003232/**
3233 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3234 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003235 *
3236 * This routine will check the mode of adapter and if it is required then it
3237 * will initialize the TDLS operations
3238 *
3239 * Return: QDF_STATUS
3240 */
3241#ifdef FEATURE_WLAN_TDLS
Jeff Johnson9d295242017-08-29 14:39:48 -07003242static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003243{
Dustin Brownd28772b2017-03-17 14:16:07 -07003244 if (adapter->device_mode == QDF_IBSS_MODE)
3245 return QDF_STATUS_SUCCESS;
3246
3247 if (wlan_hdd_tdls_init(adapter)) {
3248 hdd_err("wlan_hdd_tdls_init failed");
3249 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003250 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003251 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3252
Krunal Soni8c37e322016-02-03 16:08:37 -08003253 return QDF_STATUS_SUCCESS;
3254}
3255#else
Jeff Johnson9d295242017-08-29 14:39:48 -07003256static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003257{
3258 return QDF_STATUS_SUCCESS;
3259}
3260#endif
3261
Jeff Johnson9d295242017-08-29 14:39:48 -07003262int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263{
Dustin Brownd28772b2017-03-17 14:16:07 -07003264 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265
Dustin Brownd28772b2017-03-17 14:16:07 -07003266 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003267 if (QDF_IS_STATUS_ERROR(status))
3268 return qdf_status_to_os_return(status);
3269
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003270 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003271 if (QDF_IS_STATUS_ERROR(status))
3272 return qdf_status_to_os_return(status);
3273
3274 if (wma_capability_enhanced_mcast_filter())
3275 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3276 else
3277 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003278
3279 return qdf_status_to_os_return(status);
3280}
3281
Jeff Johnson9d295242017-08-29 14:39:48 -07003282int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003283{
3284 QDF_STATUS status;
3285 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003286 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003287 unsigned long rc;
3288
3289 hdd_info("destroying vdev %d", adapter->sessionId);
3290
3291 /* vdev created sanity check */
3292 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3293 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3294 return -EINVAL;
3295 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003296 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003297 /*
3298 * In SSR case, there is no need to destroy vdev in firmware since
3299 * it has already asserted. vdev can be released directly.
3300 */
3301 if (cds_is_driver_recovering())
3302 goto release_vdev;
3303
Dustin Brownd28772b2017-03-17 14:16:07 -07003304 /* close sme session (destroy vdev in firmware via legacy API) */
3305 INIT_COMPLETION(adapter->session_close_comp_var);
3306 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3307 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3308 hdd_sme_close_session_callback, adapter);
3309 if (QDF_IS_STATUS_ERROR(status)) {
3310 hdd_err("failed to close sme session: %d", status);
3311 return qdf_status_to_os_return(status);
3312 }
3313
3314 /* block on a completion variable until sme session is closed */
3315 rc = wait_for_completion_timeout(
3316 &adapter->session_close_comp_var,
3317 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3318 if (!rc) {
3319 hdd_err("timed out waiting for close sme session: %ld", rc);
3320 if (adapter->device_mode == QDF_NDI_MODE)
3321 hdd_ndp_session_end_handler(adapter);
3322 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3323 return -ETIMEDOUT;
3324 }
Yue Maf9782842017-05-08 12:49:49 -07003325release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003326 /* do vdev logical destroy via objmgr */
3327 errno = hdd_objmgr_destroy_vdev(adapter);
3328 if (errno) {
3329 hdd_err("failed to destroy objmgr vdev: %d", errno);
3330 return errno;
3331 }
3332
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003333 /* now that sme session is closed, allow physical vdev destroy */
3334 errno = hdd_objmgr_release_vdev(adapter);
3335 if (errno) {
3336 hdd_err("failed to release objmgr vdev: %d", errno);
3337 return errno;
3338 }
3339
Dustin Brownd28772b2017-03-17 14:16:07 -07003340 hdd_info("vdev destroyed successfully");
3341
3342 return 0;
3343}
3344
Jeff Johnson9d295242017-08-29 14:39:48 -07003345int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003346{
3347 QDF_STATUS status;
3348 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003349 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003350 uint32_t type;
3351 uint32_t sub_type;
3352 unsigned long rc;
3353
3354 hdd_info("creating new vdev");
3355
3356 /* determine vdev (sub)type */
3357 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303358 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003359 hdd_err("failed to get vdev type: %d", status);
3360 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003362
3363 /* do vdev create via objmgr */
3364 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003365 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003366 if (errno) {
3367 hdd_err("failed to create objmgr vdev: %d", errno);
3368 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003370
3371 /* Open a SME session (prepare vdev in firmware via legacy API) */
3372 INIT_COMPLETION(adapter->session_open_comp_var);
3373 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3374 (uint8_t *)&adapter->macAddressCurrent,
3375 adapter->sessionId, type, sub_type);
3376 if (QDF_IS_STATUS_ERROR(status)) {
3377 hdd_err("failed to open sme session: %d", status);
3378 errno = qdf_status_to_os_return(status);
3379 goto objmgr_vdev_destroy;
3380 }
3381
3382 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383 rc = wait_for_completion_timeout(
3384 &adapter->session_open_comp_var,
3385 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3386 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003387 hdd_err("timed out waiting for open sme session: %ld", rc);
3388 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303389 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3390 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003391 }
3392
3393 /* firmware ready for component communication, raise vdev_ready event */
3394 errno = hdd_vdev_ready(adapter);
3395 if (errno) {
3396 hdd_err("failed to dispatch vdev ready event: %d", errno);
3397 goto hdd_vdev_destroy;
3398 }
3399
3400 hdd_info("vdev %d created successfully", adapter->sessionId);
3401
3402 return 0;
3403
3404 /*
3405 * Due to legacy constraints, we need to destroy in the same order as
3406 * create. So, split error handling into 2 cases to accommodate.
3407 */
3408
3409objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003410 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003411
3412 return errno;
3413
3414hdd_vdev_destroy:
3415 QDF_BUG(!hdd_vdev_destroy(adapter));
3416
3417 return errno;
3418}
3419
Jeff Johnson9d295242017-08-29 14:39:48 -07003420QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003421{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003422 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003423 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003424 QDF_STATUS status;
3425 int ret_val;
3426
3427 ret_val = hdd_vdev_create(adapter);
3428 if (ret_val) {
3429 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303430 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 }
3432
Dustin Brownd28772b2017-03-17 14:16:07 -07003433 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3434 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3435 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003436 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003437
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003439 status = hdd_register_wext(adapter->dev);
3440 if (QDF_IS_STATUS_ERROR(status)) {
3441 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442 goto error_register_wext;
3443 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003444 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303446 qdf_mem_set(pHddStaCtx->conn_info.staId,
3447 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3448
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003449 /* set fast roaming capability in sme session */
3450 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3451 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 /* Set the default operation channel */
3453 pHddStaCtx->conn_info.operationChannel =
3454 hdd_ctx->config->OperatingChannel;
3455
3456 /* Make the default Auth Type as OPEN */
3457 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3458
3459 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303460 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003461 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 status, status);
3463 goto error_init_txrx;
3464 }
3465
3466 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3467
3468 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303469 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003470 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 status, status);
3472 goto error_wmm_init;
3473 }
3474
3475 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3476
Naveen Rawat247a8682017-06-05 15:00:31 -07003477 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 WMI_PDEV_PARAM_BURST_ENABLE,
3479 hdd_ctx->config->enableSifsBurst,
3480 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003481 if (ret_val)
3482 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483
Dustin Brownd28772b2017-03-17 14:16:07 -07003484 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003485 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003488 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303489 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003491error_tdls_init:
3492 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3493 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494error_wmm_init:
3495 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3496 hdd_deinit_tx_rx(adapter);
3497error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003498 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003500 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502 return status;
3503}
3504
Jeff Johnson9d295242017-08-29 14:39:48 -07003505void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506{
3507 hdd_cfg80211_state_t *cfgState;
3508
3509 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3510
3511 if (NULL != cfgState->buf) {
3512 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514 rc = wait_for_completion_timeout(
3515 &adapter->tx_action_cnf_event,
3516 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3517 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003518 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303519 /*
3520 * Inform tx status as FAILURE to upper layer and free
3521 * cfgState->buf
3522 */
3523 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 }
3525 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526}
3527
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303528/**
3529 * hdd_station_adapter_deinit() - De-initialize the station adapter
3530 * @hdd_ctx: global hdd context
3531 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003532 * @rtnl_held: Used to indicate whether or not the caller is holding
3533 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303534 *
3535 * This function De-initializes the STA/P2P/OCB adapter.
3536 *
3537 * Return: None.
3538 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003539static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003540 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003541 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303542{
3543 ENTER_DEV(adapter->dev);
3544
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303545 if (adapter->dev) {
3546 if (rtnl_held)
3547 adapter->dev->wireless_handlers = NULL;
3548 else {
3549 rtnl_lock();
3550 adapter->dev->wireless_handlers = NULL;
3551 rtnl_unlock();
3552 }
3553 }
3554
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303555 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3556 hdd_deinit_tx_rx(adapter);
3557 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3558 }
3559
3560 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3561 hdd_wmm_adapter_close(adapter);
3562 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3563 }
3564
3565 hdd_cleanup_actionframe(hdd_ctx, adapter);
3566 wlan_hdd_tdls_exit(adapter);
3567
3568 EXIT();
3569}
3570
3571/**
3572 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3573 * @hdd_ctx: global hdd context
3574 * @adapter: HDD adapter
3575 * @rtnl_held: the rtnl lock hold flag
3576 * This function De-initializes the AP/P2PGo adapter.
3577 *
3578 * Return: None.
3579 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003580static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003581 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003582 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303583{
3584 ENTER_DEV(adapter->dev);
3585
3586 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3587 hdd_wmm_adapter_close(adapter);
3588 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3589 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003590 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303591
3592 hdd_cleanup_actionframe(hdd_ctx, adapter);
3593
3594 hdd_unregister_hostapd(adapter, rtnl_held);
3595
3596 EXIT();
3597}
3598
Jeff Johnson9d295242017-08-29 14:39:48 -07003599void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 bool rtnl_held)
3601{
3602 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003605 case QDF_STA_MODE:
3606 case QDF_P2P_CLIENT_MODE:
3607 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303609 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 break;
3611 }
3612
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003613 case QDF_SAP_MODE:
3614 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615 {
3616
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303617 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 break;
3619 }
3620
3621 default:
3622 break;
3623 }
3624
3625 EXIT();
3626}
3627
Jeff Johnson9d295242017-08-29 14:39:48 -07003628static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003629 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630{
3631 struct net_device *pWlanDev = NULL;
3632
3633 if (adapter)
3634 pWlanDev = adapter->dev;
3635 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003636 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 return;
3638 }
3639
Rajeev Kumardca5f812016-02-04 17:28:06 -08003640 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303641
3642 if (adapter->scan_info.default_scan_ies) {
3643 qdf_mem_free(adapter->scan_info.default_scan_ies);
3644 adapter->scan_info.default_scan_ies = NULL;
3645 }
3646
Komal Seelama89be8d2016-09-29 11:09:26 +05303647 hdd_adapter_runtime_suspend_denit(adapter);
3648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 /*
3650 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3651 * the driver is almost closed and cannot handle either control
3652 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003653 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3654 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 * is not right. Setting this flag helps hdd_stop() to recognize that
3656 * the interface is closed and restricts any operations on that
3657 */
3658 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3659
3660 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003661 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003663 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 /*
3666 * Note that the adapter is no longer valid at this point
3667 * since the memory has been reclaimed
3668 */
3669 }
3670}
3671
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003672static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003673 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674{
3675 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003676 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303677 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303680 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 adapter = adapterNode->pAdapter;
3682 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303683 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303685 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 }
3687 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3688 adapterNode = pNext;
3689 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303690 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003692
Arun Khandavalli2358d522016-05-16 18:05:37 +05303693#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3694/**
3695 * hdd_set_fw_log_params() - Set log parameters to FW
3696 * @hdd_ctx: HDD Context
3697 * @adapter: HDD Adapter
3698 *
3699 * This function set the FW Debug log level based on the INI.
3700 *
3701 * Return: None
3702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003703static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003704 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303705{
3706 uint8_t count = 0, numentries = 0,
3707 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3708 uint32_t value = 0;
3709 int ret;
3710
Arun Khandavallifae92942016-08-01 13:31:08 +05303711 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3712 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003713 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303714 return;
3715 }
3716
Arun Khandavallifae92942016-08-01 13:31:08 +05303717 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303718 hdd_ctx->fw_log_settings.dl_type =
3719 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003720 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303721 WMI_DBGLOG_TYPE,
3722 hdd_ctx->config->enableFwLogType,
3723 DBG_CMD);
3724 if (ret != 0)
3725 hdd_err("Failed to enable FW log type ret %d",
3726 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303727
3728 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303729 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003730 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303731 WMI_DBGLOG_LOG_LEVEL,
3732 hdd_ctx->config->enableFwLogLevel,
3733 DBG_CMD);
3734 if (ret != 0)
3735 hdd_err("Failed to enable FW log level ret %d",
3736 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303737
3738 hdd_string_to_u8_array(
3739 hdd_ctx->config->enableFwModuleLogLevel,
3740 moduleloglevel,
3741 &numentries,
3742 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3743
3744 while (count < numentries) {
3745 /*
3746 * FW module log level input string looks like
3747 * below:
3748 * gFwDebugModuleLoglevel=<FW Module ID>,
3749 * <Log Level>,...
3750 * For example:
3751 * gFwDebugModuleLoglevel=
3752 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3753 * Above input string means :
3754 * For FW module ID 1 enable log level 0
3755 * For FW module ID 2 enable log level 1
3756 * For FW module ID 3 enable log level 2
3757 * For FW module ID 4 enable log level 3
3758 * For FW module ID 5 enable log level 4
3759 * For FW module ID 6 enable log level 5
3760 * For FW module ID 7 enable log level 6
3761 */
3762
Nishank Aggarwale239d962017-03-03 12:26:02 +05303763 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3764 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3765 hdd_err("Module id %d and dbglog level %d input length is more than max",
3766 moduleloglevel[count],
3767 moduleloglevel[count + 1]);
3768 return;
3769 }
3770
3771 value = moduleloglevel[count] << 16;
3772 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003773 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303774 WMI_DBGLOG_MOD_LOG_LEVEL,
3775 value, DBG_CMD);
3776 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303777 hdd_err("Failed to enable FW module log level %d ret %d",
3778 value, ret);
3779
3780 count += 2;
3781 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303782
Arun Khandavalli2358d522016-05-16 18:05:37 +05303783}
3784#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003785static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003786 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303787{
3788}
3789
3790#endif
3791
3792/**
3793 * hdd_set_fw_params() - Set parameters to firmware
3794 * @adapter: HDD adapter
3795 *
3796 * This function Sets various parameters to fw once the
3797 * adapter is started.
3798 *
3799 * Return: 0 on success or errno on failure
3800 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003801int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303802{
3803 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003804 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303805
3806 ENTER_DEV(adapter->dev);
3807
3808 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3809 if (!hdd_ctx)
3810 return -EINVAL;
3811
Dustin Brown732ab9c2017-06-15 13:24:09 -07003812 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3813 hdd_debug("FTM Mode is active; nothing to do");
3814 return 0;
3815 }
3816
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303817 ret = sme_cli_set_command(adapter->sessionId,
3818 WMI_PDEV_PARAM_DTIM_SYNTH,
3819 hdd_ctx->config->enable_lprx, PDEV_CMD);
3820 if (ret) {
3821 hdd_err("Failed to set LPRx");
3822 goto error;
3823 }
3824
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303825 if (adapter->device_mode == QDF_STA_MODE) {
3826 sme_set_smps_cfg(adapter->sessionId,
3827 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3828 hdd_ctx->config->upper_brssi_thresh);
3829
3830 sme_set_smps_cfg(adapter->sessionId,
3831 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3832 hdd_ctx->config->lower_brssi_thresh);
3833
3834 sme_set_smps_cfg(adapter->sessionId,
3835 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3836 hdd_ctx->config->enable_dtim_1chrx);
3837 }
3838
Dustin Brown732ab9c2017-06-15 13:24:09 -07003839 if (hdd_ctx->config->enable2x2) {
3840 hdd_debug("configuring 2x2 mode fw params");
3841
Naveen Rawat247a8682017-06-05 15:00:31 -07003842 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003843 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3844 hdd_ctx->config->enable_cck_tx_fir_override,
3845 PDEV_CMD);
3846 if (ret) {
3847 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3848 ret);
3849 goto error;
3850 }
3851 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852#define HDD_DTIM_1CHAIN_RX_ID 0x5
3853#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003854 hdd_debug("configuring 1x1 mode fw params");
3855
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003856 /*
3857 * Disable DTIM 1 chain Rx when in 1x1,
3858 * we are passing two value
3859 * as param_id << 29 | param_value.
3860 * Below param_value = 0(disable)
3861 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003862 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003863 WMI_STA_SMPS_PARAM_CMDID,
3864 HDD_DTIM_1CHAIN_RX_ID <<
3865 HDD_SMPS_PARAM_VALUE_S,
3866 VDEV_CMD);
3867 if (ret) {
3868 hdd_err("DTIM 1 chain set failed %d", ret);
3869 goto error;
3870 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303871
Naveen Rawat247a8682017-06-05 15:00:31 -07003872 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003873 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3874 hdd_ctx->config->txchainmask1x1,
3875 PDEV_CMD);
3876 if (ret) {
3877 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3878 ret);
3879 goto error;
3880 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303881
Naveen Rawat247a8682017-06-05 15:00:31 -07003882 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003883 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3884 hdd_ctx->config->rxchainmask1x1,
3885 PDEV_CMD);
3886 if (ret) {
3887 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3888 ret);
3889 goto error;
3890 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303891#undef HDD_DTIM_1CHAIN_RX_ID
3892#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003893 }
3894
Naveen Rawat247a8682017-06-05 15:00:31 -07003895 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003896 WMI_PDEV_PARAM_HYST_EN,
3897 hdd_ctx->config->enableMemDeepSleep,
3898 PDEV_CMD);
3899 if (ret) {
3900 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3901 goto error;
3902 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303903
Naveen Rawat247a8682017-06-05 15:00:31 -07003904 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003905 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3906 hdd_ctx->config->rts_profile,
3907 VDEV_CMD);
3908 if (ret) {
3909 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3910 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303911 }
3912
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003913 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3914
3915 ret = wma_cli_set_command(adapter->sessionId,
3916 GEN_VDEV_PARAM_AMSDU,
3917 hdd_ctx->config->max_amsdu_num,
3918 GEN_CMD);
3919 if (ret != 0) {
3920 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3921 goto error;
3922 }
3923
Arun Khandavalli2358d522016-05-16 18:05:37 +05303924 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303925 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003926
Arun Khandavalli2358d522016-05-16 18:05:37 +05303927 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303928
Arun Khandavalli2358d522016-05-16 18:05:37 +05303929error:
3930 return -EINVAL;
3931}
3932
Ryan Hsu07495ea2016-01-21 15:25:39 -08003933/**
3934 * hdd_open_adapter() - open and setup the hdd adatper
3935 * @hdd_ctx: global hdd context
3936 * @session_type: type of the interface to be created
3937 * @iface_name: User-visible name of the interface
3938 * @macAddr: MAC address to assign to the interface
3939 * @name_assign_type: the name of assign type of the netdev
3940 * @rtnl_held: the rtnl lock hold flag
3941 *
3942 * This function open and setup the hdd adpater according to the device
3943 * type request, assign the name, the mac address assigned, and then prepared
3944 * the hdd related parameters, queue, lock and ready to start.
3945 *
3946 * Return: the pointer of hdd adapter, otherwise NULL.
3947 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003948struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003950 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003951 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952{
Jeff Johnson9d295242017-08-29 14:39:48 -07003953 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303955 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958
3959 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3960 /*
3961 * Max limit reached on the number of vdevs configured by the
3962 * host. Return error
3963 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303964 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3965 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 return NULL;
3967 }
3968
3969 if (macAddr == NULL) {
3970 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303971 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return NULL;
3973 }
3974 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303975 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303976 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3977 " already exists",
3978 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 return NULL;
3980 }
3981
3982 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003983 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 /* Reset locally administered bit if the device mode is STA */
3985 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05303986 hdd_info("locally administered bit reset in sta mode: "
3987 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003989 case QDF_P2P_CLIENT_MODE:
3990 case QDF_P2P_DEVICE_MODE:
3991 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003992 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303993 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003994 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3995 name_assign_type,
3996 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997
3998 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303999 hdd_err("failed to allocate adapter for session %d",
4000 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 return NULL;
4002 }
4003
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004004 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004006 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004007 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304008 else if (QDF_MONITOR_MODE == session_type)
4009 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 else
4011 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4012
4013 adapter->device_mode = session_type;
4014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 /*
4017 * Workqueue which gets scheduled in IPv4 notification
4018 * callback
4019 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
4021 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022
4023#ifdef WLAN_NS_OFFLOAD
4024 /*
4025 * Workqueue which gets scheduled in IPv6
4026 * notification callback.
4027 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
4029 hdd_ipv6_notifier_work_queue);
4030#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304032 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304034 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035 }
4036
4037 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004038 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304040 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4041 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304042
Ravi Joshi1a292562017-05-18 16:28:54 -07004043 /* Initialize NAN Data Interface */
4044 if (QDF_NDI_MODE == session_type) {
4045 status = hdd_init_nan_data_mode(adapter);
4046 if (QDF_STATUS_SUCCESS != status)
4047 goto err_free_netdev;
4048 }
4049
4050 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004052 case QDF_P2P_GO_MODE:
4053 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004054 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4055 name_assign_type,
4056 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004058 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304059 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 return NULL;
4061 }
4062
4063 adapter->wdev.iftype =
4064 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004065 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 NL80211_IFTYPE_P2P_GO;
4067 adapter->device_mode = session_type;
4068
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004069 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304070 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4072 goto err_free_netdev;
4073 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004074 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304076 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4077 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304079 case QDF_FTM_MODE:
4080 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4081 name_assign_type,
4082 "wlan0");
4083 if (NULL == adapter) {
4084 hdd_err("Failed to allocate adapter for FTM mode");
4085 return NULL;
4086 }
4087 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4088 adapter->device_mode = session_type;
4089 status = hdd_register_interface(adapter, rtnl_held);
4090 if (QDF_STATUS_SUCCESS != status) {
4091 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4092 goto err_free_netdev;
4093 }
4094 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004095 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304096 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304097 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4098 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304099 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004101 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304102 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103 return NULL;
4104 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105
hqueaa33ee2017-05-04 17:56:35 +08004106 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4109 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4110
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304111 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 /* Add it to the hdd's session list. */
4113 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304114 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304116 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004117 } else {
4118 pHddAdapterNode->pAdapter = adapter;
4119 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4120 }
4121 }
4122
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304123 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124 if (NULL != adapter) {
4125 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4126 adapter = NULL;
4127 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004128 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304129 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 return NULL;
4132 }
4133
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304134 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004135 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4136 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 /* Adapter successfully added. Increment the vdev count */
4139 hdd_ctx->current_intf_count++;
4140
Jeff Johnson5880d792016-08-15 13:32:30 -07004141 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 hdd_ctx->current_intf_count);
4143
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004144 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 }
4146
Rajeev Kumardca5f812016-02-04 17:28:06 -08004147 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004148 hdd_err("Interface %s wow debug_fs init failed",
4149 netdev_name(adapter->dev));
4150
4151 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4152 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153
4154 return adapter;
4155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004156err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304158 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159
4160 return NULL;
4161}
4162
Jeff Johnson9d295242017-08-29 14:39:48 -07004163QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004164 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165{
4166 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304167 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168
4169 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304170 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004171 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172 status);
4173 return status;
4174 }
4175
4176 while (pCurrent->pAdapter != adapter) {
4177 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304178 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 break;
4180
4181 pCurrent = pNext;
4182 }
4183 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304184 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004185 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004186 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304187 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004188
4189 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004190 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4191 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304194 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195 adapterNode = NULL;
4196
Dustin Brown5ec6b552017-03-31 12:11:40 -07004197 /* conditionally restart the bw timer */
4198 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4199
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 /* Adapter removed. Decrement vdev count */
4201 if (hdd_ctx->current_intf_count != 0)
4202 hdd_ctx->current_intf_count--;
4203
4204 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304205 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304208 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209}
4210
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004211/**
4212 * hdd_close_all_adapters - Close all open adapters
4213 * @hdd_ctx: Hdd context
4214 * rtnl_held: True if RTNL lock held
4215 *
4216 * Close all open adapters.
4217 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304218 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004219 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004220QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221{
4222 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304223 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224
4225 ENTER();
4226
4227 do {
4228 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304229 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304230 wlan_hdd_release_intf_addr(hdd_ctx,
4231 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004233 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304234 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304235 /* Adapter removed. Decrement vdev count */
4236 if (hdd_ctx->current_intf_count != 0)
4237 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304239 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240
4241 EXIT();
4242
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304243 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244}
4245
Jeff Johnson9d295242017-08-29 14:39:48 -07004246void wlan_hdd_reset_prob_rspies(struct hdd_adapter *pHostapdAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304248 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004252 case QDF_STA_MODE:
4253 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004255 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004256 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004257 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258 break;
4259 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004260 case QDF_SAP_MODE:
4261 case QDF_P2P_GO_MODE:
4262 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004263 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004264 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 break;
4266 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004267 case QDF_FTM_MODE:
4268 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 default:
4270 /*
4271 * wlan_hdd_reset_prob_rspies should not have been called
4272 * for these kind of devices
4273 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004274 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 pHostapdAdapter->device_mode);
4276 return;
4277 }
4278
Anurag Chouhanc5548422016-02-24 18:33:27 +05304279 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4281 updateIE.ieBufferlength = 0;
4282 updateIE.pAdditionIEBuffer = NULL;
4283 updateIE.append = true;
4284 updateIE.notify = false;
4285 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4286 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304287 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004288 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004289 }
4290}
4291
Jeff Johnson9d295242017-08-29 14:39:48 -07004292QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 const bool bCloseSession)
4294{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304295 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4297 union iwreq_data wrqu;
4298 tSirUpdateIE updateIE;
4299 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004300 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301
4302 ENTER();
4303
Sachin Ahuja988fd102016-09-15 17:16:25 +05304304 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004305 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304306 wlan_hdd_netif_queue_control(adapter,
4307 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4308 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004310 case QDF_STA_MODE:
4311 case QDF_P2P_CLIENT_MODE:
4312 case QDF_IBSS_MODE:
4313 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004314 case QDF_NDI_MODE:
4315 if ((QDF_NDI_MODE == adapter->device_mode) ||
4316 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4318 hdd_is_connecting(
4319 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004320 INIT_COMPLETION(adapter->disconnect_comp_var);
4321 /*
4322 * For NDI do not use pWextState from sta_ctx, if needed
4323 * extract from ndi_ctx.
4324 */
4325 if (QDF_NDI_MODE == adapter->device_mode)
4326 qdf_ret_status = sme_roam_disconnect(
4327 hdd_ctx->hHal,
4328 adapter->sessionId,
4329 eCSR_DISCONNECT_REASON_NDI_DELETE);
4330 else if (pWextState->roamProfile.BSSType ==
4331 eCSR_BSS_TYPE_START_IBSS)
4332 qdf_ret_status = sme_roam_disconnect(
4333 hdd_ctx->hHal,
4334 adapter->sessionId,
4335 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004336 else if (QDF_STA_MODE == adapter->device_mode)
4337 qdf_ret_status =
4338 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004340 qdf_ret_status = sme_roam_disconnect(
4341 hdd_ctx->hHal,
4342 adapter->sessionId,
4343 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004344 /* success implies disconnect command got
4345 * queued up successfully
4346 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004347 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4348 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 rc = wait_for_completion_timeout(
4350 &adapter->disconnect_comp_var,
4351 msecs_to_jiffies
4352 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004353 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004354 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004356 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4357 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 memset(&wrqu, '\0', sizeof(wrqu));
4359 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4360 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4361 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4362 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304363 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004364 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304365 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004366
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304367 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304368 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369
4370#ifdef WLAN_OPEN_SOURCE
4371 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4372#endif
4373
4374 hdd_deregister_tx_flow_control(adapter);
4375
4376#ifdef WLAN_NS_OFFLOAD
4377#ifdef WLAN_OPEN_SOURCE
4378 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4379#endif
4380#endif
4381
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304382 if (adapter->device_mode == QDF_STA_MODE)
4383 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4384 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 /*
4386 * It is possible that the caller of this function does not
4387 * wish to close the session
4388 */
Krunal Soni985b8132017-02-10 18:49:08 -08004389 if (true == bCloseSession) {
4390 if (0 != wlan_hdd_try_disconnect(adapter)) {
4391 hdd_err("Error: Can't disconnect adapter");
4392 return QDF_STATUS_E_FAILURE;
4393 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004394 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004395 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 break;
4397
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004398 case QDF_SAP_MODE:
Govind Singh1dab23b2017-08-12 13:31:00 +05304399 /* Flush IPA exception path packets */
4400 hdd_ipa_flush(hdd_ctx);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004401 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004403 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4405
4406 hdd_deregister_tx_flow_control(adapter);
4407
Kapil Guptac1224bf2017-06-22 21:22:40 +05304408 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409 mutex_lock(&hdd_ctx->sap_lock);
4410 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304411 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304412 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413
4414 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 status = wlansap_stop_bss(
4416 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304418 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 hdd_hostapd_state_t *hostapd_state =
4420 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304421 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304422 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304423 qdf_status =
4424 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004425 qdf_stop_bss_event,
4426 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427
Anurag Chouhance0dc992016-02-16 18:18:03 +05304428 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004429 hdd_err("failure waiting for wlansap_stop_bss %d",
4430 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 }
4432 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004433 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434 }
4435 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004436 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4437 adapter->device_mode,
4438 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439
Anurag Chouhanc5548422016-02-24 18:33:27 +05304440 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004441 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442 updateIE.smeSessionId = adapter->sessionId;
4443 updateIE.ieBufferlength = 0;
4444 updateIE.pAdditionIEBuffer = NULL;
4445 updateIE.append = false;
4446 updateIE.notify = false;
4447 /* Probe bcn reset */
4448 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4449 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304450 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004451 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452 }
4453 /* Assoc resp reset */
4454 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4455 &updateIE,
4456 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304457 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004458 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004459 }
4460 /* Reset WNI_CFG_PROBE_RSP Flags */
4461 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004462 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004463 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4464 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304465 /*
4466 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4467 */
4468 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4469 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4470
Peng Xu66162de2016-02-11 17:01:20 -08004471 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004472 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004473 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004475 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004476 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004477 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004478 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479 break;
4480 default:
4481 break;
4482 }
4483
4484 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304485 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486}
4487
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304488/**
4489 * hdd_deinit_all_adapters - deinit all adapters
4490 * @hdd_ctx: HDD context
4491 * @rtnl_held: True if RTNL lock held
4492 *
4493 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004494void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304495{
4496 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4497 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004498 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304499
4500 ENTER();
4501
4502 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4503
4504 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4505 adapter = adapter_node->pAdapter;
4506 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4507 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4508 adapter_node = next;
4509 }
4510
4511 EXIT();
4512}
4513
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004514QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004515{
4516 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304517 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004518 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004519
4520 ENTER();
4521
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304522 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4523
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004524 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4525
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304526 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527 adapter = adapterNode->pAdapter;
4528 hdd_stop_adapter(hdd_ctx, adapter, true);
4529 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4530 adapterNode = pNext;
4531 }
4532
4533 EXIT();
4534
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304535 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536}
4537
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004538QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004539{
4540 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304541 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004542 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004543 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004544 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545
4546 ENTER();
4547
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304548 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4549
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004554 hdd_notice("Disabling queues for adapter type: %d",
4555 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304556
4557 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004558 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304559 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004560 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304561
Arun Khandavallicc544b32017-01-30 19:52:16 +05304562 if (hdd_ctx->config->sap_internal_restart &&
4563 adapter->device_mode == QDF_SAP_MODE) {
4564 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304565 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304566 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004567 if (test_bit(SOFTAP_BSS_STARTED,
4568 &adapter->event_flags)) {
4569 hdd_sap_indicate_disconnect_for_sta(adapter);
4570 hdd_cleanup_actionframe(hdd_ctx, adapter);
4571 hdd_sap_destroy_events(adapter);
4572 }
4573 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4574 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304575 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304576 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004577 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004578 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579
4580 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4581
4582 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004583 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4584 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4586 hdd_wmm_adapter_close(adapter);
4587 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4588 }
4589
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304590 if (adapter->device_mode == QDF_STA_MODE)
4591 hdd_clear_fils_connection_info(adapter);
4592
Wu Gao3545e642017-07-14 19:24:41 +08004593 if (adapter->device_mode == QDF_SAP_MODE) {
4594 /*
4595 * If adapter is SAP, set session ID to invalid
4596 * since SAP session will be cleanup during SSR.
4597 */
Wu Gao36717432016-11-21 15:09:48 +08004598 wlansap_set_invalid_session(
4599 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4600
Wu Gao3545e642017-07-14 19:24:41 +08004601 wlansap_cleanup_cac_timer(
4602 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4603 }
4604
Yue Mad5b4b9f2017-05-26 16:23:40 -07004605 /* Delete peers if any for STA and P2P client modes */
4606 if (adapter->device_mode == QDF_STA_MODE ||
4607 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4608 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4609 qdf_copy_macaddr(&peerMacAddr,
4610 &pHddStaCtx->conn_info.bssId);
4611
4612 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4613 peerMacAddr.bytes);
4614 }
4615
Yue Maf9782842017-05-08 12:49:49 -07004616 /* Destroy vdev which will be recreated during reinit. */
4617 hdd_vdev_destroy(adapter);
4618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4620 adapterNode = pNext;
4621 }
4622
4623 EXIT();
4624
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304625 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004626}
4627
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004628bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304629{
4630 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4631 QDF_STATUS status;
4632 bool close_modules = true;
4633
Arun Khandavalliba479c42017-07-26 21:29:40 +05304634 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4635 hdd_info("FTM mode, don't close the module");
4636 return false;
4637 }
4638
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304639 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4640 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4641 if (test_bit(DEVICE_IFACE_OPENED,
4642 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004643 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304644 close_modules = false;
4645 break;
4646 }
4647 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4648 adapter_node = next;
4649 }
4650
4651 return close_modules;
4652}
4653
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304654bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304655{
4656 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4657 return true;
4658 else
4659 return false;
4660}
4661
Anurag Chouhanc4092922016-09-08 15:56:11 +05304662#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004663 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304664struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4665 struct ieee80211_channel *channel,
4666 const u8 *bssid, const u8 *ssid,
4667 size_t ssid_len)
4668{
4669 return cfg80211_get_bss(wiphy, channel, bssid,
4670 ssid, ssid_len,
4671 WLAN_CAPABILITY_ESS,
4672 WLAN_CAPABILITY_ESS);
4673}
4674#else
4675struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4676 struct ieee80211_channel *channel,
4677 const u8 *bssid, const u8 *ssid,
4678 size_t ssid_len)
4679{
4680 return cfg80211_get_bss(wiphy, channel, bssid,
4681 ssid, ssid_len,
4682 IEEE80211_BSS_TYPE_ESS,
4683 IEEE80211_PRIVACY_ANY);
4684}
4685#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304686
Abhishek Singha84d3952016-09-13 13:45:05 +05304687#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304688#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4689 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4690/**
4691 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4692 * @timeout_reason: reason for connect timeout
4693 *
4694 * This function is used to convert host timeout
4695 * reason enum to kernel specific enum.
4696 *
4697 * Return: nl timeout enum
4698 */
4699static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4700 tSirResultCodes timeout_reason)
4701{
4702 switch (timeout_reason) {
4703 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4704 return NL80211_TIMEOUT_SCAN;
4705 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4706 return NL80211_TIMEOUT_AUTH;
4707 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4708 return NL80211_TIMEOUT_ASSOC;
4709 default:
4710 return NL80211_TIMEOUT_UNSPECIFIED;
4711 }
4712}
4713
4714/**
4715 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4716 * @dev: network device
4717 * @bssid: bssid to which we want to associate
4718 * @timeout_reason: reason for connect timeout
4719 *
4720 * This API is used to send connection timeout reason to supplicant
4721 *
4722 * Return: void
4723 */
4724static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4725 const u8 *bssid,
4726 tSirResultCodes timeout_reason)
4727{
4728 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004729
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304730 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4731
4732 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4733 nl_timeout_reason);
4734}
4735
4736/**
4737 * __hdd_connect_bss() - API to send connection status to supplicant
4738 * @dev: network device
4739 * @bssid: bssid to which we want to associate
4740 * @req_ie: Request Information Element
4741 * @req_ie_len: len of the req IE
4742 * @resp_ie: Response IE
4743 * @resp_ie_len: len of ht response IE
4744 * @status: status
4745 * @gfp: Kernel Flag
4746 * @timeout_reason: reason for connect timeout
4747 *
4748 * Return: void
4749 */
4750static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4751 struct cfg80211_bss *bss, const u8 *req_ie,
4752 size_t req_ie_len, const u8 *resp_ie,
4753 size_t resp_ie_len, int status, gfp_t gfp,
4754 tSirResultCodes timeout_reason)
4755{
4756 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004757
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304758 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4759
4760 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4761 resp_ie, resp_ie_len, status, gfp,
4762 nl_timeout_reason);
4763}
4764#else
4765#if defined CFG80211_CONNECT_TIMEOUT
4766static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4767 const u8 *bssid,
4768 tSirResultCodes timeout_reason)
4769{
4770 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4771}
4772#endif
4773
4774static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4775 struct cfg80211_bss *bss, const u8 *req_ie,
4776 size_t req_ie_len, const u8 *resp_ie,
4777 size_t resp_ie_len, int status, gfp_t gfp,
4778 tSirResultCodes timeout_reason)
4779{
4780 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4781 resp_ie, resp_ie_len, status, gfp);
4782}
4783#endif
4784
Abhishek Singha84d3952016-09-13 13:45:05 +05304785/**
4786 * hdd_connect_bss() - API to send connection status to supplicant
4787 * @dev: network device
4788 * @bssid: bssid to which we want to associate
4789 * @req_ie: Request Information Element
4790 * @req_ie_len: len of the req IE
4791 * @resp_ie: Response IE
4792 * @resp_ie_len: len of ht response IE
4793 * @status: status
4794 * @gfp: Kernel Flag
4795 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304796 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304797 *
4798 * The API is a wrapper to send connection status to supplicant
4799 *
4800 * Return: Void
4801 */
4802#if defined CFG80211_CONNECT_TIMEOUT
4803static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4804 struct cfg80211_bss *bss, const u8 *req_ie,
4805 size_t req_ie_len, const u8 *resp_ie,
4806 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304807 bool connect_timeout,
4808 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304809{
4810 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304811 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304812 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304813 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4814 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304815}
4816#else
4817static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4818 struct cfg80211_bss *bss, const u8 *req_ie,
4819 size_t req_ie_len, const u8 *resp_ie,
4820 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304821 bool connect_timeout,
4822 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304823{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304824 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4825 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304826}
4827#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304828
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304829#ifdef WLAN_FEATURE_FILS_SK
4830#ifdef CFG80211_CONNECT_DONE
4831#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4832/**
4833 * hdd_populate_fils_params() - Populate FILS keys to connect response
4834 * @fils_params: connect response to supplicant
4835 * @fils_kek: FILS kek
4836 * @fils_kek_len: FILS kek length
4837 * @pmk: FILS PMK
4838 * @pmk_len: FILS PMK length
4839 * @pmkid: PMKID
4840 * @fils_seq_num: FILS Seq number
4841 *
4842 * Return: None
4843 */
4844static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4845 *fils_params, const uint8_t *fils_kek,
4846 size_t fils_kek_len, const uint8_t *pmk,
4847 size_t pmk_len, const uint8_t *pmkid,
4848 uint16_t fils_seq_num)
4849{
4850 /* Increament seq number to be used for next FILS */
4851 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4852 fils_params->update_erp_next_seq_num = true;
4853 fils_params->fils_kek = fils_kek;
4854 fils_params->fils_kek_len = fils_kek_len;
4855 fils_params->pmk = pmk;
4856 fils_params->pmk_len = pmk_len;
4857 fils_params->pmkid = pmkid;
4858}
4859#else
4860static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4861 *fils_params, const uint8_t
4862 *fils_kek, size_t fils_kek_len,
4863 const uint8_t *pmk, size_t pmk_len,
4864 const uint8_t *pmkid,
4865 uint16_t fils_seq_num)
4866{ }
4867#endif
4868
4869/**
4870 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4871 * @dev: network device
4872 * @bssid: bssid to which we want to associate
4873 * @bss: cfg80211 bss info
4874 * @roam_info: information about connected bss
4875 * @req_ie: Request Information Element
4876 * @req_ie_len: len of the req IE
4877 * @resp_ie: Response IE
4878 * @resp_ie_len: len of ht response IE
4879 * @status: status
4880 * @gfp: allocation flags
4881 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4882 * @timeout_reason: reason for connect timeout
4883 * @roam_fils_params: FILS join response params
4884 *
4885 * This API is used as wrapper to send FILS key/sequence number
4886 * params etc. to supplicant in case of FILS connection
4887 *
4888 * Return: None
4889 */
4890static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4891 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4892 const u8 *req_ie, size_t req_ie_len,
4893 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4894 gfp_t gfp, bool connect_timeout, tSirResultCodes
4895 timeout_reason, struct fils_join_rsp_params
4896 *roam_fils_params)
4897{
4898 struct cfg80211_connect_resp_params fils_params;
4899 qdf_mem_zero(&fils_params, sizeof(fils_params));
4900
4901 if (!roam_fils_params) {
4902 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4903 } else {
4904 fils_params.status = status;
4905 fils_params.bssid = bssid;
4906 fils_params.timeout_reason = timeout_reason;
4907 fils_params.req_ie = req_ie;
4908 fils_params.req_ie_len = req_ie_len;
4909 fils_params.resp_ie = resp_ie;
4910 fils_params.resp_ie_len = resp_ie_len;
4911 fils_params.bss = bss;
4912 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4913 roam_fils_params->kek_len,
4914 roam_fils_params->fils_pmk,
4915 roam_fils_params->fils_pmk_len,
4916 roam_fils_params->fils_pmkid,
4917 roam_info->fils_seq_num);
4918 }
4919 hdd_debug("FILS indicate connect status %d seq no %d",
4920 fils_params.status,
4921 fils_params.fils_erp_next_seq_num);
4922
4923 cfg80211_connect_done(dev, &fils_params, gfp);
4924
4925 /* Clear all the FILS key info */
4926 if (roam_fils_params && roam_fils_params->fils_pmk)
4927 qdf_mem_free(roam_fils_params->fils_pmk);
4928 if (roam_fils_params)
4929 qdf_mem_free(roam_fils_params);
4930 roam_info->fils_join_rsp = NULL;
4931}
4932#else
4933static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4934 struct cfg80211_bss *bss, tCsrRoamInfo
4935 *roam_info, const u8 *req_ie,
4936 size_t req_ie_len, const u8 *resp_ie,
4937 size_t resp_ie_len, u16 status, gfp_t gfp,
4938 bool connect_timeout, tSirResultCodes
4939 timeout_reason, struct fils_join_rsp_params
4940 *roam_fils_params)
4941{ }
4942#endif
4943#endif
4944
4945#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4946/**
4947 * hdd_fils_update_connect_results() - API to send fils connection status to
4948 * supplicant.
4949 * @dev: network device
4950 * @bssid: bssid to which we want to associate
4951 * @bss: cfg80211 bss info
4952 * @roam_info: information about connected bss
4953 * @req_ie: Request Information Element
4954 * @req_ie_len: len of the req IE
4955 * @resp_ie: Response IE
4956 * @resp_ie_len: len of ht response IE
4957 * @status: status
4958 * @gfp: allocation flags
4959 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4960 * @timeout_reason: reason for connect timeout
4961 *
4962 * The API is a wrapper to send connection status to supplicant
4963 *
4964 * Return: 0 if success else failure
4965 */
4966static int hdd_fils_update_connect_results(struct net_device *dev,
4967 const u8 *bssid,
4968 struct cfg80211_bss *bss,
4969 tCsrRoamInfo *roam_info, const u8 *req_ie,
4970 size_t req_ie_len, const u8 *resp_ie,
4971 size_t resp_ie_len, u16 status, gfp_t gfp,
4972 bool connect_timeout,
4973 tSirResultCodes timeout_reason)
4974{
4975 ENTER();
4976 if (!roam_info || !roam_info->is_fils_connection)
4977 return -EINVAL;
4978
4979 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4980 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4981 timeout_reason, roam_info->fils_join_rsp);
4982 return 0;
4983}
4984#else
4985static inline int hdd_fils_update_connect_results(struct net_device *dev,
4986 const u8 *bssid,
4987 struct cfg80211_bss *bss,
4988 tCsrRoamInfo *roam_info, const u8 *req_ie,
4989 size_t req_ie_len, const u8 *resp_ie,
4990 size_t resp_ie_len, u16 status, gfp_t gfp,
4991 bool connect_timeout,
4992 tSirResultCodes timeout_reason)
4993{
4994 return -EINVAL;
4995}
4996#endif
4997
Anurag Chouhanc4092922016-09-08 15:56:11 +05304998/**
4999 * hdd_connect_result() - API to send connection status to supplicant
5000 * @dev: network device
5001 * @bssid: bssid to which we want to associate
5002 * @roam_info: information about connected bss
5003 * @req_ie: Request Information Element
5004 * @req_ie_len: len of the req IE
5005 * @resp_ie: Response IE
5006 * @resp_ie_len: len of ht response IE
5007 * @status: status
5008 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305009 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305010 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305011 *
5012 * The API is a wrapper to send connection status to supplicant
5013 * and allow runtime suspend
5014 *
5015 * Return: Void
5016 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305017void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5018 tCsrRoamInfo *roam_info, const u8 *req_ie,
5019 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305020 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305021 bool connect_timeout,
5022 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305023{
Jeff Johnson9d295242017-08-29 14:39:48 -07005024 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305025 struct cfg80211_bss *bss = NULL;
5026
5027 if (WLAN_STATUS_SUCCESS == status) {
5028 struct ieee80211_channel *chan;
5029 int freq;
5030 int chan_no = roam_info->pBssDesc->channelId;
5031
5032 if (chan_no <= 14)
5033 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005034 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305035 else
5036 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005037 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305038
5039 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5040 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5041 roam_info->u.pConnectedProfile->SSID.ssId,
5042 roam_info->u.pConnectedProfile->SSID.length);
5043 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305044
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305045 if (hdd_fils_update_connect_results(dev, bssid, bss,
5046 roam_info, req_ie, req_ie_len, resp_ie,
5047 resp_ie_len, status, gfp, connect_timeout,
5048 timeout_reason) != 0) {
5049 hdd_connect_bss(dev, bssid, bss, req_ie,
5050 req_ie_len, resp_ie, resp_ie_len,
5051 status, gfp, connect_timeout, timeout_reason);
5052 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305053
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005054 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005055 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305056}
5057#else
5058void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5059 tCsrRoamInfo *roam_info, const u8 *req_ie,
5060 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305061 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305062 bool connect_timeout,
5063 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305064{
Jeff Johnson9d295242017-08-29 14:39:48 -07005065 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305066
Anurag Chouhanc4092922016-09-08 15:56:11 +05305067 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5068 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005069
5070 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005071 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305072}
5073#endif
5074
5075
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005076QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077{
5078 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305079 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005080 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305082 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083#endif
5084 eConnectionState connState;
5085
5086 ENTER();
5087
5088 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305089 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090 adapter = adapterNode->pAdapter;
5091
Arun Khandavallifae92942016-08-01 13:31:08 +05305092 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305093 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095 hdd_wmm_init(adapter);
5096
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005097 adapter->scan_info.mScanPending = false;
5098
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005100 case QDF_STA_MODE:
5101 case QDF_P2P_CLIENT_MODE:
5102 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005103
5104 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5105 ->conn_info.connState;
5106
5107 hdd_init_station_mode(adapter);
5108 /* Open the gates for HDD to receive Wext commands */
5109 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005111 /* Indicate disconnect event to supplicant
5112 * if associated previously
5113 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005114 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005115 eConnectionState_IbssConnected == connState ||
5116 eConnectionState_NotConnected == connState ||
5117 eConnectionState_IbssDisconnected == connState ||
5118 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121 memset(&wrqu, '\0', sizeof(wrqu));
5122 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5123 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5124 wireless_send_event(adapter->dev, SIOCGIWAP,
5125 &wrqu, NULL);
5126 adapter->sessionCtx.station.
5127 hdd_ReassocScenario = false;
5128
5129 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305130 wlan_hdd_cfg80211_indicate_disconnect(
5131 adapter->dev, false,
5132 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 } else if (eConnectionState_Connecting == connState) {
5134 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005135 * Indicate connect failure to supplicant if we
5136 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305138 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305139 NULL, 0, NULL, 0,
5140 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005141 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 }
5143
5144 hdd_register_tx_flow_control(adapter,
5145 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005146 hdd_tx_resume_cb,
5147 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148
5149 break;
5150
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005151 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005152 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305153 hdd_init_ap_mode(adapter, true);
5154
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155 break;
5156
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005157 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005159 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5161#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005162 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 /* event supplicant to restart */
5164 cfg80211_del_sta(adapter->dev,
5165 (const u8 *)&bcastMac.bytes[0],
5166 GFP_KERNEL);
5167#endif
5168 break;
5169
5170 default:
5171 break;
5172 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005173 /*
5174 * Action frame registered in one adapter which will
5175 * applicable to all interfaces
5176 */
5177 wlan_hdd_cfg80211_register_frames(adapter);
5178
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305179get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5181 adapterNode = pNext;
5182 }
5183
5184 EXIT();
5185
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305186 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187}
5188
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005189QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 hdd_adapter_list_node_t **padapterNode)
5191{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305192 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005193
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005194 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305195 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5196 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005197 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 return status;
5199}
5200
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005201QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 hdd_adapter_list_node_t *adapterNode,
5203 hdd_adapter_list_node_t **pNextAdapterNode)
5204{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305205 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005206
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005207 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305208 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5209 (qdf_list_node_t *) adapterNode,
5210 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005211
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005212 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005213 return status;
5214}
5215
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005216QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 hdd_adapter_list_node_t *adapterNode)
5218{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305219 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005220
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005221 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305222 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005224 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 return status;
5226}
5227
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005228QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229 hdd_adapter_list_node_t **padapterNode)
5230{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305231 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005232
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005233 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305234 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5235 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005236 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 return status;
5238}
5239
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005240QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 hdd_adapter_list_node_t *adapterNode)
5242{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305243 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005244
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005245 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305246 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5247 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005248 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 return status;
5250}
5251
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005252QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 hdd_adapter_list_node_t *adapterNode)
5254{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305255 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005256
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005257 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305258 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5259 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005260 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261 return status;
5262}
5263
Jeff Johnson9d295242017-08-29 14:39:48 -07005264struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 tSirMacAddr macAddr)
5266{
5267 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005268 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305269 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270
5271 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5272
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305273 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005274 adapter = adapterNode->pAdapter;
5275
5276 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305277 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005278 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5282 adapterNode = pNext;
5283 }
5284
5285 return NULL;
5286
5287}
5288
Jeff Johnson9d295242017-08-29 14:39:48 -07005289struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005290 uint32_t vdev_id)
5291{
5292 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005293 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305294 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305296 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305298 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 adapter = adapterNode->pAdapter;
5300
5301 if (adapter->sessionId == vdev_id)
5302 return adapter;
5303
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305304 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5306 adapterNode = pNext;
5307 }
5308
Jeff Johnson5880d792016-08-15 13:32:30 -07005309 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310
5311 return NULL;
5312}
5313
Abhishek Singh7996eb72015-12-30 17:24:02 +05305314/**
5315 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5316 * the sessionid
5317 * @hdd_ctx: hdd context.
5318 * @sme_session_id: sme session is for the adapter to get.
5319 *
5320 * This function is used to get the adapter with provided session id
5321 *
5322 * Return: adapter pointer if found
5323 *
5324 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005325struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305326 uint32_t sme_session_id)
5327{
5328 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005329 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305330 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305331
5332
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305333 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305334
5335 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305336 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305337 adapter = adapter_node->pAdapter;
5338
5339 if (adapter &&
5340 adapter->sessionId == sme_session_id)
5341 return adapter;
5342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305343 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305344 hdd_get_next_adapter(hdd_ctx,
5345 adapter_node, &next);
5346 adapter_node = next;
5347 }
5348 return NULL;
5349}
5350
Jeff Johnson9d295242017-08-29 14:39:48 -07005351struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005352 const char *iface_name)
5353{
5354 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005355 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005356 QDF_STATUS qdf_status;
5357
5358 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5359
5360 while ((NULL != adapter_node) &&
5361 (QDF_STATUS_SUCCESS == qdf_status)) {
5362 adapter = adapter_node->pAdapter;
5363
5364 if (adapter &&
5365 !qdf_str_cmp(adapter->dev->name, iface_name))
5366 return adapter;
5367
5368 qdf_status =
5369 hdd_get_next_adapter(hdd_ctx,
5370 adapter_node, &next);
5371 adapter_node = next;
5372 }
5373 return NULL;
5374}
5375
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005376/**
5377 * hdd_get_adapter() - to get adapter matching the mode
5378 * @hdd_ctx: hdd context
5379 * @mode: adapter mode
5380 *
5381 * This routine will return the pointer to adapter matching
5382 * with the passed mode.
5383 *
5384 * Return: pointer to adapter or null
5385 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005386struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005387 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388{
5389 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005390 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305391 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392
5393 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5394
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305395 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 adapter = adapterNode->pAdapter;
5397
5398 if (adapter && (mode == adapter->device_mode))
5399 return adapter;
5400
5401 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5402 adapterNode = pNext;
5403 }
5404
5405 return NULL;
5406
5407}
5408
5409/**
5410 * hdd_get_operating_channel() - return operating channel of the device mode
5411 * @hdd_ctx: Pointer to the HDD context.
5412 * @mode: Device mode for which operating channel is required.
5413 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005414 * QDF_STA_MODE,
5415 * QDF_P2P_CLIENT_MODE,
5416 * QDF_SAP_MODE,
5417 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005418 *
5419 * This API returns the operating channel of the requested device mode
5420 *
5421 * Return: channel number. "0" id the requested device is not found OR it is
5422 * not connected.
5423 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005424uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005425 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005426{
5427 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305428 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005429 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005430 uint8_t operatingChannel = 0;
5431
5432 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5433
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305434 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435 adapter = adapterNode->pAdapter;
5436
5437 if (mode == adapter->device_mode) {
5438 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005439 case QDF_STA_MODE:
5440 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441 if (hdd_conn_is_connected
5442 (WLAN_HDD_GET_STATION_CTX_PTR
5443 (adapter))) {
5444 operatingChannel =
5445 (WLAN_HDD_GET_STATION_CTX_PTR
5446 (adapter))->conn_info.
5447 operationChannel;
5448 }
5449 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005450 case QDF_SAP_MODE:
5451 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452 /* softap connection info */
5453 if (test_bit
5454 (SOFTAP_BSS_STARTED,
5455 &adapter->event_flags))
5456 operatingChannel =
5457 (WLAN_HDD_GET_AP_CTX_PTR
5458 (adapter))->operatingChannel;
5459 break;
5460 default:
5461 break;
5462 }
5463
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005464 /* Found the device of interest. break the loop */
5465 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005466 }
5467
5468 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5469 adapterNode = pNext;
5470 }
5471 return operatingChannel;
5472}
5473
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005474static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005475 hdd_ctx)
5476{
5477 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305478 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005479 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480
5481 ENTER();
5482
5483 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5484
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305485 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005486 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005487 if ((adapter->device_mode == QDF_STA_MODE) ||
5488 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5489 (adapter->device_mode == QDF_IBSS_MODE) ||
5490 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5491 (adapter->device_mode == QDF_SAP_MODE) ||
5492 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005493 wlan_hdd_cfg80211_deregister_frames(adapter);
5494 hdd_unregister_wext(adapter->dev);
5495 }
5496 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5497 adapterNode = pNext;
5498 }
5499
5500 EXIT();
5501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305502 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005503}
5504
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005505QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506{
5507 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305508 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005509 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510
5511 ENTER();
5512
5513 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5514
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305515 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005516 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005517 if ((adapter->device_mode == QDF_STA_MODE) ||
5518 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5519 (adapter->device_mode == QDF_IBSS_MODE) ||
5520 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5521 (adapter->device_mode == QDF_SAP_MODE) ||
5522 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305523 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5524 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005525 }
5526 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5527 adapterNode = pNext;
5528 }
5529
5530 EXIT();
5531
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305532 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533}
5534
Dustin Brownf27bce82016-11-03 12:52:27 -07005535/**
5536 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5537 * adapters
5538 * @hdd_ctx: The HDD context containing the adapters to operate on
5539 *
5540 * return: QDF_STATUS_SUCCESS
5541 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005542static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005543{
5544 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5545 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005546 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005547 int err;
5548
5549 ENTER();
5550
5551 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5552
5553 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5554 adapter = adapter_node->pAdapter;
5555 if ((adapter->device_mode == QDF_STA_MODE) ||
5556 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5557 (adapter->device_mode == QDF_IBSS_MODE) ||
5558 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5559 (adapter->device_mode == QDF_SAP_MODE) ||
5560 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5561 err = wlan_hdd_sched_scan_stop(adapter->dev);
5562 if (err)
5563 hdd_err("Unable to stop scheduled scan");
5564 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005565 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5566 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005567 adapter_node = next_node;
5568 }
5569
5570 EXIT();
5571
5572 return QDF_STATUS_SUCCESS;
5573}
5574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005575#ifdef WLAN_NS_OFFLOAD
5576/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005577 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578 * @hdd_ctx: Pointer to hdd context
5579 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005580 * Unregister for IPv6 address change notifications.
5581 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582 * Return: None
5583 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005584static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005585{
5586 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587}
5588
5589/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005590 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005591 * @hdd_ctx: Pointer to hdd context
5592 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005593 * Register for IPv6 address change notifications.
5594 *
5595 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005596 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005597static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598{
5599 int ret;
5600
5601 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5602 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005603 if (ret) {
5604 hdd_err("Failed to register IPv6 notifier: %d", ret);
5605 goto out;
5606 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005608 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005609out:
5610 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611}
5612#else
5613/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005614 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615 * @hdd_ctx: Pointer to hdd context
5616 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005617 * Unregister for IPv6 address change notifications.
5618 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005619 * Return: None
5620 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005621static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005622{
5623}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005626 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005627 * @hdd_ctx: Pointer to hdd context
5628 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005629 * Register for IPv6 address change notifications.
5630 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 * Return: None
5632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005633static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005634{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005635 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005636}
5637#endif
5638
5639/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005640 * hdd_register_notifiers - Register netdev notifiers.
5641 * @hdd_ctx: HDD context
5642 *
5643 * Register netdev notifiers like IPv4 and IPv6.
5644 *
5645 * Return: 0 on success and errno on failure
5646 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005647static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005648{
5649 int ret;
5650
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005651 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5652 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305653 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005654
5655 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5656 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5657 if (ret) {
5658 hdd_err("Failed to register IPv4 notifier: %d", ret);
5659 goto unregister_ip6_notifier;
5660 }
5661
5662 return 0;
5663
5664unregister_ip6_notifier:
5665 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005666out:
5667 return ret;
5668
5669}
5670
5671/**
5672 * hdd_unregister_notifiers - Unregister netdev notifiers.
5673 * @hdd_ctx: HDD context
5674 *
5675 * Unregister netdev notifiers like IPv4 and IPv6.
5676 *
5677 * Return: None.
5678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005679void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005680{
5681 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5682
5683 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005684}
5685
5686/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005687 * hdd_exit_netlink_services - Exit netlink services
5688 * @hdd_ctx: HDD context
5689 *
5690 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5691 * nl service.
5692 *
5693 * Return: None.
5694 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005695static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005696{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005697 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005698 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005699 ptt_sock_deactivate_svc();
5700
5701 nl_srv_exit();
5702}
5703
5704/**
5705 * hdd_init_netlink_services- Init netlink services
5706 * @hdd_ctx: HDD context
5707 *
5708 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5709 * nl service.
5710 *
5711 * Return: 0 on success and errno on failure.
5712 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005713static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005714{
5715 int ret;
5716
Ryan Hsuceddceb2016-04-28 10:20:14 -07005717 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005718 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005719 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005720 goto out;
5721 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005722 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005723
Naveen Rawat910726a2017-03-06 11:42:51 -08005724 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005725 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005726 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005727 goto err_nl_srv;
5728 }
5729
5730 ret = ptt_sock_activate_svc();
5731 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005732 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005733 goto err_nl_srv;
5734 }
5735
5736 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005737 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005738 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005739
5740 ret = cnss_diag_activate_service();
5741 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005742 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005743 goto err_close_cesium;
5744 }
5745
5746 return 0;
5747
5748err_close_cesium:
5749 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005750 ptt_sock_deactivate_svc();
5751err_nl_srv:
5752 nl_srv_exit();
5753out:
5754 return ret;
5755}
5756
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005757/**
5758 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5759 * @hdd_ctx: HDD context.
5760 *
5761 * Destroy RX wakelock.
5762 *
5763 * Return: None.
5764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005765static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005766{
5767 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5768}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005769
5770/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005771 * hdd_rx_wake_lock_create() - Create RX wakelock
5772 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005773 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005774 * Create RX wakelock.
5775 *
5776 * Return: None.
5777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005778static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005779{
5780 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5781}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005782
5783/**
5784 * hdd_roc_context_init() - Init ROC context
5785 * @hdd_ctx: HDD context.
5786 *
5787 * Initialize ROC context.
5788 *
5789 * Return: 0 on success and errno on failure.
5790 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005791static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005792{
5793 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5794 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5795
5796 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5797
5798 return 0;
5799}
5800
5801/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305802 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5803 * @hdd_ctx: HDD context.
5804 *
5805 * Free memory allocations made in ROC Req Queue nodes.
5806 *
5807 * Return: None.
5808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005809static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305810{
5811 hdd_roc_req_t *hdd_roc_req;
5812 QDF_STATUS status;
5813
5814 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5815
5816 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5817 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5818 (qdf_list_node_t **) &hdd_roc_req);
5819
5820 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305821 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5822 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305823 QDF_ASSERT(0);
5824 return;
5825 }
5826
5827 if (hdd_roc_req->pRemainChanCtx)
5828 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5829
5830 qdf_mem_free(hdd_roc_req);
5831 }
5832
5833 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5834}
5835
5836/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005837 * hdd_roc_context_destroy() - Destroy ROC context
5838 * @hdd_ctx: HDD context.
5839 *
5840 * Destroy roc list and flush the pending roc work.
5841 *
5842 * Return: None.
5843 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005844static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005845{
5846 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305847 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005848 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005849}
5850
5851/**
Houston Hoffman160db392016-10-10 17:37:51 -07005852 * hdd_context_deinit() - Deinitialize HDD context
5853 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005854 *
Houston Hoffman160db392016-10-10 17:37:51 -07005855 * Deinitialize HDD context along with all the feature specific contexts but
5856 * do not free hdd context itself. Caller of this API is supposed to free
5857 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005858 *
Houston Hoffman160db392016-10-10 17:37:51 -07005859 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005861static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005862{
Houston Hoffman160db392016-10-10 17:37:51 -07005863 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005864
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005865 hdd_roc_context_destroy(hdd_ctx);
5866
5867 hdd_sap_context_destroy(hdd_ctx);
5868
5869 hdd_rx_wake_lock_destroy(hdd_ctx);
5870
5871 hdd_tdls_context_destroy(hdd_ctx);
5872
5873 hdd_scan_context_destroy(hdd_ctx);
5874
5875 qdf_list_destroy(&hdd_ctx->hddAdapters);
5876
Houston Hoffman160db392016-10-10 17:37:51 -07005877 return 0;
5878}
5879
5880/**
5881 * hdd_context_destroy() - Destroy HDD context
5882 * @hdd_ctx: HDD context to be destroyed.
5883 *
5884 * Free config and HDD context as well as destroy all the resources.
5885 *
5886 * Return: None
5887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005888static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005889{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305890
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305891 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5892
Houston Hoffman160db392016-10-10 17:37:51 -07005893 hdd_context_deinit(hdd_ctx);
5894
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305895 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005896 hdd_ctx->config = NULL;
5897
5898 wiphy_free(hdd_ctx->wiphy);
5899}
5900
5901/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305902 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5903 *
5904 * This function is used to destroy bug report lock
5905 *
5906 * Return: None
5907 */
5908static void wlan_destroy_bug_report_lock(void)
5909{
5910 p_cds_contextType p_cds_context;
5911
5912 p_cds_context = cds_get_global_context();
5913 if (!p_cds_context) {
5914 hdd_err("cds context is NULL");
5915 return;
5916 }
5917
5918 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5919}
5920
5921/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005922 * hdd_wlan_exit() - HDD WLAN exit function
5923 * @hdd_ctx: Pointer to the HDD Context
5924 *
5925 * This is the driver exit point (invoked during rmmod)
5926 *
5927 * Return: None
5928 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005929static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005930{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305931 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305933 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934
5935 ENTER();
5936
Arun Khandavallifae92942016-08-01 13:31:08 +05305937 if (QDF_TIMER_STATE_RUNNING ==
5938 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005939 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305940 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 }
5942
Arun Khandavallifae92942016-08-01 13:31:08 +05305943 if (!QDF_IS_STATUS_SUCCESS
5944 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5945 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005946
Arun Khandavallifae92942016-08-01 13:31:08 +05305947
5948 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005949
Nitesh Shah61c10d92016-10-19 19:29:15 +05305950 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5951
Prashanth Bhattaab004382016-10-11 16:08:11 -07005952 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005953
5954#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305955 if (QDF_TIMER_STATE_RUNNING ==
5956 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5957 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005958 }
5959
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305960 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305961 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005962 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005964 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5965 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5966 hdd_ctx->last_acs_channel_list = NULL;
5967 hdd_ctx->num_of_channels = 0;
5968 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005969#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970
Arun Khandavallifae92942016-08-01 13:31:08 +05305971 mutex_lock(&hdd_ctx->iface_change_lock);
5972 driver_status = hdd_ctx->driver_status;
5973 mutex_unlock(&hdd_ctx->iface_change_lock);
5974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005975 /*
5976 * Powersave Offload Case
5977 * Disable Idle Power Save Mode
5978 */
5979 hdd_set_idle_ps_config(hdd_ctx, false);
5980
Arun Khandavallifae92942016-08-01 13:31:08 +05305981 if (driver_status != DRIVER_MODULES_CLOSED) {
5982 hdd_unregister_wext_all_adapters(hdd_ctx);
5983 /*
5984 * Cancel any outstanding scan requests. We are about to close
5985 * all of our adapters, but an adapter structure is what SME
5986 * passes back to our callback function. Hence if there
5987 * are any outstanding scan requests then there is a
5988 * race condition between when the adapter is closed and
5989 * when the callback is invoked. We try to resolve that
5990 * race condition here by canceling any outstanding scans
5991 * before we close the adapters.
5992 * Note that the scans may be cancelled in an asynchronous
5993 * manner, so ideally there needs to be some kind of
5994 * synchronization. Rather than introduce a new
5995 * synchronization here, we will utilize the fact that we are
5996 * about to Request Full Power, and since that is synchronized,
5997 * the expectation is that by the time Request Full Power has
5998 * completed, all scans will be cancelled
5999 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07006000 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05306001 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006002 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05306003 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004 }
6005
6006 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306007 * Close the scheduler before calling cds_close to make sure
6008 * no thread is scheduled after the each module close is
6009 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010 */
Jeff Johnson7d562272017-09-13 15:12:54 -07006011 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306012 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05306013 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306014 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306017 unregister_netdevice_notifier(&hdd_netdev_notifier);
6018
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006019 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306020
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306021 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6022 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6023 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 /*
6026 * Close CDS
6027 * This frees pMac(HAL) context. There should not be any call
6028 * that requires pMac access after this.
6029 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006031 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006032 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006033
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006034 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006035
6036 hdd_ipa_cleanup(hdd_ctx);
6037
6038 /* Free up RoC request queue and flush workqueue */
6039 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006040
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306041 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306042 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306043 /*
6044 * If there is re_init failure wiphy would have already de-registered
6045 * check the wiphy status before un-registering again
6046 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306047 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306048 wiphy_unregister(wiphy);
6049 wlan_hdd_cfg80211_deinit(wiphy);
6050 hdd_lpass_notify_stop(hdd_ctx);
6051 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006052
Arun Khandavallifae92942016-08-01 13:31:08 +05306053 hdd_exit_netlink_services(hdd_ctx);
6054 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306055#ifdef FEATURE_WLAN_CH_AVOID
6056 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6057#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306058
6059 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6060 if (driver_status)
6061 hdd_err("Pdev delete failed");
6062
6063 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6064 if (driver_status)
6065 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006066
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006067 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006068}
6069
6070void __hdd_wlan_exit(void)
6071{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006072 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073
6074 ENTER();
6075
Anurag Chouhan6d760662016-02-20 16:05:43 +05306076 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006078 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079 EXIT();
6080 return;
6081 }
6082
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006083 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306084 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 /* Do all the cleanup before deregistering the driver */
6087 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006088
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 EXIT();
6090}
6091
6092#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006093/**
6094 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006095 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006096 *
6097 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6098 * Then new ACS request will do a fresh scan without reusing the cached
6099 * scan information.
6100 *
6101 * Return: void
6102 */
Tang Yingying523322d2017-01-17 23:28:43 +08006103static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006105 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006107 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006109 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6110 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6111 hdd_ctx->last_acs_channel_list = NULL;
6112 hdd_ctx->num_of_channels = 0;
6113 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114
6115 if (!hdd_ctx->hHal)
6116 return;
6117 sme_scan_flush_result(hdd_ctx->hHal);
6118}
6119#endif
6120
6121#ifdef QCA_HT_2040_COEX
6122/**
6123 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6124 * @adapter: pointer to adapter
6125 * @staId: station id
6126 * @macAddrSTA: station MAC address
6127 * @channel_type: channel type
6128 *
6129 * This function notifies FW with HT20/HT40 mode
6130 *
6131 * Return: 0 if successful, error number otherwise
6132 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006133int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306134 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006135{
6136 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306137 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006138 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139
6140 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6141
6142 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306143 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146 if (!hdd_ctx->hHal)
6147 return -EINVAL;
6148
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306149 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306151 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006152 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 return -EINVAL;
6154 }
6155
6156 return 0;
6157}
6158#endif
6159
6160/**
6161 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6162 * @state: state
6163 *
6164 * This function notifies FW with modem power status
6165 *
6166 * Return: 0 if successful, error number otherwise
6167 */
6168int hdd_wlan_notify_modem_power_state(int state)
6169{
6170 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306171 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006172 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173
Anurag Chouhan6d760662016-02-20 16:05:43 +05306174 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306176 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306178
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179 if (!hdd_ctx->hHal)
6180 return -EINVAL;
6181
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306182 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6183 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006184 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 state);
6186 return -EINVAL;
6187 }
6188 return 0;
6189}
6190
6191/**
6192 *
6193 * hdd_post_cds_enable_config() - HDD post cds start config helper
6194 * @adapter - Pointer to the HDD
6195 *
6196 * Return: None
6197 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006198QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306200 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201
6202 /*
6203 * Send ready indication to the HDD. This will kick off the MAC
6204 * into a 'running' state and should kick off an initial scan.
6205 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306206 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6207 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006208 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6209 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306210 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 }
6212
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306213 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214}
6215
6216/* wake lock APIs for HDD */
6217void hdd_prevent_suspend(uint32_t reason)
6218{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306219 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220}
6221
6222void hdd_allow_suspend(uint32_t reason)
6223{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306224 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225}
6226
6227void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6228{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306229 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6230 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231}
6232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006234QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006236
Amar Singhal6f8592b2017-04-26 14:31:58 -07006237 return sme_init_chan_list(hdd_ctx->hHal,
6238 hdd_ctx->reg.alpha2,
6239 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240}
6241
6242/**
6243 * hdd_is_5g_supported() - check if hardware supports 5GHz
6244 * @hdd_ctx: Pointer to the hdd context
6245 *
6246 * HDD function to know if hardware supports 5GHz
6247 *
6248 * Return: true if hardware supports 5GHz
6249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006250bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006252 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006253 return true;
6254
Amar Singhal58b45ef2017-08-01 13:43:54 -07006255 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006256 return true;
6257 else
6258 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259}
6260
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006261static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262{
6263 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006264 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265
6266 wiphy = hdd_ctx->wiphy;
6267
6268 /*
6269 * The channel information in
6270 * wiphy needs to be initialized before wiphy registration
6271 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006272 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6273 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006274 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006275 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276 }
6277
6278#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6279 wiphy->wowlan = &wowlan_support_reg_init;
6280#else
6281 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6282 WIPHY_WOWLAN_MAGIC_PKT |
6283 WIPHY_WOWLAN_DISCONNECT |
6284 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6285 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6286 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6287 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6288 WIPHY_WOWLAN_RFKILL_RELEASE;
6289
6290 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6291 WOW_MAX_FILTERS_PER_LIST);
6292 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6293 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6294#endif
6295
6296 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006297 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306298 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006299 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306300 return ret_val;
6301 }
6302
Amar Singhal5cccafe2017-02-15 12:42:58 -08006303 if (!hdd_ctx->reg_offload)
6304 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305
Amar Singhale4f28ee2015-10-21 14:36:56 -07006306 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307}
6308
Ravi Joshie2331e82015-07-01 18:18:54 -07006309/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006310 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006311 * @hdd_ctx - handle to hdd context
6312 * @tx_packets - transmit packet count
6313 * @rx_packets - receive packet count
6314 *
6315 * The function controls the bus bandwidth and dynamic control of
6316 * tcp delayed ack configuration
6317 *
6318 * Returns: None
6319 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006321static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006322 const uint64_t tx_packets,
6323 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006324{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006326 uint64_t temp_rx = 0;
6327 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006328 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006329 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006330 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006331 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006332 uint16_t index = 0;
6333 bool vote_level_change = false;
6334 bool rx_level_change = false;
6335 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006338 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006340 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006341 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006342 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006343 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006344 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006347 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6348 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006350 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006351 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306352 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306353 if (hdd_ctx->hbw_requested) {
6354 pld_remove_pm_qos(hdd_ctx->parent_dev);
6355 hdd_ctx->hbw_requested = false;
6356 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306357 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006358 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306359 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306360 if (!hdd_ctx->hbw_requested) {
6361 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6362 hdd_ctx->hbw_requested = true;
6363 }
6364
Nirav Shah3bbfa512016-05-12 16:43:49 +05306365 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006366 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306367 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006368 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006370
Mohit Khannaf8f96822017-05-17 17:11:59 -07006371 qdf_dp_trace_throttle_live_mode(
6372 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6373
Mohit Khannae71e2262015-11-10 09:37:24 -08006374 /* fine-tuning parameters for RX Flows */
6375 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006377 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006378
Ravi Joshifed83572016-10-07 16:20:37 -07006379 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6380 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6381 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6382 next_rx_level = WLAN_SVC_TP_HIGH;
6383 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006384 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006385 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006386 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006387 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006390 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391 next_rx_level, temp_rx);
6392 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006393 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006394 /* Send throughput indication only if it is enabled.
6395 * Disabling tcp_del_ack will revert the tcp stack behavior
6396 * to default delayed ack. Note that this will disable the
6397 * dynamic delayed ack mechanism across the system
6398 */
6399 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306400 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6401 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 &next_rx_level,
6403 sizeof(next_rx_level));
6404 }
6405
Mohit Khannae71e2262015-11-10 09:37:24 -08006406 /* fine-tuning parameters for TX Flows */
6407 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6408 hdd_ctx->prev_tx = tx_packets;
6409 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6410 next_tx_level = WLAN_SVC_TP_HIGH;
6411 else
6412 next_tx_level = WLAN_SVC_TP_LOW;
6413
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006414 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006415 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6416 next_tx_level, temp_tx);
6417 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006418 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306419 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6420 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006421 &next_tx_level,
6422 sizeof(next_tx_level));
6423 }
6424
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006425 index = hdd_ctx->hdd_txrx_hist_idx;
6426
6427 if (vote_level_change || tx_level_change || rx_level_change) {
6428 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6429 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6430 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6431 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6432 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6433 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6434 hdd_ctx->hdd_txrx_hist_idx++;
6435 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6436 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437}
6438
6439#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306440static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006442 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306443 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006444 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306445 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306446 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6447 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448 uint64_t total_tx = 0, total_rx = 0;
6449 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306450 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306451 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006452 bool connected = false;
6453 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6454
Prashanth Bhattaab004382016-10-11 16:08:11 -07006455 if (wlan_hdd_validate_context(hdd_ctx))
6456 return;
6457
Jingxiang Gec64e1932017-08-22 14:38:59 +08006458 if (hdd_ctx->isWiphySuspended)
6459 goto restart_timer;
6460
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006461 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306462 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463 status =
6464 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6465
6466 if (adapterNode->pAdapter == NULL)
6467 continue;
6468 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306469 /*
6470 * Validate magic so we don't end up accessing
6471 * an invalid adapter.
6472 */
6473 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6474 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006475
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006476 if ((adapter->device_mode == QDF_STA_MODE ||
6477 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006478 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6479 != eConnectionState_Associated) {
6480
6481 continue;
6482 }
6483
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006484 if ((adapter->device_mode == QDF_SAP_MODE ||
6485 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006486 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6487
6488 continue;
6489 }
6490
6491 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6492 adapter->prev_tx_packets);
6493 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6494 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306495
6496 if (adapter->device_mode == QDF_SAP_MODE ||
6497 adapter->device_mode == QDF_P2P_GO_MODE ||
6498 adapter->device_mode == QDF_IBSS_MODE) {
6499
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006500 ret = cdp_get_intra_bss_fwd_pkts_count(
6501 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306502 adapter->sessionId,
6503 &fwd_tx_packets, &fwd_rx_packets);
6504 if (ret == A_OK) {
6505 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6506 fwd_tx_packets,
6507 adapter->prev_fwd_tx_packets);
6508 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6509 fwd_tx_packets,
6510 adapter->prev_fwd_rx_packets);
6511 }
6512 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006513
6514 total_rx += adapter->stats.rx_packets;
6515 total_tx += adapter->stats.tx_packets;
6516
6517 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6518 adapter->prev_tx_packets = adapter->stats.tx_packets;
6519 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306520 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6521 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6523 connected = true;
6524 }
6525
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306526 /* add intra bss forwarded tx and rx packets */
6527 tx_packets += fwd_tx_packets_diff;
6528 rx_packets += fwd_rx_packets_diff;
6529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006530 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6531 tx_packets += (uint64_t)ipa_tx_packets;
6532 rx_packets += (uint64_t)ipa_rx_packets;
6533
6534 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006535 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536 return;
6537 }
6538
Yuanyuan Liu13738502016-04-06 17:41:37 -07006539 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540
6541 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6542 hdd_ipa_uc_stat_request(adapter, 2);
6543
Jingxiang Gec64e1932017-08-22 14:38:59 +08006544restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006545 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006546 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006547 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306548 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006549 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006550 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006552
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306553/**
6554 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6555 * @arg: Argument of timer function
6556 *
6557 * Schedule a workqueue in this function where all the processing is done.
6558 *
6559 * Return: None.
6560 */
6561static void __hdd_bus_bw_cbk(void *arg)
6562{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006563 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306564
6565 if (wlan_hdd_validate_context(hdd_ctx))
6566 return;
6567
6568 schedule_work(&hdd_ctx->bus_bw_work);
6569}
6570
6571/**
6572 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6573 * @arg: Argument of timer function
6574 *
6575 * Return: None.
6576 */
6577static void hdd_bus_bw_cbk(void *arg)
6578{
6579 cds_ssr_protect(__func__);
6580 __hdd_bus_bw_cbk(arg);
6581 cds_ssr_unprotect(__func__);
6582}
6583
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006584int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006585{
6586 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306587 INIT_WORK(&hdd_ctx->bus_bw_work,
6588 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006589 hdd_ctx->bus_bw_timer_running = false;
6590 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306591 qdf_timer_init(NULL,
6592 &hdd_ctx->bus_bw_timer,
6593 hdd_bus_bw_cbk, (void *)hdd_ctx,
6594 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006595
6596 return 0;
6597}
6598
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006599void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006600{
Dustin Brownfce08d12017-01-17 16:29:38 -08006601 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006602 hdd_reset_tcp_delack(hdd_ctx);
6603
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006604 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306605 cancel_work_sync(&hdd_ctx->bus_bw_work);
6606 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006607 hdd_ctx->bus_bw_timer_running = false;
6608 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006609}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610#endif
6611
6612/**
Nirav Shahed34b212016-04-25 10:59:16 +05306613 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6614 * @hdd_ctx: hdd context
6615 *
6616 * Return: 0 for success or error code
6617 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006618static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306619{
6620 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6621 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6622 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006623 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306624 return -ENOMEM;
6625 }
6626 return 0;
6627}
6628
6629/**
6630 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6631 * @hdd_ctx: hdd context
6632 *
6633 * Return: none
6634 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006635void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306636{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306637 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6638 return;
6639
6640 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6641 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306642}
6643
Nirav Shahda008342016-05-17 18:50:40 +05306644static uint8_t *convert_level_to_string(uint32_t level)
6645{
6646 switch (level) {
6647 /* initialize the wlan sub system */
6648 case WLAN_SVC_TP_NONE:
6649 return "NONE";
6650 case WLAN_SVC_TP_LOW:
6651 return "LOW";
6652 case WLAN_SVC_TP_MEDIUM:
6653 return "MED";
6654 case WLAN_SVC_TP_HIGH:
6655 return "HIGH";
6656 default:
6657 return "INVAL";
6658 }
6659}
6660
Nirav Shahed34b212016-04-25 10:59:16 +05306661
6662/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006663 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6664 * @hdd_ctx: hdd context
6665 *
6666 * Return: none
6667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006668void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669{
6670 int i;
6671
6672#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006673 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306674 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006675 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006676 hdd_ctx->config->busBandwidthHighThreshold,
6677 hdd_ctx->config->busBandwidthMediumThreshold,
6678 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006679 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306680 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006681 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682 hdd_ctx->config->tcpDelackThresholdHigh,
6683 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006684 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306685 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686#endif
6687
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006688 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306689 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6690
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006691 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692
6693 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006694 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006695 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006696 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006697 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6698 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006699 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006700 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6701 convert_level_to_string(
6702 hdd_ctx->hdd_txrx_hist[i].
6703 next_vote_level),
6704 convert_level_to_string(
6705 hdd_ctx->hdd_txrx_hist[i].
6706 next_rx_level),
6707 convert_level_to_string(
6708 hdd_ctx->hdd_txrx_hist[i].
6709 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006711
6712 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713}
6714
6715/**
6716 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6717 * @hdd_ctx: hdd context
6718 *
6719 * Return: none
6720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006721void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722{
6723 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306724 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6725 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726}
6727
6728/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006729 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006730 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 *
6732 * Return: none
6733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006734void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006735{
6736
Jeff Johnson9d295242017-08-29 14:39:48 -07006737 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006738 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306739 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006740 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306741 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742
6743 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306744 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745 adapter = adapter_node->pAdapter;
6746
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006747 hdd_debug("Netif queue operation statistics:");
6748 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306749 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006750 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306751 curr_time = qdf_system_ticks();
6752 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306753 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306754 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306755 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306756 unpause = adapter->total_unpause_time;
6757 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306758 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306759 pause = adapter->total_pause_time;
6760 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006761 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306762 qdf_system_ticks_to_msecs(total),
6763 qdf_system_ticks_to_msecs(pause),
6764 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006765 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766
Nirav Shahda008342016-05-17 18:50:40 +05306767 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6768 qdf_time_t pause_delta = 0;
6769
6770 if (adapter->pause_map & (1 << i))
6771 pause_delta = delta;
6772
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006773 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006774 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006775 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776 hdd_reason_type_to_string(i),
6777 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306778 adapter->queue_oper_stats[i].unpause_count,
6779 qdf_system_ticks_to_msecs(
6780 adapter->queue_oper_stats[i].total_pause_time +
6781 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006782 }
6783
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006784 hdd_debug("Netif queue operation history:");
6785 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306786 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6787
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006788 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789
6790 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006791 /* using hdd_log to avoid printing function name */
6792 if (adapter->queue_oper_history[i].time == 0)
6793 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006794 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006795 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306796 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797 adapter->queue_oper_history[i].time),
6798 hdd_action_type_to_string(
6799 adapter->queue_oper_history[i].netif_action),
6800 hdd_reason_type_to_string(
6801 adapter->queue_oper_history[i].netif_reason),
6802 adapter->queue_oper_history[i].pause_map);
6803 }
6804
6805 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6806 adapter_node = next;
6807 }
6808
6809
6810}
6811
6812/**
6813 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6814 * @hdd_ctx: hdd context
6815 *
6816 * Return: none
6817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006818void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819{
Jeff Johnson9d295242017-08-29 14:39:48 -07006820 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306822 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823
6824 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306825 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826 adapter = adapter_node->pAdapter;
6827
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306828 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006829 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306830 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306832 adapter->history_index = 0;
6833 adapter->start_time = adapter->last_time = qdf_system_ticks();
6834 adapter->total_pause_time = 0;
6835 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006836 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6837 adapter_node = next;
6838 }
6839}
6840
6841/**
6842 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6843 * @halHandle: Hal handle
6844 * @pContext: Pointer to the context
6845 * @sessionId: Session ID
6846 * @scanId: Scan ID
6847 * @status: Status
6848 *
6849 * This is the callback to be executed when 11d scan is completed to flush out
6850 * the scan results
6851 *
6852 * 11d scan is done during driver load and is a passive scan on all
6853 * channels supported by the device, 11d scans may find some APs on
6854 * frequencies which are forbidden to be used in the regulatory domain
6855 * the device is operating in. If these APs are notified to the supplicant
6856 * it may try to connect to these APs, thus flush out all the scan results
6857 * which are present in SME after 11d scan is done.
6858 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306859 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306861static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 uint8_t sessionId, uint32_t scanId,
6863 eCsrScanStatus status)
6864{
6865 ENTER();
6866
6867 sme_scan_flush_result(halHandle);
6868
6869 EXIT();
6870
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306871 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872}
6873
6874#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6875/**
6876 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6877 * @hdd_ctx: hdd global context
6878 *
6879 * Return: none
6880 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006881static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882{
6883 uint8_t i;
6884
6885 mutex_init(&hdd_ctx->op_ctx.op_lock);
6886 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6887 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6888 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6889 }
6890}
6891#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006892static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893{
6894}
6895#endif
6896
Yingying Tang95409972016-10-20 15:16:15 +08006897#ifdef WLAN_FEATURE_WOW_PULSE
6898/**
6899 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006900 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006901 * @enable: enable or disable this behaviour
6902 *
6903 * Return: int
6904 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006905static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006906{
6907 struct hdd_config *pcfg_ini = phddctx->config;
6908 struct wow_pulse_mode wow_pulse_set_info;
6909 QDF_STATUS status;
6910
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006911 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006912
6913 if (false == phddctx->config->wow_pulse_support)
6914 return 0;
6915
6916 /* prepare the request to send to SME */
6917 if (enable == true) {
6918 wow_pulse_set_info.wow_pulse_enable = true;
6919 wow_pulse_set_info.wow_pulse_pin =
6920 pcfg_ini->wow_pulse_pin;
6921 wow_pulse_set_info.wow_pulse_interval_low =
6922 pcfg_ini->wow_pulse_interval_low;
6923 wow_pulse_set_info.wow_pulse_interval_high =
6924 pcfg_ini->wow_pulse_interval_high;
6925 } else {
6926 wow_pulse_set_info.wow_pulse_enable = false;
6927 wow_pulse_set_info.wow_pulse_pin = 0;
6928 wow_pulse_set_info.wow_pulse_interval_low = 0;
6929 wow_pulse_set_info.wow_pulse_interval_high = 0;
6930 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006931 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006932 wow_pulse_set_info.wow_pulse_enable,
6933 wow_pulse_set_info.wow_pulse_pin,
6934 wow_pulse_set_info.wow_pulse_interval_low,
6935 wow_pulse_set_info.wow_pulse_interval_high);
6936
6937 status = sme_set_wow_pulse(&wow_pulse_set_info);
6938 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006939 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006940 return -EIO;
6941 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006942 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006943 return 0;
6944}
6945#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006947{
6948 return 0;
6949}
6950#endif
6951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952#ifdef WLAN_FEATURE_FASTPATH
6953/**
6954 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6955 * @hdd_cfg: hdd config
6956 * @context: lower layer context
6957 *
6958 * Return: none
6959 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306960void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006961 void *context)
6962{
6963 if (hdd_cfg->fastpath_enable)
6964 hif_enable_fastpath(context);
6965}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006966#endif
6967
Yuanyuan Liu13738502016-04-06 17:41:37 -07006968#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006969/**
6970 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006971 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006972 * @level: thermal level
6973 *
6974 * Change IPA data path to SW path when the thermal throttle level greater
6975 * than 0, and restore the original data path when throttle level is 0
6976 *
6977 * Return: none
6978 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006979static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006981 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983 /* Change IPA to SW path when throttle level greater than 0 */
6984 if (level > THROTTLE_LEVEL_0)
6985 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6986 else
6987 /* restore original concurrency mode */
6988 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6989}
6990
6991/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306992 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6993 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306994 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306996 * Get a safe channel to restart SAP. PCL already takes into account the
6997 * unsafe channels. So, the PCL is validated with the ACS range to provide
6998 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307000 * Return: Channel number to restart SAP in case of success. In case of any
7001 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007002 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307003static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007004 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307006 struct sir_pcl_list pcl;
7007 QDF_STATUS status;
7008 uint32_t i, j;
7009 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007010 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307011 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307013 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7014 if (!hdd_ctx) {
7015 hdd_err("invalid HDD context");
7016 return INVALID_CHANNEL_ID;
7017 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307019 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7020 if (!hal_handle) {
7021 hdd_err("invalid HAL handle");
7022 return INVALID_CHANNEL_ID;
7023 }
7024
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007025 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7026 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007027 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7028 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307029 if (QDF_IS_STATUS_ERROR(status)) {
7030 hdd_err("Get PCL failed");
7031 return INVALID_CHANNEL_ID;
7032 }
7033
Frank Liudc2cefb2017-06-21 15:38:18 +08007034 /*
7035 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7036 * channel is unsafe channel, the pcl may be empty, instead of return,
7037 * try to choose a safe channel from acs range.
7038 */
7039 if (!pcl.pcl_len)
7040 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307041
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007042 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307043 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7044 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7045
7046 /* PCL already takes unsafe channel into account */
7047 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007048 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049 if ((pcl.pcl_list[i] >=
7050 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7051 (pcl.pcl_list[i] <=
7052 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007053 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307054 return pcl.pcl_list[i];
7055 }
7056 }
7057
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007058 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307059
7060 /* Try for safe channel from all valid channel */
7061 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007062 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307063 &pcl.pcl_len);
7064 if (QDF_IS_STATUS_ERROR(status)) {
7065 hdd_err("error in getting valid channel list");
7066 return INVALID_CHANNEL_ID;
7067 }
7068
7069 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007070 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307071 found = false;
7072 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007073 if (pcl.pcl_list[i] ==
7074 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007075 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307076 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077 break;
7078 }
7079 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307080
7081 if (found)
7082 continue;
7083
7084 if ((pcl.pcl_list[i] >=
7085 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7086 (pcl.pcl_list[i] <=
7087 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007088 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307089 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007090 }
7091 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307092
7093 return INVALID_CHANNEL_ID;
7094}
7095
7096/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007097 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307098 * @adapter: AP adapter
7099 * @channel: Channel
7100 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007101 * Moves the SAP interface by invoking the function which
7102 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307103 *
7104 * Return: None
7105 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007106void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307107{
Jeff Johnson87251032017-08-29 13:31:11 -07007108 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307109 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007110 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307111
7112 if (!adapter) {
7113 hdd_err("invalid adapter");
7114 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307116
7117 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7118
7119 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7120 if (!hal_handle) {
7121 hdd_err("invalid HAL handle");
7122 return;
7123 }
7124
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007125 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7126
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307127 hdd_ap_ctx->sapConfig.channel = channel;
7128 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7129 hdd_ap_ctx->sapConfig.ch_width_orig;
7130
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007131 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307132 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7133
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007134 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7135 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307136 hdd_ap_ctx->sapConfig.sec_ch,
7137 &hdd_ap_ctx->sapConfig.ch_params);
7138
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007139 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7140 adapter->sessionId, channel,
7141 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307143
Jeff Johnson9d295242017-08-29 14:39:48 -07007144int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307145{
7146 struct hdd_external_acs_timer_context *timer_context;
7147
7148 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7149
7150 if (QDF_TIMER_STATE_RUNNING ==
7151 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7152 ap.vendor_acs_timer)) {
7153 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7154 }
7155 timer_context = (struct hdd_external_acs_timer_context *)
7156 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7157 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307158 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307159 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307160 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7161 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307162 hdd_notice("Updated ACS config to nl with reason %d", reason);
7163
7164 return 0;
7165}
7166
Agrawal Ashish467dde42016-09-08 18:44:22 +05307167/**
7168 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7169 * @hdd_ctx: hdd context pointer
7170 *
7171 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7172 * and if ACS is enabled, driver will ask userspace to restart the
7173 * sap. User space on LTE coex indication restart driver.
7174 *
7175 * Return - none
7176 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007177void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307178{
7179 QDF_STATUS status;
7180 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007181 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307182 uint32_t i;
7183 bool found = false;
7184 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007185
Agrawal Ashish467dde42016-09-08 18:44:22 +05307186 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7187 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7188 adapter_temp = adapter_node->pAdapter;
7189
7190 if (!adapter_temp) {
7191 hdd_err("adapter is NULL, moving to next one");
7192 goto next_adapater;
7193 }
7194
7195 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7196 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007197 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307198 adapter_temp->device_mode,
7199 adapter_temp->sessionCtx.ap.sapConfig.
7200 acs_cfg.acs_mode);
7201 goto next_adapater;
7202 }
7203
7204 found = false;
7205 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007206 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307207 hdd_ctxt->unsafe_channel_list[i]) {
7208 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007209 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307210 adapter_temp->sessionCtx.ap.operatingChannel);
7211 break;
7212 }
7213 }
7214
7215 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007216 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307217 adapter_temp->sessionCtx.ap.operatingChannel);
7218 goto next_adapater;
7219 }
7220
Kapil Gupta8878ad92017-02-13 11:56:04 +05307221 if (hdd_ctxt->config->vendor_acs_support &&
7222 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7223 hdd_update_acs_timer_reason(adapter_temp,
7224 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7225 goto next_adapater;
7226 } else
7227 restart_chan =
7228 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307229 adapter_temp);
7230 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007231 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307232 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007233 /*
7234 * SAP restart due to unsafe channel. While
7235 * restarting the SAP, make sure to clear
7236 * acs_channel, channel to reset to
7237 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307238 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007239 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307240 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7241 adapter_temp->sessionCtx.ap.sapConfig.channel =
7242 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007243 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307244 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7245 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007246 hdd_debug("driver to start sap: %d",
7247 hdd_ctxt->config->sap_internal_restart);
7248 if (hdd_ctxt->config->sap_internal_restart)
7249 hdd_switch_sap_channel(adapter_temp, restart_chan);
7250 else
7251 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307252 }
7253
7254next_adapater:
7255 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7256 adapter_node = next;
7257 }
7258}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007260/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007261 * hdd_init_channel_avoidance() - Initialize channel avoidance
7262 * @hdd_ctx: HDD global context
7263 *
7264 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007265 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007266 * down to the lower layers. Then subscribe to subsequent channel
7267 * avoidance events.
7268 *
7269 * Return: None
7270 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007271static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007272{
7273 uint16_t unsafe_channel_count;
7274 int index;
7275
Yuanyuan Liu13738502016-04-06 17:41:37 -07007276 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7277 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007279 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007281 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007282 hdd_ctx->unsafe_channel_count);
7283
Anurag Chouhan6d760662016-02-20 16:05:43 +05307284 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007285 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286
7287 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007288 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007289 hdd_ctx->unsafe_channel_list[index]);
7290
7291 }
7292
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007293}
Dustin Brown676a2322017-08-15 13:16:13 -07007294
Jeff Johnson9d295242017-08-29 14:39:48 -07007295static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007296 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007297{
7298 uint8_t restart_chan;
7299
7300 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7301 if (!restart_chan) {
7302 hdd_alert("fail to restart SAP");
7303 return;
7304 }
7305
7306 /* SAP restart due to unsafe channel. While restarting
7307 * the SAP, make sure to clear acs_channel, channel to
7308 * reset to 0. Otherwise these settings will override
7309 * the ACS while restart.
7310 */
7311 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7312 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7313
7314 hdd_debug("sending coex indication");
7315
7316 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7317 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7318 hdd_switch_sap_channel(adapter, restart_chan);
7319}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007320
7321int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7322 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7323{
7324 uint32_t size;
7325 uint16_t *unsafe_list;
7326 uint16_t chan_count;
7327
7328 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7329 return -EINVAL;
7330
7331 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7332 NUM_CHANNELS);
7333 if (chan_count) {
7334 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7335 unsafe_list = qdf_mem_malloc(size);
7336 if (!unsafe_list) {
7337 hdd_err("No memory for unsafe chan list size%d",
7338 size);
7339 return -ENOMEM;
7340 }
7341 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7342 } else {
7343 unsafe_list = NULL;
7344 }
7345
7346 *local_unsafe_list = unsafe_list;
7347 *local_unsafe_list_count = chan_count;
7348
7349 return 0;
7350}
7351
7352bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7353 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7354{
7355 int i, j;
7356
7357 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7358 return true;
7359 if (local_unsafe_list_count == 0)
7360 return false;
7361 for (i = 0; i < local_unsafe_list_count; i++) {
7362 for (j = 0; j < local_unsafe_list_count; j++)
7363 if (local_unsafe_list[i] ==
7364 hdd_ctx->unsafe_channel_list[j])
7365 break;
7366 if (j >= local_unsafe_list_count)
7367 break;
7368 }
7369 if (i >= local_unsafe_list_count) {
7370 hdd_info("unsafe chan list same");
7371 return false;
7372 }
7373
7374 return true;
7375}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007376#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007377static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007378{
7379}
Dustin Brown676a2322017-08-15 13:16:13 -07007380
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007381static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007382{
7383}
Dustin Brown676a2322017-08-15 13:16:13 -07007384
Jeff Johnson9d295242017-08-29 14:39:48 -07007385static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007386 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007387{
7388 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7389}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007390#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007391
7392/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007393 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7394 * user space
7395 * @frame_ind: Management frame data to be informed.
7396 *
7397 * This function is used to indicate management frame to
7398 * user space
7399 *
7400 * Return: None
7401 *
7402 */
7403void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7404{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007405 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007406 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007407 int i;
7408
Rajeev Kumard004abc2016-02-17 12:09:56 -08007409 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007410 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007411
7412 if (0 != wlan_hdd_validate_context(hdd_ctx))
7413 return;
7414
7415 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7416 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7417 adapter =
7418 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7419 if (adapter)
7420 break;
7421 }
7422 } else {
7423 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7424 frame_ind->sessionId);
7425 }
7426
7427 if ((NULL != adapter) &&
7428 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7429 __hdd_indicate_mgmt_frame(adapter,
7430 frame_ind->frame_len,
7431 frame_ind->frameBuf,
7432 frame_ind->frameType,
7433 frame_ind->rxChan,
7434 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007435}
7436
Kapil Gupta8878ad92017-02-13 11:56:04 +05307437void hdd_acs_response_timeout_handler(void *context)
7438{
7439 struct hdd_external_acs_timer_context *timer_context =
7440 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007441 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007442 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307443 uint8_t reason;
7444
7445 ENTER();
7446 if (!timer_context) {
7447 hdd_err("invlaid timer context");
7448 return;
7449 }
7450 adapter = timer_context->adapter;
7451 reason = timer_context->reason;
7452
7453
7454 if ((!adapter) ||
7455 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7456 hdd_err("invalid adapter or adapter has invalid magic");
7457 return;
7458 }
7459 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7460 if (wlan_hdd_validate_context(hdd_ctx))
7461 return;
7462
7463 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7464 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7465 else
7466 return;
7467
7468 hdd_err("ACS timeout happened for %s reason %d",
7469 adapter->dev->name, reason);
7470 switch (reason) {
7471 /* SAP init case */
7472 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7473 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7474 false);
7475 wlan_hdd_cfg80211_start_acs(adapter);
7476 break;
7477 /* DFS detected on current channel */
7478 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7479 wlan_sap_update_next_channel(
7480 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7481 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7482 adapter->sessionId);
7483 break;
7484 /* LTE coex event on current channel */
7485 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7486 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7487 break;
7488 default:
7489 hdd_info("invalid reason for timer invoke");
7490
7491 }
7492}
7493
Rajeev Kumard004abc2016-02-17 12:09:56 -08007494/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7496 * @hdd_ctx: HDD context
7497 *
7498 * Disables all the dual mac features like DBS, Agile DFS etc.
7499 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307500 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007501 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007502static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007504 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307505 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007506
7507 if (!hdd_ctx) {
7508 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307509 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510 }
7511
7512 cfg.scan_config = 0;
7513 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007514 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007515
7516 hdd_debug("Disabling all dual mac features...");
7517
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007518 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307519 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7521 return status;
7522 }
7523
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307524 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007525}
7526
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007527static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007528wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007529{
7530 struct policy_mgr_dual_mac_config cfg = {0};
7531 QDF_STATUS status;
7532
7533 if (!hdd_ctx) {
7534 hdd_err("HDD context is NULL");
7535 return QDF_STATUS_E_FAILURE;
7536 }
7537
7538 cfg.scan_config = 0;
7539 cfg.fw_mode_config = 0;
7540 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7541 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7542 hdd_ctx->hdd_psoc, &cfg.scan_config,
7543 &cfg.fw_mode_config,
7544 hdd_ctx->config->dual_mac_feature_disable);
7545
7546 if (status != QDF_STATUS_SUCCESS) {
7547 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7548 status);
7549 return status;
7550 }
7551
7552 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7553 cfg.scan_config, cfg.fw_mode_config);
7554
7555 status = sme_soc_set_dual_mac_config(cfg);
7556 if (status != QDF_STATUS_SUCCESS) {
7557 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7558 return status;
7559 }
7560
7561 return QDF_STATUS_SUCCESS;
7562}
7563
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007565 * hdd_override_ini_config - Override INI config
7566 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007567 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007568 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007570 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007572static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007575 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7576 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007577 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007578 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007579 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007580 if (0 == enable_11d || 1 == enable_11d) {
7581 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007582 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007583 }
Leo Chang11545d62016-10-17 14:53:50 -07007584
7585 if (!hdd_ipa_is_present(hdd_ctx))
7586 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007587}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007588
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007589/**
7590 * hdd_set_trace_level_for_each - Set trace level for each INI config
7591 * @hdd_ctx - HDD context
7592 *
7593 * Set trace level for each module based on INI config.
7594 *
7595 * Return: None
7596 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007597static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007598{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307599 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7600 hdd_ctx->config->qdf_trace_enable_wdi);
7601 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7602 hdd_ctx->config->qdf_trace_enable_hdd);
7603 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7604 hdd_ctx->config->qdf_trace_enable_sme);
7605 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7606 hdd_ctx->config->qdf_trace_enable_pe);
7607 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7608 hdd_ctx->config->qdf_trace_enable_wma);
7609 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7610 hdd_ctx->config->qdf_trace_enable_sys);
7611 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7612 hdd_ctx->config->qdf_trace_enable_qdf);
7613 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7614 hdd_ctx->config->qdf_trace_enable_sap);
7615 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7616 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7617 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7618 hdd_ctx->config->qdf_trace_enable_bmi);
7619 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7620 hdd_ctx->config->qdf_trace_enable_cfg);
7621 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7622 hdd_ctx->config->qdf_trace_enable_epping);
7623 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7624 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7625 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007626 hdd_ctx->config->qdf_trace_enable_txrx);
7627 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7628 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307629 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7630 hdd_ctx->config->qdf_trace_enable_htc);
7631 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7632 hdd_ctx->config->qdf_trace_enable_hif);
7633 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7634 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7635 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7636 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007637 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7638 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007639 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7640 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007641 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7642 hdd_ctx->config->qdf_trace_enable_regulatory);
7643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007645}
7646
7647/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007648 * hdd_context_init() - Initialize HDD context
7649 * @hdd_ctx: HDD context.
7650 *
7651 * Initialize HDD context along with all the feature specific contexts.
7652 *
7653 * return: 0 on success and errno on failure.
7654 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007655static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007656{
7657 int ret;
7658
7659 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7660 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7661
7662 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307663 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007664
7665 init_completion(&hdd_ctx->mc_sus_event_var);
7666 init_completion(&hdd_ctx->ready_to_suspend);
7667
7668 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307669 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007670 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307671
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007672 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7673
7674 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7675
7676 ret = hdd_scan_context_init(hdd_ctx);
7677 if (ret)
7678 goto list_destroy;
7679
Nitesh Shahd1266d72017-01-25 22:07:07 +05307680 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007681
7682 hdd_rx_wake_lock_create(hdd_ctx);
7683
7684 ret = hdd_sap_context_init(hdd_ctx);
7685 if (ret)
7686 goto scan_destroy;
7687
7688 ret = hdd_roc_context_init(hdd_ctx);
7689 if (ret)
7690 goto sap_destroy;
7691
7692 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7693
7694 hdd_init_offloaded_packets_ctx(hdd_ctx);
7695
7696 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7697 hdd_ctx->config);
7698 if (ret)
7699 goto roc_destroy;
7700
7701 return 0;
7702
7703roc_destroy:
7704 hdd_roc_context_destroy(hdd_ctx);
7705
7706sap_destroy:
7707 hdd_sap_context_destroy(hdd_ctx);
7708
7709scan_destroy:
7710 hdd_scan_context_destroy(hdd_ctx);
7711 hdd_rx_wake_lock_destroy(hdd_ctx);
7712 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007713list_destroy:
7714 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007715
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007716 return ret;
7717}
7718
7719/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307720 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7721 * @hdd_ctx: pointer to hdd context
7722 *
7723 * Return: status of initialization
7724 * 0 - success
7725 * negative value - failure
7726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007727static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307728{
7729 int ret;
7730
7731 if (!hdd_ctx->config->probe_req_ie_whitelist)
7732 return 0;
7733
7734 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7735 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7736 hdd_ctx->config->probe_req_ie_whitelist = false;
7737 return -EINVAL;
7738 }
7739
7740 /* parse ini string probe req oui */
7741 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7742 if (ret) {
7743 hdd_err("parsing error: disable ie whitelisting");
7744 hdd_ctx->config->probe_req_ie_whitelist = false;
7745 }
7746
7747 return ret;
7748}
7749
7750/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007751 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307752 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007753 *
7754 * Allocate and initialize HDD context. HDD context is allocated as part of
7755 * wiphy allocation and then context is initialized.
7756 *
7757 * Return: HDD context on success and ERR_PTR on failure
7758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007759static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007760{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307761 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007762 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007763 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007764 v_CONTEXT_t p_cds_context;
7765
7766 ENTER();
7767
7768 p_cds_context = cds_get_global_context();
7769 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007770 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007771 ret = -EINVAL;
7772 goto err_out;
7773 }
7774
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007775 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007776
7777 if (hdd_ctx == NULL) {
7778 ret = -ENOMEM;
7779 goto err_out;
7780 }
7781
7782 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007783 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307784 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007785
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307786 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007787 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007788 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007789 ret = -ENOMEM;
7790 goto err_free_hdd_context;
7791 }
7792
7793 /* Read and parse the qcom_cfg.ini file */
7794 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307795 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307796 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007797 WLAN_INI_FILE);
7798 ret = -EINVAL;
7799 goto err_free_config;
7800 }
7801
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307802 ie_whitelist_attrs_init(hdd_ctx);
7803
Dustin Brown7f939932017-05-18 15:02:17 -07007804 hdd_debug("setting timer multiplier: %u",
7805 hdd_ctx->config->timer_multiplier);
7806 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7807
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007808
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307809 if (hdd_ctx->config->fhostNSOffload)
7810 hdd_ctx->ns_offload_enable = true;
7811
Abhishek Singh5ea86532016-04-27 14:10:53 +05307812 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7813
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007814 hdd_override_ini_config(hdd_ctx);
7815
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007816 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007817
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007818 ret = hdd_context_init(hdd_ctx);
7819
7820 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007821 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007822
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007823 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307824 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007825
Anurag Chouhan6d760662016-02-20 16:05:43 +05307826 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007827 goto skip_multicast_logging;
7828
7829 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7830
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007831 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7832 if (ret)
7833 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307834
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007835 ret = hdd_init_netlink_services(hdd_ctx);
7836 if (ret)
7837 goto err_deinit_txrx_histogram;
7838
Dustin Brown7b3dea22017-07-10 13:02:47 -07007839 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7840 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307841
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007842skip_multicast_logging:
7843 hdd_set_trace_level_for_each(hdd_ctx);
7844
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007845 EXIT();
7846
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007847 return hdd_ctx;
7848
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007849err_deinit_txrx_histogram:
7850 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7851
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007852err_deinit_hdd_context:
7853 hdd_context_deinit(hdd_ctx);
7854
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007855err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307856 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007857
7858err_free_hdd_context:
7859 wiphy_free(hdd_ctx->wiphy);
7860
7861err_out:
7862 return ERR_PTR(ret);
7863}
7864
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007865#ifdef WLAN_OPEN_P2P_INTERFACE
7866/**
7867 * hdd_open_p2p_interface - Open P2P interface
7868 * @hdd_ctx: HDD context
7869 * @rtnl_held: True if RTNL lock held
7870 *
7871 * Open P2P interface during probe. This function called to open the P2P
7872 * interface at probe along with STA interface.
7873 *
7874 * Return: 0 on success and errno on failure
7875 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007876static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007877{
Jeff Johnson9d295242017-08-29 14:39:48 -07007878 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007879 uint8_t *p2p_dev_addr;
7880
7881 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7882 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307883 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007884 hdd_ctx->config->intfMacAddr[0].bytes,
7885 sizeof(tSirMacAddr));
7886
7887 /*
7888 * Generate the P2P Device Address. This consists of
7889 * the device's primary MAC address with the locally
7890 * administered bit set.
7891 */
7892 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7893 } else {
7894 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7895 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007896 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007897 return -ENOSPC;
7898 }
7899
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307900 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307901 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007902 }
7903
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007904 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007905 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007906 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007907
7908 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007909 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007910 return -ENOSPC;
7911 }
7912
7913 return 0;
7914}
7915#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007916static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007917 bool rtnl_held)
7918{
7919 return 0;
7920}
7921#endif
7922
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007923static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007924{
Jeff Johnson9d295242017-08-29 14:39:48 -07007925 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007926 int ret = 0;
7927
7928 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7929 wlan_hdd_get_intf_addr(hdd_ctx),
7930 NET_NAME_UNKNOWN, rtnl_held);
7931 if (adapter == NULL) {
7932 hdd_err("Failed to open 802.11p interface");
7933 ret = -ENOSPC;
7934 }
7935
7936 return ret;
7937}
7938
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007939/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307940 * hdd_start_station_adapter()- Start the Station Adapter
7941 * @adapter: HDD adapter
7942 *
7943 * This function initializes the adapter for the station mode.
7944 *
7945 * Return: 0 on success or errno on failure.
7946 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007947int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307948{
7949 QDF_STATUS status;
7950
7951 ENTER_DEV(adapter->dev);
7952
7953 status = hdd_init_station_mode(adapter);
7954
7955 if (QDF_STATUS_SUCCESS != status) {
7956 hdd_err("Error Initializing station mode: %d", status);
7957 return qdf_status_to_os_return(status);
7958 }
7959
Arun Khandavallifae92942016-08-01 13:31:08 +05307960 hdd_register_tx_flow_control(adapter,
7961 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007962 hdd_tx_resume_cb,
7963 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307964
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307965 EXIT();
7966 return 0;
7967}
7968
7969/**
7970 * hdd_start_ap_adapter()- Start AP Adapter
7971 * @adapter: HDD adapter
7972 *
7973 * This function initializes the adapter for the AP mode.
7974 *
7975 * Return: 0 on success errno on failure.
7976 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007977int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307978{
7979 QDF_STATUS status;
7980
7981 ENTER();
7982
Arun Khandavallicc544b32017-01-30 19:52:16 +05307983 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307984
7985 if (QDF_STATUS_SUCCESS != status) {
7986 hdd_err("Error Initializing the AP mode: %d", status);
7987 return qdf_status_to_os_return(status);
7988 }
7989
Arun Khandavallifae92942016-08-01 13:31:08 +05307990 hdd_register_tx_flow_control(adapter,
7991 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007992 hdd_softap_tx_resume_cb,
7993 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307994
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307995 EXIT();
7996 return 0;
7997}
7998
7999/**
8000 * hdd_start_ftm_adapter()- Start FTM adapter
8001 * @adapter: HDD adapter
8002 *
8003 * This function initializes the adapter for the FTM mode.
8004 *
8005 * Return: 0 on success or errno on failure.
8006 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008007int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308008{
8009 QDF_STATUS qdf_status;
8010
8011 ENTER_DEV(adapter->dev);
8012
8013 qdf_status = hdd_init_tx_rx(adapter);
8014
8015 if (QDF_STATUS_SUCCESS != qdf_status) {
8016 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8017 return qdf_status_to_os_return(qdf_status);
8018 }
8019
8020 return 0;
8021 EXIT();
8022}
8023
8024/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008025 * hdd_open_interfaces - Open all required interfaces
8026 * hdd_ctx: HDD context
8027 * rtnl_held: True if RTNL lock is held
8028 *
8029 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8030 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008031 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008033static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008034{
Jeff Johnson9d295242017-08-29 14:39:48 -07008035 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008036 int ret;
8037
Ravi Joshia307f632017-07-17 23:41:41 -07008038 /* open monitor mode adapter if con_mode is monitor mode */
8039 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8040 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8041 wlan_hdd_get_intf_addr(hdd_ctx),
8042 NET_NAME_UNKNOWN, rtnl_held);
8043 if (!adapter) {
8044 hdd_err("open adapter failed");
8045 return -ENOSPC;
8046 }
8047 return 0;
8048 }
8049
Jeff Johnson957bc272017-02-02 08:54:48 -08008050 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308051 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008052 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008053
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008054 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008055 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008056 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008057
8058 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008059 return -ENOSPC;
8060
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008061 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8062 adapter->fast_roaming_allowed = true;
8063
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008064 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8065 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008066 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008067
8068 /* Open 802.11p Interface */
8069 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008070 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8071 if (ret)
8072 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008073 }
8074
Jeff Johnson957bc272017-02-02 08:54:48 -08008075 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008076
Jeff Johnson957bc272017-02-02 08:54:48 -08008077err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008078 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008079 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008080}
8081
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008082/**
8083 * hdd_update_country_code - Update country code
8084 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008085 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008086 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008087 *
8088 * Return: 0 on success and errno on failure
8089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008090static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008091{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008092 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008093 return 0;
8094
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008095 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008096}
8097
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308098#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8099/**
8100 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8101 * @cds_cfg: CDS Configuration
8102 * @hdd_ctx: Pointer to hdd context
8103 *
8104 * Return: none
8105 */
8106static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8107 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008108 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308109{
8110 cds_cfg->tx_flow_stop_queue_th =
8111 hdd_ctx->config->TxFlowStopQueueThreshold;
8112 cds_cfg->tx_flow_start_queue_offset =
8113 hdd_ctx->config->TxFlowStartQueueOffset;
8114}
8115#else
8116static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8117 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008118 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308119{
8120}
8121#endif
8122
8123#ifdef FEATURE_WLAN_RA_FILTERING
8124/**
8125 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8126 * @cds_cfg: CDS Configuration
8127 * @hdd_ctx: Pointer to hdd context
8128 *
8129 * Return: none
8130 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308131static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008132 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308133{
8134 cds_cfg->ra_ratelimit_interval =
8135 hdd_ctx->config->RArateLimitInterval;
8136 cds_cfg->is_ra_ratelimit_enabled =
8137 hdd_ctx->config->IsRArateLimitEnabled;
8138}
8139#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308140static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008141 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308142{
8143}
8144#endif
8145
8146/**
8147 * hdd_update_cds_config() - API to update cds configuration parameters
8148 * @hdd_ctx: HDD Context
8149 *
8150 * Return: 0 for Success, errno on failure
8151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008152static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308153{
8154 struct cds_config_info *cds_cfg;
8155
8156 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8157 if (!cds_cfg) {
8158 hdd_err("failed to allocate cds config");
8159 return -ENOMEM;
8160 }
8161
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008162 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008163 if (!hdd_ctx->config->nMaxPsPoll ||
8164 !hdd_ctx->config->enablePowersaveOffload) {
8165 cds_cfg->powersave_offload_enabled =
8166 hdd_ctx->config->enablePowersaveOffload;
8167 } else {
8168 if ((hdd_ctx->config->enablePowersaveOffload ==
8169 PS_QPOWER_NODEEPSLEEP) ||
8170 (hdd_ctx->config->enablePowersaveOffload ==
8171 PS_LEGACY_NODEEPSLEEP))
8172 cds_cfg->powersave_offload_enabled =
8173 PS_LEGACY_NODEEPSLEEP;
8174 else
8175 cds_cfg->powersave_offload_enabled =
8176 PS_LEGACY_DEEPSLEEP;
8177 hdd_info("Qpower disabled in cds config, %d",
8178 cds_cfg->powersave_offload_enabled);
8179 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308180 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8181 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8182 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8183 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8184 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8185
8186 /* Here ol_ini_info is used to store ini status of arp offload
8187 * ns offload and others. Currently 1st bit is used for arp
8188 * off load and 2nd bit for ns offload currently, rest bits are unused
8189 */
8190 if (hdd_ctx->config->fhostArpOffload)
8191 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8192 if (hdd_ctx->config->fhostNSOffload)
8193 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8194
8195 /*
8196 * Copy the DFS Phyerr Filtering Offload status.
8197 * This parameter reflects the value of the
8198 * dfs_phyerr_filter_offload flag as set in the ini.
8199 */
8200 cds_cfg->dfs_phyerr_filter_offload =
8201 hdd_ctx->config->fDfsPhyerrFilterOffload;
8202 if (hdd_ctx->config->ssdp)
8203 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8204
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308205 cds_cfg->force_target_assert_enabled =
8206 hdd_ctx->config->crash_inject_enabled;
8207
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308208 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8209 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8210
8211 cds_cfg->ap_maxoffload_reorderbuffs =
8212 hdd_ctx->config->apMaxOffloadReorderBuffs;
8213
8214 cds_cfg->ap_disable_intrabss_fwd =
8215 hdd_ctx->config->apDisableIntraBssFwd;
8216
8217 cds_cfg->dfs_pri_multiplier =
8218 hdd_ctx->config->dfsRadarPriMultiplier;
8219 cds_cfg->reorder_offload =
8220 hdd_ctx->config->reorderOffloadSupport;
8221
8222 /* IPA micro controller data path offload resource config item */
8223 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008224 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8225 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008226 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008227 hdd_ctx->config->IpaUcTxBufCount);
8228 hdd_ctx->config->IpaUcTxBufCount =
8229 rounddown_pow_of_two(
8230 hdd_ctx->config->IpaUcTxBufCount);
8231 if (!hdd_ctx->config->IpaUcTxBufCount) {
8232 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308233 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008234 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008235 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008236 hdd_ctx->config->IpaUcTxBufCount);
8237 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308238 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8239 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008240 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8241 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008242 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008243 hdd_ctx->config->IpaUcRxIndRingCount);
8244 hdd_ctx->config->IpaUcRxIndRingCount =
8245 rounddown_pow_of_two(
8246 hdd_ctx->config->IpaUcRxIndRingCount);
8247 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8248 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308249 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008250 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008251 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008252 hdd_ctx->config->IpaUcRxIndRingCount);
8253 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308254 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008255 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308256 cds_cfg->uc_tx_partition_base =
8257 hdd_ctx->config->IpaUcTxPartitionBase;
8258 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8259
8260 cds_cfg->ip_tcp_udp_checksum_offload =
8261 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308262 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308263 cds_cfg->ce_classify_enabled =
8264 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008265 cds_cfg->bpf_packet_filter_enable =
8266 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308267 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8268 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8269 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008270 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008271 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008272 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008273 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308274 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8275 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308276 cds_cfg->auto_power_save_fail_mode =
8277 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308278
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308279 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8280
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308281 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8282 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8283 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008284 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308285 cds_init_ini_config(cds_cfg);
8286 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308287
8288exit:
8289 qdf_mem_free(cds_cfg);
8290 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308291}
8292
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008293/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008294 * hdd_update_user_config() - API to update user configuration
8295 * parameters to obj mgr which are used by multiple components
8296 * @hdd_ctx: HDD Context
8297 *
8298 * Return: 0 for Success, errno on failure
8299 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008300static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008301{
8302 struct wlan_objmgr_psoc_user_config *user_config;
8303
8304 user_config = qdf_mem_malloc(sizeof(*user_config));
8305 if (user_config == NULL) {
8306 hdd_alert("Failed to alloc memory for user_config!");
8307 return -ENOMEM;
8308 }
8309
8310 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8311 user_config->dual_mac_feature_disable =
8312 hdd_ctx->config->dual_mac_feature_disable;
8313 user_config->indoor_channel_support =
8314 hdd_ctx->config->indoor_channel_support;
8315 user_config->is_11d_support_enabled =
8316 hdd_ctx->config->Is11dSupportEnabled;
8317 user_config->is_11h_support_enabled =
8318 hdd_ctx->config->Is11hSupportEnabled;
8319 user_config->optimize_chan_avoid_event =
8320 hdd_ctx->config->goptimize_chan_avoid_event;
8321 user_config->skip_dfs_chnl_in_p2p_search =
8322 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008323 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008324 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8325
8326 qdf_mem_free(user_config);
8327 return 0;
8328}
8329
8330/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008331 * hdd_init_thermal_info - Initialize thermal level
8332 * @hdd_ctx: HDD context
8333 *
8334 * Initialize thermal level at SME layer and set the thermal level callback
8335 * which would be called when a configured thermal threshold is hit.
8336 *
8337 * Return: 0 on success and errno on failure
8338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008339static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008340{
8341 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308342 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008343
8344 thermal_param.smeThermalMgmtEnabled =
8345 hdd_ctx->config->thermalMitigationEnable;
8346 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8347
Poddar, Siddarth83905022016-04-16 17:56:08 -07008348 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8349 hdd_ctx->config->throttle_dutycycle_level0;
8350 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8351 hdd_ctx->config->throttle_dutycycle_level1;
8352 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8353 hdd_ctx->config->throttle_dutycycle_level2;
8354 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8355 hdd_ctx->config->throttle_dutycycle_level3;
8356
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008357 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8358 hdd_ctx->config->thermalTempMinLevel0;
8359 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8360 hdd_ctx->config->thermalTempMaxLevel0;
8361 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8362 hdd_ctx->config->thermalTempMinLevel1;
8363 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8364 hdd_ctx->config->thermalTempMaxLevel1;
8365 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8366 hdd_ctx->config->thermalTempMinLevel2;
8367 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8368 hdd_ctx->config->thermalTempMaxLevel2;
8369 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8370 hdd_ctx->config->thermalTempMinLevel3;
8371 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8372 hdd_ctx->config->thermalTempMaxLevel3;
8373
8374 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8375
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308376 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308377 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008378
8379 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8380 hdd_set_thermal_level_cb);
8381
8382 return 0;
8383
8384}
8385
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008386#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8387/**
8388 * hdd_hold_rtnl_lock - Hold RTNL lock
8389 *
8390 * Hold RTNL lock
8391 *
8392 * Return: True if held and false otherwise
8393 */
8394static inline bool hdd_hold_rtnl_lock(void)
8395{
8396 rtnl_lock();
8397 return true;
8398}
8399
8400/**
8401 * hdd_release_rtnl_lock - Release RTNL lock
8402 *
8403 * Release RTNL lock
8404 *
8405 * Return: None
8406 */
8407static inline void hdd_release_rtnl_lock(void)
8408{
8409 rtnl_unlock();
8410}
8411#else
8412static inline bool hdd_hold_rtnl_lock(void) { return false; }
8413static inline void hdd_release_rtnl_lock(void) { }
8414#endif
8415
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008416#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008417
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308418/* MAX iwpriv command support */
8419#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308420#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308421#define MAX_PKTLOG_SIZE 16
8422
8423/**
8424 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8425 * @hdd_ctx: hdd context
8426 * @set_value2: pktlog buffer size value
8427 *
8428 *
8429 * Return: 0 for success or error.
8430 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008431static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308432{
8433 struct sir_wifi_start_log start_log = { 0 };
8434 QDF_STATUS status;
8435
8436 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8437 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8438 start_log.ini_triggered = cds_is_packet_log_enabled();
8439 start_log.user_triggered = 1;
8440 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308441 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308442
8443 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8444 if (!QDF_IS_STATUS_SUCCESS(status)) {
8445 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8446 EXIT();
8447 return -EINVAL;
8448 }
8449
8450 return 0;
8451}
8452
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008453/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308454 * hdd_pktlog_clear_buff() - clear pktlog buffer
8455 * @hdd_ctx: hdd context
8456 *
8457 * Return: 0 for success or error.
8458 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008459static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308460{
8461 struct sir_wifi_start_log start_log;
8462 QDF_STATUS status;
8463
8464 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8465 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8466 start_log.ini_triggered = cds_is_packet_log_enabled();
8467 start_log.user_triggered = 1;
8468 start_log.size = 0;
8469 start_log.is_pktlog_buff_clear = true;
8470
8471 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8472 if (!QDF_IS_STATUS_SUCCESS(status)) {
8473 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8474 EXIT();
8475 return -EINVAL;
8476 }
8477
8478 return 0;
8479}
8480
8481
8482/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008483 * hdd_process_pktlog_command() - process pktlog command
8484 * @hdd_ctx: hdd context
8485 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308486 * @set_value2: pktlog buffer size value
8487 *
8488 * This function process pktlog command.
8489 * set_value2 only matters when set_value is 3 (set buff size)
8490 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008491 *
8492 * Return: 0 for success or error.
8493 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008494int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308495 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008496{
8497 int ret;
8498 bool enable;
8499 uint8_t user_triggered = 0;
8500
8501 ret = wlan_hdd_validate_context(hdd_ctx);
8502 if (0 != ret)
8503 return ret;
8504
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008505 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008506
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308507 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008508 hdd_err("invalid pktlog value %d", set_value);
8509 return -EINVAL;
8510 }
8511
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308512 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8513 if (set_value2 <= 0) {
8514 hdd_err("invalid pktlog size %d", set_value2);
8515 return -EINVAL;
8516 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8517 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8518 return -EINVAL;
8519 }
8520 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308521 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8522 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308523 }
8524
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008525 /*
8526 * set_value = 0 then disable packetlog
8527 * set_value = 1 enable packetlog forcefully
8528 * set_vlaue = 2 then disable packetlog if disabled through ini or
8529 * enable packetlog with AUTO type.
8530 */
8531 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8532 true : false;
8533
8534 if (1 == set_value) {
8535 enable = true;
8536 user_triggered = 1;
8537 }
8538
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308539 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008540}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008541/**
8542 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8543 * @hdd_ctx: HDD context
8544 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308545 * @user_triggered: triggered through iwpriv
8546 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008547 *
8548 * Return: 0 on success; error number otherwise
8549 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008550int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308551 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008552{
8553 struct sir_wifi_start_log start_log;
8554 QDF_STATUS status;
8555
8556 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8557 start_log.verbose_level =
8558 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008559 start_log.ini_triggered = cds_is_packet_log_enabled();
8560 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308561 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308562 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308563 /*
8564 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8565 * commands. Host uses this flag to decide whether to send pktlog
8566 * disable command to fw without sending pktlog enable command
8567 * previously. For eg, If vendor sends pktlog disable command without
8568 * sending pktlog enable command, then host discards the packet
8569 * but for iwpriv command, host will send it to fw.
8570 */
8571 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008572 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8573 if (!QDF_IS_STATUS_SUCCESS(status)) {
8574 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8575 EXIT();
8576 return -EINVAL;
8577 }
8578
8579 return 0;
8580}
8581#endif /* REMOVE_PKT_LOG */
8582
Komal Seelam92fff912016-03-24 11:51:41 +05308583/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008584 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8585 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308586 * @dev: Device Pointer
8587 * @num: Number of Valid Mac address
8588 *
8589 * Return: Pointer to MAC address buffer
8590 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008591static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8592 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308593{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008594 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308595}
Komal Seelam92fff912016-03-24 11:51:41 +05308596
8597/**
8598 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8599 * @hdd_ctx: HDD Context
8600 * @num: Number of random mac addresses needed
8601 *
8602 * Generate random addresses using bit manipulation on the base mac address
8603 *
8604 * Return: None
8605 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008606void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308607{
8608 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8609 uint32_t iter;
8610 struct hdd_config *ini = hdd_ctx->config;
8611 uint8_t *buf = NULL;
8612 uint8_t macaddr_b3, tmp_br3;
8613 uint8_t *src = ini->intfMacAddr[0].bytes;
8614
8615 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8616 buf = ini->intfMacAddr[iter].bytes;
8617 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8618 macaddr_b3 = buf[3];
8619 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8620 INTF_MACADDR_MASK;
8621 macaddr_b3 += tmp_br3;
8622 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8623 buf[0] |= 0x02;
8624 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008625 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308626 }
8627}
8628
8629/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008630 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308631 * @hdd_ctx: HDD Context
8632 *
8633 * API to get mac addresses from platform driver and update the driver
8634 * structures and configure FW with the base mac address.
8635 * Return: int
8636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008637static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308638{
8639 uint32_t no_of_mac_addr, iter;
8640 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8641 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8642 uint8_t *addr, *buf;
8643 struct device *dev = hdd_ctx->parent_dev;
8644 struct hdd_config *ini = hdd_ctx->config;
8645 tSirMacAddr mac_addr;
8646 QDF_STATUS status;
8647
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008648 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308649
8650 if (no_of_mac_addr == 0 || !addr) {
8651 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8652 return -EINVAL;
8653 }
8654
8655 if (no_of_mac_addr > max_mac_addr)
8656 no_of_mac_addr = max_mac_addr;
8657
8658 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8659
8660 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8661 buf = ini->intfMacAddr[iter].bytes;
8662 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008663 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308664 }
8665
8666 status = sme_set_custom_mac_addr(mac_addr);
8667
8668 if (!QDF_IS_STATUS_SUCCESS(status))
8669 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008670
Komal Seelam92fff912016-03-24 11:51:41 +05308671 if (no_of_mac_addr < max_mac_addr)
8672 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8673 no_of_mac_addr);
8674 return 0;
8675}
8676
8677/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008678 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8679 * @hdd_ctx: HDD Context
8680 *
8681 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8682 * will generate its own MAC and update it to FW.
8683 *
8684 * Return: 0 for success
8685 * Non-zero error code for failure
8686 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008687static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008688{
8689 tSirMacAddr customMacAddr;
8690 QDF_STATUS status;
8691
8692 qdf_mem_copy(&customMacAddr,
8693 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8694 sizeof(tSirMacAddr));
8695 status = sme_set_custom_mac_addr(customMacAddr);
8696 if (!QDF_IS_STATUS_SUCCESS(status))
8697 return -EAGAIN;
8698 return 0;
8699}
8700
8701/**
Komal Seelam92fff912016-03-24 11:51:41 +05308702 * hdd_initialize_mac_address() - API to get wlan mac addresses
8703 * @hdd_ctx: HDD Context
8704 *
8705 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8706 * is provisioned with mac addresses, driver uses it, else it will use
8707 * wlan_mac.bin to update HW MAC addresses.
8708 *
8709 * Return: None
8710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008711static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308712{
8713 QDF_STATUS status;
8714 int ret;
8715
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008716 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308717 if (ret == 0)
8718 return;
8719
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008720 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8721 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308722
8723 status = hdd_update_mac_config(hdd_ctx);
8724
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008725 if (QDF_IS_STATUS_SUCCESS(status))
8726 return;
8727
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008728 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8729 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008730
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008731 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008732 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008733 if (ret != 0) {
8734 hdd_err("MAC address out-of-sync, ret:%d", ret);
8735 QDF_ASSERT(ret);
8736 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008737 }
Komal Seelam92fff912016-03-24 11:51:41 +05308738}
8739
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008740static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008741{
8742 int vdev_id = 0;
8743 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8744 int value = hdd_ctx->config->smart_chainmask_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 Johnsona89e25d2017-02-24 12:25:07 -08008749 if (ret)
8750 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8751
8752 return ret;
8753}
8754
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008755static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008756{
8757 int vdev_id = 0;
8758 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8759 int value = hdd_ctx->config->alternative_chainmask_enabled;
8760 int vpdev = PDEV_CMD;
8761 int ret;
8762
Naveen Rawat247a8682017-06-05 15:00:31 -07008763 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008764 if (ret)
8765 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8766 ret);
8767
8768 return ret;
8769}
8770
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008771static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008772{
8773 int vdev_id = 0;
8774 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8775 int value = hdd_ctx->config->ani_enabled;
8776 int vpdev = PDEV_CMD;
8777 int ret;
8778
Naveen Rawat247a8682017-06-05 15:00:31 -07008779 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008780 if (ret)
8781 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8782
8783 return ret;
8784}
8785
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008786/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008787 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8788 * @hdd_ctx: HDD context
8789 *
8790 * Pre configurations to be done at lower layer before calling cds enable.
8791 *
8792 * Return: 0 on success and errno on failure.
8793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008794static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008795{
8796 int ret;
8797 QDF_STATUS status;
8798 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008799 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008800
Leo Changfdb45c32016-10-28 11:09:23 -07008801 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008802 /*
8803 * Set 802.11p config
8804 * TODO-OCB: This has been temporarily added here to ensure this
8805 * parameter is set in CSR when we init the channel list. This should
8806 * be removed once the 5.9 GHz channels are added to the regulatory
8807 * domain.
8808 */
8809 hdd_set_dot11p_config(hdd_ctx);
8810
8811 /*
8812 * Note that the cds_pre_enable() sequence triggers the cfg download.
8813 * The cfg download must occur before we update the SME config
8814 * since the SME config operation must access the cfg database
8815 */
8816 status = hdd_set_sme_config(hdd_ctx);
8817
8818 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008819 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008820 ret = qdf_status_to_os_return(status);
8821 goto out;
8822 }
8823
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008824 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8825 if (QDF_STATUS_SUCCESS != status) {
8826 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8827 ret = qdf_status_to_os_return(status);
8828 goto out;
8829 }
8830
Naveen Rawat247a8682017-06-05 15:00:31 -07008831 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008832 hdd_ctx->config->tx_chain_mask_1ss,
8833 PDEV_CMD);
8834 if (0 != ret) {
8835 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8836 goto out;
8837 }
8838
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008839 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8840 if (ret)
8841 goto out;
8842
8843 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8844 if (ret)
8845 goto out;
8846
Jeff Johnson12a744b2017-04-04 08:19:37 -07008847 ret = hdd_set_ani_enabled(hdd_ctx);
8848 if (ret)
8849 goto out;
8850
Naveen Rawat247a8682017-06-05 15:00:31 -07008851 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008852 hdd_ctx->config->arp_ac_category,
8853 PDEV_CMD);
8854 if (0 != ret) {
8855 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8856 hdd_ctx->config->arp_ac_category, ret);
8857 goto out;
8858 }
8859
8860
Prashanth Bhatta07998752016-04-28 12:35:33 -07008861 status = hdd_set_sme_chan_list(hdd_ctx);
8862 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008863 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008864 ret = qdf_status_to_os_return(status);
8865 goto out;
8866 }
8867
8868 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008869 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008870 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008871 ret = -EINVAL;
8872 goto out;
8873 }
8874
Prashanth Bhatta07998752016-04-28 12:35:33 -07008875 /*
8876 * Set the MAC Address Currently this is used by HAL to add self sta.
8877 * Remove this once self sta is added as part of session open.
8878 */
8879 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8880 hdd_ctx->config->intfMacAddr[0].bytes,
8881 sizeof(hdd_ctx->config->intfMacAddr[0]));
8882
8883 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8884 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8885 hal_status, hal_status);
8886 ret = -EINVAL;
8887 goto out;
8888 }
8889
8890 hdd_init_channel_avoidance(hdd_ctx);
8891
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308892 /* update enable sap mandatory chan list */
8893 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8894 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008895out:
8896 return ret;
8897}
8898
8899/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008900 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8901 * @context_ptr - hdd context pointer
8902 * @event_ptr - event structure pointer
8903 *
8904 * This is the p2p listen offload stop event handler, it sends vendor
8905 * event back to supplicant to notify the stop reason.
8906 *
8907 * Return: None
8908 */
8909static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8910 void *event_ptr)
8911{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008912 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008913 struct sir_p2p_lo_event *evt = event_ptr;
8914 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008915 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008916
8917 ENTER();
8918
8919 if (hdd_ctx == NULL) {
8920 hdd_err("Invalid HDD context pointer");
8921 return;
8922 }
8923
Peng Xu5c682812017-08-06 07:39:13 -07008924 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8925 if (!adapter) {
8926 hdd_err("Cannot find adapter by vdev_id = %d",
8927 evt->vdev_id);
8928 return;
8929 }
8930
Peng Xu8fdaa492016-06-22 10:20:47 -07008931 vendor_event =
8932 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008933 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008934 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8935 GFP_KERNEL);
8936
8937 if (!vendor_event) {
8938 hdd_err("cfg80211_vendor_event_alloc failed");
8939 return;
8940 }
8941
8942 if (nla_put_u32(vendor_event,
8943 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8944 evt->reason_code)) {
8945 hdd_err("nla put failed");
8946 kfree_skb(vendor_event);
8947 return;
8948 }
8949
8950 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008951 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8952 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008953}
8954
8955/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308956 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8957 * @hdd_ctx: HDD context
8958 *
8959 * This function sends the adaptive dwell time config configuration to the
8960 * firmware via WMA
8961 *
8962 * Return: 0 - success, < 0 - failure
8963 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008964static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308965{
8966 QDF_STATUS status;
8967 struct adaptive_dwelltime_params dwelltime_params;
8968
8969 dwelltime_params.is_enabled =
8970 hdd_ctx->config->adaptive_dwell_mode_enabled;
8971 dwelltime_params.dwelltime_mode =
8972 hdd_ctx->config->global_adapt_dwelltime_mode;
8973 dwelltime_params.lpf_weight =
8974 hdd_ctx->config->adapt_dwell_lpf_weight;
8975 dwelltime_params.passive_mon_intval =
8976 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8977 dwelltime_params.wifi_act_threshold =
8978 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8979
8980 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8981 &dwelltime_params);
8982
8983 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8984 if (!QDF_IS_STATUS_SUCCESS(status)) {
8985 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8986 return -EAGAIN;
8987 }
8988 return 0;
8989}
8990
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008991int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308992{
8993 QDF_STATUS status;
8994 struct wmi_dbs_scan_sel_params dbs_scan_params;
8995 uint32_t i = 0;
8996 uint8_t count = 0, numentries = 0;
8997 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8998 * CDS_DBS_SCAN_CLIENTS_MAX];
8999
9000 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009001 if (hdd_ctx->config->dual_mac_feature_disable ==
9002 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309003 return -EINVAL;
9004
9005 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9006 dbs_scan_config, &numentries,
9007 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9008 * CDS_DBS_SCAN_CLIENTS_MAX));
9009
9010 hdd_info("numentries %hu", numentries);
9011 if (!numentries) {
9012 hdd_info("Donot send scan_selection_config");
9013 return 0;
9014 }
9015
9016 /* hdd_set_fw_log_params */
9017 dbs_scan_params.num_clients = 0;
9018 while (count < (numentries - 2)) {
9019 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9020 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9021 dbs_scan_params.num_non_dbs_scans[i] =
9022 dbs_scan_config[count + 2];
9023 dbs_scan_params.num_clients++;
9024 hdd_debug("module:%d NDS:%d NNDS:%d",
9025 dbs_scan_params.module_id[i],
9026 dbs_scan_params.num_dbs_scans[i],
9027 dbs_scan_params.num_non_dbs_scans[i]);
9028 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9029 i++;
9030 }
9031
9032 dbs_scan_params.pdev_id = 0;
9033
9034 hdd_debug("clients:%d pdev:%d",
9035 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9036
9037 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9038 &dbs_scan_params);
9039 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9040 if (!QDF_IS_STATUS_SUCCESS(status)) {
9041 hdd_err("Failed to send DBS Scan selection configuration!");
9042 return -EAGAIN;
9043 }
9044 return 0;
9045}
9046
Arun Khandavallid4349a92016-07-25 11:10:43 +05309047#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9048/**
9049 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9050 * @hdd_ctx: HDD context
9051 *
9052 * Set auto shutdown callback to get indications from firmware to indicate
9053 * userspace to shutdown WLAN after a configured amount of inactivity.
9054 *
9055 * Return: 0 on success and errno on failure.
9056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009057static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309058{
9059 QDF_STATUS status;
9060
9061 if (!hdd_ctx->config->WlanAutoShutdown)
9062 return 0;
9063
9064 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9065 wlan_hdd_auto_shutdown_cb);
9066 if (status != QDF_STATUS_SUCCESS)
9067 hdd_err("Auto shutdown feature could not be enabled: %d",
9068 status);
9069
9070 return qdf_status_to_os_return(status);
9071}
9072#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009073static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309074{
9075 return 0;
9076}
9077#endif
9078
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009079static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009080{
9081 QDF_STATUS status = QDF_STATUS_SUCCESS;
9082
9083 switch (hdd_ctx->config->dual_mac_feature_disable) {
9084 case DISABLE_DBS_CXN_AND_SCAN:
9085 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9086 if (status != QDF_STATUS_SUCCESS)
9087 hdd_err("Failed to disable dual mac features");
9088 break;
9089 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9090 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9091 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9092 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9093 if (status != QDF_STATUS_SUCCESS)
9094 hdd_err("Failed to set dbs scan and fw mode config");
9095 break;
9096 default:
9097 break;
9098 }
9099
9100 return status;
9101}
9102
Arun Khandavallid4349a92016-07-25 11:10:43 +05309103/**
9104 * hdd_features_init() - Init features
9105 * @hdd_ctx: HDD context
9106 * @adapter: Primary adapter context
9107 *
9108 * Initialize features and their feature context after WLAN firmware is up.
9109 *
9110 * Return: 0 on success and errno on failure.
9111 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009112static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309113{
9114 tSirTxPowerLimit hddtxlimit;
9115 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309116 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309117 int ret;
9118
9119 ENTER();
9120
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009121 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309122 if (ret) {
9123 hdd_err("Failed to update country code: %d", ret);
9124 goto out;
9125 }
9126
9127 /* FW capabilities received, Set the Dot11 mode */
9128 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009129 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9130 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309131
Arun Khandavallid4349a92016-07-25 11:10:43 +05309132
9133 if (hdd_ctx->config->fIsImpsEnabled)
9134 hdd_set_idle_ps_config(hdd_ctx, true);
9135 else
9136 hdd_set_idle_ps_config(hdd_ctx, false);
9137
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309138 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009139 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309140
Arun Khandavallid4349a92016-07-25 11:10:43 +05309141 if (hdd_lro_init(hdd_ctx))
9142 hdd_err("Unable to initialize LRO in fw");
9143
9144 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9145 hdd_err("Unable to send adaptive dwelltime setting to FW");
9146
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309147 if (hdd_dbs_scan_selection_init(hdd_ctx))
9148 hdd_err("Unable to send DBS scan selection setting to FW");
9149
Arun Khandavallid4349a92016-07-25 11:10:43 +05309150 ret = hdd_init_thermal_info(hdd_ctx);
9151 if (ret) {
9152 hdd_err("Error while initializing thermal information");
9153 goto deregister_frames;
9154 }
9155
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309156 if (cds_is_packet_log_enabled())
9157 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9158
Arun Khandavallid4349a92016-07-25 11:10:43 +05309159 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9160 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9161 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9162 if (!QDF_IS_STATUS_SUCCESS(status))
9163 hdd_err("Error setting txlimit in sme: %d", status);
9164
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009165 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309166
Arun Khandavallid4349a92016-07-25 11:10:43 +05309167 ret = hdd_register_cb(hdd_ctx);
9168 if (ret) {
9169 hdd_err("Failed to register HDD callbacks!");
9170 goto deregister_frames;
9171 }
9172
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009173 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9174 if (!QDF_IS_STATUS_SUCCESS(status)) {
9175 hdd_err("Failed to set dbs scan and fw mode cfg");
9176 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309177 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009178
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309179 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9180 status = sme_enable_disable_chanavoidind_event(
9181 hdd_ctx->hHal, 0);
9182 if (!QDF_IS_STATUS_SUCCESS(status)) {
9183 hdd_err("Failed to disable Chan Avoidance Indication");
9184 goto deregister_cb;
9185 }
9186 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309187
Manjeet Singha9cae432017-02-28 11:58:22 +05309188 if (hdd_ctx->config->enable_5g_band_pref) {
9189 band_pref_params.rssi_boost_threshold_5g =
9190 hdd_ctx->config->rssi_boost_threshold_5g;
9191 band_pref_params.rssi_boost_factor_5g =
9192 hdd_ctx->config->rssi_boost_factor_5g;
9193 band_pref_params.max_rssi_boost_5g =
9194 hdd_ctx->config->max_rssi_boost_5g;
9195 band_pref_params.rssi_penalize_threshold_5g =
9196 hdd_ctx->config->rssi_penalize_threshold_5g;
9197 band_pref_params.rssi_penalize_factor_5g =
9198 hdd_ctx->config->rssi_penalize_factor_5g;
9199 band_pref_params.max_rssi_penalize_5g =
9200 hdd_ctx->config->max_rssi_penalize_5g;
9201 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9202 }
9203
Arun Khandavallid4349a92016-07-25 11:10:43 +05309204 /* register P2P Listen Offload event callback */
9205 if (wma_is_p2p_lo_capable())
9206 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9207 wlan_hdd_p2p_lo_event_callback);
9208
9209 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9210
9211 if (ret)
9212 goto deregister_cb;
9213
9214 EXIT();
9215 return 0;
9216
9217deregister_cb:
9218 hdd_deregister_cb(hdd_ctx);
9219deregister_frames:
9220 wlan_hdd_cfg80211_deregister_frames(adapter);
9221out:
9222 return -EINVAL;
9223
9224}
9225
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009226/**
9227 * hdd_features_deinit() - Deinit features
9228 * @hdd_ctx: HDD context
9229 *
9230 * De-Initialize features and their feature context.
9231 *
9232 * Return: none.
9233 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009234static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009235{
9236 wlan_hdd_tsf_deinit(hdd_ctx);
9237}
9238
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309239/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009240 * hdd_register_bcn_cb() - register scan beacon callback
9241 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309242 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009243 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309244 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009245static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309246{
9247 QDF_STATUS status;
9248
9249 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9250 wlan_cfg80211_inform_bss_frame,
9251 SCAN_CB_TYPE_INFORM_BCN);
9252 if (!QDF_IS_STATUS_SUCCESS(status)) {
9253 hdd_err("failed with status code %08d [x%08x]",
9254 status, status);
9255 return status;
9256 }
9257
9258 return QDF_STATUS_SUCCESS;
9259}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309260
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309261/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309262 * hdd_configure_cds() - Configure cds modules
9263 * @hdd_ctx: HDD context
9264 * @adapter: Primary adapter context
9265 *
9266 * Enable Cds modules after WLAN firmware is up.
9267 *
9268 * Return: 0 on success and errno on failure.
9269 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009270int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309271{
9272 int ret;
9273 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309274
9275 ret = hdd_pre_enable_configure(hdd_ctx);
9276 if (ret) {
9277 hdd_err("Failed to pre-configure cds");
9278 goto out;
9279 }
9280
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009281 /* Always get latest IPA resources allocated from cds_open and configure
9282 * IPA module before configuring them to FW. Sequence required as crash
9283 * observed otherwise.
9284 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009285 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9286 hdd_err("Failed to setup pipes");
9287 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009288 }
9289
Arun Khandavallifae92942016-08-01 13:31:08 +05309290 /*
9291 * Start CDS which starts up the SME/MAC/HAL modules and everything
9292 * else
9293 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009294 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309295
9296 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009297 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309298 goto out;
9299 }
9300
9301 status = hdd_post_cds_enable_config(hdd_ctx);
9302 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009303 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009304 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309305 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309306 status = hdd_register_bcn_cb(hdd_ctx);
9307 if (!QDF_IS_STATUS_SUCCESS(status)) {
9308 hdd_alert("hdd_post_cds_enable_config failed");
9309 goto cds_disable;
9310 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309311
9312 ret = hdd_features_init(hdd_ctx, adapter);
9313 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009314 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309315
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309316 if (hdd_enable_egap(hdd_ctx))
9317 hdd_debug("enhance green ap is not enabled");
9318
Nachiket Kukadedd302662017-07-13 17:31:44 +05309319 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9320 hdd_debug("Failed to set wow pulse");
9321
Arun Khandavallifae92942016-08-01 13:31:08 +05309322 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009323
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009324cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009325 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009326
Arun Khandavallifae92942016-08-01 13:31:08 +05309327out:
9328 return -EINVAL;
9329}
9330
9331/**
9332 * hdd_deconfigure_cds() -De-Configure cds
9333 * @hdd_ctx: HDD context
9334 *
9335 * Deconfigure Cds modules before WLAN firmware is down.
9336 *
9337 * Return: 0 on success and errno on failure.
9338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009339static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309340{
9341 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009342 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309343
9344 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009345
9346 /* De-init features */
9347 hdd_features_deinit(hdd_ctx);
9348
Arun Khandavallifae92942016-08-01 13:31:08 +05309349 /* De-register the SME callbacks */
9350 hdd_deregister_cb(hdd_ctx);
9351
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009352 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309353 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9354 hdd_err("Failed to Disable the CDS Modules! :%d",
9355 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009356 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309357 }
9358
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309359 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9360 hdd_err("Failed to disconnect pipes");
9361 ret = -EINVAL;
9362 }
9363
Arun Khandavallifae92942016-08-01 13:31:08 +05309364 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009365 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309366}
9367
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009368#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9369static void hdd_deregister_policy_manager_callback(
9370 struct wlan_objmgr_psoc *psoc)
9371{
9372 if (QDF_STATUS_SUCCESS !=
9373 policy_mgr_deregister_hdd_cb(psoc)) {
9374 hdd_err("HDD callback deregister with policy manager failed");
9375 }
9376}
9377#else
9378static void hdd_deregister_policy_manager_callback(
9379 struct wlan_objmgr_psoc *psoc)
9380{
9381}
9382#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309383
9384/**
9385 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9386 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009387 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309388 *
9389 * This function maintains the driver state machine it will be invoked from
9390 * exit, shutdown and con_mode change handler. Depending on the driver state
9391 * shall perform the stopping/closing of the modules.
9392 *
9393 * Return: 0 for success; non-zero for failure
9394 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009395int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309396{
9397 void *hif_ctx;
9398 qdf_device_t qdf_ctx;
9399 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309400 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009401 bool is_idle_stop = !cds_is_driver_unloading() &&
9402 !cds_is_driver_recovering();
9403 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309404
9405 ENTER();
9406
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009407 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9408
Arun Khandavallifae92942016-08-01 13:31:08 +05309409 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9410 if (!qdf_ctx) {
9411 hdd_err("QDF device context NULL");
9412 return -EINVAL;
9413 }
9414
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309415 mutex_lock(&hdd_ctx->iface_change_lock);
9416 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309417
Dustin Brown70111822017-03-30 15:31:40 -07009418 active_threads = cds_return_external_threads_count();
9419 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009420 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009421 active_threads, hdd_ctx->isWiphySuspended);
9422
9423 cds_print_external_threads();
9424
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009425 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009426 mutex_unlock(&hdd_ctx->iface_change_lock);
9427 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009428 hdd_ctx->config->iface_change_wait_time);
9429 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009430 return 0;
9431 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009432 }
9433
Arun Khandavallifae92942016-08-01 13:31:08 +05309434 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9435
9436 switch (hdd_ctx->driver_status) {
9437 case DRIVER_MODULES_UNINITIALIZED:
9438 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309439 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309440 case DRIVER_MODULES_CLOSED:
9441 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309442 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309443 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309444 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309445 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009446 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309447 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309448 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309449 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009450 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309451 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9452 break;
9453 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009454 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309455 break;
9456 default:
9457 hdd_err("Trying to stop wlan in a wrong state: %d",
9458 hdd_ctx->driver_status);
9459 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309460 ret = -EINVAL;
9461 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309462 }
9463
Rajeev Kumarbe021242017-02-16 16:12:23 -08009464 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309465 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9466 hdd_err("Failed to process post CDS disable Modules! :%d",
9467 qdf_status);
9468 ret = -EINVAL;
9469 QDF_ASSERT(0);
9470 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009471 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309472 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009473 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309474 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309475 QDF_ASSERT(0);
9476 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009477
Arun Khandavallifae92942016-08-01 13:31:08 +05309478 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9479 if (!hif_ctx) {
9480 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309481 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309482 }
9483
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309484 hdd_runtime_suspend_context_deinit(hdd_ctx);
9485
Arunk Khandavalli4b404332017-09-26 12:46:00 +05309486 if (hdd_ctx->target_hw_name) {
9487 qdf_mem_free(hdd_ctx->target_hw_name);
9488 hdd_ctx->target_hw_name = NULL;
9489 }
9490
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309491 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309492
9493 ol_cds_free();
9494
Dustin Brown70111822017-03-30 15:31:40 -07009495 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309496 ret = pld_power_off(qdf_ctx->dev);
9497 if (ret)
9498 hdd_err("CNSS power down failed put device into Low power mode:%d",
9499 ret);
9500 }
9501 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009502 /*
9503 * Reset total mac phy during module stop such that during
9504 * next module start same psoc is used to populate new service
9505 * ready data
9506 */
9507 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309508
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309509done:
9510 hdd_ctx->stop_modules_in_progress = false;
9511 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309512 EXIT();
9513
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309514 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309515
9516}
9517
9518/**
9519 * hdd_iface_change_callback() - Function invoked when stop modules expires
9520 * @priv: pointer to hdd context
9521 *
9522 * This function is invoked when the timer waiting for the interface change
9523 * expires, it shall cut-down the power to wlan and stop all the modules.
9524 *
9525 * Return: void
9526 */
9527static void hdd_iface_change_callback(void *priv)
9528{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009529 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309530 int ret;
9531 int status = wlan_hdd_validate_context(hdd_ctx);
9532
9533 if (status)
9534 return;
9535
9536 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009537 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009538 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309539 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009540 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309541 EXIT();
9542}
9543
9544/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309545 * hdd_state_info_dump() - prints state information of hdd layer
9546 * @buf: buffer pointer
9547 * @size: size of buffer to be filled
9548 *
9549 * This function is used to dump state information of hdd layer
9550 *
9551 * Return: None
9552 */
9553static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9554{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009555 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309556 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9557 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009558 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009559 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309560 uint16_t len = 0;
9561 char *buf = *buf_ptr;
9562
9563 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9564 if (!hdd_ctx) {
9565 hdd_err("Failed to get hdd context ");
9566 return;
9567 }
9568
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009569 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309570
9571 len += scnprintf(buf + len, *size - len,
9572 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9573 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009574 "\n is_scheduler_suspended %d",
9575 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309576
9577 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9578
9579 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9580 adapter = adapter_node->pAdapter;
9581 if (adapter->dev)
9582 len += scnprintf(buf + len, *size - len,
9583 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009584 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309585 "\n device_mode: %d", adapter->device_mode);
9586 switch (adapter->device_mode) {
9587 case QDF_STA_MODE:
9588 case QDF_P2P_CLIENT_MODE:
9589 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9590 len += scnprintf(buf + len, *size - len,
9591 "\n connState: %d",
9592 hdd_sta_ctx->conn_info.connState);
9593 break;
9594
9595 default:
9596 break;
9597 }
9598 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9599 adapter_node = next;
9600 }
9601
9602 *size -= len;
9603 *buf_ptr += len;
9604}
9605
9606/**
9607 * hdd_register_debug_callback() - registration function for hdd layer
9608 * to print hdd state information
9609 *
9610 * Return: None
9611 */
9612static void hdd_register_debug_callback(void)
9613{
9614 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9615}
9616
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309617/*
9618 * wlan_init_bug_report_lock() - Initialize bug report lock
9619 *
9620 * This function is used to create bug report lock
9621 *
9622 * Return: None
9623 */
9624static void wlan_init_bug_report_lock(void)
9625{
9626 p_cds_contextType p_cds_context;
9627
9628 p_cds_context = cds_get_global_context();
9629 if (!p_cds_context) {
9630 hdd_err("cds context is NULL");
9631 return;
9632 }
9633
9634 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9635}
9636
Mohit Khannaf8f96822017-05-17 17:11:59 -07009637void hdd_dp_trace_init(struct hdd_config *config)
9638{
9639
9640 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9641 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9642 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9643 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9644 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9645 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9646 uint8_t num_entries = 0;
9647
9648 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9649 &num_entries, sizeof(config_params));
9650
9651 /* calculating, num bw timer intervals in a second (1000ms) */
9652 if (config->busBandwidthComputeInterval)
9653 thresh_time_limit =
9654 (1000 / config->busBandwidthComputeInterval);
9655 else
9656 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9657
9658 switch (num_entries) {
9659 case 4:
9660 proto_bitmap = config_params[3];
9661 case 3:
9662 verbosity = config_params[2];
9663 case 2:
9664 thresh = config_params[1];
9665 case 1:
9666 live_mode = config_params[0];
9667 default:
9668 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9669 live_mode, thresh, thresh_time_limit,
9670 verbosity, proto_bitmap);
9671 };
9672
9673 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9674 verbosity, proto_bitmap);
9675
9676}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309677/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009678 * hdd_wlan_startup() - HDD init function
9679 * @dev: Pointer to the underlying device
9680 *
9681 * This is the driver startup code executed once a WLAN device has been detected
9682 *
9683 * Return: 0 for success, < 0 for failure
9684 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309685int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009686{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309687 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009688 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009689 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009690 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309691 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009692 uint32_t num_abg_tx_chains = 0;
9693 uint32_t num_11b_tx_chains = 0;
9694 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009695
9696 ENTER();
9697
Arun Khandavallifae92942016-08-01 13:31:08 +05309698 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009699
9700 if (IS_ERR(hdd_ctx))
9701 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009702
Abhishek Singhe9068f12017-03-31 14:14:52 +05309703 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9704 DEFAULT_PSOC_ID);
9705 if (ret) {
9706 hdd_err("Psoc creation fails!");
9707 QDF_BUG(0);
9708 goto err_hdd_free_context;
9709 }
9710
Arun Khandavallifae92942016-08-01 13:31:08 +05309711 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9712 hdd_iface_change_callback, (void *)hdd_ctx);
9713
9714 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309715#ifdef FEATURE_WLAN_CH_AVOID
9716 mutex_init(&hdd_ctx->avoid_freq_lock);
9717#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309718
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009719 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009720 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309721
Jeff Johnson957bc272017-02-02 08:54:48 -08009722 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309723 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009724 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009725 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009726 }
9727
Yingying Tang80e15f32016-09-27 18:23:01 +08009728 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009729
Anurag Chouhan6d760662016-02-20 16:05:43 +05309730 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009731
9732 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009733 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309734 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009735 }
9736
Prashanth Bhatta07998752016-04-28 12:35:33 -07009737 ret = hdd_wiphy_init(hdd_ctx);
9738 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009739 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309740 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009741 }
9742
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309743 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009744 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309745
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309746 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009747 goto err_wiphy_unregister;
9748
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309749 wlan_hdd_init_chan_info(hdd_ctx);
9750
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009751 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009752
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309753 ret = hdd_register_notifiers(hdd_ctx);
9754 if (ret)
9755 goto err_ipa_cleanup;
9756
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009757 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009758
Jeff Johnson957bc272017-02-02 08:54:48 -08009759 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9760 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009761 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009762 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009763 }
9764
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009765 hdd_release_rtnl_lock();
9766 rtnl_held = false;
9767
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009768 wlan_hdd_update_11n_mode(hdd_ctx->config);
9769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009770#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309771 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309772 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009773 hdd_skip_acs_scan_timer_handler,
9774 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309775 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009776 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009777 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009778#endif
9779
Nitesh Shah61c10d92016-10-19 19:29:15 +05309780 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9781 QDF_TIMER_TYPE_SW,
9782 wlan_hdd_change_tdls_mode,
9783 hdd_ctx);
9784
Prashanth Bhattaab004382016-10-11 16:08:11 -07009785 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009786
Jeff Johnson9afc5012016-09-23 13:56:27 -07009787 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009788
Nirav Shahbd36b062016-07-18 11:12:59 +05309789 if (hdd_ctx->rps)
9790 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009791
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309792 status = wlansap_global_init();
9793 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009794 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009795
Komal Seelam8634b772016-09-29 12:12:24 +05309796 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009797 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309798 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009799
Arun Khandavallifae92942016-08-01 13:31:08 +05309800 if (hdd_ctx->config->fIsImpsEnabled)
9801 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309802
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309803 if (hdd_ctx->config->sifs_burst_duration) {
9804 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9805 hdd_ctx->config->sifs_burst_duration;
9806
9807 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009808 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309809 set_value, PDEV_CMD);
9810 }
9811
Paul Zhang42dade02017-05-12 19:20:37 +08009812 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009813 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009814 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309815 /* set chip power save failure detected callback */
9816 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9817 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009818
lifeng959a04c2017-05-10 14:21:28 +08009819 if (hdd_ctx->config->max_mpdus_inampdu) {
9820 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009821 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009822 set_value, PDEV_CMD);
9823 }
9824
9825 if (hdd_ctx->config->enable_rts_sifsbursting) {
9826 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009827 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009828 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9829 set_value, PDEV_CMD);
9830 }
9831
Will Huang496b36c2017-07-11 16:38:50 +08009832 if (hdd_ctx->config->sap_get_peer_info) {
9833 set_value = hdd_ctx->config->sap_get_peer_info;
9834 sme_cli_set_command(0,
9835 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9836 set_value, PDEV_CMD);
9837 }
9838
Naveen Rawat247a8682017-06-05 15:00:31 -07009839 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9840 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9841 if (!hdd_ctx->config->enable2x2) {
9842 if (num_11b_tx_chains > 1)
9843 num_11b_tx_chains = 1;
9844 if (num_11ag_tx_chains > 1)
9845 num_11ag_tx_chains = 1;
9846 }
9847 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9848 num_11b_tx_chains);
9849 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9850 num_11ag_tx_chains);
9851 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9852 num_abg_tx_chains, PDEV_CMD);
9853
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309854 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9855 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309856 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309857
Sachin Ahujadddd2632017-03-07 19:07:24 +05309858 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009859 goto success;
9860
Jeff Johnson957bc272017-02-02 08:54:48 -08009861err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009862 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009863
Jeff Johnson46bde382017-02-01 15:31:16 -08009864err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309865 if (rtnl_held)
9866 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867
Arun Khandavalli08479ba2017-08-07 19:56:23 +05309868err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +05309869 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009871err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009872 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873
Arun Khandavallifae92942016-08-01 13:31:08 +05309874err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009875 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309876
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009877err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309878 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009879 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309880 if (!QDF_IS_STATUS_SUCCESS(status)) {
9881 hdd_err("Failed to close CDS Scheduler");
9882 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9883 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009884 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009885
Houston Hoffman47a4a052016-11-14 23:22:44 -08009886 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009887 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009888 hdd_exit_netlink_services(hdd_ctx);
9889
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309890 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009891
Dustin Brown20912462017-06-07 13:48:25 -07009892 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9893
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009894err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309895 if (cds_is_fw_down())
9896 hdd_err("Not setting the complete event as fw is down");
9897 else
9898 hdd_start_complete(ret);
9899
Arun Khandavallifae92942016-08-01 13:31:08 +05309900 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9901 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009902 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009903 return -EIO;
9904
9905success:
9906 EXIT();
9907 return 0;
9908}
9909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009910/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309911 * hdd_wlan_update_target_info() - update target type info
9912 * @hdd_ctx: HDD context
9913 * @context: hif context
9914 *
9915 * Update target info received from firmware in hdd context
9916 * Return:None
9917 */
9918
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009919void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309920{
9921 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9922
9923 if (!tgt_info) {
9924 hdd_err("Target info is Null");
9925 return;
9926 }
9927
9928 hdd_ctx->target_type = tgt_info->target_type;
9929}
9930
9931/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05309932 * hdd_get_nud_stats_cb() - callback api to update the stats
9933 * received from the firmware
9934 * @data: pointer to adapter.
9935 * @rsp: pointer to data received from FW.
9936 *
9937 * This is called when wlan driver received response event for
9938 * get arp stats to firmware.
9939 *
9940 * Return: None
9941 */
9942static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
9943{
9944 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
9945 struct hdd_nud_stats_context *context;
9946 int status;
9947 struct hdd_adapter *adapter = NULL;
9948
9949 ENTER();
9950
9951 if (!rsp) {
9952 hdd_err("data is null");
9953 return;
9954 }
9955
9956 status = wlan_hdd_validate_context(hdd_ctx);
9957 if (0 != status)
9958 return;
9959
9960 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
9961 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
9962 hdd_err("Invalid adapter or adapter has invalid magic");
9963 return;
9964 }
9965
9966 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
9967 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
9968 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
9969 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
9970 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
9971 rsp->out_of_order_arp_rsp_drop_cnt);
9972 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
9973 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
9974 hdd_notice("rsp->ba_session_establishment_status :%x",
9975 rsp->ba_session_establishment_status);
9976
9977 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
9978 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
9979 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
9980 adapter->dad |= rsp->dad_detected;
9981 adapter->con_status = rsp->connect_status;
9982
9983 spin_lock(&hdd_context_lock);
9984 context = &hdd_ctx->nud_stats_context;
9985 complete(&context->response_event);
9986 spin_unlock(&hdd_context_lock);
9987
9988 EXIT();
9989
9990 return;
9991}
9992
9993/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309994 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309995 * @hdd_ctx: HDD context
9996 *
9997 * Register the HDD callbacks to CDS/SME.
9998 *
9999 * Return: 0 for success or Error code for failure
10000 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010001int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010002{
10003 QDF_STATUS status;
10004 int ret = 0;
10005
10006 ENTER();
10007
10008 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10009
10010 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10011 hdd_send_oem_data_rsp_msg);
10012
10013 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10014 wlan_hdd_cfg80211_fw_mem_dump_cb);
10015 if (!QDF_IS_STATUS_SUCCESS(status)) {
10016 hdd_err("Failed to register memdump callback");
10017 ret = -EINVAL;
10018 return ret;
10019 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010020 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10021 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010022 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10023 sme_nan_register_callback(hdd_ctx->hHal,
10024 wlan_hdd_cfg80211_nan_callback);
10025 sme_stats_ext_register_callback(hdd_ctx->hHal,
10026 wlan_hdd_cfg80211_stats_ext_callback);
10027
10028 sme_ext_scan_register_callback(hdd_ctx->hHal,
10029 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010030 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10031 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010032
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010033 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10034 hdd_rssi_threshold_breached);
10035
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010036 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10037
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010038 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10039 wlan_hdd_cfg80211_link_layer_stats_callback);
10040
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010041 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10042
Zhang Qianca38fb12016-12-23 11:10:48 +080010043 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10044 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10045
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010046 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10047 hdd_lost_link_info_cb);
10048 /* print error and not block the startup process */
10049 if (!QDF_IS_STATUS_SUCCESS(status))
10050 hdd_err("set lost link info callback failed");
10051
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010052 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10053
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010054 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010055 hdd_set_connection_in_progress,
10056 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010057
10058 status = sme_congestion_register_callback(hdd_ctx->hHal,
10059 hdd_update_cca_info_cb);
10060 if (!QDF_IS_STATUS_SUCCESS(status))
10061 hdd_err("set congestion callback failed");
10062
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010063 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10064 hdd_bt_activity_cb);
10065 if (!QDF_IS_STATUS_SUCCESS(status))
10066 hdd_err("set bt activity info callback failed");
10067
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010068 EXIT();
10069
10070 return ret;
10071}
10072
10073/**
10074 * hdd_deregister_cb() - De-Register HDD callbacks.
10075 * @hdd_ctx: HDD context
10076 *
10077 * De-Register the HDD callbacks to CDS/SME.
10078 *
10079 * Return: void
10080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010081void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010082{
10083 QDF_STATUS status;
10084
10085 ENTER();
10086
10087 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10088 if (!QDF_IS_STATUS_SUCCESS(status))
10089 hdd_err("De-register of dcc stats callback failed: %d",
10090 status);
10091
10092 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010093 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10094
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010095 sme_stats_ext_register_callback(hdd_ctx->hHal,
10096 wlan_hdd_cfg80211_stats_ext_callback);
10097
10098 sme_nan_deregister_callback(hdd_ctx->hHal);
10099 status = sme_reset_tsfcb(hdd_ctx->hHal);
10100 if (!QDF_IS_STATUS_SUCCESS(status))
10101 hdd_err("Failed to de-register tsfcb the callback:%d",
10102 status);
10103 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10104 if (!QDF_IS_STATUS_SUCCESS(status))
10105 hdd_err("Failed to de-register the fw mem dump callback: %d",
10106 status);
10107
10108 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10109 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10110
10111 EXIT();
10112}
10113
10114/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010115 * hdd_softap_sta_deauth() - handle deauth req from HDD
10116 * @adapter: Pointer to the HDD
10117 * @enable: bool value
10118 *
10119 * This to take counter measure to handle deauth req from HDD
10120 *
10121 * Return: None
10122 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010123QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010124 struct tagCsrDelStaParams *pDelStaParams)
10125{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010126 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010127
10128 ENTER();
10129
Jeff Johnson36e74c42017-09-18 08:15:42 -070010130 hdd_debug("hdd_softap_sta_deauth:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010131 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10132
10133 /* Ignore request to deauth bcmc station */
10134 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010135 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010136
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010137 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010138 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10139 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010140
10141 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010142 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010143}
10144
10145/**
10146 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10147 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010148 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010149 *
10150 * This to take counter measure to handle deauth req from HDD
10151 *
10152 * Return: None
10153 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010154void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010155 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010156{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010157 ENTER();
10158
Jeff Johnson36e74c42017-09-18 08:15:42 -070010159 hdd_debug("hdd_softap_sta_disassoc:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010160 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10161
10162 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010163 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010164 return;
10165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010166 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010167 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010168}
10169
Jeff Johnson9d295242017-08-29 14:39:48 -070010170void hdd_softap_tkip_mic_fail_counter_measure(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010171 bool enable)
10172{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010173 ENTER();
10174
Jeff Johnson36e74c42017-09-18 08:15:42 -070010175 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10179 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010180}
10181
10182/**
10183 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10184 * @hdd_ctx: HDD Context
10185 *
10186 * API to find if there is any STA or P2P-Client is connected
10187 *
10188 * Return: true if connected; false otherwise
10189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010190QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010191{
10192 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10193}
10194
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010195/**
10196 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10197 * @adapter: HDD adapter pointer
10198 *
10199 * This function loop through each adapter and disable roaming on each STA
10200 * device mode except the input adapter.
10201 *
10202 * Note: On the input adapter roaming is not enabled yet hence no need to
10203 * disable.
10204 *
10205 * Return: None
10206 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010207void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010208{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010209 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010210 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010211 hdd_adapter_list_node_t *adapterNode = NULL;
10212 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010213 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010214
10215 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010216 hdd_ctx->config->isRoamOffloadScanEnabled &&
10217 QDF_STA_MODE == adapter->device_mode &&
10218 policy_mgr_is_sta_active_connection_exists(
10219 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010220 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010221 adapter->sessionId);
10222 /*
10223 * Loop through adapter and disable roaming for each STA device
10224 * mode except the input adapter.
10225 */
10226 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10227
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010228 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010229 adapterIdx = adapterNode->pAdapter;
10230
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010231 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010233 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010234 adapterIdx->sessionId);
10235 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10236 (adapterIdx),
10237 adapterIdx->sessionId, 0);
10238 }
10239
10240 status = hdd_get_next_adapter(hdd_ctx,
10241 adapterNode,
10242 &pNext);
10243 adapterNode = pNext;
10244 }
10245 }
10246}
10247
10248/**
10249 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10250 * @adapter: HDD adapter pointer
10251 *
10252 * This function loop through each adapter and enable roaming on each STA
10253 * device mode except the input adapter.
10254 * Note: On the input adapter no need to enable roaming because link got
10255 * disconnected on this.
10256 *
10257 * Return: None
10258 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010259void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010260{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010261 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010262 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010263 hdd_adapter_list_node_t *adapterNode = NULL;
10264 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010265 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010266
10267 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010268 hdd_ctx->config->isRoamOffloadScanEnabled &&
10269 QDF_STA_MODE == adapter->device_mode &&
10270 policy_mgr_is_sta_active_connection_exists(
10271 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010272 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010273 adapter->sessionId);
10274 /*
10275 * Loop through adapter and enable roaming for each STA device
10276 * mode except the input adapter.
10277 */
10278 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10279
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010280 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010281 adapterIdx = adapterNode->pAdapter;
10282
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010283 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010284 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010285 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010286 adapterIdx->sessionId);
10287 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10288 (adapterIdx),
10289 adapterIdx->sessionId,
10290 REASON_CONNECT);
10291 }
10292
10293 status = hdd_get_next_adapter(hdd_ctx,
10294 adapterNode,
10295 &pNext);
10296 adapterNode = pNext;
10297 }
10298 }
10299}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010300
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010301/**
10302 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10303 * @skb: sk buffer pointer
10304 *
10305 * Sends the bcast message to SVC multicast group with generic nl socket
10306 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10307 *
10308 * Return: None
10309 */
10310static void nl_srv_bcast_svc(struct sk_buff *skb)
10311{
10312#ifdef CNSS_GENL
10313 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10314#else
10315 nl_srv_bcast(skb);
10316#endif
10317}
10318
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010319void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010320{
10321 struct sk_buff *skb;
10322 struct nlmsghdr *nlh;
10323 tAniMsgHdr *ani_hdr;
10324 void *nl_data = NULL;
10325 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010326 struct radio_index_tlv *radio_info;
10327 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010328
10329 if (in_interrupt() || irqs_disabled() || in_atomic())
10330 flags = GFP_ATOMIC;
10331
10332 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10333
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010334 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010335 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010336
10337 nlh = (struct nlmsghdr *)skb->data;
10338 nlh->nlmsg_pid = 0; /* from kernel */
10339 nlh->nlmsg_flags = 0;
10340 nlh->nlmsg_seq = 0;
10341 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10342
10343 ani_hdr = NLMSG_DATA(nlh);
10344 ani_hdr->type = type;
10345
10346 switch (type) {
10347 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010348 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010349 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010350 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010351 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010352 ani_hdr->length = 0;
10353 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010354 break;
10355 case WLAN_SVC_WLAN_STATUS_IND:
10356 case WLAN_SVC_WLAN_VERSION_IND:
10357 case WLAN_SVC_DFS_CAC_START_IND:
10358 case WLAN_SVC_DFS_CAC_END_IND:
10359 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10360 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10361 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010362 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010363 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010364 ani_hdr->length = len;
10365 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10366 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10367 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010368 break;
10369
10370 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010371 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010372 type);
10373 kfree_skb(skb);
10374 return;
10375 }
10376
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010377 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010378 * Add radio index at the end of the svc event in TLV format
10379 * to maintain the backward compatibility with userspace
10380 * applications.
10381 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010382
10383 tlv_len = 0;
10384
10385 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10386 < WLAN_NL_MAX_PAYLOAD) {
10387 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10388 sizeof(*ani_hdr) + len);
10389 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10390 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10391 radio_info->radio = radio;
10392 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010393 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010394 "Added radio index tlv - radio index %d",
10395 radio_info->radio);
10396 }
10397
10398 nlh->nlmsg_len += tlv_len;
10399 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10400
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010401 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402}
10403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010404#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10405void wlan_hdd_auto_shutdown_cb(void)
10406{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010407 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010408
10409 if (!hdd_ctx)
10410 return;
10411
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010412 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010413 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10414 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010415}
10416
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010417void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010418{
10419 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010420 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010421 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010422 bool ap_connected = false, sta_connected = false;
10423 tHalHandle hal_handle;
10424
10425 hal_handle = hdd_ctx->hHal;
10426 if (hal_handle == NULL)
10427 return;
10428
10429 if (hdd_ctx->config->WlanAutoShutdown == 0)
10430 return;
10431
10432 if (enable == false) {
10433 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010434 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010435 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010436 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010437 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010438 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010439 return;
10440 }
10441
10442 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010443 if (policy_mgr_concurrent_open_sessions_running(
10444 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010445 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10446
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010447 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010448 adapter = adapterNode->pAdapter;
10449 if (adapter
10450 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010451 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010452 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10453 conn_info.connState ==
10454 eConnectionState_Associated) {
10455 sta_connected = true;
10456 break;
10457 }
10458 }
10459 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010460 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010461 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10462 bApActive == true) {
10463 ap_connected = true;
10464 break;
10465 }
10466 }
10467 status = hdd_get_next_adapter(hdd_ctx,
10468 adapterNode,
10469 &pNext);
10470 adapterNode = pNext;
10471 }
10472 }
10473
10474 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010475 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010476 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477 }
Jeff Johnson68755312017-02-10 11:46:55 -080010478
10479 if (sme_set_auto_shutdown_timer(hal_handle,
10480 hdd_ctx->config->WlanAutoShutdown)
10481 != QDF_STATUS_SUCCESS)
10482 hdd_err("Failed to start wlan auto shutdown timer");
10483 else
10484 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10485 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010486}
10487#endif
10488
Jeff Johnson9d295242017-08-29 14:39:48 -070010489struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010490 bool check_start_bss)
10491{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010492 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010493 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010494 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10496
10497 con_sap_adapter = NULL;
10498
10499 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010500 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010501 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010502 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10503 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010504 adapter != this_sap_adapter) {
10505 if (check_start_bss) {
10506 if (test_bit(SOFTAP_BSS_STARTED,
10507 &adapter->event_flags)) {
10508 con_sap_adapter = adapter;
10509 break;
10510 }
10511 } else {
10512 con_sap_adapter = adapter;
10513 break;
10514 }
10515 }
10516 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10517 adapterNode = pNext;
10518 }
10519
10520 return con_sap_adapter;
10521}
10522
10523#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010524static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010525{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010526 return adapter->device_mode == QDF_STA_MODE ||
10527 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528}
10529
Jeff Johnson9d295242017-08-29 14:39:48 -070010530static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010532 return adapter->device_mode == QDF_SAP_MODE ||
10533 adapter->device_mode == QDF_P2P_GO_MODE;
10534}
10535
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010536static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010537{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010538 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010539 hdd_adapter_list_node_t *node;
10540
10541 status = hdd_get_front_adapter(hdd_ctx, &node);
10542 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson9d295242017-08-29 14:39:48 -070010543 struct hdd_adapter *adapter = node->pAdapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010544
10545 if (adapter &&
10546 hdd_adapter_is_sta(adapter) &&
10547 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10548 conn_info.connState == eConnectionState_Associated) {
10549 return true;
10550 }
10551
10552 if (adapter &&
10553 hdd_adapter_is_ap(adapter) &&
10554 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10555 return true;
10556 }
10557
10558 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10559 }
10560
10561 return false;
10562}
10563
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010564static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010565{
10566 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010567
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010568 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010569 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010570 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571
Dustin Brown5ec6b552017-03-31 12:11:40 -070010572 return is_running;
10573}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010574
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010575static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010576{
10577 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10578 hdd_ctx->bus_bw_timer_running = true;
10579 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10580 hdd_ctx->config->busBandwidthComputeInterval);
10581 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10582}
10583
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010584void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010585{
10586 ENTER();
10587
10588 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10589 hdd_debug("Bandwidth compute timer already started");
10590 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010591 }
10592
Dustin Brown5ec6b552017-03-31 12:11:40 -070010593 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10594
10595 EXIT();
10596}
10597
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010598void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010599{
10600 ENTER();
10601
10602 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10603 hdd_debug("Bandwidth compute timer already started");
10604 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010605 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010606
10607 if (hdd_any_adapter_is_assoc(hdd_ctx))
10608 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10609
10610 EXIT();
10611}
10612
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010613static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010614{
10615 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10616
10617 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10618 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10619 hdd_ctx->bus_bw_timer_running = false;
10620 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10621
10622 hdd_reset_tcp_delack(hdd_ctx);
10623}
10624
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010625void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010626{
10627 ENTER();
10628
10629 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10630 hdd_debug("Bandwidth compute timer already stopped");
10631 return;
10632 }
10633
10634 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10635
10636 EXIT();
10637}
10638
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010639void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010640{
10641 ENTER();
10642
10643 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10644 hdd_debug("Bandwidth compute timer already stopped");
10645 return;
10646 }
10647
10648 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10649 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10650
10651 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010652}
10653#endif
10654
10655/**
10656 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10657 * and sta's operating channel.
10658 * @sta_adapter: Describe the first argument to foobar.
10659 * @ap_adapter: Describe the second argument to foobar.
10660 * @roam_profile: Roam profile of AP to which STA wants to connect.
10661 * @concurrent_chnl_same: If both SAP and STA channels are same then
10662 * set this flag to true else false.
10663 *
10664 * This function checks the sap's operating channel and sta's operating channel.
10665 * if both are same then it will return false else it will restart the sap in
10666 * sta's channel and return true.
10667 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010668 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010669 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010670QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10671 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010672 tCsrRoamProfile *roam_profile,
10673 tScanResultHandle *scan_cache,
10674 bool *concurrent_chnl_same)
10675{
Jeff Johnson87251032017-08-29 13:31:11 -070010676 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010677 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010678 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010679 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010680 *concurrent_chnl_same = true;
10681
10682 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10683 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010684 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010685 scan_cache,
10686 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010687 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010688 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010689 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10690 if (hdd_ap_ctx->operatingChannel != channel_id) {
10691 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010692 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010693 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010694 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010695 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10696 if (hdd_ap_ctx->operatingChannel != channel_id) {
10697 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010698 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699 }
10700 }
10701 } else {
10702 /*
10703 * Lets handle worst case scenario here, Scan cache lookup is
10704 * failed so we have to stop the SAP to avoid any channel
10705 * discrepancy between SAP's channel and STA's channel.
10706 * Return the status as failure so caller function could know
10707 * that scan look up is failed.
10708 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010709 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010710 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010711 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010712 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010713}
10714
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010715/**
10716 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10717 * @ap_adapter: SAP adapter
10718 *
10719 * This function will process the stopping of sap adapter.
10720 *
10721 * Return: None
10722 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010723void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
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
10730 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010731 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732 return;
10733 }
10734
10735 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10736 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010737 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010738 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740 mutex_lock(&hdd_ctx->sap_lock);
10741 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010742 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010743 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10744 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010745 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010746 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010747 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010748 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010749 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010750 qdf_stop_bss_event,
10751 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010752 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010754 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755 return;
10756 }
10757 }
10758 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010759 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10760 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010761 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010762 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010764 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765 }
10766 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010767}
10768
10769/**
10770 * wlan_hdd_start_sap() - this function starts bss of SAP.
10771 * @ap_adapter: SAP adapter
10772 *
10773 * This function will process the starting of sap adapter.
10774 *
10775 * Return: None
10776 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010777void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010778{
Jeff Johnson87251032017-08-29 13:31:11 -070010779 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010781 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010782 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010783 tsap_Config_t *sap_config;
10784
10785 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010786 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010787 return;
10788 }
10789
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010790 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010791 hdd_err("SoftAp role has not been enabled");
10792 return;
10793 }
10794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010795 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10796 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10797 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10798 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010800 mutex_lock(&hdd_ctx->sap_lock);
10801 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10802 goto end;
10803
10804 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010805 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10807 goto end;
10808 }
10809
Wei Song2f76f642016-11-18 16:32:53 +080010810 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010811 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10812 &hdd_ap_ctx->sapConfig,
10813 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010814 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010815 goto end;
10816
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010817 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010818 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010819 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010820 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010821 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010822 goto end;
10823 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010824 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010825 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010826 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010827 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10828 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010829 ap_adapter->sessionId);
10830 hostapd_state->bCommit = true;
10831
10832end:
10833 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010834 /* SAP context and beacon cleanup will happen during driver unload
10835 * in hdd_stop_adapter
10836 */
10837 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010840
10841/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010842 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10843 * mac scan config
10844 * @status: Status of set antenna mode
10845 *
10846 * Callback on setting the dual mac configuration
10847 *
10848 * Return: None
10849 */
10850void wlan_hdd_soc_set_antenna_mode_cb(
10851 enum set_antenna_mode_status status)
10852{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010853 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010854
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010855 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010856
10857 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10858 if (0 != wlan_hdd_validate_context(hdd_ctx))
10859 return;
10860
10861 /* Signal the completion of set dual mac config */
10862 complete(&hdd_ctx->set_antenna_mode_cmpl);
10863}
10864
10865/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010866 * hdd_get_fw_version() - Get FW version
10867 * @hdd_ctx: pointer to HDD context.
10868 * @major_spid: FW version - major spid.
10869 * @minor_spid: FW version - minor spid
10870 * @ssid: FW version - ssid
10871 * @crmid: FW version - crmid
10872 *
10873 * This function is called to get the firmware build version stored
10874 * as part of the HDD context
10875 *
10876 * Return: None
10877 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010878void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879 uint32_t *major_spid, uint32_t *minor_spid,
10880 uint32_t *siid, uint32_t *crmid)
10881{
10882 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10883 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10884 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10885 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10886}
10887
10888#ifdef QCA_CONFIG_SMP
10889/**
10890 * wlan_hdd_get_cpu() - get cpu_index
10891 *
10892 * Return: cpu_index
10893 */
10894int wlan_hdd_get_cpu(void)
10895{
10896 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010898 put_cpu();
10899 return cpu_index;
10900}
10901#endif
10902
10903/**
10904 * hdd_get_fwpath() - get framework path
10905 *
10906 * This function is used to get the string written by
10907 * userspace to start the wlan driver
10908 *
10909 * Return: string
10910 */
10911const char *hdd_get_fwpath(void)
10912{
10913 return fwpath.string;
10914}
10915
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010916static int hdd_qdf_print_init(void)
10917{
10918 int qdf_print_idx;
10919 QDF_STATUS status;
10920
10921 status = qdf_print_setup();
10922 if (status != QDF_STATUS_SUCCESS) {
10923 pr_err("qdf_print_setup failed\n");
10924 return -EINVAL;
10925 }
10926
10927 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10928
10929 if (qdf_print_idx < 0) {
10930 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10931 qdf_print_idx);
10932 return -EINVAL;
10933 }
10934
10935 qdf_set_pidx(qdf_print_idx);
10936
10937 return 0;
10938}
10939
10940static void hdd_qdf_print_deinit(void)
10941{
10942 int qdf_print_idx;
10943
10944 qdf_print_idx = qdf_get_pidx();
10945 qdf_print_ctrl_cleanup(qdf_print_idx);
10946}
10947
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010948/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010949 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010950 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010951 * This function initilizes CDS global context with the help of cds_init. This
10952 * has to be the first function called after probe to get a valid global
10953 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010954 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010955 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010956 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010957int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010958{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010959 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010960 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010961
Houston Hoffman9e06e542016-12-12 12:06:26 -080010962 p_cds_context = cds_init();
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053010963
10964 wlan_init_bug_report_lock();
10965
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010966#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10967 wlan_logging_sock_init_svc();
10968#endif
10969
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010970 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010971 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010972 ret = -ENOMEM;
10973 goto err_out;
10974 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010975
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010976 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010977 hdd_qdf_print_init();
10978
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010979 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010980
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010981err_out:
10982 return ret;
10983}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010984
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010985/**
10986 * hdd_deinit() - Deinitialize Driver
10987 *
10988 * This function frees CDS global context with the help of cds_deinit. This
10989 * has to be the last function call in remove callback to free the global
10990 * context.
10991 */
10992void hdd_deinit(void)
10993{
Dustin Brownedce4a52017-05-10 11:59:15 -070010994 hdd_deinit_wowl();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010995
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010996 hdd_qdf_print_deinit();
10997
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010998#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10999 wlan_logging_sock_deinit_svc();
11000#endif
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011001
11002 wlan_destroy_bug_report_lock();
11003 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011004}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011005
Yue Ma6e7b1a02017-04-03 14:17:46 -070011006#ifdef QCA_WIFI_NAPIER_EMULATION
11007#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11008#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011010#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011011
Sachin Ahujadddd2632017-03-07 19:07:24 +053011012static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11013 struct file *file)
11014{
11015 return 0;
11016}
11017
11018static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11019 const char __user *user_buf,
11020 size_t count,
11021 loff_t *f_pos)
11022{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011023 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011024 static const char wlan_off_str[] = "OFF";
11025 static const char wlan_on_str[] = "ON";
11026 int ret;
11027 unsigned long rc;
11028
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011029 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011030 pr_err("Failed to read buffer\n");
11031 return -EINVAL;
11032 }
11033
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011034 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011035 pr_debug("Wifi turning off from UI\n");
11036 goto exit;
11037 }
11038
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011039 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011040 pr_err("Invalid value received from framework");
11041 goto exit;
11042 }
11043
11044 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011045 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011046 rc = wait_for_completion_timeout(&wlan_start_comp,
11047 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11048 if (!rc) {
11049 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11050 ret = -EINVAL;
11051 hdd_start_complete(ret);
11052 return ret;
11053 }
11054
11055 hdd_start_complete(0);
11056 }
11057
11058exit:
11059 return count;
11060}
11061
11062
11063const struct file_operations wlan_hdd_state_fops = {
11064 .owner = THIS_MODULE,
11065 .open = wlan_hdd_state_ctrl_param_open,
11066 .write = wlan_hdd_state_ctrl_param_write,
11067};
11068
11069static int wlan_hdd_state_ctrl_param_create(void)
11070{
11071 unsigned int wlan_hdd_state_major = 0;
11072 int ret;
11073 struct device *dev;
11074
11075 device = MKDEV(wlan_hdd_state_major, 0);
11076
11077 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11078 if (ret) {
11079 pr_err("Failed to register qcwlanstate");
11080 goto dev_alloc_err;
11081 }
11082 wlan_hdd_state_major = MAJOR(device);
11083
11084 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11085 if (IS_ERR(class)) {
11086 pr_err("wlan_hdd_state class_create error");
11087 goto class_err;
11088 }
11089
11090 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11091 if (IS_ERR(dev)) {
11092 pr_err("wlan_hdd_statedevice_create error");
11093 goto err_class_destroy;
11094 }
11095
11096 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11097 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11098 if (ret) {
11099 pr_err("Failed to add cdev error");
11100 goto cdev_add_err;
11101 }
11102
11103 pr_info("wlan_hdd_state %s major(%d) initialized",
11104 WLAN_MODULE_NAME, wlan_hdd_state_major);
11105
11106 return 0;
11107
11108cdev_add_err:
11109 device_destroy(class, device);
11110err_class_destroy:
11111 class_destroy(class);
11112class_err:
11113 unregister_chrdev_region(device, dev_num);
11114dev_alloc_err:
11115 return -ENODEV;
11116}
11117
11118static void wlan_hdd_state_ctrl_param_destroy(void)
11119{
11120 cdev_del(&wlan_hdd_state_cdev);
11121 device_destroy(class, device);
11122 class_destroy(class);
11123 unregister_chrdev_region(device, dev_num);
11124
11125 pr_info("Device node unregistered");
11126}
11127
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011128/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011129 * component_init - API to init cld component's
11130 *
11131 * Return: None
11132 */
11133static void component_init(void)
11134{
11135 pmo_init();
11136}
11137
11138/**
11139 * component_deinit - API to deinit cld component's
11140 *
11141 * Return: None
11142 */
11143static void component_deinit(void)
11144{
11145 pmo_deinit();
11146}
11147
11148/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011149 * __hdd_module_init - Module init helper
11150 *
11151 * Module init helper function used by both module and static driver.
11152 *
11153 * Return: 0 for success, errno on failure
11154 */
11155static int __hdd_module_init(void)
11156{
11157 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011158
Dustin Brownab482ac2017-06-09 17:00:44 -070011159 pr_err("%s: Loading driver v%s (%s)%s\n",
11160 WLAN_MODULE_NAME,
11161 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011162 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011163 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011164
Sachin Ahujadddd2632017-03-07 19:07:24 +053011165 ret = wlan_hdd_state_ctrl_param_create();
11166 if (ret) {
11167 pr_err("wlan_hdd_state_create:%x\n", ret);
11168 goto err_dev_state;
11169 }
11170
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011171 pld_init();
11172
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011173 ret = hdd_init();
11174 if (ret) {
11175 pr_err("hdd_init failed %x\n", ret);
11176 goto err_hdd_init;
11177 }
11178
Rajeev Kumar97767a02016-11-30 11:20:40 -080011179 dispatcher_init();
11180
Mukul Sharmad75a6672017-06-22 15:40:53 +053011181 /* Ensure to call post objmgr init */
11182 component_init();
11183
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011184 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011185
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011186 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011187
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011188 ret = wlan_hdd_register_driver();
11189 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011190 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11191 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011192 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011193 }
11194
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011195 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011196
11197 return 0;
11198out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011199 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011200 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011201 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011202
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011203err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011204 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011205 wlan_hdd_state_ctrl_param_destroy();
11206err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011207 return ret;
11208}
11209
11210/**
11211 * __hdd_module_exit - Module exit helper
11212 *
11213 * Module exit helper function used by both module and static driver.
11214 */
11215static void __hdd_module_exit(void)
11216{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011217
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011218 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11219 QWLAN_VERSIONSTR);
11220
bings6028ee82017-03-29 07:51:40 +080011221 cds_set_unload_in_progress(true);
11222
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011223 hdd_wait_for_recovery_completion();
11224
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011225 wlan_hdd_unregister_driver();
11226
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011227 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011228
Mukul Sharmad75a6672017-06-22 15:40:53 +053011229 /* Ensure to call prior to objmgr deinit */
11230 component_deinit();
11231
Rajeev Kumar97767a02016-11-30 11:20:40 -080011232 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011233 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011234 pld_deinit();
11235
Sachin Ahujadddd2632017-03-07 19:07:24 +053011236 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011237}
11238
Arun Khandavallifae92942016-08-01 13:31:08 +053011239#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011240/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011241 * wlan_boot_cb() - Wlan boot callback
11242 * @kobj: object whose directory we're creating the link in.
11243 * @attr: attribute the user is interacting with
11244 * @buff: the buffer containing the user data
11245 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011246 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011247 * This callback is invoked when the fs is ready to start the
11248 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011249 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011250 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011251 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011252static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011253 struct kobj_attribute *attr,
11254 const char *buf,
11255 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011256{
Arun Khandavallifae92942016-08-01 13:31:08 +053011257
Arun Khandavallifae92942016-08-01 13:31:08 +053011258 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011259 pr_err("%s: wlan driver already initialized\n", __func__);
11260 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011261 }
11262
Arun Khandavallifae92942016-08-01 13:31:08 +053011263 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011264 pr_err("%s: wlan driver initialization failed\n", __func__);
11265 return -EIO;
11266 }
11267
11268 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011269
11270 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011271}
Arun Khandavallifae92942016-08-01 13:31:08 +053011272
11273/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011274 * hdd_sysfs_cleanup() - cleanup sysfs
11275 *
11276 * Return: None
11277 *
11278 */
11279static void hdd_sysfs_cleanup(void)
11280{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011281 /* remove from group */
11282 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11283 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11284 wlan_loader->attr_group);
11285
11286 /* unlink the object from parent */
11287 kobject_del(wlan_loader->boot_wlan_obj);
11288
11289 /* free the object */
11290 kobject_put(wlan_loader->boot_wlan_obj);
11291
11292 kfree(wlan_loader->attr_group);
11293 kfree(wlan_loader);
11294
11295 wlan_loader = NULL;
11296}
11297
11298/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011299 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11300 * ready
11301 *
11302 * This is creates the syfs entry boot_wlan. Which shall be invoked
11303 * when the filesystem is ready.
11304 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011305 * QDF API cannot be used here since this function is called even before
11306 * initializing WLAN driver.
11307 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011308 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011309 */
11310static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011311{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011312 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011313
11314 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011315 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011316 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011317
11318 wlan_loader->boot_wlan_obj = NULL;
11319 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11320 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011321 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011322 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011323
11324 wlan_loader->loaded_state = 0;
11325 wlan_loader->attr_group->attrs = attrs;
11326
11327 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11328 kernel_kobj);
11329 if (!wlan_loader->boot_wlan_obj) {
11330 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 goto error_return;
11332 }
11333
11334 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11335 wlan_loader->attr_group);
11336 if (ret) {
11337 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11338 goto error_return;
11339 }
11340
11341 return 0;
11342
11343error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011344 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011345
11346 return ret;
11347}
11348
11349/**
11350 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11351 *
11352 * Return: 0 on success or errno on failure
11353 */
11354static int wlan_deinit_sysfs(void)
11355{
Arun Khandavallifae92942016-08-01 13:31:08 +053011356 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011357 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011358 return -EINVAL;
11359 }
11360
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011361 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011362 return 0;
11363}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011364
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011365#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011366
11367#ifdef MODULE
11368/**
11369 * __hdd_module_init - Module init helper
11370 *
11371 * Module init helper function used by both module and static driver.
11372 *
11373 * Return: 0 for success, errno on failure
11374 */
11375static int hdd_module_init(void)
11376{
Arun Khandavallifae92942016-08-01 13:31:08 +053011377 if (__hdd_module_init()) {
11378 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011379 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011380 }
11381
Dustin Brownab482ac2017-06-09 17:00:44 -070011382 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011383}
11384#else
11385static int __init hdd_module_init(void)
11386{
11387 int ret = -EINVAL;
11388
11389 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011390 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011391 pr_err("Failed to create sysfs entry for loading wlan");
11392
11393 return ret;
11394}
11395#endif
11396
11397
11398#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011399/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011400 * hdd_module_exit() - Exit function
11401 *
11402 * This is the driver exit point (invoked when module is unloaded using rmmod)
11403 *
11404 * Return: None
11405 */
11406static void __exit hdd_module_exit(void)
11407{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011408 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011409}
Arun Khandavallifae92942016-08-01 13:31:08 +053011410#else
11411static void __exit hdd_module_exit(void)
11412{
11413 __hdd_module_exit();
11414 wlan_deinit_sysfs();
11415}
11416#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011417
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011418static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11419{
11420 return param_set_copystring(kmessage, kp);
11421}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011422
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011423/**
11424 * is_con_mode_valid() check con mode is valid or not
11425 * @mode: global con mode
11426 *
11427 * Return: TRUE on success FALSE on failure
11428 */
11429static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11430{
11431 switch (mode) {
11432 case QDF_GLOBAL_MONITOR_MODE:
11433 case QDF_GLOBAL_FTM_MODE:
11434 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011435 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011436 return true;
11437 default:
11438 return false;
11439 }
11440}
11441
11442/**
11443 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11444 * @mode: global con mode
11445 *
11446 * Return: adapter mode
11447 */
11448static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11449 enum tQDF_GLOBAL_CON_MODE mode)
11450{
11451
11452 switch (mode) {
11453 case QDF_GLOBAL_MISSION_MODE:
11454 return QDF_STA_MODE;
11455 case QDF_GLOBAL_MONITOR_MODE:
11456 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011457 case QDF_GLOBAL_EPPING_MODE:
11458 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011459 case QDF_GLOBAL_FTM_MODE:
11460 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011461 case QDF_GLOBAL_QVIT_MODE:
11462 return QDF_QVIT_MODE;
11463 default:
11464 return QDF_MAX_NO_OF_MODE;
11465 }
11466}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011467
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011468static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011469 enum tQDF_GLOBAL_CON_MODE curr_mode)
11470{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011471 int driver_status;
11472
11473 driver_status = hdd_ctx->driver_status;
11474
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011475 switch (curr_mode) {
11476 case QDF_GLOBAL_MISSION_MODE:
11477 case QDF_GLOBAL_MONITOR_MODE:
11478 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011479 if (driver_status != DRIVER_MODULES_CLOSED) {
11480 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11481 hdd_stop_all_adapters(hdd_ctx);
11482 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011483 hdd_deinit_all_adapters(hdd_ctx, false);
11484 hdd_close_all_adapters(hdd_ctx, false);
11485 break;
11486 case QDF_GLOBAL_EPPING_MODE:
11487 epping_disable();
11488 epping_close();
11489 break;
11490 default:
11491 return;
11492 }
11493}
11494
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011495static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011496 enum tQDF_GLOBAL_CON_MODE mode)
11497{
Jeff Johnson9d295242017-08-29 14:39:48 -070011498 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011499 int ret = 0;
11500 bool rtnl_held;
11501 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11502 QDF_STATUS status;
11503
11504 if (!qdf_dev) {
11505 hdd_err("qdf device context is Null return!");
11506 return -EINVAL;
11507 }
11508
11509 rtnl_held = hdd_hold_rtnl_lock();
11510 switch (mode) {
11511 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011512 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11513 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011514 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011515 break;
11516 case QDF_GLOBAL_FTM_MODE:
11517 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11518 wlan_hdd_get_intf_addr(hdd_ctx),
11519 NET_NAME_UNKNOWN, rtnl_held);
11520 if (adapter == NULL)
11521 ret = -EINVAL;
11522 break;
11523 case QDF_GLOBAL_MONITOR_MODE:
11524 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11525 wlan_hdd_get_intf_addr(hdd_ctx),
11526 NET_NAME_UNKNOWN, rtnl_held);
11527 if (adapter == NULL)
11528 ret = -EINVAL;
11529 break;
11530 case QDF_GLOBAL_EPPING_MODE:
11531 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011532 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011533 hdd_err("Failed to open in eeping mode: %d", status);
11534 ret = -EINVAL;
11535 break;
11536 }
11537 ret = epping_enable(qdf_dev->dev);
11538 if (ret) {
11539 hdd_err("Failed to enable in epping mode : %d", ret);
11540 epping_close();
11541 }
11542 break;
11543 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011544 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011545 ret = -ENOTSUPP;
11546 break;
11547 }
11548 hdd_release_rtnl_lock();
11549 rtnl_held = false;
11550 return ret;
11551}
11552
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011553/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011554 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011555 * @kmessage: con mode name on which driver to be bring up
11556 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011557 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011558 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011559 * This function is invoked when user updates con mode using sys entry,
11560 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011561 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011562 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011563 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011564static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011565 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011566{
11567 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011568 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011569 enum tQDF_GLOBAL_CON_MODE curr_mode;
11570 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011571
Dustin Brownab6029b2017-05-24 13:04:19 -070011572 hdd_info("con_mode handler: %s", kmessage);
11573
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011574 ret = wlan_hdd_validate_context(hdd_ctx);
11575 if (ret)
11576 return ret;
11577
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011578 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011579
11580 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011581
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011582 if (!(is_con_mode_valid(con_mode))) {
11583 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011584 ret = -EINVAL;
11585 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011586 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011587
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011588 curr_mode = hdd_get_conparam();
11589 if (curr_mode == con_mode) {
11590 hdd_err("curr mode: %d is same as user triggered mode %d",
11591 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011592 ret = 0;
11593 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011594 }
11595
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011596 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011597 if (ret) {
11598 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011599 goto reset_flags;
11600 }
11601
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011602 /* Cleanup present mode before switching to new mode */
11603 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11604
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011605 hdd_set_conparam(con_mode);
11606
11607 /* Register for new con_mode & then kick_start modules again */
11608 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11609 if (ret) {
11610 hdd_err("Failed to register for new mode");
11611 goto reset_flags;
11612 }
11613
11614 adapter_mode = hdd_get_adpter_mode(con_mode);
11615 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11616 hdd_err("invalid adapter");
11617 ret = -EINVAL;
11618 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011619 }
11620
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011621 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011622 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011623 hdd_err("Failed to get adapter:%d", adapter_mode);
11624 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011625 }
11626
11627 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11628 if (ret) {
11629 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011630 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011631 }
11632
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011633 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11634 con_mode == QDF_GLOBAL_FTM_MODE) {
11635 if (hdd_start_adapter(adapter)) {
11636 hdd_err("Failed to start %s adapter", kmessage);
11637 ret = -EINVAL;
11638 goto reset_flags;
11639 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011640 }
11641
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011642 hdd_info("Mode successfully changed to %s", kmessage);
11643 ret = 0;
11644
11645reset_flags:
11646 cds_set_load_in_progress(false);
11647 return ret;
11648}
11649
11650
11651static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11652{
11653 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011654 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011655
11656 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11657 ret = wlan_hdd_validate_context(hdd_ctx);
11658 if (ret)
11659 return ret;
11660
11661 cds_ssr_protect(__func__);
11662 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11663 cds_ssr_unprotect(__func__);
11664
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011665 return ret;
11666}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011667
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011668static int con_mode_handler_ftm(const char *kmessage,
11669 struct kernel_param *kp)
11670{
11671 int ret;
11672
11673 ret = param_set_int(kmessage, kp);
11674
11675 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11676 pr_err("Only FTM mode supported!");
11677 return -ENOTSUPP;
11678 }
11679
11680 hdd_set_conparam(con_mode_ftm);
11681 con_mode = con_mode_ftm;
11682
11683 return ret;
11684}
11685
Ravi Joshia307f632017-07-17 23:41:41 -070011686static int con_mode_handler_monitor(const char *kmessage,
11687 struct kernel_param *kp)
11688{
11689 int ret;
11690
11691 ret = param_set_int(kmessage, kp);
11692
11693 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11694 pr_err("Only Monitor mode supported!");
11695 return -ENOTSUPP;
11696 }
11697
11698 hdd_set_conparam(con_mode_monitor);
11699 con_mode = con_mode_monitor;
11700
11701 return ret;
11702}
11703
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011704/**
11705 * hdd_get_conparam() - driver exit point
11706 *
11707 * This is the driver exit point (invoked when module is unloaded using rmmod)
11708 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011709 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011710 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011711enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011712{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011713 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011714}
11715
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011716void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011717{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011718 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011719}
11720
Komal Seelamc11bb222016-01-27 18:57:10 +053011721/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011722 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11723 * @hdd_ctx: HDD context
11724 *
11725 * Cleans up the pre cac interface, if it exists
11726 *
11727 * Return: None
11728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011729void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011730{
11731 uint8_t session_id;
11732 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011733 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011734
11735 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11736 if (QDF_IS_STATUS_ERROR(status)) {
11737 hdd_err("failed to get pre cac vdev id");
11738 return;
11739 }
11740
11741 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11742 if (!precac_adapter) {
11743 hdd_err("invalid pre cac adapater");
11744 return;
11745 }
11746
11747 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11748 wlan_hdd_sap_pre_cac_failure,
11749 (void *)precac_adapter);
11750 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11751
11752}
11753
11754/**
Komal Seelamec702b02016-02-24 18:42:16 +053011755 * hdd_update_ol_config - API to update ol configuration parameters
11756 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011757 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011758 * Return: void
11759 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011760static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011761{
Komal Seelamec702b02016-02-24 18:42:16 +053011762 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011763 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011764
Komal Seelamec702b02016-02-24 18:42:16 +053011765 if (!ol_ctx)
11766 return;
11767
11768 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11769 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11770 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11771 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011772 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011773
11774 ol_init_ini_config(ol_ctx, &cfg);
11775}
11776
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011777#ifdef FEATURE_RUNTIME_PM
11778/**
11779 * hdd_populate_runtime_cfg() - populate runtime configuration
11780 * @hdd_ctx: hdd context
11781 * @cfg: pointer to the configuration memory being populated
11782 *
11783 * Return: void
11784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011785static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011786 struct hif_config_info *cfg)
11787{
11788 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11789 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11790}
11791#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011792static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011793 struct hif_config_info *cfg)
11794{
11795}
11796#endif
11797
Komal Seelamec702b02016-02-24 18:42:16 +053011798/**
11799 * hdd_update_hif_config - API to update HIF configuration parameters
11800 * @hdd_ctx: HDD Context
11801 *
11802 * Return: void
11803 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011804static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011805{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011806 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011807 struct hif_config_info cfg;
11808
11809 if (!scn)
11810 return;
11811
11812 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011813 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011814 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011815
11816 if (hdd_ctx->config->prevent_link_down)
11817 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011818}
11819
11820/**
11821 * hdd_update_config() - Initialize driver per module ini parameters
11822 * @hdd_ctx: HDD Context
11823 *
11824 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011825 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011827int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011828{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011829 int ret;
11830
Komal Seelamec702b02016-02-24 18:42:16 +053011831 hdd_update_ol_config(hdd_ctx);
11832 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011833 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11834 ret = hdd_update_cds_config_ftm(hdd_ctx);
11835 else
11836 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011837 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011838
11839 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011840}
11841
Mukul Sharma9d797a02017-01-05 20:26:03 +053011842#ifdef FEATURE_WLAN_RA_FILTERING
11843/**
11844 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11845 * @psoc_cfg: pmo psoc Configuration
11846 * @hdd_ctx: Pointer to hdd context
11847 *
11848 * Return: none
11849 */
11850static inline void hdd_ra_populate_pmo_config(
11851 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011852 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011853{
11854 psoc_cfg->ra_ratelimit_interval =
11855 hdd_ctx->config->RArateLimitInterval;
11856 psoc_cfg->ra_ratelimit_enable =
11857 hdd_ctx->config->IsRArateLimitEnabled;
11858}
11859#else
11860static inline void hdd_ra_populate_pmo_config(
11861 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011862 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011863{
11864}
11865#endif
11866/**
11867 * hdd_update_pmo_config - API to update pmo configuration parameters
11868 * @hdd_ctx: HDD context
11869 *
11870 * Return: void
11871 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011872static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011873{
11874 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11875 struct pmo_psoc_cfg psoc_cfg;
11876 QDF_STATUS status;
11877
11878 /*
11879 * Value of hdd_ctx->wowEnable can be,
11880 * 0 - Disable both magic pattern match and pattern byte match.
11881 * 1 - Enable magic pattern match on all interfaces.
11882 * 2 - Enable pattern byte match on all interfaces.
11883 * 3 - Enable both magic patter and pattern byte match on
11884 * all interfaces.
11885 */
11886 psoc_cfg.magic_ptrn_enable =
11887 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11888 psoc_cfg.ptrn_match_enable_all_vdev =
11889 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11890 psoc_cfg.bpf_enable =
11891 hdd_ctx->config->bpf_packet_filter_enable;
11892 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011893 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011894 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11895 if (hdd_ctx->config->fhostNSOffload)
11896 psoc_cfg.ns_offload_enable_dynamic = true;
11897 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11898 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11899 psoc_cfg.active_mode_offload =
11900 hdd_ctx->config->active_mode_offload;
11901 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11902 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011903 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11904 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11905 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11906 psoc_cfg.power_save_mode =
11907 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011908 psoc_cfg.auto_power_save_fail_mode =
11909 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011910
11911 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011912 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11913 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011914 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11915 if (status != QDF_STATUS_SUCCESS) {
11916 hdd_err("failed pmo psoc configuration");
11917 return -EINVAL;
11918 }
11919
11920 return 0;
11921}
11922
Abhishek Singhb20db962017-03-03 21:28:46 +053011923#ifdef FEATURE_WLAN_SCAN_PNO
11924static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11925 struct hdd_config *cfg)
11926{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011927 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
11928
Abhishek Singhb20db962017-03-03 21:28:46 +053011929 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11930 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11931 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11932 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11933 pno_cfg->channel_prediction_full_scan =
11934 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011935 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
11936 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
11937 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
11938 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053011939}
11940#else
11941static inline void
11942hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11943 struct hdd_config *cfg)
11944{
11945 return;
11946}
11947#endif
11948
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011949void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11950 struct hdd_config *cfg)
11951{
11952 uint8_t i = 0;
11953
11954 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11955 if (!ie_whitelist->white_list)
11956 return;
11957
11958 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11959 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11960 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11961 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11962 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11963 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11964 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11965 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11966
11967 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11968 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11969 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11970}
11971
Abhishek Singh257a9482017-03-06 16:52:39 +053011972/**
11973 * hdd_update_scan_config - API to update scan configuration parameters
11974 * @hdd_ctx: HDD context
11975 *
11976 * Return: 0 if success else err
11977 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011978static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011979{
11980 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11981 struct scan_user_cfg scan_cfg;
11982 struct hdd_config *cfg = hdd_ctx->config;
11983 QDF_STATUS status;
11984
11985 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11986 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11987 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11988 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11989 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11990 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11991 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011992 /* convert to ms */
11993 scan_cfg.scan_cache_aging_time =
11994 cfg->scanAgingTimeout * 1000;
11995 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11996 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11997 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11998 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011999 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012000 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053012001
Abhishek Singhb20db962017-03-03 21:28:46 +053012002 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012003 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012004
Abhishek Singh257a9482017-03-06 16:52:39 +053012005 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12006 if (status != QDF_STATUS_SUCCESS) {
12007 hdd_err("failed pmo psoc configuration");
12008 return -EINVAL;
12009 }
12010
12011 return 0;
12012}
Abhishek Singh257a9482017-03-06 16:52:39 +053012013
Frank Liud4b2fa02017-03-29 11:46:48 +080012014#ifdef CONVERGED_TDLS_ENABLE
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012015static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012016{
12017 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12018 struct tdls_start_params tdls_cfg;
12019 struct tdls_user_config *config = &tdls_cfg.config;
12020 struct hdd_config *cfg = hdd_ctx->config;
12021 QDF_STATUS status;
12022
12023 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
12024 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
12025 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
12026 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
12027 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
12028 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
12029 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
12030 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
12031 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
12032 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
12033 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
12034 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
12035 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
12036 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
12037 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
12038 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
12039 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
12040 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
12041 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
12042 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
12043 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
12044 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
12045 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
12046 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
12047 (cfg->fEnableTDLSImplicitTrigger ?
12048 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
12049 (cfg->fTDLSExternalControl ?
12050 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
12051
12052 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
12053 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
12054 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
12055 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012056 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012057 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080012058 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
12059 tdls_cfg.tdls_evt_cb_data = psoc;
12060 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
12061 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
12062 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070012063 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
12064 tdls_cfg.tdls_wmm_cb_data = psoc;
12065 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
12066 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012067 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080012068
12069 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12070 if (status != QDF_STATUS_SUCCESS) {
12071 hdd_err("failed pmo psoc configuration");
12072 return -EINVAL;
12073 }
12074
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012075 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannanc0e3d582017-09-13 00:26:33 -070012076 /* enable napier specific tdls data path */
12077 hdd_ctx->tdls_nap_active = true;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012078
Frank Liud4b2fa02017-03-29 11:46:48 +080012079 return 0;
12080}
12081#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012082static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012083{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012084 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012085 /* disable napier specific tdls data path */
12086 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080012087 return 0;
12088}
12089#endif
12090
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012091int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012092{
12093 int ret;
12094
12095 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012096 if (ret)
12097 return ret;
12098 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012099 if (ret)
12100 return ret;
12101 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012102
12103 return ret;
12104}
12105
Agrawal Ashish65634612016-08-18 13:24:32 +053012106/**
12107 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12108 * @mode : cfg80211 DFS mode
12109 *
12110 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12111 */
12112enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12113{
12114 switch (mode) {
12115 case DFS_MODE_ENABLE:
12116 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012117 case DFS_MODE_DISABLE:
12118 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012119 case DFS_MODE_DEPRIORITIZE:
12120 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012121 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012122 hdd_debug("ACS dfs mode is NONE");
12123 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012124 }
12125}
12126
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012127/**
12128 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12129 * @hddctx: pointer to hdd context
12130 * @set_value: enable/disable
12131 *
12132 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12133 * Host(even though it is duplicate). When Host send vendor command
12134 * disable,FW doesn't perform any action. Whenever any change in
12135 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12136 *
12137 * return - 0 on success, appropriate error values on failure.
12138 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012139int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012140{
12141 QDF_STATUS status;
12142
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012143 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012144 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012145
12146 if (!hddctx->config->goptimize_chan_avoid_event) {
12147 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12148 return -EINVAL;
12149 }
12150
12151 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12152 if (!QDF_IS_STATUS_SUCCESS(status)) {
12153 hdd_err("Failed to send chan avoid command to SME");
12154 return -EINVAL;
12155 }
12156 return 0;
12157}
Agrawal Ashish65634612016-08-18 13:24:32 +053012158
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012159/**
12160 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12161 * @value: value to set
12162 *
12163 * This function will set the passed value to roaming in progress flag.
12164 *
12165 * Return: None
12166 */
12167void hdd_set_roaming_in_progress(bool value)
12168{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012169 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012170
12171 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12172 if (!hdd_ctx) {
12173 hdd_err("HDD context is NULL");
12174 return;
12175 }
12176
12177 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012178 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012179}
12180
12181/**
12182 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012183 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012184 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012185 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012186 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012187bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012188{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012189 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012190 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012191
12192 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12193 if (!hdd_ctx) {
12194 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012195 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012196 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012197 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12198 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012199 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12200 hdd_ctx->roaming_in_progress);
12201
12202 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012203}
12204
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012205/**
12206 * hdd_is_connection_in_progress() - check if connection is in
12207 * progress
12208 * @session_id: session id
12209 * @reason: scan reject reason
12210 *
12211 * Go through each adapter and check if Connection is in progress
12212 *
12213 * Return: true if connection is in progress else false
12214 */
12215bool hdd_is_connection_in_progress(uint8_t *session_id,
12216 enum scan_reject_states *reason)
12217{
12218 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012219 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012220 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012221 QDF_STATUS status = 0;
12222 uint8_t sta_id = 0;
12223 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012224 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012225
12226 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12227 if (!hdd_ctx) {
12228 hdd_err("HDD context is NULL");
12229 return false;
12230 }
12231
12232 if (true == hdd_ctx->btCoexModeSet) {
12233 hdd_info("BTCoex Mode operation in progress");
12234 return true;
12235 }
12236 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12237 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
12238 adapter = adapter_node->pAdapter;
12239 if (!adapter)
12240 goto end;
12241
12242 hdd_info("Adapter with device mode %s(%d) exists",
12243 hdd_device_mode_to_string(adapter->device_mode),
12244 adapter->device_mode);
12245 if (((QDF_STA_MODE == adapter->device_mode)
12246 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12247 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12248 && (eConnectionState_Connecting ==
12249 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12250 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012251 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012252 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12253 adapter->sessionId);
12254 if (session_id && reason) {
12255 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012256 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012257 }
12258 return true;
12259 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012260 /*
12261 * sme_neighbor_middle_of_roaming is for LFR2
12262 * hdd_is_roaming_in_progress is for LFR3
12263 */
12264 if (((QDF_STA_MODE == adapter->device_mode) &&
12265 sme_neighbor_middle_of_roaming(
12266 WLAN_HDD_GET_HAL_CTX(adapter),
12267 adapter->sessionId)) ||
12268 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012269 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012270 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12271 adapter->sessionId);
12272 if (session_id && reason) {
12273 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012274 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012275 }
12276 return true;
12277 }
12278 if ((QDF_STA_MODE == adapter->device_mode) ||
12279 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12280 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12281 hdd_sta_ctx =
12282 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12283 if ((eConnectionState_Associated ==
12284 hdd_sta_ctx->conn_info.connState)
12285 && (false ==
12286 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12287 sta_mac = (uint8_t *)
12288 &(adapter->macAddressCurrent.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012289 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012290 " is in middle of WPS/EAPOL exchange.",
12291 MAC_ADDR_ARRAY(sta_mac));
12292 if (session_id && reason) {
12293 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012294 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012295 }
12296 return true;
12297 }
12298 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12299 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12300 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12301 sta_id++) {
12302 if (!((adapter->aStaInfo[sta_id].isUsed)
12303 && (OL_TXRX_PEER_STATE_CONN ==
12304 adapter->aStaInfo[sta_id].tlSTAState)))
12305 continue;
12306
12307 sta_mac = (uint8_t *)
12308 &(adapter->aStaInfo[sta_id].
12309 macAddrSTA.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012310 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012311 " of SAP/GO is in middle of WPS/EAPOL exchange",
12312 MAC_ADDR_ARRAY(sta_mac));
12313 if (session_id && reason) {
12314 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012315 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012316 }
12317 return true;
12318 }
12319 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012320 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012321 return true;
12322 }
12323 }
12324end:
12325 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12326 adapter_node = next;
12327 }
12328 return false;
12329}
12330
12331/**
12332 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012333 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012334 *
12335 * Return: None
12336 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012337void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012338{
Jeff Johnson87251032017-08-29 13:31:11 -070012339 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012340 hdd_hostapd_state_t *hostapd_state;
12341 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012342 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012343 tsap_Config_t *sap_config;
12344 void *sap_ctx;
12345
12346 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12347 sap_config = &hdd_ap_ctx->sapConfig;
12348 sap_ctx = hdd_ap_ctx->sapContext;
12349
12350 mutex_lock(&hdd_ctx->sap_lock);
12351 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12352 wlan_hdd_del_station(ap_adapter);
12353 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12354 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12355 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12356 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12357 qdf_status =
12358 qdf_wait_single_event(&hostapd_state->
12359 qdf_stop_bss_event,
12360 SME_CMD_TIMEOUT_VALUE);
12361
12362 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12363 cds_err("SAP Stop Failed");
12364 goto end;
12365 }
12366 }
12367 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012368 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012369 ap_adapter->device_mode, ap_adapter->sessionId);
12370 cds_err("SAP Stop Success");
12371
12372 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12373 cds_err("SAP Not able to set AP IEs");
12374 wlansap_reset_sap_config_add_ie(sap_config,
12375 eUPDATE_IE_ALL);
12376 goto end;
12377 }
12378
12379 qdf_event_reset(&hostapd_state->qdf_event);
12380 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12381 sap_config,
12382 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12383 cds_err("SAP Start Bss fail");
12384 wlansap_reset_sap_config_add_ie(sap_config,
12385 eUPDATE_IE_ALL);
12386 goto end;
12387 }
12388
12389 cds_info("Waiting for SAP to start");
12390 qdf_status =
12391 qdf_wait_single_event(&hostapd_state->qdf_event,
12392 SME_CMD_TIMEOUT_VALUE);
12393 wlansap_reset_sap_config_add_ie(sap_config,
12394 eUPDATE_IE_ALL);
12395 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12396 cds_err("SAP Start failed");
12397 goto end;
12398 }
12399 cds_err("SAP Start Success");
12400 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12401 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012402 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12403 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012404 ap_adapter->sessionId);
12405 hostapd_state->bCommit = true;
12406 }
12407end:
12408 mutex_unlock(&hdd_ctx->sap_lock);
12409 return;
12410}
12411
12412/**
12413 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12414 * with non dfs acs
12415 *
12416 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12417 *
12418 * Return: None
12419 */
12420void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12421{
Jeff Johnson9d295242017-08-29 14:39:48 -070012422 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012423 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012424 cds_context_type *cds_ctx;
12425
12426 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12427 if (!hdd_ctx) {
12428 cds_err("HDD context is NULL");
12429 return;
12430 }
12431
12432 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12433 if (!cds_ctx) {
12434 cds_err("Invalid CDS Context");
12435 return;
12436 }
12437
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012438 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12439 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012440 cds_info("Concurrency mode is not SAP");
12441 return;
12442 }
12443
12444 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012445 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12446 &ap_adapter->event_flags) &&
12447 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12448 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012449
12450 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12451 ap_adapter->sessionCtx.ap.sapConfig.channel =
12452 AUTO_CHANNEL_SELECT;
12453 ap_adapter->sessionCtx.ap.sapConfig.
12454 acs_cfg.acs_mode = true;
12455
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012456 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012457 }
12458}
12459
12460/**
12461 * hdd_set_connection_in_progress() - to set the connection in
12462 * progress flag
12463 * @value: value to set
12464 *
12465 * This function will set the passed value to connection in progress flag.
12466 * If value is previously being set to true then no need to set it again.
12467 *
12468 * Return: true if value is being set correctly and false otherwise.
12469 */
12470bool hdd_set_connection_in_progress(bool value)
12471{
12472 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012473 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012474
12475 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12476 if (!hdd_ctx) {
12477 cds_err("HDD context is NULL");
12478 return false;
12479 }
12480
12481 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12482 /*
12483 * if the value is set to true previously and if someone is
12484 * trying to make it true again then it could be some race
12485 * condition being triggered. Avoid this situation by returning
12486 * false
12487 */
12488 if (hdd_ctx->connection_in_progress && value)
12489 status = false;
12490 else
12491 hdd_ctx->connection_in_progress = value;
12492 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12493 return status;
12494}
12495
Jeff Johnson9d295242017-08-29 14:39:48 -070012496int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012497{
12498 if (!adapter) {
12499 hdd_err("Invalid adapter");
12500 return -EINVAL;
12501 }
12502 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012503 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012504 WMA_VDEV_MCC_SET_TIME_QUOTA,
12505 set_value, VDEV_CMD);
12506 return 0;
12507
12508}
12509
Jeff Johnson9d295242017-08-29 14:39:48 -070012510int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012511{
12512 if (!adapter) {
12513 hdd_err("Invalid adapter");
12514 return -EINVAL;
12515 }
12516
12517 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012518 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012519 WMA_VDEV_MCC_SET_TIME_LATENCY,
12520 set_value, VDEV_CMD);
12521 return 0;
12522}
12523
Jeff Johnson9d295242017-08-29 14:39:48 -070012524struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012525 *psoc, uint8_t vdev_id)
12526{
Jeff Johnson9d295242017-08-29 14:39:48 -070012527 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012528 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012529
12530 /*
12531 * Currently PSOC is not being used. But this logic will
12532 * change once we have the converged implementation of
12533 * HDD context per PSOC in place. This would break if
12534 * multiple vdev objects reuse the vdev id.
12535 */
12536 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12537 if (!adapter)
12538 hdd_err("Get adapter by vdev id failed");
12539
12540 return adapter;
12541}
12542
Jeff Johnson9d295242017-08-29 14:39:48 -070012543int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012544 int8_t *rssi, int8_t *snr)
12545{
12546 QDF_STATUS status;
12547 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12548 tCsrRoamProfile *profile = &wext_state->roamProfile;
12549
12550 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12551 profile, bssid, rssi, snr);
12552 if (QDF_STATUS_SUCCESS != status) {
12553 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12554 return -EINVAL;
12555 }
12556
12557 return 0;
12558}
12559
Ganesh Kondabattini35739572017-06-21 16:26:39 +053012560/**
12561 * hdd_send_limit_off_chan_cmd() - send limit off-channel command parameters
12562 * @param - pointer to sir_limit_off_chan
12563 *
12564 * Return: 0 on success and non zero value on failure
12565 */
12566static int hdd_send_limit_off_chan_cmd(struct sir_limit_off_chan *param)
12567{
12568 struct scheduler_msg msg = {0};
12569
12570 msg.type = WMA_SET_LIMIT_OFF_CHAN;
12571 msg.reserved = 0;
12572 msg.bodyptr = param;
12573
12574 if (!QDF_IS_STATUS_SUCCESS(scheduler_post_msg(QDF_MODULE_ID_WMA,
12575 &msg))) {
12576 QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_ERROR,
12577 FL("Not able to post WMA_SET_LIMIT_OFF_CHAN to WMA"));
12578 return QDF_STATUS_E_FAILURE;
12579 }
12580
12581 return 0;
12582}
12583
12584/**
12585 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
12586 * @adapter - HDD adapter
12587 * @tos - type of service
12588 * @status - status of the traffic
12589 *
12590 * Return: 0 on success and non zero value on failure
12591 */
12592
12593int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
12594 bool is_tos_active)
12595{
12596 int ac_bit;
12597 struct sir_limit_off_chan *cmd;
12598 struct hdd_context *hdd_ctx;
12599 int ret;
12600
12601 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
12602 ret = wlan_hdd_validate_context(hdd_ctx);
12603
12604 if (ret < 0) {
12605 hdd_err("failed to set limit off chan params");
12606 return ret;
12607 }
12608
12609 cmd = qdf_mem_malloc(sizeof(struct sir_limit_off_chan));
12610 if (!cmd) {
12611 hdd_err("qdf_mem_malloc failed for limit off channel");
12612 return -ENOMEM;
12613 }
12614
12615 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
12616
12617 if (is_tos_active)
12618 hdd_ctx->active_ac |= ac_bit;
12619 else
12620 hdd_ctx->active_ac &= ~ac_bit;
12621
12622 if (hdd_ctx->active_ac) {
12623 if (hdd_ctx->active_ac & HDD_AC_VO_BIT) {
12624 cmd->max_off_chan_time =
12625 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
12626 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12627 PM_LATENCY);
12628 } else if (hdd_ctx->active_ac & HDD_AC_VI_BIT) {
12629 cmd->max_off_chan_time =
12630 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
12631 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12632 PM_LATENCY);
12633 } else {
12634 /*ignore this command if only BE/BK is active */
12635 is_tos_active = false;
12636 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12637 hdd_ctx->config->conc_system_pref);
12638 }
12639 } else {
12640 /* No active tos */
12641 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
12642 hdd_ctx->config->conc_system_pref);
12643 }
12644
12645 cmd->vdev_id = adapter->sessionId;
12646 cmd->is_tos_active = is_tos_active;
12647 cmd->rest_time = hdd_ctx->config->nRestTimeConc;
12648 cmd->skip_dfs_chans = true;
12649
12650 ret = hdd_send_limit_off_chan_cmd(cmd);
12651 if (ret)
12652 qdf_mem_free(cmd);
12653
12654 return ret;
12655}
12656
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012657/* Register the module init/exit functions */
12658module_init(hdd_module_init);
12659module_exit(hdd_module_exit);
12660
12661MODULE_LICENSE("Dual BSD/GPL");
12662MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12663MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012665module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12666 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012667
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012668module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12669 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12670
Ravi Joshia307f632017-07-17 23:41:41 -070012671module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12672 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012674module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12675 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12676
12677module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12678
12679module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12680
12681module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);