blob: b27798f733cdf22cde2630ac4e2079e83628dc9b [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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530259struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260
261struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700263static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800264#endif
265
Sachin Ahujadddd2632017-03-07 19:07:24 +0530266void hdd_start_complete(int ret)
267{
268 wlan_start_ret_val = ret;
269
270 complete(&wlan_start_comp);
271}
272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530274 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700275 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530276 *
277 * Return: none
278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700279static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530280{
Jeff Johnson9d295242017-08-29 14:39:48 -0700281 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530282 hdd_adapter_list_node_t *adapter_node, *next;
283 QDF_STATUS status = QDF_STATUS_SUCCESS;
284
285 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
286 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
287 adapter = adapter_node->pAdapter;
288 if (NULL != adapter)
289 hdd_send_rps_ind(adapter);
290 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
291 adapter_node = next;
292 }
293}
294
295/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
297 * @vdev_id: vdev_id
298 * @action: action type
299 * @reason: reason type
300 *
301 * Return: none
302 */
303void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
304 enum netif_action_type action, enum netif_reason_type reason)
305{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700306 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700307 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800308
309 if (!hdd_ctx) {
310 hdd_err("hdd ctx is NULL");
311 return;
312 }
313 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
314
315 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800316}
317
318/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700319 * Store WLAN driver version and timestamp info in global variables such that
320 * crash debugger can extract them from driver debug symbol and crashdump for
321 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 */
323uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700324
325#ifndef BUILD_TIMESTAMP
326#define BUILD_TIMESTAMP ""
327#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700328uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329
330/**
331 * hdd_device_mode_to_string() - return string conversion of device mode
332 * @device_mode: device mode
333 *
334 * This utility function helps log string conversion of device mode.
335 *
336 * Return: string conversion of device mode, if match found;
337 * "Unknown" otherwise.
338 */
339const char *hdd_device_mode_to_string(uint8_t device_mode)
340{
341 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800342 CASE_RETURN_STRING(QDF_STA_MODE);
343 CASE_RETURN_STRING(QDF_SAP_MODE);
344 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
345 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
346 CASE_RETURN_STRING(QDF_FTM_MODE);
347 CASE_RETURN_STRING(QDF_IBSS_MODE);
348 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
349 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700350 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351 default:
352 return "Unknown";
353 }
354}
355
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530356/**
357 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
358 * @adapter: HDD adapter
359 * @chan_number: Channel number
360 * @chan_bw: Bandwidth
361 *
362 * Checks if the given bandwidth is valid for the given channel number.
363 *
364 * Return: 0 for success, non-zero for failure
365 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700366int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530367 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800368 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530369{
370 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
371 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
372 bool found = false;
373 tHalHandle hal;
374
375 hal = WLAN_HDD_GET_HAL_CTX(adapter);
376 if (!hal) {
377 hdd_err("Invalid HAL context");
378 return -EINVAL;
379 }
380
381 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
382 hdd_err("No valid channel list");
383 return -EOPNOTSUPP;
384 }
385
386 for (i = 0; i < len; i++) {
387 if (chan[i] == chan_number) {
388 found = true;
389 break;
390 }
391 }
392
393 if (found == false) {
394 hdd_err("Channel not in driver's valid channel list");
395 return -EOPNOTSUPP;
396 }
397
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700398 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
399 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530400 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
401 return -EINVAL;
402 }
403
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700404 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530405 if (chan_bw == CH_WIDTH_80MHZ) {
406 hdd_err("BW80 not possible in 2.4GHz band");
407 return -EINVAL;
408 }
409 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
410 (chan_bw != CH_WIDTH_MAX)) {
411 hdd_err("Only BW20 possible on channel 14");
412 return -EINVAL;
413 }
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530417 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
418 (chan_bw != CH_WIDTH_MAX)) {
419 hdd_err("Only BW20 possible on channel 165");
420 return -EINVAL;
421 }
422 }
423
424 return 0;
425}
426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427static int __hdd_netdev_notifier_call(struct notifier_block *nb,
428 unsigned long state, void *data)
429{
430#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
431 struct netdev_notifier_info *dev_notif_info = data;
432 struct net_device *dev = dev_notif_info->dev;
433#else
434 struct net_device *dev = data;
435#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700436 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700437 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800438
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800439 ENTER_DEV(dev);
440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 /* Make sure that this callback corresponds to our device. */
442 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
443 return NOTIFY_DONE;
444
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530445 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700447 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 return NOTIFY_DONE;
449 }
450
451 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700452 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 return NOTIFY_DONE;
454 }
455
456 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
457 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800458 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530459 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 return NOTIFY_DONE;
461 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530462 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800463 return NOTIFY_DONE;
464
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800465 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 dev->name, state);
467
468 switch (state) {
469 case NETDEV_REGISTER:
470 break;
471
472 case NETDEV_UNREGISTER:
473 break;
474
475 case NETDEV_UP:
476 sme_ch_avoid_update_req(hdd_ctx->hHal);
477 break;
478
479 case NETDEV_DOWN:
480 break;
481
482 case NETDEV_CHANGE:
483 if (true == adapter->isLinkUpSvcNeeded)
484 complete(&adapter->linkup_event_var);
485 break;
486
487 case NETDEV_GOING_DOWN:
488 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530489 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
490 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 } else {
hqueaa33ee2017-05-04 17:56:35 +0800492 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800493 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 }
495 break;
496
497 default:
498 break;
499 }
500
501 return NOTIFY_DONE;
502}
503
504/**
505 * hdd_netdev_notifier_call() - netdev notifier callback function
506 * @nb: pointer to notifier block
507 * @state: state
508 * @ndev: ndev pointer
509 *
510 * Return: 0 on success, error number otherwise.
511 */
512static int hdd_netdev_notifier_call(struct notifier_block *nb,
513 unsigned long state,
514 void *ndev)
515{
516 int ret;
517
518 cds_ssr_protect(__func__);
519 ret = __hdd_netdev_notifier_call(nb, state, ndev);
520 cds_ssr_unprotect(__func__);
521
522 return ret;
523}
524
525struct notifier_block hdd_netdev_notifier = {
526 .notifier_call = hdd_netdev_notifier_call,
527};
528
529/* variable to hold the insmod parameters */
530static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800531
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530532static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700533int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530534
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800535/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800537
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530538/**
539 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
540 * @ch_width: NL channel width
541 *
542 * Converts the NL channel width to the driver's internal representation
543 *
544 * Return: Converted channel width. In case of non matching NL channel width,
545 * CH_WIDTH_MAX will be returned.
546 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800547enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530548{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800549 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700550
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800551 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530552 switch (ch_width) {
553 case NL80211_CHAN_WIDTH_20_NOHT:
554 case NL80211_CHAN_WIDTH_20:
555 return CH_WIDTH_20MHZ;
556 case NL80211_CHAN_WIDTH_40:
557 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530558 case NL80211_CHAN_WIDTH_80:
559 return CH_WIDTH_80MHZ;
560 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800561 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
562 return CH_WIDTH_80P80MHZ;
563 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
564 return CH_WIDTH_160MHZ;
565 else
566 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530567 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800568 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
569 return CH_WIDTH_160MHZ;
570 else
571 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530572 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800573 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530574 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800575 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530576 default:
577 hdd_err("Invalid channel width %d, setting to default",
578 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800579 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530580 }
581}
582
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530583/* wlan_hdd_find_opclass() - Find operating class for a channel
584 * @hal: handler to HAL
585 * @channel: channel id
586 * @bw_offset: bandwidth offset
587 *
588 * Function invokes sme api to find the operating class
589 *
590 * Return: operating class
591 */
592uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
593 uint8_t bw_offset)
594{
595 uint8_t opclass = 0;
596
597 sme_get_opclass(hal, channel, bw_offset, &opclass);
598 return opclass;
599}
600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530602 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530603 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604 * @bitmask: Bitmask of log levels to be enabled
605 *
606 * Called immediately after the cfg.ini is read in order to configure
607 * the desired trace levels.
608 *
609 * Return: None
610 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530611int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800612{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530613 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530614 int qdf_print_idx = -1;
615 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616 /*
617 * if the bitmask is the default value, then a bitmask was not
618 * specified in cfg.ini, so leave the logging level alone (it
619 * will remain at the "compiled in" default value)
620 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700621 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530622 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530624 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530626 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530627 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530628 QDF_TRACE_LEVEL_NONE, 0);
629
630 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530631 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800632 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530633 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800634 while (0 != bitmask) {
635 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530636 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530637 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530638 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530639 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800640 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642 level++;
643 bitmask >>= 1;
644 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530645 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800646}
647
648/**
Chris Guo1751acf2017-07-03 14:09:01 +0800649 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
650 * @hdd_ctx: HDD context pointer
651 *
652 * Return: 0 if the context is valid. Error code otherwise
653 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700654int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800655{
656 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
657 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
658 return -ENODEV;
659 }
660
661 if (cds_is_driver_recovering()) {
662 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
663 (void *)_RET_IP_, cds_get_driver_state());
664 return -EAGAIN;
665 }
666
667 if (hdd_ctx->start_modules_in_progress ||
668 hdd_ctx->stop_modules_in_progress) {
669 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
670 (void *)_RET_IP_);
671 return -EAGAIN;
672 }
673
674 return 0;
675}
676
677
678/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679 * wlan_hdd_validate_context() - check the HDD context
680 * @hdd_ctx: HDD context pointer
681 *
682 * Return: 0 if the context is valid. Error code otherwise
683 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700684int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530687 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688 return -ENODEV;
689 }
690
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800691 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800692 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530693 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694 return -EAGAIN;
695 }
696
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700697 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530699
700 if (hdd_ctx->start_modules_in_progress ||
701 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800702 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530703 (void *)_RET_IP_);
704 return -EAGAIN;
705 }
706
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530707 if (cds_is_driver_in_bad_state()) {
708 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
709 (void *)_RET_IP_, cds_get_driver_state());
710 return -ENODEV;
711 }
712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713 return 0;
714}
715
Jeff Johnson9d295242017-08-29 14:39:48 -0700716int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700717{
718 if (!adapter) {
719 hdd_err("adapter is null");
720 return -EINVAL;
721 }
722
723 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
724 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
725 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
726 return -EINVAL;
727 }
728
729 if (!adapter->dev) {
730 hdd_err("adapter net_device is null");
731 return -EINVAL;
732 }
733
734 if (!(adapter->dev->flags & IFF_UP)) {
735 hdd_info("adapter net_device is not up");
736 return -EAGAIN;
737 }
738
739 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
740 hdd_info("adapter session is not open");
741 return -EAGAIN;
742 }
743
744 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
745 hdd_err("bad adapter session Id: %u", adapter->sessionId);
746 return -EINVAL;
747 }
748
749 return 0;
750}
751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530753 * wlan_hdd_validate_modules_state() - Check modules status
754 * @hdd_ctx: HDD context pointer
755 *
756 * Check's the driver module's state and returns true if the
757 * modules are enabled returns false if modules are closed.
758 *
759 * Return: True if modules are enabled or false.
760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700761bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530762{
763 mutex_lock(&hdd_ctx->iface_change_lock);
764 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
765 mutex_unlock(&hdd_ctx->iface_change_lock);
766 hdd_notice("Modules not enabled, Present status: %d",
767 hdd_ctx->driver_status);
768 return false;
769 }
770 mutex_unlock(&hdd_ctx->iface_change_lock);
771 return true;
772}
773
774/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700776 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 *
778 * This function sets the IBSS power save config parameters to WMA
779 * which will send it to firmware if FW supports IBSS power save
780 * before vdev start.
781 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530782 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 * on failure.
784 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700785QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800786{
787 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700788 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789
790 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700791 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530792 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 }
794
Naveen Rawat247a8682017-06-05 15:00:31 -0700795 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
797 hdd_ctx->config->ibssATIMWinSize,
798 VDEV_CMD);
799 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700800 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530801 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802 }
803
Naveen Rawat247a8682017-06-05 15:00:31 -0700804 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
806 hdd_ctx->config->isIbssPowerSaveAllowed,
807 VDEV_CMD);
808 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700809 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
810 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530811 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 }
813
Naveen Rawat247a8682017-06-05 15:00:31 -0700814 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
816 hdd_ctx->config->
817 isIbssPowerCollapseAllowed, VDEV_CMD);
818 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700819 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
820 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530821 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822 }
823
Naveen Rawat247a8682017-06-05 15:00:31 -0700824 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
826 hdd_ctx->config->isIbssAwakeOnTxRx,
827 VDEV_CMD);
828 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700829 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530830 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 }
832
Naveen Rawat247a8682017-06-05 15:00:31 -0700833 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
835 hdd_ctx->config->ibssInactivityCount,
836 VDEV_CMD);
837 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700838 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530839 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 }
841
Naveen Rawat247a8682017-06-05 15:00:31 -0700842 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
844 hdd_ctx->config->ibssTxSpEndInactivityTime,
845 VDEV_CMD);
846 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700847 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
848 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530849 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 }
851
Naveen Rawat247a8682017-06-05 15:00:31 -0700852 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
854 hdd_ctx->config->ibssPsWarmupTime,
855 VDEV_CMD);
856 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700857 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
858 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530859 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 }
861
Naveen Rawat247a8682017-06-05 15:00:31 -0700862 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
864 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
865 VDEV_CMD);
866 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700867 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
868 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530869 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 }
871
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530872 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873}
874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875#define INTF_MACADDR_MASK 0x7
876
877/**
878 * hdd_update_macaddr() - update mac address
879 * @config: hdd configuration
880 * @hw_macaddr: mac address
881 *
882 * Mac address for multiple virtual interface is found as following
883 * i) The mac address of the first interface is just the actual hw mac address.
884 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
885 * define the mac address for the remaining interfaces and locally
886 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
887 * supported virtual interfaces, right now this is 0x07 (meaning 8
888 * interface).
889 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
890 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
891 *
892 * Return: None
893 */
894void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530895 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896{
897 int8_t i;
898 uint8_t macaddr_b3, tmp_br3;
899
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530900 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530901 QDF_MAC_ADDR_SIZE);
902 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530903 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530904 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 macaddr_b3 = config->intfMacAddr[i].bytes[3];
906 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
907 INTF_MACADDR_MASK;
908 macaddr_b3 += tmp_br3;
909
910 /* XOR-ing bit-24 of the mac address. This will give enough
911 * mac address range before collision
912 */
913 macaddr_b3 ^= (1 << 7);
914
915 /* Set locally administered bit */
916 config->intfMacAddr[i].bytes[0] |= 0x02;
917 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800918 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 MAC_ADDRESS_STR, i,
920 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
921 }
922}
923
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700924static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 struct wma_tgt_services *cfg)
926{
927 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928
929 /* Set up UAPSD */
930 config->apUapsdEnabled &= cfg->uapsd;
931
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800932 /* 11AX mode support */
933 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
934 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
935 config->dot11Mode = eHDD_DOT11_MODE_11ac;
936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 /* 11AC mode support */
938 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
939 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
940 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800941
942 /* ARP offload: override user setting if invalid */
943 config->fhostArpOffload &= cfg->arp_offload;
944
945#ifdef FEATURE_WLAN_SCAN_PNO
946 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800947 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 if (cfg->pno_offload)
949 config->PnoOffload = true;
950#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951#ifdef FEATURE_WLAN_TDLS
952 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530953 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
954 cfg->en_tdls_offchan;
955 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
956 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700957 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700959 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962#ifdef WLAN_FEATURE_ROAM_OFFLOAD
963 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
964#endif
Will Huang496b36c2017-07-11 16:38:50 +0800965 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700966 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967
968}
969
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700970/**
971 * hdd_update_vdev_nss() - sets the vdev nss
972 * @hdd_ctx: HDD context
973 *
974 * Sets the Nss per vdev type based on INI
975 *
976 * Return: None
977 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700978static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700979{
980 struct hdd_config *cfg_ini = hdd_ctx->config;
981 uint8_t max_supp_nss = 1;
982
Naveen Rawat10b1c152017-01-18 11:16:06 -0800983 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700984 max_supp_nss = 2;
985
986 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
987 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
988
989 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
990 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
991}
992
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530993/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +0530994 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
995 * @hdd_ctx: HDD context
996 *
997 * Updates wiphy vhtcap fields
998 *
999 * Return: None
1000 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001001static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301002{
1003 struct ieee80211_supported_band *band_5g =
1004 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1005 uint32_t val;
1006
1007 if (!band_5g) {
1008 hdd_debug("5GHz band disabled, skipping capability population");
1009 return;
1010 }
1011
1012 val = hdd_ctx->config->txBFCsnValue;
1013 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1014
1015 val = NUM_OF_SOUNDING_DIMENSIONS;
1016 band_5g->vht_cap.cap |=
1017 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1018
1019 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1020 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1021}
1022
1023/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301024 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1025 * @hdd_ctx: HDD context
1026 *
1027 * Sets the DBS capability as per INI and firmware capability
1028 *
1029 * Return: None
1030 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001031static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301032{
1033 struct hdd_config *cfg_ini = hdd_ctx->config;
1034 uint8_t hw_dbs_capable = 0;
1035
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001036 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1037 ((cfg_ini->dual_mac_feature_disable ==
1038 ENABLE_DBS_CXN_AND_SCAN) ||
1039 (cfg_ini->dual_mac_feature_disable ==
1040 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301041 hw_dbs_capable = 1;
1042
1043 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1044}
1045
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001046static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 struct wma_tgt_ht_cap *cfg)
1048{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301049 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 uint32_t value, val32;
1051 uint16_t val16;
1052 struct hdd_config *pconfig = hdd_ctx->config;
1053 tSirMacHTCapabilityInfo *phtCapInfo;
1054 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1055 uint8_t enable_tx_stbc;
1056
1057 /* check and update RX STBC */
1058 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1059 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1060
1061 /* get the MPDU density */
1062 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1063
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301064 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001065 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 value = 0;
1067 }
1068
1069 /*
1070 * MPDU density:
1071 * override user's setting if value is larger
1072 * than the one supported by target
1073 */
1074 if (value > cfg->mpdu_density) {
1075 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1076 cfg->mpdu_density);
1077
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301078 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001079 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 }
1081
1082 /* get the HT capability info */
1083 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301084 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001085 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001086 return;
1087 }
1088 val16 = (uint16_t) val32;
1089 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1090
1091 /* Set the LDPC capability */
1092 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1093
1094 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1095 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1096
1097 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1098 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1099
1100 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1101 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1102
1103 enable_tx_stbc = pconfig->enableTxSTBC;
1104
1105 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1106 pconfig->enable2x2 = 1;
1107 } else {
1108 pconfig->enable2x2 = 0;
1109 enable_tx_stbc = 0;
1110
1111 /* 1x1 */
1112 /* Update Rx Highest Long GI data Rate */
1113 if (sme_cfg_set_int(hdd_ctx->hHal,
1114 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001115 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301116 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001117 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118 }
1119
1120 /* Update Tx Highest Long GI data Rate */
1121 if (sme_cfg_set_int
1122 (hdd_ctx->hHal,
1123 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001124 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301125 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001126 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 }
1128 }
1129 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1130 enable_tx_stbc = 0;
1131 phtCapInfo->txSTBC = enable_tx_stbc;
1132
1133 val32 = val16;
1134 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301135 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001136 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1138 value = SIZE_OF_SUPPORTED_MCS_SET;
1139 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301140 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001141 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001142
1143 if (pconfig->enable2x2) {
1144 for (value = 0; value < cfg->num_rf_chains; value++)
1145 mcs_set[value] =
1146 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1147
1148 status =
1149 sme_cfg_set_str(hdd_ctx->hHal,
1150 WNI_CFG_SUPPORTED_MCS_SET,
1151 mcs_set,
1152 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301153 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001154 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155 }
1156 }
1157#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1158}
1159
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001160static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 struct wma_tgt_vht_cap *cfg)
1162{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301163 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001164 uint32_t value = 0;
1165 struct hdd_config *pconfig = hdd_ctx->config;
1166 struct wiphy *wiphy = hdd_ctx->wiphy;
1167 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001168 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001169 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001170 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001171 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172
Dustin Brown5e06bd32016-10-04 12:49:10 -07001173 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001174 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001175 return;
1176 }
1177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 /* Get the current MPDU length */
1179 status =
1180 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1181 &value);
1182
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301183 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001184 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185 value = 0;
1186 }
1187
1188 /*
1189 * VHT max MPDU length:
1190 * override if user configured value is too high
1191 * that the target cannot support
1192 */
1193 if (value > cfg->vht_max_mpdu) {
1194 status = sme_cfg_set_int(hdd_ctx->hHal,
1195 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1196 cfg->vht_max_mpdu);
1197
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001198 if (status == QDF_STATUS_E_FAILURE)
1199 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 }
1201
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001202 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1203 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1204
1205 if (pconfig->enable2x2)
1206 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1207
1208 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1209 QDF_STATUS_E_FAILURE) {
1210 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1211 }
1212
1213 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1214 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1215 if (pconfig->enable2x2)
1216 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1217
1218 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1219 QDF_STATUS_E_FAILURE) {
1220 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1221 }
1222
1223 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1224 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1225 if (pconfig->enable2x2)
1226 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1227
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001228 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001229 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1230
1231 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1232 QDF_STATUS_E_FAILURE) {
1233 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1234 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001236 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 &value);
1238
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301239 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001240 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 value = 0;
1242 }
1243
jiad4a7a33c2017-08-08 15:32:24 +08001244 /* Set HW RX LDPC capability */
1245 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1246 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001247 status = sme_cfg_set_int(hdd_ctx->hHal,
1248 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001249 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001251 if (status == QDF_STATUS_E_FAILURE)
1252 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001253 }
1254
1255 /* Get current GI 80 value */
1256 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1257 &value);
1258
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301259 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001260 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 value = 0;
1262 }
1263
1264 /* set the Guard interval 80MHz */
1265 if (value && !cfg->vht_short_gi_80) {
1266 status = sme_cfg_set_int(hdd_ctx->hHal,
1267 WNI_CFG_VHT_SHORT_GI_80MHZ,
1268 cfg->vht_short_gi_80);
1269
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001270 if (status == QDF_STATUS_E_FAILURE)
1271 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001272 }
1273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 /* Get VHT TX STBC cap */
1275 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1276
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301277 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001278 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001279 value = 0;
1280 }
1281
1282 /* VHT TX STBC cap */
1283 if (value && !cfg->vht_tx_stbc) {
1284 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1285 cfg->vht_tx_stbc);
1286
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001287 if (status == QDF_STATUS_E_FAILURE)
1288 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001289 }
1290
1291 /* Get VHT RX STBC cap */
1292 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1293
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301294 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001295 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 value = 0;
1297 }
1298
1299 /* VHT RX STBC cap */
1300 if (value && !cfg->vht_rx_stbc) {
1301 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1302 cfg->vht_rx_stbc);
1303
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001304 if (status == QDF_STATUS_E_FAILURE)
1305 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001306 }
1307
1308 /* Get VHT SU Beamformer cap */
1309 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1310 &value);
1311
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301312 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001313 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 value = 0;
1315 }
1316
1317 /* set VHT SU Beamformer cap */
1318 if (value && !cfg->vht_su_bformer) {
1319 status = sme_cfg_set_int(hdd_ctx->hHal,
1320 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1321 cfg->vht_su_bformer);
1322
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001323 if (status == QDF_STATUS_E_FAILURE)
1324 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 }
1326
1327 /* check and update SU BEAMFORMEE capabality */
1328 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1329 pconfig->enableTxBF = cfg->vht_su_bformee;
1330
1331 status = sme_cfg_set_int(hdd_ctx->hHal,
1332 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1333 pconfig->enableTxBF);
1334
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001335 if (status == QDF_STATUS_E_FAILURE)
1336 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337
1338 /* Get VHT MU Beamformer cap */
1339 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1340 &value);
1341
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001343 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 value = 0;
1345 }
1346
1347 /* set VHT MU Beamformer cap */
1348 if (value && !cfg->vht_mu_bformer) {
1349 status = sme_cfg_set_int(hdd_ctx->hHal,
1350 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1351 cfg->vht_mu_bformer);
1352
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001353 if (status == QDF_STATUS_E_FAILURE)
1354 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355 }
1356
1357 /* Get VHT MU Beamformee cap */
1358 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1359 &value);
1360
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301361 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001362 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 value = 0;
1364 }
1365
1366 /* set VHT MU Beamformee cap */
1367 if (value && !cfg->vht_mu_bformee) {
1368 status = sme_cfg_set_int(hdd_ctx->hHal,
1369 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1370 cfg->vht_mu_bformee);
1371
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001372 if (status == QDF_STATUS_E_FAILURE)
1373 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 }
1375
1376 /* Get VHT MAX AMPDU Len exp */
1377 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1378 &value);
1379
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301380 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001381 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 value = 0;
1383 }
1384
1385 /*
1386 * VHT max AMPDU len exp:
1387 * override if user configured value is too high
1388 * that the target cannot support.
1389 * Even though Rome publish ampdu_len=7, it can
1390 * only support 4 because of some h/w bug.
1391 */
1392
1393 if (value > cfg->vht_max_ampdu_len_exp) {
1394 status = sme_cfg_set_int(hdd_ctx->hHal,
1395 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1396 cfg->vht_max_ampdu_len_exp);
1397
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001398 if (status == QDF_STATUS_E_FAILURE)
1399 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 }
1401
1402 /* Get VHT TXOP PS CAP */
1403 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1404
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301405 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001406 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 value = 0;
1408 }
1409
1410 /* set VHT TXOP PS cap */
1411 if (value && !cfg->vht_txop_ps) {
1412 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1413 cfg->vht_txop_ps);
1414
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001415 if (status == QDF_STATUS_E_FAILURE)
1416 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 }
1418
1419 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1420 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1421 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1422 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1423 else
1424 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1425
1426
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001427 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1428 status = sme_cfg_set_int(hdd_ctx->hHal,
1429 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1430 VHT_CAP_160_AND_80P80_SUPP);
1431 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001432 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 band_5g->vht_cap.cap |=
1434 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001435 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1436 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1437 status = sme_cfg_set_int(hdd_ctx->hHal,
1438 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1439 VHT_CAP_160_SUPP);
1440 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001441 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 band_5g->vht_cap.cap |=
1443 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001444 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1445 }
1446 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1447 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301448 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001449 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301450 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001451 &value);
1452 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301453 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001454 value = 0;
1455 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301456 /* set the Guard interval 160MHz */
1457 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001458 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301459 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1460 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001461
1462 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301463 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001464 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465
1466 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1467 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1468
1469 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1470 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1471 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1472 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1473
1474 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1475 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1476
1477 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1478 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1479 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1480 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1481 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1482 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1483
1484 band_5g->vht_cap.cap |=
1485 (cfg->vht_max_ampdu_len_exp <<
1486 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1487
1488 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1489 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1490 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1491 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1492 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1493 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1494 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1495 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1496
1497 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1498 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1499
1500}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001502/**
1503 * hdd_generate_macaddr_auto() - Auto-generate mac address
1504 * @hdd_ctx: Pointer to the HDD context
1505 *
1506 * Auto-generate mac address using device serial number.
1507 * Keep the first 3 bytes of OUI as before and replace
1508 * the last 3 bytes with the lower 3 bytes of serial number.
1509 *
1510 * Return: 0 for success
1511 * Non zero failure code for errors
1512 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001513static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001514{
1515 unsigned int serialno = 0;
1516 struct qdf_mac_addr mac_addr = {
1517 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1518 };
1519
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001520 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001521 if (serialno == 0)
1522 return -EINVAL;
1523
1524 serialno &= 0x00ffffff;
1525
1526 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1527 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1528 mac_addr.bytes[5] = serialno & 0xff;
1529
1530 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1531 return 0;
1532}
1533
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301534/**
1535 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1536 * configuration to cfg_ini in HDD
1537 * @hdd_ctx: Pointer to hdd_ctx
1538 * @cfg: target configuration
1539 *
1540 * Return: None
1541 */
1542#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001543static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301544 struct wma_tgt_cfg *cfg)
1545{
1546 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1547}
1548#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001549static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301550 struct wma_tgt_cfg *cfg)
1551{
1552}
1553#endif
1554
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555void hdd_update_tgt_cfg(void *context, void *param)
1556{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001557 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001558 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 struct wma_tgt_cfg *cfg = param;
1560 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001561 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301562 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301563
Yue Mae3e86ab2017-05-08 10:48:24 -07001564 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301565 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1566 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1567 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1568 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1569 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001570 /* Restore pdev to MAC/WMA contexts */
1571 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001572 } else {
1573 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1574 if (ret) {
1575 hdd_err("pdev creation fails!");
1576 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301577 } else
1578 hdd_debug("New pdev has been created with pdev_id = %u",
1579 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301580 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001581
Naveen Rawat64e477e2016-05-20 10:34:56 -07001582 if (cds_cfg) {
1583 if (hdd_ctx->config->enable_sub_20_channel_width !=
1584 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1585 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1586 cds_cfg->sub_20_channel_width =
1587 WLAN_SUB_20_CH_WIDTH_NONE;
1588 } else {
1589 cds_cfg->sub_20_channel_width =
1590 hdd_ctx->config->enable_sub_20_channel_width;
1591 }
1592 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593
1594 /* first store the INI band capability */
1595 temp_band_cap = hdd_ctx->config->nBandCapability;
1596
1597 hdd_ctx->config->nBandCapability = cfg->band_cap;
1598
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001599 /*
1600 * now overwrite the target band capability with INI
1601 * setting if INI setting is a subset
1602 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603
1604 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1605 (temp_band_cap != eCSR_BAND_ALL))
1606 hdd_ctx->config->nBandCapability = temp_band_cap;
1607 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1608 (temp_band_cap != eCSR_BAND_ALL) &&
1609 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001610 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 }
1612
Amar Singhal58b45ef2017-08-01 13:43:54 -07001613 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1614
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301615 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1617 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1618 }
1619
1620 /* This can be extended to other configurations like ht, vht cap... */
1621
Anurag Chouhanc5548422016-02-24 18:33:27 +05301622 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001624 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001626 static struct qdf_mac_addr default_mac_addr = {
1627 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1628 };
1629 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1630 &default_mac_addr)) {
1631 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1632 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1633 MAC_ADDRESS_STR,
1634 MAC_ADDR_ARRAY(hdd_ctx->config->
1635 intfMacAddr[0].bytes));
1636 } else {
1637 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1638 MAC_ADDRESS_STR,
1639 MAC_ADDR_ARRAY(hdd_ctx->config->
1640 intfMacAddr[0].bytes));
1641 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001642 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 }
1644
1645 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001646 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647
1648 hdd_ctx->max_intf_count = cfg->max_intf_count;
1649
Jeff Johnsonc875e242016-09-23 18:12:34 -07001650 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001651 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1654 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1655
1656 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1657
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001659 if (cfg->services.en_11ax) {
1660 hdd_info("11AX: 11ax is enabled - update HDD config");
1661 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1662 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001663
1664 hdd_update_vdev_nss(hdd_ctx);
1665
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301666 hdd_update_hw_dbs_capable(hdd_ctx);
1667
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001668 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001669 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001670 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001671 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001672
Nitesh Shahe50711f2017-04-26 16:30:45 +05301673 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1674 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1675 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001676 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001677 hdd_ctx->current_antenna_mode);
1678
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001679 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1680 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301681 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301682
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301683 if ((hdd_ctx->config->txBFCsnValue >
1684 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1685 !cfg->tx_bfee_8ss_enabled)
1686 hdd_ctx->config->txBFCsnValue =
1687 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1688
1689 if (sme_cfg_set_int(hdd_ctx->hHal,
1690 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1691 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1692 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1693
1694
1695 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1696 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1697 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301698
1699 /*
1700 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1701 */
1702 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301703 /*
1704 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1705 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1706 * configure the STA mode wow pattern.
1707 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301708 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301709 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301710
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301711 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1712
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001713 /* Configure NAN datapath features */
1714 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001715 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716}
1717
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001718bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07001721 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301722 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001723 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724
Arif Hussaincd151632017-02-11 16:57:19 -08001725 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001726 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001727 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301728 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001729 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730
Arif Hussaincd151632017-02-11 16:57:19 -08001731 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1732 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1733 adapter = adapterNode->pAdapter;
1734 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1735
1736 if ((QDF_SAP_MODE == adapter->device_mode ||
1737 QDF_P2P_GO_MODE == adapter->device_mode) &&
1738 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1739 ap_ctx->operatingChannel))) {
1740 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1741 true;
1742 hdd_info("tx blocked for session: %d",
1743 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301744 }
Arif Hussaincd151632017-02-11 16:57:19 -08001745 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1746 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301748
1749 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751
1752/**
1753 * hdd_is_valid_mac_address() - validate MAC address
1754 * @pMacAddr: Pointer to the input MAC address
1755 *
1756 * This function validates whether the given MAC address is valid or not
1757 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1758 * where X is the hexa decimal digit character and separated by ':'
1759 * This algorithm works even if MAC address is not separated by ':'
1760 *
1761 * This code checks given input string mac contains exactly 12 hexadecimal
1762 * digits and a separator colon : appears in the input string only after
1763 * an even number of hex digits.
1764 *
1765 * Return: 1 for valid and 0 for invalid
1766 */
1767bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1768{
1769 int xdigit = 0;
1770 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 while (*pMacAddr) {
1773 if (isxdigit(*pMacAddr)) {
1774 xdigit++;
1775 } else if (':' == *pMacAddr) {
1776 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1777 break;
1778
1779 ++separator;
1780 } else {
1781 /* Invalid MAC found */
1782 return 0;
1783 }
1784 ++pMacAddr;
1785 }
1786 return xdigit == 12 && (separator == 5 || separator == 0);
1787}
1788
1789/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301790 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1791 * @dev: Handle to struct net_device to be updated.
1792 *
1793 * Return: None
1794 */
1795static void hdd_mon_mode_ether_setup(struct net_device *dev)
1796{
1797 dev->header_ops = NULL;
1798 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1799 dev->hard_header_len = ETH_HLEN;
1800 dev->mtu = ETH_DATA_LEN;
1801 dev->addr_len = ETH_ALEN;
1802 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1803 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1804 dev->priv_flags |= IFF_TX_SKB_SHARING;
1805
1806 memset(dev->broadcast, 0xFF, ETH_ALEN);
1807}
1808
1809/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001810 * __hdd__mon_open() - HDD Open function
1811 * @dev: Pointer to net_device structure
1812 *
1813 * This is called in response to ifconfig up
1814 *
1815 * Return: 0 for success; non-zero for failure
1816 */
1817static int __hdd_mon_open(struct net_device *dev)
1818{
1819 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07001820 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1821 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001822
1823 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001824
1825 ret = wlan_hdd_validate_context(hdd_ctx);
1826 if (ret)
1827 return ret;
1828
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301829 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07001830
1831 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
1832 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
1833 if (ret) {
1834 hdd_err("Failed to start WLAN modules return");
1835 return ret;
1836 }
1837 hdd_err("hdd_wlan_start_modules() successful !");
1838
1839 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
1840 ret = hdd_start_adapter(adapter);
1841 if (ret) {
1842 hdd_err("Failed to start adapter :%d",
1843 adapter->device_mode);
1844 return ret;
1845 }
1846 hdd_err("hdd_start_adapters() successful !");
1847 }
1848 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
1849 }
1850
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001851 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001852
1853 if (!ret)
1854 ret = hdd_enable_monitor_mode(dev);
1855
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001856 return ret;
1857}
1858
1859/**
1860 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1861 * @dev: Pointer to net_device structure
1862 *
1863 * This is called in response to ifconfig up
1864 *
1865 * Return: 0 for success; non-zero for failure
1866 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001867static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001868{
1869 int ret;
1870
1871 cds_ssr_protect(__func__);
1872 ret = __hdd_mon_open(dev);
1873 cds_ssr_unprotect(__func__);
1874
1875 return ret;
1876}
1877
1878/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301879 * hdd_start_adapter() - Wrapper function for device specific adapter
1880 * @adapter: pointer to HDD adapter
1881 *
1882 * This function is called to start the device specific adapter for
1883 * the mode passed in the adapter's device_mode.
1884 *
1885 * Return: 0 for success; non-zero for failure
1886 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001887int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301888{
1889
1890 int ret;
1891 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1892
1893 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001894 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301895
1896 switch (device_mode) {
1897 case QDF_P2P_CLIENT_MODE:
1898 case QDF_P2P_DEVICE_MODE:
1899 case QDF_OCB_MODE:
1900 case QDF_STA_MODE:
1901 case QDF_MONITOR_MODE:
1902 ret = hdd_start_station_adapter(adapter);
1903 if (ret)
1904 goto err_start_adapter;
1905 break;
1906 case QDF_P2P_GO_MODE:
1907 case QDF_SAP_MODE:
1908 ret = hdd_start_ap_adapter(adapter);
1909 if (ret)
1910 goto err_start_adapter;
1911 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301912 case QDF_IBSS_MODE:
1913 /*
1914 * For IBSS interface is initialized as part of
1915 * hdd_init_station_mode()
1916 */
1917 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301918 case QDF_FTM_MODE:
1919 ret = hdd_start_ftm_adapter(adapter);
1920 if (ret)
1921 goto err_start_adapter;
1922 break;
1923 default:
1924 hdd_err("Invalid session type %d", device_mode);
1925 QDF_ASSERT(0);
1926 goto err_start_adapter;
1927 }
1928 if (hdd_set_fw_params(adapter))
1929 hdd_err("Failed to set the FW params for the adapter!");
1930
1931 /*
1932 * Action frame registered in one adapter which will
1933 * applicable to all interfaces
1934 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301935 ret = wlan_hdd_cfg80211_register_frames(adapter);
1936 if (ret < 0) {
1937 hdd_err("Failed to register frames - ret %d", ret);
1938 goto err_start_adapter;
1939 }
1940
Arun Khandavallifae92942016-08-01 13:31:08 +05301941 EXIT();
1942 return 0;
1943err_start_adapter:
1944 return -EINVAL;
1945}
1946
1947/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301948 * hdd_enable_power_management() - API to Enable Power Management
1949 *
1950 * API invokes Bus Interface Layer power management functionality
1951 *
1952 * Return: None
1953 */
1954static void hdd_enable_power_management(void)
1955{
1956 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1957
1958 if (!hif_ctx) {
1959 hdd_err("Bus Interface Context is Invalid");
1960 return;
1961 }
1962
1963 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1964}
1965
1966/**
1967 * hdd_disable_power_management() - API to disable Power Management
1968 *
1969 * API disable Bus Interface Layer Power management functionality
1970 *
1971 * Return: None
1972 */
1973static void hdd_disable_power_management(void)
1974{
1975 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1976
1977 if (!hif_ctx) {
1978 hdd_err("Bus Interface Context is Invalid");
1979 return;
1980 }
1981
1982 hif_disable_power_management(hif_ctx);
1983}
1984
1985/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301986 * hdd_update_hw_sw_info() - API to update the HW/SW information
1987 *
1988 * API to update the HW and SW information in the driver
1989 *
1990 * Return: None
1991 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001992static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301993{
1994 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07001995 size_t target_hw_name_len;
1996 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301997
1998 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1999 if (!hif_sc) {
2000 hdd_err("HIF context is NULL");
2001 return;
2002 }
2003
2004 /*
2005 * target hw version/revision would only be retrieved after firmware
2006 * download
2007 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002008 hif_get_hw_info(hif_sc,
2009 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302010 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002011 &target_hw_name);
2012
2013 if (hdd_ctx->target_hw_name)
2014 qdf_mem_free(hdd_ctx->target_hw_name);
2015
2016 target_hw_name_len = strlen(target_hw_name) + 1;
2017 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2018 if (hdd_ctx->target_hw_name)
2019 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2020 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302021
2022 /* Get the wlan hw/fw version */
2023 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302024}
2025
2026/**
gbian62edd7e2017-03-07 13:12:13 +08002027 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2028 * @hdd_ctx: Pointer to hdd context
2029 *
2030 * Return: none
2031 */
2032static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002033hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002034{
2035 uint8_t num_entries = 0;
2036 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2037 uint8_t *tx_sched_wrr_ac;
2038 int i;
2039 cds_context_type *cds_ctx;
2040
2041 if (NULL == hdd_ctx)
2042 return;
2043
2044 if (NULL == hdd_ctx->config) {
2045 /* Do nothing if hdd_ctx is invalid */
2046 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2047 return;
2048 }
2049
2050 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2051
2052 if (!cds_ctx) {
2053 hdd_err("Invalid CDS Context");
2054 return;
2055 }
2056
2057 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2058 switch (i) {
2059 case OL_TX_WMM_AC_BE:
2060 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2061 break;
2062 case OL_TX_WMM_AC_BK:
2063 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2064 break;
2065 case OL_TX_WMM_AC_VI:
2066 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2067 break;
2068 case OL_TX_WMM_AC_VO:
2069 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2070 break;
2071 default:
2072 tx_sched_wrr_ac = NULL;
2073 break;
2074 }
2075
2076 hdd_string_to_u8_array(tx_sched_wrr_ac,
2077 tx_sched_wrr_param,
2078 &num_entries,
2079 sizeof(tx_sched_wrr_param));
2080
2081 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2082 cds_ctx->ac_specs[i].wrr_skip_weight =
2083 tx_sched_wrr_param[0];
2084 cds_ctx->ac_specs[i].credit_threshold =
2085 tx_sched_wrr_param[1];
2086 cds_ctx->ac_specs[i].send_limit =
2087 tx_sched_wrr_param[2];
2088 cds_ctx->ac_specs[i].credit_reserve =
2089 tx_sched_wrr_param[3];
2090 cds_ctx->ac_specs[i].discard_weight =
2091 tx_sched_wrr_param[4];
2092 }
2093
2094 num_entries = 0;
2095 }
2096}
2097
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002098#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002099static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2100 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2101{
Jeff Johnson9d295242017-08-29 14:39:48 -07002102 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002103 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002104
2105 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2106 if (!adapter) {
2107 hdd_err("Adapter is NULL");
2108 return PM_MAX_NUM_OF_MODE;
2109 }
2110
2111 return policy_mgr_convert_device_mode_to_qdf_type(
2112 adapter->device_mode);
2113}
2114
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002115static void hdd_register_policy_manager_callback(
2116 struct wlan_objmgr_psoc *psoc)
2117{
2118 struct policy_mgr_hdd_cbacks hdd_cbacks;
2119 hdd_cbacks.sap_restart_chan_switch_cb =
2120 sap_restart_chan_switch_cb;
2121 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2122 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002123 hdd_cbacks.get_mode_for_non_connected_vdev =
2124 wlan_hdd_get_mode_for_non_connected_vdev;
2125
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002126 if (QDF_STATUS_SUCCESS !=
2127 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2128 hdd_err("HDD callback registration with policy manager failed");
2129 }
2130}
2131#else
2132static void hdd_register_policy_manager_callback(
2133 struct wlan_objmgr_psoc *psoc)
2134{
2135}
2136#endif
2137
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002138#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002139static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002140{
2141 struct nan_callbacks cb_obj = {0};
2142
2143 cb_obj.ndi_open = hdd_ndi_open;
2144 cb_obj.ndi_close = hdd_ndi_close;
2145 cb_obj.ndi_start = hdd_ndi_start;
2146 cb_obj.ndi_delete = hdd_ndi_delete;
2147 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2148 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2149
Naveen Rawat37f62c82017-03-26 22:24:43 -07002150 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2151 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002152 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002153
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002154 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2155}
2156#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002157static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002158{
2159}
2160#endif
2161
gbian62edd7e2017-03-07 13:12:13 +08002162/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302163 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2164 * @hdd_ctx: HDD context
2165 * @adapter: HDD adapter
2166 * @reinit: flag to indicate from SSR or normal path
2167 *
2168 * This function maintains the driver state machine it will be invoked from
2169 * startup, reinit and change interface. Depending on the driver state shall
2170 * perform the opening of the modules.
2171 *
2172 * Return: 0 for success; non-zero for failure
2173 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002174int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302175 bool reinit)
2176{
2177 int ret;
2178 qdf_device_t qdf_dev;
2179 QDF_STATUS status;
2180 p_cds_contextType p_cds_context;
2181 bool unint = false;
2182 void *hif_ctx;
2183
2184 ENTER();
2185
2186 p_cds_context = cds_get_global_context();
2187 if (!p_cds_context) {
2188 hdd_err("Global Context is NULL");
2189 QDF_ASSERT(0);
2190 return -EINVAL;
2191 }
2192
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002193 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302194 hdd_ctx->driver_status, reinit);
2195
2196 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2197 if (!qdf_dev) {
2198 hdd_err("QDF Device Context is Invalid return");
2199 return -EINVAL;
2200 }
2201
2202 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302203 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302204
2205 if (QDF_TIMER_STATE_RUNNING ==
2206 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2207
2208 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002209 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302210 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2211 }
2212
2213 switch (hdd_ctx->driver_status) {
2214 case DRIVER_MODULES_UNINITIALIZED:
2215 unint = true;
2216 /* Fall through dont add break here */
2217 case DRIVER_MODULES_CLOSED:
2218 if (!reinit && !unint) {
2219 ret = pld_power_on(qdf_dev->dev);
2220 if (ret) {
2221 hdd_err("Failed to Powerup the device: %d", ret);
2222 goto release_lock;
2223 }
2224 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002225
2226 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2227 hdd_ctx->config->enable_fw_log);
2228
Arun Khandavallifae92942016-08-01 13:31:08 +05302229 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2230 qdf_dev->bus_type,
2231 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2232 HIF_ENABLE_TYPE_PROBE);
2233 if (ret) {
2234 hdd_err("Failed to open hif: %d", ret);
2235 goto power_down;
2236 }
2237
2238 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302239 if (!hif_ctx) {
2240 hdd_err("hif context is null!!");
2241 goto power_down;
2242 }
2243
Arun Khandavallifae92942016-08-01 13:31:08 +05302244 status = ol_cds_init(qdf_dev, hif_ctx);
2245 if (status != QDF_STATUS_SUCCESS) {
2246 hdd_err("No Memory to Create BMI Context :%d", status);
2247 goto hif_close;
2248 }
2249
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002250 ret = hdd_update_config(hdd_ctx);
2251 if (ret) {
2252 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302253 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002254 }
2255
gbian62edd7e2017-03-07 13:12:13 +08002256 hdd_update_cds_ac_specs_params(hdd_ctx);
2257
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302258 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302259 if (!QDF_IS_STATUS_SUCCESS(status)) {
2260 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302261 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302262 }
2263
Mukul Sharma9d797a02017-01-05 20:26:03 +05302264 /* initalize components configurations after psoc open */
2265 ret = hdd_update_components_config(hdd_ctx);
2266 if (ret) {
2267 hdd_err("Failed to update components configs :%d",
2268 ret);
2269 goto close;
2270 }
2271
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002272 /*
2273 * NAN compoenet requires certian operations like, open adapter,
2274 * close adapter, etc. to be initiated by HDD, for those
2275 * register HDD callbacks with UMAC's NAN componenet.
2276 */
2277 hdd_nan_register_callbacks(hdd_ctx);
2278
Arun Khandavallifae92942016-08-01 13:31:08 +05302279 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2280
Jeff Johnson3a280122017-09-13 07:42:00 -07002281 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302282 if (!QDF_IS_STATUS_SUCCESS(status)) {
2283 hdd_err("Failed to pre-enable CDS: %d", status);
2284 goto close;
2285 }
2286
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002287 hdd_register_policy_manager_callback(
2288 hdd_ctx->hdd_psoc);
2289
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302290 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302291 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302292
Arun Khandavallifae92942016-08-01 13:31:08 +05302293 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2294 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2295 hdd_ftm_mc_process_msg);
2296 break;
2297 }
2298 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002299 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302300 break;
2301 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302302
2303 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002304 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2305 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002306 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002307 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302308 }
2309
Arun Khandavallifae92942016-08-01 13:31:08 +05302310 /* Fall through dont add break here */
2311 case DRIVER_MODULES_OPENED:
2312 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002313 hdd_alert("adapter is Null");
2314 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302315 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302316 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2317 hdd_err("in ftm mode, no need to configure cds modules");
2318 break;
2319 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302320 if (hdd_configure_cds(hdd_ctx, adapter)) {
2321 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002322 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302323 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302324 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 hdd_info("Driver Modules Successfully Enabled");
2326 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2327 break;
2328 case DRIVER_MODULES_ENABLED:
2329 hdd_info("Driver modules already Enabled");
2330 break;
2331 default:
2332 hdd_err("WLAN start invoked in wrong state! :%d\n",
2333 hdd_ctx->driver_status);
2334 goto release_lock;
2335 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302336 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302337 mutex_unlock(&hdd_ctx->iface_change_lock);
2338 EXIT();
2339 return 0;
2340
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002341post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002342 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002343
Arun Khandavallifae92942016-08-01 13:31:08 +05302344close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002345 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002346 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302347
2348ol_cds_free:
2349 ol_cds_free();
2350
2351hif_close:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302352 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302353power_down:
2354 if (!reinit && !unint)
2355 pld_power_off(qdf_dev->dev);
2356release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302357 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302358 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302359 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002360
Arun Khandavallifae92942016-08-01 13:31:08 +05302361 return -EINVAL;
2362}
2363
Naveen Rawat910726a2017-03-06 11:42:51 -08002364#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002365static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002366{
2367 int ret = os_if_wifi_pos_register_nl();
2368
2369 if (ret)
2370 hdd_err("os_if_wifi_pos_register_nl failed");
2371
2372 return ret;
2373}
2374
2375static int hdd_deactivate_wifi_pos(void)
2376{
2377 int ret = os_if_wifi_pos_deregister_nl();
2378
2379 if (ret)
2380 hdd_err("os_if_wifi_pos_deregister_nl failed");
2381
2382 return ret;
2383}
2384
2385/**
2386 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2387 * @hdd_ctx: hdd context
2388 *
2389 * Return: status of operation
2390 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002391static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002392{
2393 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2394 struct hdd_config *cfg = hdd_ctx->config;
2395
2396 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2397 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2398 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2399 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2400 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2401 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2402 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2403 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2404}
2405#else
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 return oem_activate_service(hdd_ctx);
2409}
2410
2411static int hdd_deactivate_wifi_pos(void)
2412{
2413 return 0;
2414}
2415
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002416static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002417{
2418}
2419#endif
2420
Arun Khandavallifae92942016-08-01 13:31:08 +05302421/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002422 * __hdd_open() - HDD Open function
2423 * @dev: Pointer to net_device structure
2424 *
2425 * This is called in response to ifconfig up
2426 *
2427 * Return: 0 for success; non-zero for failure
2428 */
2429static int __hdd_open(struct net_device *dev)
2430{
Jeff Johnson9d295242017-08-29 14:39:48 -07002431 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002432 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 int ret;
2434
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002435 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302436 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302437 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002438
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302439 /* Nothing to be done if device is unloading */
2440 if (cds_is_driver_unloading()) {
2441 hdd_err("Driver is unloading can not open the hdd");
2442 return -EBUSY;
2443 }
2444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002445 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302446 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002447 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002449
Arun Khandavallifae92942016-08-01 13:31:08 +05302450 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2451 if (ret) {
2452 hdd_err("Failed to start WLAN modules return");
2453 return -ret;
2454 }
2455
2456
2457 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2458 ret = hdd_start_adapter(adapter);
2459 if (ret) {
2460 hdd_err("Failed to start adapter :%d",
2461 adapter->device_mode);
2462 return ret;
2463 }
2464 }
2465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002466 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2467 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002468 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002469 /* Enable TX queues only when we are connected */
2470 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302471 WLAN_START_ALL_NETIF_QUEUE,
2472 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002473 }
2474
Naveen Rawat286def52016-09-23 15:38:02 -07002475 /* Enable carrier and transmit queues for NDI */
2476 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002477 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002478 wlan_hdd_netif_queue_control(adapter,
2479 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2480 WLAN_CONTROL_PATH);
2481 }
2482
Naveen Rawat910726a2017-03-06 11:42:51 -08002483 hdd_populate_wifi_pos_cfg(hdd_ctx);
2484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485 return ret;
2486}
2487
Arun Khandavallifae92942016-08-01 13:31:08 +05302488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002489/**
2490 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2491 * @dev: Pointer to net_device structure
2492 *
2493 * This is called in response to ifconfig up
2494 *
2495 * Return: 0 for success; non-zero for failure
2496 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002497static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002498{
2499 int ret;
2500
2501 cds_ssr_protect(__func__);
2502 ret = __hdd_open(dev);
2503 cds_ssr_unprotect(__func__);
2504
2505 return ret;
2506}
2507
2508/**
2509 * __hdd_stop() - HDD stop function
2510 * @dev: Pointer to net_device structure
2511 *
2512 * This is called in response to ifconfig down
2513 *
2514 * Return: 0 for success; non-zero for failure
2515 */
2516static int __hdd_stop(struct net_device *dev)
2517{
Jeff Johnson9d295242017-08-29 14:39:48 -07002518 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002519 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002520 int ret;
2521
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002522 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002523
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302524 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002525 adapter->sessionId, adapter->device_mode));
2526
2527 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302528 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002529 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530
2531 /* Nothing to be done if the interface is not opened */
2532 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002533 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002534 return -ENODEV;
2535 }
2536
2537 /* Make sure the interface is marked as closed */
2538 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302539
2540 hdd_debug("Disabling Auto Power save timer");
2541 sme_ps_disable_auto_ps_timer(
2542 WLAN_HDD_GET_HAL_CTX(adapter),
2543 adapter->sessionId);
2544
2545 /*
2546 * Disable TX on the interface, after this hard_start_xmit() will not
2547 * be called on that interface
2548 */
2549 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302550 wlan_hdd_netif_queue_control(adapter,
2551 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2552 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002553
2554 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002555 * NAN data interface is different in some sense. The traffic on NDI is
2556 * bursty in nature and depends on the need to transfer. The service
2557 * layer may down the interface after the usage and up again when
2558 * required. In some sense, the NDI is expected to be available
2559 * (like SAP) iface until NDI delete request is issued by the service
2560 * layer. Skip BSS termination and adapter deletion for NAN Data
2561 * interface (NDI).
2562 */
2563 if (WLAN_HDD_IS_NDI(adapter))
2564 return 0;
2565
2566 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 * The interface is marked as down for outside world (aka kernel)
2568 * But the driver is pretty much alive inside. The driver needs to
2569 * tear down the existing connection on the netdev (session)
2570 * cleanup the data pipes and wait until the control plane is stabilized
2571 * for this interface. The call also needs to wait until the above
2572 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002573 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574 * That is intentional to be able to scan if it is a STA/P2P interface
2575 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302576 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577
2578 /* DeInit the adapter. This ensures datapath cleanup as well */
2579 hdd_deinit_adapter(hdd_ctx, adapter, true);
2580
Arun Khandavallifae92942016-08-01 13:31:08 +05302581
2582 /*
2583 * Find if any iface is up. If any iface is up then can't put device to
2584 * sleep/power save mode
2585 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302586 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002587 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302588 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302589 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302590 }
2591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002592 EXIT();
2593 return 0;
2594}
2595
2596/**
2597 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2598 * @dev: pointer to net_device structure
2599 *
2600 * This is called in response to ifconfig down
2601 *
2602 * Return: 0 for success and error number for failure
2603 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002604static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605{
2606 int ret;
2607
2608 cds_ssr_protect(__func__);
2609 ret = __hdd_stop(dev);
2610 cds_ssr_unprotect(__func__);
2611
2612 return ret;
2613}
2614
2615/**
2616 * __hdd_uninit() - HDD uninit function
2617 * @dev: Pointer to net_device structure
2618 *
2619 * This is called during the netdev unregister to uninitialize all data
2620 * associated with the device
2621 *
2622 * Return: None
2623 */
2624static void __hdd_uninit(struct net_device *dev)
2625{
Jeff Johnson9d295242017-08-29 14:39:48 -07002626 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002627 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002629 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002630
2631 do {
2632 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002633 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 break;
2635 }
2636
Jeff Johnson399c6272017-08-30 10:51:00 -07002637 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2638 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002639 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640 break;
2641 }
2642
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002643 if (dev != adapter->dev)
2644 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002645
Jeff Johnson399c6272017-08-30 10:51:00 -07002646 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647
2648 /* after uninit our adapter structure will no longer be valid */
2649 adapter->dev = NULL;
2650 adapter->magic = 0;
2651 } while (0);
2652
2653 EXIT();
2654}
2655
2656/**
2657 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2658 * @dev: pointer to net_device structure
2659 *
2660 * This is called during the netdev unregister to uninitialize all data
2661 * associated with the device
2662 *
2663 * Return: none
2664 */
2665static void hdd_uninit(struct net_device *dev)
2666{
2667 cds_ssr_protect(__func__);
2668 __hdd_uninit(dev);
2669 cds_ssr_unprotect(__func__);
2670}
2671
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002672static int hdd_open_cesium_nl_sock(void)
2673{
2674#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2675 struct netlink_kernel_cfg cfg = {
2676 .groups = WLAN_NLINK_MCAST_GRP_ID,
2677 .input = NULL
2678 };
2679#endif
2680 int ret = 0;
2681
2682#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2683 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2684#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2685 THIS_MODULE,
2686#endif
2687 &cfg);
2688#else
2689 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2690 WLAN_NLINK_MCAST_GRP_ID,
2691 NULL, NULL, THIS_MODULE);
2692#endif
2693
2694 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002695 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002696 ret = -ECONNREFUSED;
2697 }
2698
2699 return ret;
2700}
2701
2702static void hdd_close_cesium_nl_sock(void)
2703{
2704 if (NULL != cesium_nl_srv_sock) {
2705 netlink_kernel_release(cesium_nl_srv_sock);
2706 cesium_nl_srv_sock = NULL;
2707 }
2708}
2709
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710/**
2711 * __hdd_set_mac_address() - set the user specified mac address
2712 * @dev: Pointer to the net device.
2713 * @addr: Pointer to the sockaddr.
2714 *
2715 * This function sets the user specified mac address using
2716 * the command ifconfig wlanX hw ether <mac adress>.
2717 *
2718 * Return: 0 for success, non zero for failure
2719 */
2720static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2721{
Jeff Johnson9d295242017-08-29 14:39:48 -07002722 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002723 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002724 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302725 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726 int ret;
2727
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002728 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002729
2730 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2731 ret = wlan_hdd_validate_context(hdd_ctx);
2732 if (0 != ret)
2733 return ret;
2734
2735 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2736 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2737
2738 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302739 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740}
2741
2742/**
2743 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2744 * function from SSR
2745 * @dev: pointer to net_device structure
2746 * @addr: Pointer to the sockaddr
2747 *
2748 * This function sets the user specified mac address using
2749 * the command ifconfig wlanX hw ether <mac adress>.
2750 *
2751 * Return: 0 for success.
2752 */
2753static int hdd_set_mac_address(struct net_device *dev, void *addr)
2754{
2755 int ret;
2756
2757 cds_ssr_protect(__func__);
2758 ret = __hdd_set_mac_address(dev, addr);
2759 cds_ssr_unprotect(__func__);
2760
2761 return ret;
2762}
2763
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002764uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765{
2766 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002767
Anurag Chouhan6d760662016-02-20 16:05:43 +05302768 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002769 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2770 break;
2771 }
2772
Anurag Chouhan6d760662016-02-20 16:05:43 +05302773 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774 return NULL;
2775
2776 hdd_ctx->config->intfAddrMask |= (1 << i);
2777 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2778}
2779
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002780void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781{
2782 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002783
Anurag Chouhan6d760662016-02-20 16:05:43 +05302784 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785 if (!memcmp(releaseAddr,
2786 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2787 6)) {
2788 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2789 break;
2790 }
2791 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792}
2793
2794#ifdef WLAN_FEATURE_PACKET_FILTERING
2795/**
2796 * __hdd_set_multicast_list() - set the multicast address list
2797 * @dev: Pointer to the WLAN device.
2798 * @skb: Pointer to OS packet (sk_buff).
2799 *
2800 * This funciton sets the multicast address list.
2801 *
2802 * Return: None
2803 */
2804static void __hdd_set_multicast_list(struct net_device *dev)
2805{
Jeff Johnson9d295242017-08-29 14:39:48 -07002806 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807 int i = 0, status;
2808 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002809 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302810 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2811 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2812 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002813
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002814 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302815 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302816 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302819 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302820 goto out;
2821
Dustin Brownc788acb2017-08-01 17:43:51 -07002822 status = hdd_validate_adapter(adapter);
2823 if (status)
2824 goto out;
2825
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302826 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2827 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002828 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302829 goto out;
2830 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302832 /* Delete already configured multicast address list */
2833 if (adapter->mc_addr_list.mc_cnt > 0) {
2834 hdd_info("clear previously configured MC address list");
2835 hdd_disable_and_flush_mc_addr_list(adapter,
2836 pmo_mc_list_change_notify);
2837 }
2838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002840 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302841 hdd_disable_and_flush_mc_addr_list(adapter,
2842 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 } else {
2844 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302845 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002846 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302847 pmo_ucfg_max_mc_addr_supported(psoc));
2848 hdd_disable_and_flush_mc_addr_list(adapter,
2849 pmo_mc_list_change_notify);
2850 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002853 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302854 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 if (i == mc_count)
2856 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302857 memset(&(mc_list_request->mc_addr[i].bytes),
2858 0, ETH_ALEN);
2859 memcpy(&(mc_list_request->mc_addr[i].bytes),
2860 ha->addr, ETH_ALEN);
2861 hdd_info("mlist[%d] = %pM", i,
2862 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863 i++;
2864 }
2865 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302866
2867 mc_list_request->psoc = psoc;
2868 mc_list_request->vdev_id = adapter->sessionId;
2869 mc_list_request->count = mc_count;
2870 status = hdd_cache_mc_addr_list(mc_list_request);
2871 if (status == 0) {
2872 hdd_enable_mc_addr_filtering(adapter,
2873 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302875 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302877out:
2878 if (mc_list_request)
2879 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302880 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881}
2882
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884/**
2885 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2886 * @dev: pointer to net_device
2887 *
2888 * Return: none
2889 */
2890static void hdd_set_multicast_list(struct net_device *dev)
2891{
2892 cds_ssr_protect(__func__);
2893 __hdd_set_multicast_list(dev);
2894 cds_ssr_unprotect(__func__);
2895}
2896#endif
2897
2898/**
2899 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2900 * @dev: Pointer to the WLAN device.
2901 * @skb: Pointer to OS packet (sk_buff).
2902 *
2903 * This function is registered with the Linux OS for network
2904 * core to decide which queue to use first.
2905 *
2906 * Return: ac, Queue Index/access category corresponding to UP in IP header
2907 */
2908static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2909#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2910 , void *accel_priv
2911#endif
2912#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2913 , select_queue_fallback_t fallback
2914#endif
2915)
2916{
2917 return hdd_wmm_select_queue(dev, skb);
2918}
2919
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002920static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 .ndo_open = hdd_open,
2922 .ndo_stop = hdd_stop,
2923 .ndo_uninit = hdd_uninit,
2924 .ndo_start_xmit = hdd_hard_start_xmit,
2925 .ndo_tx_timeout = hdd_tx_timeout,
2926 .ndo_get_stats = hdd_get_stats,
2927 .ndo_do_ioctl = hdd_ioctl,
2928 .ndo_set_mac_address = hdd_set_mac_address,
2929 .ndo_select_queue = hdd_select_queue,
2930#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002931 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932#endif
2933};
2934
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002935/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002936static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002937 .ndo_open = hdd_mon_open,
2938 .ndo_stop = hdd_stop,
2939 .ndo_get_stats = hdd_get_stats,
2940};
2941
2942/**
2943 * hdd_set_station_ops() - update net_device ops for monitor mode
2944 * @pWlanDev: Handle to struct net_device to be updated.
2945 * Return: None
2946 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947void hdd_set_station_ops(struct net_device *pWlanDev)
2948{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002949 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2950 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2951 else
2952 pWlanDev->netdev_ops = &wlan_drv_ops;
2953}
2954
Komal Seelama89be8d2016-09-29 11:09:26 +05302955#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302956/**
2957 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2958 * @hdd_ctx: HDD context
2959 *
2960 * Return: None
2961 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002962static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302963{
2964 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2965
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002966 qdf_runtime_lock_init(&ctx->roc);
2967 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05302968}
2969
2970/**
2971 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2972 * @hdd_ctx: HDD Context
2973 *
2974 * Return: None
2975 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002976static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302977{
2978 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2979
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002980 qdf_runtime_lock_deinit(&ctx->roc);
2981 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302982
2983 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302984}
2985
Jeff Johnson9d295242017-08-29 14:39:48 -07002986static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05302987{
2988 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2989
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002990 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302991}
2992
Jeff Johnson9d295242017-08-29 14:39:48 -07002993static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05302994{
2995 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2996
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002997 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302998}
2999#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003000static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
3001static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07003002static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
3003static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05303004#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003005/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003006 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3007 * @hdd_ctx: global hdd context
3008 * @macAddr: mac address to assign to the interface
3009 * @name: User-visible name of the interface
3010 *
3011 * hdd adapter pointer would point to the netdev->priv space, this function
3012 * would retrive the pointer, and setup the hdd adapter configuration.
3013 *
3014 * Return: the pointer to hdd adapter, otherwise NULL
3015 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003016static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003018 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003019 const char *name)
3020{
3021 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003022 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003023 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003024 /*
3025 * cfg80211 initialization and registration....
3026 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003027 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003028#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3029 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003031 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3032 hdd_mon_mode_ether_setup : ether_setup),
3033 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034
3035 if (pWlanDev != NULL) {
3036
3037 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003038 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003039
Jeff Johnson9d295242017-08-29 14:39:48 -07003040 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303041 sta_ctx = &adapter->sessionCtx.station;
3042 qdf_mem_set(sta_ctx->conn_info.staId,
3043 sizeof(sta_ctx->conn_info.staId),
3044 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003046 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003047 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303048 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049
3050 init_completion(&adapter->session_open_comp_var);
3051 init_completion(&adapter->session_close_comp_var);
3052 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303053 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003054 init_completion(&adapter->linkup_event_var);
3055 init_completion(&adapter->cancel_rem_on_chan_var);
3056 init_completion(&adapter->rem_on_chan_ready_event);
3057 init_completion(&adapter->sta_authorized_event);
3058 init_completion(&adapter->offchannel_tx_event);
3059 init_completion(&adapter->tx_action_cnf_event);
3060#ifdef FEATURE_WLAN_TDLS
3061 init_completion(&adapter->tdls_add_station_comp);
3062 init_completion(&adapter->tdls_del_station_comp);
3063 init_completion(&adapter->tdls_mgmt_comp);
3064 init_completion(&adapter->tdls_link_establish_req_comp);
3065#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003066 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067 init_completion(&adapter->change_country_code);
3068
3069
3070 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303071 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003072
3073 adapter->offloads_configured = false;
3074 adapter->isLinkUpSvcNeeded = false;
3075 adapter->higherDtimTransition = true;
3076 /* Init the net_device structure */
3077 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3078
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303079 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303081 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 sizeof(tSirMacAddr));
3083 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084
3085 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3086 pWlanDev->features |=
3087 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3088 pWlanDev->features |= NETIF_F_RXCSUM;
3089
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003090 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3091
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003092 hdd_set_station_ops(adapter->dev);
3093
Dustin Brownc81dd412017-08-15 16:26:28 -07003094 hdd_dev_setup_destructor(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003096 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 adapter->wdev.wiphy = hdd_ctx->wiphy;
3098 adapter->wdev.netdev = pWlanDev;
3099 /* set pWlanDev's parent to underlying device */
3100 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3101 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303102 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303104 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 }
3106
3107 return adapter;
3108}
3109
Jeff Johnson9d295242017-08-29 14:39:48 -07003110static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003112 struct net_device *dev = adapter->dev;
3113 int ret;
3114
3115 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003116
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003117 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003118 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3119
3120 ret = dev_alloc_name(dev, dev->name);
3121 if (ret < 0) {
3122 hdd_err(
3123 "unable to get dev name: %s, err = 0x%x",
3124 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303125 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126 }
3127 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003128
3129 ret = register_netdevice(dev);
3130 if (ret) {
3131 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3132 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303133 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 }
3135 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003136 ret = register_netdev(dev);
3137 if (ret) {
3138 hdd_err("register_netdev(%s) failed, err = 0x%x",
3139 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303140 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 }
3142 }
3143 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3144
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003145 EXIT();
3146
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303147 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148}
3149
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003150QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151{
Jeff Johnson9d295242017-08-29 14:39:48 -07003152 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153
3154 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003155 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303156 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 }
3158
3159 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003160 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303161 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 }
3163
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003164 /*
3165 * For NAN Data interface, the close session results in the final
3166 * indication to the userspace
3167 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003168 if (adapter->device_mode == QDF_NDI_MODE)
3169 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173 /*
3174 * We can be blocked while waiting for scheduled work to be
3175 * flushed, and the adapter structure can potentially be freed, in
3176 * which case the magic will have been reset. So make sure the
3177 * magic is still good, and hence the adapter structure is still
3178 * valid, before signaling completion
3179 */
3180 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3181 complete(&adapter->session_close_comp_var);
3182
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303183 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184}
3185
Krunal Soni8c37e322016-02-03 16:08:37 -08003186/**
3187 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3188 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003189 *
3190 * This routine will check the mode of adapter and if it is required then it
3191 * will initialize the TDLS operations
3192 *
3193 * Return: QDF_STATUS
3194 */
3195#ifdef FEATURE_WLAN_TDLS
Jeff Johnson9d295242017-08-29 14:39:48 -07003196static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003197{
Dustin Brownd28772b2017-03-17 14:16:07 -07003198 if (adapter->device_mode == QDF_IBSS_MODE)
3199 return QDF_STATUS_SUCCESS;
3200
3201 if (wlan_hdd_tdls_init(adapter)) {
3202 hdd_err("wlan_hdd_tdls_init failed");
3203 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003204 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003205 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3206
Krunal Soni8c37e322016-02-03 16:08:37 -08003207 return QDF_STATUS_SUCCESS;
3208}
3209#else
Jeff Johnson9d295242017-08-29 14:39:48 -07003210static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003211{
3212 return QDF_STATUS_SUCCESS;
3213}
3214#endif
3215
Jeff Johnson9d295242017-08-29 14:39:48 -07003216int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217{
Dustin Brownd28772b2017-03-17 14:16:07 -07003218 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219
Dustin Brownd28772b2017-03-17 14:16:07 -07003220 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003221 if (QDF_IS_STATUS_ERROR(status))
3222 return qdf_status_to_os_return(status);
3223
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003224 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003225 if (QDF_IS_STATUS_ERROR(status))
3226 return qdf_status_to_os_return(status);
3227
3228 if (wma_capability_enhanced_mcast_filter())
3229 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3230 else
3231 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003232
3233 return qdf_status_to_os_return(status);
3234}
3235
Jeff Johnson9d295242017-08-29 14:39:48 -07003236int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003237{
3238 QDF_STATUS status;
3239 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003240 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003241 unsigned long rc;
3242
3243 hdd_info("destroying vdev %d", adapter->sessionId);
3244
3245 /* vdev created sanity check */
3246 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3247 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3248 return -EINVAL;
3249 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003250 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003251 /*
3252 * In SSR case, there is no need to destroy vdev in firmware since
3253 * it has already asserted. vdev can be released directly.
3254 */
3255 if (cds_is_driver_recovering())
3256 goto release_vdev;
3257
Dustin Brownd28772b2017-03-17 14:16:07 -07003258 /* close sme session (destroy vdev in firmware via legacy API) */
3259 INIT_COMPLETION(adapter->session_close_comp_var);
3260 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3261 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3262 hdd_sme_close_session_callback, adapter);
3263 if (QDF_IS_STATUS_ERROR(status)) {
3264 hdd_err("failed to close sme session: %d", status);
3265 return qdf_status_to_os_return(status);
3266 }
3267
3268 /* block on a completion variable until sme session is closed */
3269 rc = wait_for_completion_timeout(
3270 &adapter->session_close_comp_var,
3271 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3272 if (!rc) {
3273 hdd_err("timed out waiting for close sme session: %ld", rc);
3274 if (adapter->device_mode == QDF_NDI_MODE)
3275 hdd_ndp_session_end_handler(adapter);
3276 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3277 return -ETIMEDOUT;
3278 }
Yue Maf9782842017-05-08 12:49:49 -07003279release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003280 /* do vdev logical destroy via objmgr */
3281 errno = hdd_objmgr_destroy_vdev(adapter);
3282 if (errno) {
3283 hdd_err("failed to destroy objmgr vdev: %d", errno);
3284 return errno;
3285 }
3286
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003287 /* now that sme session is closed, allow physical vdev destroy */
3288 errno = hdd_objmgr_release_vdev(adapter);
3289 if (errno) {
3290 hdd_err("failed to release objmgr vdev: %d", errno);
3291 return errno;
3292 }
3293
Dustin Brownd28772b2017-03-17 14:16:07 -07003294 hdd_info("vdev destroyed successfully");
3295
3296 return 0;
3297}
3298
Jeff Johnson9d295242017-08-29 14:39:48 -07003299int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003300{
3301 QDF_STATUS status;
3302 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003303 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003304 uint32_t type;
3305 uint32_t sub_type;
3306 unsigned long rc;
3307
3308 hdd_info("creating new vdev");
3309
3310 /* determine vdev (sub)type */
3311 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303312 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003313 hdd_err("failed to get vdev type: %d", status);
3314 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003315 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003316
3317 /* do vdev create via objmgr */
3318 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003319 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003320 if (errno) {
3321 hdd_err("failed to create objmgr vdev: %d", errno);
3322 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003323 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003324
3325 /* Open a SME session (prepare vdev in firmware via legacy API) */
3326 INIT_COMPLETION(adapter->session_open_comp_var);
3327 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3328 (uint8_t *)&adapter->macAddressCurrent,
3329 adapter->sessionId, type, sub_type);
3330 if (QDF_IS_STATUS_ERROR(status)) {
3331 hdd_err("failed to open sme session: %d", status);
3332 errno = qdf_status_to_os_return(status);
3333 goto objmgr_vdev_destroy;
3334 }
3335
3336 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337 rc = wait_for_completion_timeout(
3338 &adapter->session_open_comp_var,
3339 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3340 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003341 hdd_err("timed out waiting for open sme session: %ld", rc);
3342 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303343 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3344 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003345 }
3346
3347 /* firmware ready for component communication, raise vdev_ready event */
3348 errno = hdd_vdev_ready(adapter);
3349 if (errno) {
3350 hdd_err("failed to dispatch vdev ready event: %d", errno);
3351 goto hdd_vdev_destroy;
3352 }
3353
3354 hdd_info("vdev %d created successfully", adapter->sessionId);
3355
3356 return 0;
3357
3358 /*
3359 * Due to legacy constraints, we need to destroy in the same order as
3360 * create. So, split error handling into 2 cases to accommodate.
3361 */
3362
3363objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003364 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003365
3366 return errno;
3367
3368hdd_vdev_destroy:
3369 QDF_BUG(!hdd_vdev_destroy(adapter));
3370
3371 return errno;
3372}
3373
Jeff Johnson9d295242017-08-29 14:39:48 -07003374QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003375{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003376 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003377 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003378 QDF_STATUS status;
3379 int ret_val;
3380
3381 ret_val = hdd_vdev_create(adapter);
3382 if (ret_val) {
3383 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303384 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 }
3386
Dustin Brownd28772b2017-03-17 14:16:07 -07003387 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3388 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3389 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003390 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003393 status = hdd_register_wext(adapter->dev);
3394 if (QDF_IS_STATUS_ERROR(status)) {
3395 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 goto error_register_wext;
3397 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003398 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003399
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303400 qdf_mem_set(pHddStaCtx->conn_info.staId,
3401 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3402
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003403 /* set fast roaming capability in sme session */
3404 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3405 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406 /* Set the default operation channel */
3407 pHddStaCtx->conn_info.operationChannel =
3408 hdd_ctx->config->OperatingChannel;
3409
3410 /* Make the default Auth Type as OPEN */
3411 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3412
3413 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303414 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003415 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 status, status);
3417 goto error_init_txrx;
3418 }
3419
3420 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3421
3422 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303423 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003424 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 status, status);
3426 goto error_wmm_init;
3427 }
3428
3429 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3430
Naveen Rawat247a8682017-06-05 15:00:31 -07003431 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 WMI_PDEV_PARAM_BURST_ENABLE,
3433 hdd_ctx->config->enableSifsBurst,
3434 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003435 if (ret_val)
3436 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437
Dustin Brownd28772b2017-03-17 14:16:07 -07003438 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003439 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003442 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303443 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445error_tdls_init:
3446 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3447 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448error_wmm_init:
3449 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3450 hdd_deinit_tx_rx(adapter);
3451error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003452 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003454 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456 return status;
3457}
3458
Jeff Johnson9d295242017-08-29 14:39:48 -07003459void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460{
3461 hdd_cfg80211_state_t *cfgState;
3462
3463 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3464
3465 if (NULL != cfgState->buf) {
3466 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003467
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 rc = wait_for_completion_timeout(
3469 &adapter->tx_action_cnf_event,
3470 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3471 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003472 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303473 /*
3474 * Inform tx status as FAILURE to upper layer and free
3475 * cfgState->buf
3476 */
3477 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 }
3479 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480}
3481
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303482/**
3483 * hdd_station_adapter_deinit() - De-initialize the station adapter
3484 * @hdd_ctx: global hdd context
3485 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003486 * @rtnl_held: Used to indicate whether or not the caller is holding
3487 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303488 *
3489 * This function De-initializes the STA/P2P/OCB adapter.
3490 *
3491 * Return: None.
3492 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003493static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003494 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003495 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303496{
3497 ENTER_DEV(adapter->dev);
3498
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303499 if (adapter->dev) {
3500 if (rtnl_held)
3501 adapter->dev->wireless_handlers = NULL;
3502 else {
3503 rtnl_lock();
3504 adapter->dev->wireless_handlers = NULL;
3505 rtnl_unlock();
3506 }
3507 }
3508
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303509 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3510 hdd_deinit_tx_rx(adapter);
3511 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3512 }
3513
3514 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3515 hdd_wmm_adapter_close(adapter);
3516 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3517 }
3518
3519 hdd_cleanup_actionframe(hdd_ctx, adapter);
3520 wlan_hdd_tdls_exit(adapter);
3521
3522 EXIT();
3523}
3524
3525/**
3526 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3527 * @hdd_ctx: global hdd context
3528 * @adapter: HDD adapter
3529 * @rtnl_held: the rtnl lock hold flag
3530 * This function De-initializes the AP/P2PGo adapter.
3531 *
3532 * Return: None.
3533 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003534static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003535 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003536 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303537{
3538 ENTER_DEV(adapter->dev);
3539
3540 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3541 hdd_wmm_adapter_close(adapter);
3542 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3543 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003544 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303545
3546 hdd_cleanup_actionframe(hdd_ctx, adapter);
3547
3548 hdd_unregister_hostapd(adapter, rtnl_held);
3549
3550 EXIT();
3551}
3552
Jeff Johnson9d295242017-08-29 14:39:48 -07003553void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554 bool rtnl_held)
3555{
3556 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303557
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003558 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003559 case QDF_STA_MODE:
3560 case QDF_P2P_CLIENT_MODE:
3561 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303563 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 break;
3565 }
3566
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003567 case QDF_SAP_MODE:
3568 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003569 {
3570
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303571 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 break;
3573 }
3574
3575 default:
3576 break;
3577 }
3578
3579 EXIT();
3580}
3581
Jeff Johnson9d295242017-08-29 14:39:48 -07003582static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003583 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584{
3585 struct net_device *pWlanDev = NULL;
3586
3587 if (adapter)
3588 pWlanDev = adapter->dev;
3589 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003590 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 return;
3592 }
3593
Rajeev Kumardca5f812016-02-04 17:28:06 -08003594 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303595
3596 if (adapter->scan_info.default_scan_ies) {
3597 qdf_mem_free(adapter->scan_info.default_scan_ies);
3598 adapter->scan_info.default_scan_ies = NULL;
3599 }
3600
Komal Seelama89be8d2016-09-29 11:09:26 +05303601 hdd_adapter_runtime_suspend_denit(adapter);
3602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 /*
3604 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3605 * the driver is almost closed and cannot handle either control
3606 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003607 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3608 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 * is not right. Setting this flag helps hdd_stop() to recognize that
3610 * the interface is closed and restricts any operations on that
3611 */
3612 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3613
3614 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003615 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003617 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 /*
3620 * Note that the adapter is no longer valid at this point
3621 * since the memory has been reclaimed
3622 */
3623 }
3624}
3625
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003626static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003627 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628{
3629 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003630 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303631 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003632
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303634 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 adapter = adapterNode->pAdapter;
3636 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303637 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303639 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 }
3641 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3642 adapterNode = pNext;
3643 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303644 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003646
Arun Khandavalli2358d522016-05-16 18:05:37 +05303647#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3648/**
3649 * hdd_set_fw_log_params() - Set log parameters to FW
3650 * @hdd_ctx: HDD Context
3651 * @adapter: HDD Adapter
3652 *
3653 * This function set the FW Debug log level based on the INI.
3654 *
3655 * Return: None
3656 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003657static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003658 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303659{
3660 uint8_t count = 0, numentries = 0,
3661 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3662 uint32_t value = 0;
3663 int ret;
3664
Arun Khandavallifae92942016-08-01 13:31:08 +05303665 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3666 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003667 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303668 return;
3669 }
3670
Arun Khandavallifae92942016-08-01 13:31:08 +05303671 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303672 hdd_ctx->fw_log_settings.dl_type =
3673 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003674 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303675 WMI_DBGLOG_TYPE,
3676 hdd_ctx->config->enableFwLogType,
3677 DBG_CMD);
3678 if (ret != 0)
3679 hdd_err("Failed to enable FW log type ret %d",
3680 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303681
3682 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303683 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003684 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303685 WMI_DBGLOG_LOG_LEVEL,
3686 hdd_ctx->config->enableFwLogLevel,
3687 DBG_CMD);
3688 if (ret != 0)
3689 hdd_err("Failed to enable FW log level ret %d",
3690 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303691
3692 hdd_string_to_u8_array(
3693 hdd_ctx->config->enableFwModuleLogLevel,
3694 moduleloglevel,
3695 &numentries,
3696 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3697
3698 while (count < numentries) {
3699 /*
3700 * FW module log level input string looks like
3701 * below:
3702 * gFwDebugModuleLoglevel=<FW Module ID>,
3703 * <Log Level>,...
3704 * For example:
3705 * gFwDebugModuleLoglevel=
3706 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3707 * Above input string means :
3708 * For FW module ID 1 enable log level 0
3709 * For FW module ID 2 enable log level 1
3710 * For FW module ID 3 enable log level 2
3711 * For FW module ID 4 enable log level 3
3712 * For FW module ID 5 enable log level 4
3713 * For FW module ID 6 enable log level 5
3714 * For FW module ID 7 enable log level 6
3715 */
3716
Nishank Aggarwale239d962017-03-03 12:26:02 +05303717 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3718 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3719 hdd_err("Module id %d and dbglog level %d input length is more than max",
3720 moduleloglevel[count],
3721 moduleloglevel[count + 1]);
3722 return;
3723 }
3724
3725 value = moduleloglevel[count] << 16;
3726 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003727 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303728 WMI_DBGLOG_MOD_LOG_LEVEL,
3729 value, DBG_CMD);
3730 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303731 hdd_err("Failed to enable FW module log level %d ret %d",
3732 value, ret);
3733
3734 count += 2;
3735 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303736
Arun Khandavalli2358d522016-05-16 18:05:37 +05303737}
3738#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003739static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003740 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303741{
3742}
3743
3744#endif
3745
3746/**
3747 * hdd_set_fw_params() - Set parameters to firmware
3748 * @adapter: HDD adapter
3749 *
3750 * This function Sets various parameters to fw once the
3751 * adapter is started.
3752 *
3753 * Return: 0 on success or errno on failure
3754 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003755int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303756{
3757 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003758 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303759
3760 ENTER_DEV(adapter->dev);
3761
3762 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3763 if (!hdd_ctx)
3764 return -EINVAL;
3765
Dustin Brown732ab9c2017-06-15 13:24:09 -07003766 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3767 hdd_debug("FTM Mode is active; nothing to do");
3768 return 0;
3769 }
3770
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303771 ret = sme_cli_set_command(adapter->sessionId,
3772 WMI_PDEV_PARAM_DTIM_SYNTH,
3773 hdd_ctx->config->enable_lprx, PDEV_CMD);
3774 if (ret) {
3775 hdd_err("Failed to set LPRx");
3776 goto error;
3777 }
3778
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303779 if (adapter->device_mode == QDF_STA_MODE) {
3780 sme_set_smps_cfg(adapter->sessionId,
3781 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3782 hdd_ctx->config->upper_brssi_thresh);
3783
3784 sme_set_smps_cfg(adapter->sessionId,
3785 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3786 hdd_ctx->config->lower_brssi_thresh);
3787
3788 sme_set_smps_cfg(adapter->sessionId,
3789 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3790 hdd_ctx->config->enable_dtim_1chrx);
3791 }
3792
Dustin Brown732ab9c2017-06-15 13:24:09 -07003793 if (hdd_ctx->config->enable2x2) {
3794 hdd_debug("configuring 2x2 mode fw params");
3795
Naveen Rawat247a8682017-06-05 15:00:31 -07003796 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003797 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3798 hdd_ctx->config->enable_cck_tx_fir_override,
3799 PDEV_CMD);
3800 if (ret) {
3801 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3802 ret);
3803 goto error;
3804 }
3805 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303806#define HDD_DTIM_1CHAIN_RX_ID 0x5
3807#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003808 hdd_debug("configuring 1x1 mode fw params");
3809
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003810 /*
3811 * Disable DTIM 1 chain Rx when in 1x1,
3812 * we are passing two value
3813 * as param_id << 29 | param_value.
3814 * Below param_value = 0(disable)
3815 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003816 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003817 WMI_STA_SMPS_PARAM_CMDID,
3818 HDD_DTIM_1CHAIN_RX_ID <<
3819 HDD_SMPS_PARAM_VALUE_S,
3820 VDEV_CMD);
3821 if (ret) {
3822 hdd_err("DTIM 1 chain set failed %d", ret);
3823 goto error;
3824 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303825
Naveen Rawat247a8682017-06-05 15:00:31 -07003826 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003827 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3828 hdd_ctx->config->txchainmask1x1,
3829 PDEV_CMD);
3830 if (ret) {
3831 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3832 ret);
3833 goto error;
3834 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303835
Naveen Rawat247a8682017-06-05 15:00:31 -07003836 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003837 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3838 hdd_ctx->config->rxchainmask1x1,
3839 PDEV_CMD);
3840 if (ret) {
3841 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3842 ret);
3843 goto error;
3844 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303845#undef HDD_DTIM_1CHAIN_RX_ID
3846#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003847 }
3848
Naveen Rawat247a8682017-06-05 15:00:31 -07003849 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003850 WMI_PDEV_PARAM_HYST_EN,
3851 hdd_ctx->config->enableMemDeepSleep,
3852 PDEV_CMD);
3853 if (ret) {
3854 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3855 goto error;
3856 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303857
Naveen Rawat247a8682017-06-05 15:00:31 -07003858 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003859 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3860 hdd_ctx->config->rts_profile,
3861 VDEV_CMD);
3862 if (ret) {
3863 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3864 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303865 }
3866
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003867 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3868
3869 ret = wma_cli_set_command(adapter->sessionId,
3870 GEN_VDEV_PARAM_AMSDU,
3871 hdd_ctx->config->max_amsdu_num,
3872 GEN_CMD);
3873 if (ret != 0) {
3874 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3875 goto error;
3876 }
3877
Arun Khandavalli2358d522016-05-16 18:05:37 +05303878 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303879 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003880
Arun Khandavalli2358d522016-05-16 18:05:37 +05303881 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303882
Arun Khandavalli2358d522016-05-16 18:05:37 +05303883error:
3884 return -EINVAL;
3885}
3886
Ryan Hsu07495ea2016-01-21 15:25:39 -08003887/**
3888 * hdd_open_adapter() - open and setup the hdd adatper
3889 * @hdd_ctx: global hdd context
3890 * @session_type: type of the interface to be created
3891 * @iface_name: User-visible name of the interface
3892 * @macAddr: MAC address to assign to the interface
3893 * @name_assign_type: the name of assign type of the netdev
3894 * @rtnl_held: the rtnl lock hold flag
3895 *
3896 * This function open and setup the hdd adpater according to the device
3897 * type request, assign the name, the mac address assigned, and then prepared
3898 * the hdd related parameters, queue, lock and ready to start.
3899 *
3900 * Return: the pointer of hdd adapter, otherwise NULL.
3901 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003902struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003904 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003905 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906{
Jeff Johnson9d295242017-08-29 14:39:48 -07003907 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303909 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912
3913 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3914 /*
3915 * Max limit reached on the number of vdevs configured by the
3916 * host. Return error
3917 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303918 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3919 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 return NULL;
3921 }
3922
3923 if (macAddr == NULL) {
3924 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303925 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 return NULL;
3927 }
3928 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303929 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303930 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3931 " already exists",
3932 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 return NULL;
3934 }
3935
3936 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003937 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 /* Reset locally administered bit if the device mode is STA */
3939 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3940 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003941 case QDF_P2P_CLIENT_MODE:
3942 case QDF_P2P_DEVICE_MODE:
3943 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003944 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303945 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003946 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3947 name_assign_type,
3948 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949
3950 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303951 hdd_err("failed to allocate adapter for session %d",
3952 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 return NULL;
3954 }
3955
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003956 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003958 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003959 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303960 else if (QDF_MONITOR_MODE == session_type)
3961 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 else
3963 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3964
3965 adapter->device_mode = session_type;
3966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 /*
3969 * Workqueue which gets scheduled in IPv4 notification
3970 * callback
3971 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3973 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974
3975#ifdef WLAN_NS_OFFLOAD
3976 /*
3977 * Workqueue which gets scheduled in IPv6
3978 * notification callback.
3979 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3981 hdd_ipv6_notifier_work_queue);
3982#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303984 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303986 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 }
3988
3989 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003990 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303992 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3993 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303994
Ravi Joshi1a292562017-05-18 16:28:54 -07003995 /* Initialize NAN Data Interface */
3996 if (QDF_NDI_MODE == session_type) {
3997 status = hdd_init_nan_data_mode(adapter);
3998 if (QDF_STATUS_SUCCESS != status)
3999 goto err_free_netdev;
4000 }
4001
4002 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004004 case QDF_P2P_GO_MODE:
4005 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004006 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4007 name_assign_type,
4008 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004010 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304011 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 return NULL;
4013 }
4014
4015 adapter->wdev.iftype =
4016 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004017 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 NL80211_IFTYPE_P2P_GO;
4019 adapter->device_mode = session_type;
4020
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004021 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304022 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4024 goto err_free_netdev;
4025 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004026 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304028 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4029 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304031 case QDF_FTM_MODE:
4032 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4033 name_assign_type,
4034 "wlan0");
4035 if (NULL == adapter) {
4036 hdd_err("Failed to allocate adapter for FTM mode");
4037 return NULL;
4038 }
4039 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4040 adapter->device_mode = session_type;
4041 status = hdd_register_interface(adapter, rtnl_held);
4042 if (QDF_STATUS_SUCCESS != status) {
4043 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4044 goto err_free_netdev;
4045 }
4046 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004047 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304048 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304049 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4050 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304051 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004053 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304054 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055 return NULL;
4056 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057
hqueaa33ee2017-05-04 17:56:35 +08004058 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4061 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4062
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304063 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 /* Add it to the hdd's session list. */
4065 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304066 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004067 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304068 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 } else {
4070 pHddAdapterNode->pAdapter = adapter;
4071 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4072 }
4073 }
4074
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304075 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 if (NULL != adapter) {
4077 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4078 adapter = NULL;
4079 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004080 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304081 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 return NULL;
4084 }
4085
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304086 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004087 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4088 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 /* Adapter successfully added. Increment the vdev count */
4091 hdd_ctx->current_intf_count++;
4092
Jeff Johnson5880d792016-08-15 13:32:30 -07004093 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 hdd_ctx->current_intf_count);
4095
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004096 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 }
4098
Rajeev Kumardca5f812016-02-04 17:28:06 -08004099 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004100 hdd_err("Interface %s wow debug_fs init failed",
4101 netdev_name(adapter->dev));
4102
4103 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4104 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105
4106 return adapter;
4107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304110 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111
4112 return NULL;
4113}
4114
Jeff Johnson9d295242017-08-29 14:39:48 -07004115QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004116 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004117{
4118 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304119 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120
4121 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304122 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004123 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124 status);
4125 return status;
4126 }
4127
4128 while (pCurrent->pAdapter != adapter) {
4129 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304130 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 break;
4132
4133 pCurrent = pNext;
4134 }
4135 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304136 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004137 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004138 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304139 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004140
4141 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004142 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4143 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304146 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 adapterNode = NULL;
4148
Dustin Brown5ec6b552017-03-31 12:11:40 -07004149 /* conditionally restart the bw timer */
4150 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 /* Adapter removed. Decrement vdev count */
4153 if (hdd_ctx->current_intf_count != 0)
4154 hdd_ctx->current_intf_count--;
4155
4156 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304157 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304159
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304160 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161}
4162
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004163/**
4164 * hdd_close_all_adapters - Close all open adapters
4165 * @hdd_ctx: Hdd context
4166 * rtnl_held: True if RTNL lock held
4167 *
4168 * Close all open adapters.
4169 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304170 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004171 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004172QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173{
4174 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304175 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176
4177 ENTER();
4178
4179 do {
4180 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304181 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304182 wlan_hdd_release_intf_addr(hdd_ctx,
4183 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004185 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304186 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304187 /* Adapter removed. Decrement vdev count */
4188 if (hdd_ctx->current_intf_count != 0)
4189 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304191 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192
4193 EXIT();
4194
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304195 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196}
4197
Jeff Johnson9d295242017-08-29 14:39:48 -07004198void wlan_hdd_reset_prob_rspies(struct hdd_adapter *pHostapdAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304200 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004204 case QDF_STA_MODE:
4205 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004207 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004209 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 break;
4211 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004212 case QDF_SAP_MODE:
4213 case QDF_P2P_GO_MODE:
4214 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004216 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217 break;
4218 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004219 case QDF_FTM_MODE:
4220 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 default:
4222 /*
4223 * wlan_hdd_reset_prob_rspies should not have been called
4224 * for these kind of devices
4225 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004226 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227 pHostapdAdapter->device_mode);
4228 return;
4229 }
4230
Anurag Chouhanc5548422016-02-24 18:33:27 +05304231 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4233 updateIE.ieBufferlength = 0;
4234 updateIE.pAdditionIEBuffer = NULL;
4235 updateIE.append = true;
4236 updateIE.notify = false;
4237 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4238 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304239 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004240 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004241 }
4242}
4243
Jeff Johnson9d295242017-08-29 14:39:48 -07004244QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 const bool bCloseSession)
4246{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304247 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4249 union iwreq_data wrqu;
4250 tSirUpdateIE updateIE;
4251 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004252 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253
4254 ENTER();
4255
Sachin Ahuja988fd102016-09-15 17:16:25 +05304256 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004257 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304258 wlan_hdd_netif_queue_control(adapter,
4259 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4260 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004262 case QDF_STA_MODE:
4263 case QDF_P2P_CLIENT_MODE:
4264 case QDF_IBSS_MODE:
4265 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004266 case QDF_NDI_MODE:
4267 if ((QDF_NDI_MODE == adapter->device_mode) ||
4268 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4270 hdd_is_connecting(
4271 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004272 INIT_COMPLETION(adapter->disconnect_comp_var);
4273 /*
4274 * For NDI do not use pWextState from sta_ctx, if needed
4275 * extract from ndi_ctx.
4276 */
4277 if (QDF_NDI_MODE == adapter->device_mode)
4278 qdf_ret_status = sme_roam_disconnect(
4279 hdd_ctx->hHal,
4280 adapter->sessionId,
4281 eCSR_DISCONNECT_REASON_NDI_DELETE);
4282 else if (pWextState->roamProfile.BSSType ==
4283 eCSR_BSS_TYPE_START_IBSS)
4284 qdf_ret_status = sme_roam_disconnect(
4285 hdd_ctx->hHal,
4286 adapter->sessionId,
4287 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004288 else if (QDF_STA_MODE == adapter->device_mode)
4289 qdf_ret_status =
4290 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004292 qdf_ret_status = sme_roam_disconnect(
4293 hdd_ctx->hHal,
4294 adapter->sessionId,
4295 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004296 /* success implies disconnect command got
4297 * queued up successfully
4298 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004299 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4300 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 rc = wait_for_completion_timeout(
4302 &adapter->disconnect_comp_var,
4303 msecs_to_jiffies
4304 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004305 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004306 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004308 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4309 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310 memset(&wrqu, '\0', sizeof(wrqu));
4311 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4312 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4313 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4314 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304315 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004316 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304317 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004318
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304319 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304320 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321
4322#ifdef WLAN_OPEN_SOURCE
4323 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4324#endif
4325
4326 hdd_deregister_tx_flow_control(adapter);
4327
4328#ifdef WLAN_NS_OFFLOAD
4329#ifdef WLAN_OPEN_SOURCE
4330 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4331#endif
4332#endif
4333
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304334 if (adapter->device_mode == QDF_STA_MODE)
4335 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4336 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337 /*
4338 * It is possible that the caller of this function does not
4339 * wish to close the session
4340 */
Krunal Soni985b8132017-02-10 18:49:08 -08004341 if (true == bCloseSession) {
4342 if (0 != wlan_hdd_try_disconnect(adapter)) {
4343 hdd_err("Error: Can't disconnect adapter");
4344 return QDF_STATUS_E_FAILURE;
4345 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004346 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 break;
4349
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004350 case QDF_SAP_MODE:
4351 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004353 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4355
4356 hdd_deregister_tx_flow_control(adapter);
4357
Kapil Guptac1224bf2017-06-22 21:22:40 +05304358 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359 mutex_lock(&hdd_ctx->sap_lock);
4360 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304361 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304362 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363
4364 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365 status = wlansap_stop_bss(
4366 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304368 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 hdd_hostapd_state_t *hostapd_state =
4370 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304371 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304372 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304373 qdf_status =
4374 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004375 qdf_stop_bss_event,
4376 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377
Anurag Chouhance0dc992016-02-16 18:18:03 +05304378 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004379 hdd_err("failure waiting for wlansap_stop_bss %d",
4380 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 }
4382 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004383 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 }
4385 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004386 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4387 adapter->device_mode,
4388 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389
Anurag Chouhanc5548422016-02-24 18:33:27 +05304390 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004391 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392 updateIE.smeSessionId = adapter->sessionId;
4393 updateIE.ieBufferlength = 0;
4394 updateIE.pAdditionIEBuffer = NULL;
4395 updateIE.append = false;
4396 updateIE.notify = false;
4397 /* Probe bcn reset */
4398 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4399 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304400 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004401 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 }
4403 /* Assoc resp reset */
4404 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4405 &updateIE,
4406 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304407 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004408 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409 }
4410 /* Reset WNI_CFG_PROBE_RSP Flags */
4411 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004413 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4414 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304415 /*
4416 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4417 */
4418 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4419 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4420
Peng Xu66162de2016-02-11 17:01:20 -08004421 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004422 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004423 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004425 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004426 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004427 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004428 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 break;
4430 default:
4431 break;
4432 }
4433
4434 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436}
4437
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304438/**
4439 * hdd_deinit_all_adapters - deinit all adapters
4440 * @hdd_ctx: HDD context
4441 * @rtnl_held: True if RTNL lock held
4442 *
4443 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004444void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304445{
4446 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4447 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004448 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304449
4450 ENTER();
4451
4452 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4453
4454 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4455 adapter = adapter_node->pAdapter;
4456 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4457 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4458 adapter_node = next;
4459 }
4460
4461 EXIT();
4462}
4463
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004464QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465{
4466 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304467 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004468 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469
4470 ENTER();
4471
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304472 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4475
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304476 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004477 adapter = adapterNode->pAdapter;
4478 hdd_stop_adapter(hdd_ctx, adapter, true);
4479 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4480 adapterNode = pNext;
4481 }
4482
4483 EXIT();
4484
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304485 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486}
4487
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004488QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489{
4490 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304491 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004492 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004493 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004494 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495
4496 ENTER();
4497
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304498 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304502 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004503 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004504 hdd_notice("Disabling queues for adapter type: %d",
4505 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304506
4507 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004508 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304509 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004510 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304511
Arun Khandavallicc544b32017-01-30 19:52:16 +05304512 if (hdd_ctx->config->sap_internal_restart &&
4513 adapter->device_mode == QDF_SAP_MODE) {
4514 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304515 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304516 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004517 if (test_bit(SOFTAP_BSS_STARTED,
4518 &adapter->event_flags)) {
4519 hdd_sap_indicate_disconnect_for_sta(adapter);
4520 hdd_cleanup_actionframe(hdd_ctx, adapter);
4521 hdd_sap_destroy_events(adapter);
4522 }
4523 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4524 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304525 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304526 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004528 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004529
4530 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4531
4532 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004533 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4534 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4536 hdd_wmm_adapter_close(adapter);
4537 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4538 }
4539
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304540 hdd_clear_fils_connection_info(adapter);
Wu Gao3545e642017-07-14 19:24:41 +08004541 if (adapter->device_mode == QDF_SAP_MODE) {
4542 /*
4543 * If adapter is SAP, set session ID to invalid
4544 * since SAP session will be cleanup during SSR.
4545 */
Wu Gao36717432016-11-21 15:09:48 +08004546 wlansap_set_invalid_session(
4547 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4548
Wu Gao3545e642017-07-14 19:24:41 +08004549 wlansap_cleanup_cac_timer(
4550 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4551 }
4552
Yue Mad5b4b9f2017-05-26 16:23:40 -07004553 /* Delete peers if any for STA and P2P client modes */
4554 if (adapter->device_mode == QDF_STA_MODE ||
4555 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4556 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4557 qdf_copy_macaddr(&peerMacAddr,
4558 &pHddStaCtx->conn_info.bssId);
4559
4560 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4561 peerMacAddr.bytes);
4562 }
4563
Yue Maf9782842017-05-08 12:49:49 -07004564 /* Destroy vdev which will be recreated during reinit. */
4565 hdd_vdev_destroy(adapter);
4566
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4568 adapterNode = pNext;
4569 }
4570
4571 EXIT();
4572
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304573 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574}
4575
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004576bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304577{
4578 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4579 QDF_STATUS status;
4580 bool close_modules = true;
4581
Arun Khandavalliba479c42017-07-26 21:29:40 +05304582 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4583 hdd_info("FTM mode, don't close the module");
4584 return false;
4585 }
4586
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304587 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4588 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4589 if (test_bit(DEVICE_IFACE_OPENED,
4590 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004591 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304592 close_modules = false;
4593 break;
4594 }
4595 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4596 adapter_node = next;
4597 }
4598
4599 return close_modules;
4600}
4601
Arun Khandavallifae92942016-08-01 13:31:08 +05304602/**
4603 * hdd_is_interface_up()- Checkfor interface up before ssr
4604 * @hdd_ctx: HDD context
4605 *
4606 * check if there are any wlan interfaces before SSR accordingly start
4607 * the interface.
4608 *
4609 * Return: 0 if interface was opened else false
4610 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004611static bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304612{
4613 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4614 return true;
4615 else
4616 return false;
4617}
4618
Anurag Chouhanc4092922016-09-08 15:56:11 +05304619#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004620 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304621struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4622 struct ieee80211_channel *channel,
4623 const u8 *bssid, const u8 *ssid,
4624 size_t ssid_len)
4625{
4626 return cfg80211_get_bss(wiphy, channel, bssid,
4627 ssid, ssid_len,
4628 WLAN_CAPABILITY_ESS,
4629 WLAN_CAPABILITY_ESS);
4630}
4631#else
4632struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4633 struct ieee80211_channel *channel,
4634 const u8 *bssid, const u8 *ssid,
4635 size_t ssid_len)
4636{
4637 return cfg80211_get_bss(wiphy, channel, bssid,
4638 ssid, ssid_len,
4639 IEEE80211_BSS_TYPE_ESS,
4640 IEEE80211_PRIVACY_ANY);
4641}
4642#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304643
Abhishek Singha84d3952016-09-13 13:45:05 +05304644#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304645#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4646 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4647/**
4648 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4649 * @timeout_reason: reason for connect timeout
4650 *
4651 * This function is used to convert host timeout
4652 * reason enum to kernel specific enum.
4653 *
4654 * Return: nl timeout enum
4655 */
4656static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4657 tSirResultCodes timeout_reason)
4658{
4659 switch (timeout_reason) {
4660 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4661 return NL80211_TIMEOUT_SCAN;
4662 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4663 return NL80211_TIMEOUT_AUTH;
4664 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4665 return NL80211_TIMEOUT_ASSOC;
4666 default:
4667 return NL80211_TIMEOUT_UNSPECIFIED;
4668 }
4669}
4670
4671/**
4672 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4673 * @dev: network device
4674 * @bssid: bssid to which we want to associate
4675 * @timeout_reason: reason for connect timeout
4676 *
4677 * This API is used to send connection timeout reason to supplicant
4678 *
4679 * Return: void
4680 */
4681static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4682 const u8 *bssid,
4683 tSirResultCodes timeout_reason)
4684{
4685 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004686
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304687 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4688
4689 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4690 nl_timeout_reason);
4691}
4692
4693/**
4694 * __hdd_connect_bss() - API to send connection status to supplicant
4695 * @dev: network device
4696 * @bssid: bssid to which we want to associate
4697 * @req_ie: Request Information Element
4698 * @req_ie_len: len of the req IE
4699 * @resp_ie: Response IE
4700 * @resp_ie_len: len of ht response IE
4701 * @status: status
4702 * @gfp: Kernel Flag
4703 * @timeout_reason: reason for connect timeout
4704 *
4705 * Return: void
4706 */
4707static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4708 struct cfg80211_bss *bss, const u8 *req_ie,
4709 size_t req_ie_len, const u8 *resp_ie,
4710 size_t resp_ie_len, int status, gfp_t gfp,
4711 tSirResultCodes timeout_reason)
4712{
4713 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004714
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304715 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4716
4717 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4718 resp_ie, resp_ie_len, status, gfp,
4719 nl_timeout_reason);
4720}
4721#else
4722#if defined CFG80211_CONNECT_TIMEOUT
4723static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4724 const u8 *bssid,
4725 tSirResultCodes timeout_reason)
4726{
4727 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4728}
4729#endif
4730
4731static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4732 struct cfg80211_bss *bss, const u8 *req_ie,
4733 size_t req_ie_len, const u8 *resp_ie,
4734 size_t resp_ie_len, int status, gfp_t gfp,
4735 tSirResultCodes timeout_reason)
4736{
4737 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4738 resp_ie, resp_ie_len, status, gfp);
4739}
4740#endif
4741
Abhishek Singha84d3952016-09-13 13:45:05 +05304742/**
4743 * hdd_connect_bss() - API to send connection status to supplicant
4744 * @dev: network device
4745 * @bssid: bssid to which we want to associate
4746 * @req_ie: Request Information Element
4747 * @req_ie_len: len of the req IE
4748 * @resp_ie: Response IE
4749 * @resp_ie_len: len of ht response IE
4750 * @status: status
4751 * @gfp: Kernel Flag
4752 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304753 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304754 *
4755 * The API is a wrapper to send connection status to supplicant
4756 *
4757 * Return: Void
4758 */
4759#if defined CFG80211_CONNECT_TIMEOUT
4760static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4761 struct cfg80211_bss *bss, const u8 *req_ie,
4762 size_t req_ie_len, const u8 *resp_ie,
4763 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304764 bool connect_timeout,
4765 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304766{
4767 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304768 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304769 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304770 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4771 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304772}
4773#else
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,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304778 bool connect_timeout,
4779 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304780{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304781 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4782 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304783}
4784#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304785
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304786#ifdef WLAN_FEATURE_FILS_SK
4787#ifdef CFG80211_CONNECT_DONE
4788#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4789/**
4790 * hdd_populate_fils_params() - Populate FILS keys to connect response
4791 * @fils_params: connect response to supplicant
4792 * @fils_kek: FILS kek
4793 * @fils_kek_len: FILS kek length
4794 * @pmk: FILS PMK
4795 * @pmk_len: FILS PMK length
4796 * @pmkid: PMKID
4797 * @fils_seq_num: FILS Seq number
4798 *
4799 * Return: None
4800 */
4801static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4802 *fils_params, const uint8_t *fils_kek,
4803 size_t fils_kek_len, const uint8_t *pmk,
4804 size_t pmk_len, const uint8_t *pmkid,
4805 uint16_t fils_seq_num)
4806{
4807 /* Increament seq number to be used for next FILS */
4808 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4809 fils_params->update_erp_next_seq_num = true;
4810 fils_params->fils_kek = fils_kek;
4811 fils_params->fils_kek_len = fils_kek_len;
4812 fils_params->pmk = pmk;
4813 fils_params->pmk_len = pmk_len;
4814 fils_params->pmkid = pmkid;
4815}
4816#else
4817static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4818 *fils_params, const uint8_t
4819 *fils_kek, size_t fils_kek_len,
4820 const uint8_t *pmk, size_t pmk_len,
4821 const uint8_t *pmkid,
4822 uint16_t fils_seq_num)
4823{ }
4824#endif
4825
4826/**
4827 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4828 * @dev: network device
4829 * @bssid: bssid to which we want to associate
4830 * @bss: cfg80211 bss info
4831 * @roam_info: information about connected bss
4832 * @req_ie: Request Information Element
4833 * @req_ie_len: len of the req IE
4834 * @resp_ie: Response IE
4835 * @resp_ie_len: len of ht response IE
4836 * @status: status
4837 * @gfp: allocation flags
4838 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4839 * @timeout_reason: reason for connect timeout
4840 * @roam_fils_params: FILS join response params
4841 *
4842 * This API is used as wrapper to send FILS key/sequence number
4843 * params etc. to supplicant in case of FILS connection
4844 *
4845 * Return: None
4846 */
4847static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4848 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4849 const u8 *req_ie, size_t req_ie_len,
4850 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4851 gfp_t gfp, bool connect_timeout, tSirResultCodes
4852 timeout_reason, struct fils_join_rsp_params
4853 *roam_fils_params)
4854{
4855 struct cfg80211_connect_resp_params fils_params;
4856 qdf_mem_zero(&fils_params, sizeof(fils_params));
4857
4858 if (!roam_fils_params) {
4859 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4860 } else {
4861 fils_params.status = status;
4862 fils_params.bssid = bssid;
4863 fils_params.timeout_reason = timeout_reason;
4864 fils_params.req_ie = req_ie;
4865 fils_params.req_ie_len = req_ie_len;
4866 fils_params.resp_ie = resp_ie;
4867 fils_params.resp_ie_len = resp_ie_len;
4868 fils_params.bss = bss;
4869 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4870 roam_fils_params->kek_len,
4871 roam_fils_params->fils_pmk,
4872 roam_fils_params->fils_pmk_len,
4873 roam_fils_params->fils_pmkid,
4874 roam_info->fils_seq_num);
4875 }
4876 hdd_debug("FILS indicate connect status %d seq no %d",
4877 fils_params.status,
4878 fils_params.fils_erp_next_seq_num);
4879
4880 cfg80211_connect_done(dev, &fils_params, gfp);
4881
4882 /* Clear all the FILS key info */
4883 if (roam_fils_params && roam_fils_params->fils_pmk)
4884 qdf_mem_free(roam_fils_params->fils_pmk);
4885 if (roam_fils_params)
4886 qdf_mem_free(roam_fils_params);
4887 roam_info->fils_join_rsp = NULL;
4888}
4889#else
4890static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4891 struct cfg80211_bss *bss, tCsrRoamInfo
4892 *roam_info, const u8 *req_ie,
4893 size_t req_ie_len, const u8 *resp_ie,
4894 size_t resp_ie_len, u16 status, gfp_t gfp,
4895 bool connect_timeout, tSirResultCodes
4896 timeout_reason, struct fils_join_rsp_params
4897 *roam_fils_params)
4898{ }
4899#endif
4900#endif
4901
4902#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4903/**
4904 * hdd_fils_update_connect_results() - API to send fils connection status to
4905 * supplicant.
4906 * @dev: network device
4907 * @bssid: bssid to which we want to associate
4908 * @bss: cfg80211 bss info
4909 * @roam_info: information about connected bss
4910 * @req_ie: Request Information Element
4911 * @req_ie_len: len of the req IE
4912 * @resp_ie: Response IE
4913 * @resp_ie_len: len of ht response IE
4914 * @status: status
4915 * @gfp: allocation flags
4916 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4917 * @timeout_reason: reason for connect timeout
4918 *
4919 * The API is a wrapper to send connection status to supplicant
4920 *
4921 * Return: 0 if success else failure
4922 */
4923static int hdd_fils_update_connect_results(struct net_device *dev,
4924 const u8 *bssid,
4925 struct cfg80211_bss *bss,
4926 tCsrRoamInfo *roam_info, const u8 *req_ie,
4927 size_t req_ie_len, const u8 *resp_ie,
4928 size_t resp_ie_len, u16 status, gfp_t gfp,
4929 bool connect_timeout,
4930 tSirResultCodes timeout_reason)
4931{
4932 ENTER();
4933 if (!roam_info || !roam_info->is_fils_connection)
4934 return -EINVAL;
4935
4936 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4937 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4938 timeout_reason, roam_info->fils_join_rsp);
4939 return 0;
4940}
4941#else
4942static inline int hdd_fils_update_connect_results(struct net_device *dev,
4943 const u8 *bssid,
4944 struct cfg80211_bss *bss,
4945 tCsrRoamInfo *roam_info, const u8 *req_ie,
4946 size_t req_ie_len, const u8 *resp_ie,
4947 size_t resp_ie_len, u16 status, gfp_t gfp,
4948 bool connect_timeout,
4949 tSirResultCodes timeout_reason)
4950{
4951 return -EINVAL;
4952}
4953#endif
4954
Anurag Chouhanc4092922016-09-08 15:56:11 +05304955/**
4956 * hdd_connect_result() - API to send connection status to supplicant
4957 * @dev: network device
4958 * @bssid: bssid to which we want to associate
4959 * @roam_info: information about connected bss
4960 * @req_ie: Request Information Element
4961 * @req_ie_len: len of the req IE
4962 * @resp_ie: Response IE
4963 * @resp_ie_len: len of ht response IE
4964 * @status: status
4965 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304966 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304967 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304968 *
4969 * The API is a wrapper to send connection status to supplicant
4970 * and allow runtime suspend
4971 *
4972 * Return: Void
4973 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304974void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4975 tCsrRoamInfo *roam_info, const u8 *req_ie,
4976 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304977 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304978 bool connect_timeout,
4979 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304980{
Jeff Johnson9d295242017-08-29 14:39:48 -07004981 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304982 struct cfg80211_bss *bss = NULL;
4983
4984 if (WLAN_STATUS_SUCCESS == status) {
4985 struct ieee80211_channel *chan;
4986 int freq;
4987 int chan_no = roam_info->pBssDesc->channelId;
4988
4989 if (chan_no <= 14)
4990 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004991 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304992 else
4993 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004994 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304995
4996 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4997 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4998 roam_info->u.pConnectedProfile->SSID.ssId,
4999 roam_info->u.pConnectedProfile->SSID.length);
5000 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305001
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305002 if (hdd_fils_update_connect_results(dev, bssid, bss,
5003 roam_info, req_ie, req_ie_len, resp_ie,
5004 resp_ie_len, status, gfp, connect_timeout,
5005 timeout_reason) != 0) {
5006 hdd_connect_bss(dev, bssid, bss, req_ie,
5007 req_ie_len, resp_ie, resp_ie_len,
5008 status, gfp, connect_timeout, timeout_reason);
5009 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305010
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005011 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005012 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305013}
5014#else
5015void hdd_connect_result(struct net_device *dev, const u8 *bssid,
5016 tCsrRoamInfo *roam_info, const u8 *req_ie,
5017 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305018 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305019 bool connect_timeout,
5020 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305021{
Jeff Johnson9d295242017-08-29 14:39:48 -07005022 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305023
Anurag Chouhanc4092922016-09-08 15:56:11 +05305024 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5025 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005026
5027 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005028 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305029}
5030#endif
5031
5032
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005033QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034{
5035 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305036 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005037 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305039 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005040#endif
5041 eConnectionState connState;
5042
5043 ENTER();
5044
5045 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305046 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047 adapter = adapterNode->pAdapter;
5048
Arun Khandavallifae92942016-08-01 13:31:08 +05305049 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305050 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052 hdd_wmm_init(adapter);
5053
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005054 adapter->scan_info.mScanPending = false;
5055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005057 case QDF_STA_MODE:
5058 case QDF_P2P_CLIENT_MODE:
5059 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060
5061 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5062 ->conn_info.connState;
5063
5064 hdd_init_station_mode(adapter);
5065 /* Open the gates for HDD to receive Wext commands */
5066 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005067
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005068 /* Indicate disconnect event to supplicant
5069 * if associated previously
5070 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005072 eConnectionState_IbssConnected == connState ||
5073 eConnectionState_NotConnected == connState ||
5074 eConnectionState_IbssDisconnected == connState ||
5075 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078 memset(&wrqu, '\0', sizeof(wrqu));
5079 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5080 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5081 wireless_send_event(adapter->dev, SIOCGIWAP,
5082 &wrqu, NULL);
5083 adapter->sessionCtx.station.
5084 hdd_ReassocScenario = false;
5085
5086 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305087 wlan_hdd_cfg80211_indicate_disconnect(
5088 adapter->dev, false,
5089 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090 } else if (eConnectionState_Connecting == connState) {
5091 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005092 * Indicate connect failure to supplicant if we
5093 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305095 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305096 NULL, 0, NULL, 0,
5097 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005098 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 }
5100
5101 hdd_register_tx_flow_control(adapter,
5102 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005103 hdd_tx_resume_cb,
5104 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105
5106 break;
5107
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005108 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005109 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305110 hdd_init_ap_mode(adapter, true);
5111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112 break;
5113
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005114 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005116 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5118#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005119 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 /* event supplicant to restart */
5121 cfg80211_del_sta(adapter->dev,
5122 (const u8 *)&bcastMac.bytes[0],
5123 GFP_KERNEL);
5124#endif
5125 break;
5126
5127 default:
5128 break;
5129 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005130 /*
5131 * Action frame registered in one adapter which will
5132 * applicable to all interfaces
5133 */
5134 wlan_hdd_cfg80211_register_frames(adapter);
5135
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305136get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5138 adapterNode = pNext;
5139 }
5140
5141 EXIT();
5142
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305143 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144}
5145
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005146QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 hdd_adapter_list_node_t **padapterNode)
5148{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305149 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005150
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005151 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305152 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5153 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005154 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155 return status;
5156}
5157
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005158QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 hdd_adapter_list_node_t *adapterNode,
5160 hdd_adapter_list_node_t **pNextAdapterNode)
5161{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305162 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005163
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005164 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305165 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5166 (qdf_list_node_t *) adapterNode,
5167 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005169 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 return status;
5171}
5172
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005173QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 hdd_adapter_list_node_t *adapterNode)
5175{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305176 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005177
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005178 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305179 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005181 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005182 return status;
5183}
5184
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005185QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005186 hdd_adapter_list_node_t **padapterNode)
5187{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305188 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005189
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005190 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305191 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5192 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005193 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 return status;
5195}
5196
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005197QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 hdd_adapter_list_node_t *adapterNode)
5199{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305200 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005201
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005202 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305203 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5204 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005205 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 return status;
5207}
5208
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005209QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 hdd_adapter_list_node_t *adapterNode)
5211{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305212 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005213
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005214 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305215 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5216 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005217 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 return status;
5219}
5220
Jeff Johnson9d295242017-08-29 14:39:48 -07005221struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222 tSirMacAddr macAddr)
5223{
5224 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005225 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305226 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227
5228 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5229
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305230 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 adapter = adapterNode->pAdapter;
5232
5233 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305234 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005235 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005237
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5239 adapterNode = pNext;
5240 }
5241
5242 return NULL;
5243
5244}
5245
Jeff Johnson9d295242017-08-29 14:39:48 -07005246struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005247 uint32_t vdev_id)
5248{
5249 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005250 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305251 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305253 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305255 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256 adapter = adapterNode->pAdapter;
5257
5258 if (adapter->sessionId == vdev_id)
5259 return adapter;
5260
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305261 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5263 adapterNode = pNext;
5264 }
5265
Jeff Johnson5880d792016-08-15 13:32:30 -07005266 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267
5268 return NULL;
5269}
5270
Abhishek Singh7996eb72015-12-30 17:24:02 +05305271/**
5272 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5273 * the sessionid
5274 * @hdd_ctx: hdd context.
5275 * @sme_session_id: sme session is for the adapter to get.
5276 *
5277 * This function is used to get the adapter with provided session id
5278 *
5279 * Return: adapter pointer if found
5280 *
5281 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005282struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305283 uint32_t sme_session_id)
5284{
5285 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005286 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305287 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305288
5289
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305290 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305291
5292 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305293 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305294 adapter = adapter_node->pAdapter;
5295
5296 if (adapter &&
5297 adapter->sessionId == sme_session_id)
5298 return adapter;
5299
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305300 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305301 hdd_get_next_adapter(hdd_ctx,
5302 adapter_node, &next);
5303 adapter_node = next;
5304 }
5305 return NULL;
5306}
5307
Jeff Johnson9d295242017-08-29 14:39:48 -07005308struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005309 const char *iface_name)
5310{
5311 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005312 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005313 QDF_STATUS qdf_status;
5314
5315 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5316
5317 while ((NULL != adapter_node) &&
5318 (QDF_STATUS_SUCCESS == qdf_status)) {
5319 adapter = adapter_node->pAdapter;
5320
5321 if (adapter &&
5322 !qdf_str_cmp(adapter->dev->name, iface_name))
5323 return adapter;
5324
5325 qdf_status =
5326 hdd_get_next_adapter(hdd_ctx,
5327 adapter_node, &next);
5328 adapter_node = next;
5329 }
5330 return NULL;
5331}
5332
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005333/**
5334 * hdd_get_adapter() - to get adapter matching the mode
5335 * @hdd_ctx: hdd context
5336 * @mode: adapter mode
5337 *
5338 * This routine will return the pointer to adapter matching
5339 * with the passed mode.
5340 *
5341 * Return: pointer to adapter or null
5342 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005343struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005344 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345{
5346 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005347 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305348 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349
5350 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305352 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 adapter = adapterNode->pAdapter;
5354
5355 if (adapter && (mode == adapter->device_mode))
5356 return adapter;
5357
5358 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5359 adapterNode = pNext;
5360 }
5361
5362 return NULL;
5363
5364}
5365
5366/**
5367 * hdd_get_operating_channel() - return operating channel of the device mode
5368 * @hdd_ctx: Pointer to the HDD context.
5369 * @mode: Device mode for which operating channel is required.
5370 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005371 * QDF_STA_MODE,
5372 * QDF_P2P_CLIENT_MODE,
5373 * QDF_SAP_MODE,
5374 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375 *
5376 * This API returns the operating channel of the requested device mode
5377 *
5378 * Return: channel number. "0" id the requested device is not found OR it is
5379 * not connected.
5380 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005381uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005382 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005383{
5384 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305385 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005386 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387 uint8_t operatingChannel = 0;
5388
5389 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5390
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305391 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 adapter = adapterNode->pAdapter;
5393
5394 if (mode == adapter->device_mode) {
5395 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005396 case QDF_STA_MODE:
5397 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398 if (hdd_conn_is_connected
5399 (WLAN_HDD_GET_STATION_CTX_PTR
5400 (adapter))) {
5401 operatingChannel =
5402 (WLAN_HDD_GET_STATION_CTX_PTR
5403 (adapter))->conn_info.
5404 operationChannel;
5405 }
5406 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005407 case QDF_SAP_MODE:
5408 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005409 /* softap connection info */
5410 if (test_bit
5411 (SOFTAP_BSS_STARTED,
5412 &adapter->event_flags))
5413 operatingChannel =
5414 (WLAN_HDD_GET_AP_CTX_PTR
5415 (adapter))->operatingChannel;
5416 break;
5417 default:
5418 break;
5419 }
5420
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005421 /* Found the device of interest. break the loop */
5422 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423 }
5424
5425 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5426 adapterNode = pNext;
5427 }
5428 return operatingChannel;
5429}
5430
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005431static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 hdd_ctx)
5433{
5434 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305435 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005436 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437
5438 ENTER();
5439
5440 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5441
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305442 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005444 if ((adapter->device_mode == QDF_STA_MODE) ||
5445 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5446 (adapter->device_mode == QDF_IBSS_MODE) ||
5447 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5448 (adapter->device_mode == QDF_SAP_MODE) ||
5449 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005450 wlan_hdd_cfg80211_deregister_frames(adapter);
5451 hdd_unregister_wext(adapter->dev);
5452 }
5453 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5454 adapterNode = pNext;
5455 }
5456
5457 EXIT();
5458
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305459 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460}
5461
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005462QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005463{
5464 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305465 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005466 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005467
5468 ENTER();
5469
5470 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305472 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005473 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005474 if ((adapter->device_mode == QDF_STA_MODE) ||
5475 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5476 (adapter->device_mode == QDF_IBSS_MODE) ||
5477 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5478 (adapter->device_mode == QDF_SAP_MODE) ||
5479 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305480 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5481 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005482 }
5483 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5484 adapterNode = pNext;
5485 }
5486
5487 EXIT();
5488
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305489 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490}
5491
Dustin Brownf27bce82016-11-03 12:52:27 -07005492/**
5493 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5494 * adapters
5495 * @hdd_ctx: The HDD context containing the adapters to operate on
5496 *
5497 * return: QDF_STATUS_SUCCESS
5498 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005499static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005500{
5501 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5502 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005503 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005504 int err;
5505
5506 ENTER();
5507
5508 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5509
5510 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5511 adapter = adapter_node->pAdapter;
5512 if ((adapter->device_mode == QDF_STA_MODE) ||
5513 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5514 (adapter->device_mode == QDF_IBSS_MODE) ||
5515 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5516 (adapter->device_mode == QDF_SAP_MODE) ||
5517 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5518 err = wlan_hdd_sched_scan_stop(adapter->dev);
5519 if (err)
5520 hdd_err("Unable to stop scheduled scan");
5521 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005522 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5523 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005524 adapter_node = next_node;
5525 }
5526
5527 EXIT();
5528
5529 return QDF_STATUS_SUCCESS;
5530}
5531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005532#ifdef WLAN_NS_OFFLOAD
5533/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005534 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535 * @hdd_ctx: Pointer to hdd context
5536 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005537 * Unregister for IPv6 address change notifications.
5538 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005539 * Return: None
5540 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005541static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542{
5543 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544}
5545
5546/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005547 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548 * @hdd_ctx: Pointer to hdd context
5549 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005550 * Register for IPv6 address change notifications.
5551 *
5552 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005554static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555{
5556 int ret;
5557
5558 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5559 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005560 if (ret) {
5561 hdd_err("Failed to register IPv6 notifier: %d", ret);
5562 goto out;
5563 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005564
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005565 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005566out:
5567 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005568}
5569#else
5570/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005571 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572 * @hdd_ctx: Pointer to hdd context
5573 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005574 * Unregister for IPv6 address change notifications.
5575 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005576 * Return: None
5577 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005578static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579{
5580}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005581
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005583 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584 * @hdd_ctx: Pointer to hdd context
5585 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005586 * Register for IPv6 address change notifications.
5587 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 * Return: None
5589 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005590static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005591{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005592 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593}
5594#endif
5595
5596/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005597 * hdd_register_notifiers - Register netdev notifiers.
5598 * @hdd_ctx: HDD context
5599 *
5600 * Register netdev notifiers like IPv4 and IPv6.
5601 *
5602 * Return: 0 on success and errno on failure
5603 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005604static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005605{
5606 int ret;
5607
5608 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5609 if (ret) {
5610 hdd_err("register_netdevice_notifier failed: %d", ret);
5611 goto out;
5612 }
5613
5614 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5615 if (ret)
5616 goto unregister_notifier;
5617
5618 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5619 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5620 if (ret) {
5621 hdd_err("Failed to register IPv4 notifier: %d", ret);
5622 goto unregister_ip6_notifier;
5623 }
5624
5625 return 0;
5626
5627unregister_ip6_notifier:
5628 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5629unregister_notifier:
5630 unregister_netdevice_notifier(&hdd_netdev_notifier);
5631out:
5632 return ret;
5633
5634}
5635
5636/**
5637 * hdd_unregister_notifiers - Unregister netdev notifiers.
5638 * @hdd_ctx: HDD context
5639 *
5640 * Unregister netdev notifiers like IPv4 and IPv6.
5641 *
5642 * Return: None.
5643 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005644void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005645{
5646 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5647
5648 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5649
5650 unregister_netdevice_notifier(&hdd_netdev_notifier);
5651}
5652
5653/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005654 * hdd_exit_netlink_services - Exit netlink services
5655 * @hdd_ctx: HDD context
5656 *
5657 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5658 * nl service.
5659 *
5660 * Return: None.
5661 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005662static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005663{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005664 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005665 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005666 ptt_sock_deactivate_svc();
5667
5668 nl_srv_exit();
5669}
5670
5671/**
5672 * hdd_init_netlink_services- Init netlink services
5673 * @hdd_ctx: HDD context
5674 *
5675 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5676 * nl service.
5677 *
5678 * Return: 0 on success and errno on failure.
5679 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005680static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005681{
5682 int ret;
5683
Ryan Hsuceddceb2016-04-28 10:20:14 -07005684 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005685 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005686 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005687 goto out;
5688 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005689 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005690
Naveen Rawat910726a2017-03-06 11:42:51 -08005691 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005692 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005693 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005694 goto err_nl_srv;
5695 }
5696
5697 ret = ptt_sock_activate_svc();
5698 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005699 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005700 goto err_nl_srv;
5701 }
5702
5703 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005704 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005705 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005706
5707 ret = cnss_diag_activate_service();
5708 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005709 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005710 goto err_close_cesium;
5711 }
5712
5713 return 0;
5714
5715err_close_cesium:
5716 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005717 ptt_sock_deactivate_svc();
5718err_nl_srv:
5719 nl_srv_exit();
5720out:
5721 return ret;
5722}
5723
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005724/**
5725 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5726 * @hdd_ctx: HDD context.
5727 *
5728 * Destroy RX wakelock.
5729 *
5730 * Return: None.
5731 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005732static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005733{
5734 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5735}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005736
5737/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005738 * hdd_rx_wake_lock_create() - Create RX wakelock
5739 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005740 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005741 * Create RX wakelock.
5742 *
5743 * Return: None.
5744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005745static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005746{
5747 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5748}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005749
5750/**
5751 * hdd_roc_context_init() - Init ROC context
5752 * @hdd_ctx: HDD context.
5753 *
5754 * Initialize ROC context.
5755 *
5756 * Return: 0 on success and errno on failure.
5757 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005758static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005759{
5760 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5761 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5762
5763 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5764
5765 return 0;
5766}
5767
5768/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305769 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5770 * @hdd_ctx: HDD context.
5771 *
5772 * Free memory allocations made in ROC Req Queue nodes.
5773 *
5774 * Return: None.
5775 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005776static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305777{
5778 hdd_roc_req_t *hdd_roc_req;
5779 QDF_STATUS status;
5780
5781 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5782
5783 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5784 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5785 (qdf_list_node_t **) &hdd_roc_req);
5786
5787 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305788 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5789 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305790 QDF_ASSERT(0);
5791 return;
5792 }
5793
5794 if (hdd_roc_req->pRemainChanCtx)
5795 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5796
5797 qdf_mem_free(hdd_roc_req);
5798 }
5799
5800 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5801}
5802
5803/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005804 * hdd_roc_context_destroy() - Destroy ROC context
5805 * @hdd_ctx: HDD context.
5806 *
5807 * Destroy roc list and flush the pending roc work.
5808 *
5809 * Return: None.
5810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005811static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005812{
5813 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305814 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005815 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005816}
5817
5818/**
Houston Hoffman160db392016-10-10 17:37:51 -07005819 * hdd_context_deinit() - Deinitialize HDD context
5820 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005821 *
Houston Hoffman160db392016-10-10 17:37:51 -07005822 * Deinitialize HDD context along with all the feature specific contexts but
5823 * do not free hdd context itself. Caller of this API is supposed to free
5824 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005825 *
Houston Hoffman160db392016-10-10 17:37:51 -07005826 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005827 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005828static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005829{
Houston Hoffman160db392016-10-10 17:37:51 -07005830 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005831
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005832 hdd_roc_context_destroy(hdd_ctx);
5833
5834 hdd_sap_context_destroy(hdd_ctx);
5835
5836 hdd_rx_wake_lock_destroy(hdd_ctx);
5837
5838 hdd_tdls_context_destroy(hdd_ctx);
5839
5840 hdd_scan_context_destroy(hdd_ctx);
5841
5842 qdf_list_destroy(&hdd_ctx->hddAdapters);
5843
Houston Hoffman160db392016-10-10 17:37:51 -07005844 return 0;
5845}
5846
5847/**
5848 * hdd_context_destroy() - Destroy HDD context
5849 * @hdd_ctx: HDD context to be destroyed.
5850 *
5851 * Free config and HDD context as well as destroy all the resources.
5852 *
5853 * Return: None
5854 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005855static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005856{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305857
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305858 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5859
Houston Hoffman160db392016-10-10 17:37:51 -07005860 hdd_context_deinit(hdd_ctx);
5861
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305862 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005863 hdd_ctx->config = NULL;
5864
5865 wiphy_free(hdd_ctx->wiphy);
5866}
5867
5868/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305869 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5870 *
5871 * This function is used to destroy bug report lock
5872 *
5873 * Return: None
5874 */
5875static void wlan_destroy_bug_report_lock(void)
5876{
5877 p_cds_contextType p_cds_context;
5878
5879 p_cds_context = cds_get_global_context();
5880 if (!p_cds_context) {
5881 hdd_err("cds context is NULL");
5882 return;
5883 }
5884
5885 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5886}
5887
5888/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005889 * hdd_wlan_exit() - HDD WLAN exit function
5890 * @hdd_ctx: Pointer to the HDD Context
5891 *
5892 * This is the driver exit point (invoked during rmmod)
5893 *
5894 * Return: None
5895 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005896static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005897{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305898 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005899 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305900 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901
5902 ENTER();
5903
Arun Khandavallifae92942016-08-01 13:31:08 +05305904 if (QDF_TIMER_STATE_RUNNING ==
5905 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005906 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305907 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908 }
5909
Arun Khandavallifae92942016-08-01 13:31:08 +05305910 if (!QDF_IS_STATUS_SUCCESS
5911 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5912 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005913
Arun Khandavallifae92942016-08-01 13:31:08 +05305914
5915 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916
Nitesh Shah61c10d92016-10-19 19:29:15 +05305917 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5918
Prashanth Bhattaab004382016-10-11 16:08:11 -07005919 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920
5921#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305922 if (QDF_TIMER_STATE_RUNNING ==
5923 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5924 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925 }
5926
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305927 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305928 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005929 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005930 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005931 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5932 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5933 hdd_ctx->last_acs_channel_list = NULL;
5934 hdd_ctx->num_of_channels = 0;
5935 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937
Arun Khandavallifae92942016-08-01 13:31:08 +05305938 mutex_lock(&hdd_ctx->iface_change_lock);
5939 driver_status = hdd_ctx->driver_status;
5940 mutex_unlock(&hdd_ctx->iface_change_lock);
5941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 /*
5943 * Powersave Offload Case
5944 * Disable Idle Power Save Mode
5945 */
5946 hdd_set_idle_ps_config(hdd_ctx, false);
5947
Arun Khandavallifae92942016-08-01 13:31:08 +05305948 if (driver_status != DRIVER_MODULES_CLOSED) {
5949 hdd_unregister_wext_all_adapters(hdd_ctx);
5950 /*
5951 * Cancel any outstanding scan requests. We are about to close
5952 * all of our adapters, but an adapter structure is what SME
5953 * passes back to our callback function. Hence if there
5954 * are any outstanding scan requests then there is a
5955 * race condition between when the adapter is closed and
5956 * when the callback is invoked. We try to resolve that
5957 * race condition here by canceling any outstanding scans
5958 * before we close the adapters.
5959 * Note that the scans may be cancelled in an asynchronous
5960 * manner, so ideally there needs to be some kind of
5961 * synchronization. Rather than introduce a new
5962 * synchronization here, we will utilize the fact that we are
5963 * about to Request Full Power, and since that is synchronized,
5964 * the expectation is that by the time Request Full Power has
5965 * completed, all scans will be cancelled
5966 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005967 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305968 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005969 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305970 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971 }
5972
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305973 wlan_destroy_bug_report_lock();
5974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005975 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305976 * Close the scheduler before calling cds_close to make sure
5977 * no thread is scheduled after the each module close is
5978 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 */
Jeff Johnson7d562272017-09-13 15:12:54 -07005980 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305981 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305982 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305983 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005985
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005986 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305987
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305988 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5989 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5990 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005992 /*
5993 * Close CDS
5994 * This frees pMac(HAL) context. There should not be any call
5995 * that requires pMac access after this.
5996 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005998 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005999 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006000
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006001 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006002
6003 hdd_ipa_cleanup(hdd_ctx);
6004
6005 /* Free up RoC request queue and flush workqueue */
6006 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306008 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306009 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306010 /*
6011 * If there is re_init failure wiphy would have already de-registered
6012 * check the wiphy status before un-registering again
6013 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306014 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306015 wiphy_unregister(wiphy);
6016 wlan_hdd_cfg80211_deinit(wiphy);
6017 hdd_lpass_notify_stop(hdd_ctx);
6018 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006019
Arun Khandavallifae92942016-08-01 13:31:08 +05306020 hdd_exit_netlink_services(hdd_ctx);
6021 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306022#ifdef FEATURE_WLAN_CH_AVOID
6023 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6024#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306025
6026 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
6027 if (driver_status)
6028 hdd_err("Pdev delete failed");
6029
6030 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6031 if (driver_status)
6032 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006033
6034 qdf_mem_free(hdd_ctx->target_hw_name);
6035
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006036 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037}
6038
6039void __hdd_wlan_exit(void)
6040{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006041 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006042
6043 ENTER();
6044
Anurag Chouhan6d760662016-02-20 16:05:43 +05306045 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006046 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006047 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048 EXIT();
6049 return;
6050 }
6051
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006052 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306053 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006054
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055 /* Do all the cleanup before deregistering the driver */
6056 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058 EXIT();
6059}
6060
6061#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006062/**
6063 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006064 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006065 *
6066 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6067 * Then new ACS request will do a fresh scan without reusing the cached
6068 * scan information.
6069 *
6070 * Return: void
6071 */
Tang Yingying523322d2017-01-17 23:28:43 +08006072static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006074 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006076 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006077 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006078 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6079 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6080 hdd_ctx->last_acs_channel_list = NULL;
6081 hdd_ctx->num_of_channels = 0;
6082 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083
6084 if (!hdd_ctx->hHal)
6085 return;
6086 sme_scan_flush_result(hdd_ctx->hHal);
6087}
6088#endif
6089
6090#ifdef QCA_HT_2040_COEX
6091/**
6092 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6093 * @adapter: pointer to adapter
6094 * @staId: station id
6095 * @macAddrSTA: station MAC address
6096 * @channel_type: channel type
6097 *
6098 * This function notifies FW with HT20/HT40 mode
6099 *
6100 * Return: 0 if successful, error number otherwise
6101 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006102int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306103 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104{
6105 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306106 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006107 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108
6109 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6110
6111 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306112 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115 if (!hdd_ctx->hHal)
6116 return -EINVAL;
6117
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306118 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306120 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006121 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006122 return -EINVAL;
6123 }
6124
6125 return 0;
6126}
6127#endif
6128
6129/**
6130 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6131 * @state: state
6132 *
6133 * This function notifies FW with modem power status
6134 *
6135 * Return: 0 if successful, error number otherwise
6136 */
6137int hdd_wlan_notify_modem_power_state(int state)
6138{
6139 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306140 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006141 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006142
Anurag Chouhan6d760662016-02-20 16:05:43 +05306143 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306145 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006146 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006148 if (!hdd_ctx->hHal)
6149 return -EINVAL;
6150
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306151 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6152 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006153 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154 state);
6155 return -EINVAL;
6156 }
6157 return 0;
6158}
6159
6160/**
6161 *
6162 * hdd_post_cds_enable_config() - HDD post cds start config helper
6163 * @adapter - Pointer to the HDD
6164 *
6165 * Return: None
6166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006167QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306169 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006170
6171 /*
6172 * Send ready indication to the HDD. This will kick off the MAC
6173 * into a 'running' state and should kick off an initial scan.
6174 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306175 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6176 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006177 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6178 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306179 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180 }
6181
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306182 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006183}
6184
6185/* wake lock APIs for HDD */
6186void hdd_prevent_suspend(uint32_t reason)
6187{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306188 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006189}
6190
6191void hdd_allow_suspend(uint32_t reason)
6192{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306193 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006194}
6195
6196void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6197{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306198 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6199 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200}
6201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006203QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006205
Amar Singhal6f8592b2017-04-26 14:31:58 -07006206 return sme_init_chan_list(hdd_ctx->hHal,
6207 hdd_ctx->reg.alpha2,
6208 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209}
6210
6211/**
6212 * hdd_is_5g_supported() - check if hardware supports 5GHz
6213 * @hdd_ctx: Pointer to the hdd context
6214 *
6215 * HDD function to know if hardware supports 5GHz
6216 *
6217 * Return: true if hardware supports 5GHz
6218 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006219bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006221 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006222 return true;
6223
Amar Singhal58b45ef2017-08-01 13:43:54 -07006224 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006225 return true;
6226 else
6227 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228}
6229
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006230static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231{
6232 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006233 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
6235 wiphy = hdd_ctx->wiphy;
6236
6237 /*
6238 * The channel information in
6239 * wiphy needs to be initialized before wiphy registration
6240 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006241 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6242 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006243 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006244 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 }
6246
6247#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6248 wiphy->wowlan = &wowlan_support_reg_init;
6249#else
6250 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6251 WIPHY_WOWLAN_MAGIC_PKT |
6252 WIPHY_WOWLAN_DISCONNECT |
6253 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6254 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6255 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6256 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6257 WIPHY_WOWLAN_RFKILL_RELEASE;
6258
6259 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6260 WOW_MAX_FILTERS_PER_LIST);
6261 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6262 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6263#endif
6264
6265 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006266 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306267 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006268 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306269 return ret_val;
6270 }
6271
Amar Singhal5cccafe2017-02-15 12:42:58 -08006272 if (!hdd_ctx->reg_offload)
6273 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274
Amar Singhale4f28ee2015-10-21 14:36:56 -07006275 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276}
6277
Ravi Joshie2331e82015-07-01 18:18:54 -07006278/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006279 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006280 * @hdd_ctx - handle to hdd context
6281 * @tx_packets - transmit packet count
6282 * @rx_packets - receive packet count
6283 *
6284 * The function controls the bus bandwidth and dynamic control of
6285 * tcp delayed ack configuration
6286 *
6287 * Returns: None
6288 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006290static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006291 const uint64_t tx_packets,
6292 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006293{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006295 uint64_t temp_rx = 0;
6296 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006297 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006298 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006299 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006300 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006301 uint16_t index = 0;
6302 bool vote_level_change = false;
6303 bool rx_level_change = false;
6304 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006307 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006309 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006310 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006311 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006312 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006313 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006316 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6317 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006318 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006319 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006320 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306321 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306322 if (hdd_ctx->hbw_requested) {
6323 pld_remove_pm_qos(hdd_ctx->parent_dev);
6324 hdd_ctx->hbw_requested = false;
6325 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306326 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006327 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306328 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306329 if (!hdd_ctx->hbw_requested) {
6330 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6331 hdd_ctx->hbw_requested = true;
6332 }
6333
Nirav Shah3bbfa512016-05-12 16:43:49 +05306334 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006335 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306336 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006337 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006339
Mohit Khannaf8f96822017-05-17 17:11:59 -07006340 qdf_dp_trace_throttle_live_mode(
6341 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6342
Mohit Khannae71e2262015-11-10 09:37:24 -08006343 /* fine-tuning parameters for RX Flows */
6344 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006347
Ravi Joshifed83572016-10-07 16:20:37 -07006348 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6349 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6350 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6351 next_rx_level = WLAN_SVC_TP_HIGH;
6352 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006353 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006354 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006355 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006356 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006359 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360 next_rx_level, temp_rx);
6361 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006362 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006363 /* Send throughput indication only if it is enabled.
6364 * Disabling tcp_del_ack will revert the tcp stack behavior
6365 * to default delayed ack. Note that this will disable the
6366 * dynamic delayed ack mechanism across the system
6367 */
6368 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306369 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6370 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371 &next_rx_level,
6372 sizeof(next_rx_level));
6373 }
6374
Mohit Khannae71e2262015-11-10 09:37:24 -08006375 /* fine-tuning parameters for TX Flows */
6376 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6377 hdd_ctx->prev_tx = tx_packets;
6378 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6379 next_tx_level = WLAN_SVC_TP_HIGH;
6380 else
6381 next_tx_level = WLAN_SVC_TP_LOW;
6382
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006383 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006384 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6385 next_tx_level, temp_tx);
6386 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006387 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306388 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6389 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006390 &next_tx_level,
6391 sizeof(next_tx_level));
6392 }
6393
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006394 index = hdd_ctx->hdd_txrx_hist_idx;
6395
6396 if (vote_level_change || tx_level_change || rx_level_change) {
6397 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6398 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6399 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6400 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6401 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6402 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6403 hdd_ctx->hdd_txrx_hist_idx++;
6404 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6405 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406}
6407
6408#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306409static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006411 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306412 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006413 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306414 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306415 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6416 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006417 uint64_t total_tx = 0, total_rx = 0;
6418 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306419 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306420 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006421 bool connected = false;
6422 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6423
Prashanth Bhattaab004382016-10-11 16:08:11 -07006424 if (wlan_hdd_validate_context(hdd_ctx))
6425 return;
6426
Jingxiang Gec64e1932017-08-22 14:38:59 +08006427 if (hdd_ctx->isWiphySuspended)
6428 goto restart_timer;
6429
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306431 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006432 status =
6433 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6434
6435 if (adapterNode->pAdapter == NULL)
6436 continue;
6437 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306438 /*
6439 * Validate magic so we don't end up accessing
6440 * an invalid adapter.
6441 */
6442 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6443 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006444
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006445 if ((adapter->device_mode == QDF_STA_MODE ||
6446 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6448 != eConnectionState_Associated) {
6449
6450 continue;
6451 }
6452
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006453 if ((adapter->device_mode == QDF_SAP_MODE ||
6454 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006455 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6456
6457 continue;
6458 }
6459
6460 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6461 adapter->prev_tx_packets);
6462 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6463 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306464
6465 if (adapter->device_mode == QDF_SAP_MODE ||
6466 adapter->device_mode == QDF_P2P_GO_MODE ||
6467 adapter->device_mode == QDF_IBSS_MODE) {
6468
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006469 ret = cdp_get_intra_bss_fwd_pkts_count(
6470 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306471 adapter->sessionId,
6472 &fwd_tx_packets, &fwd_rx_packets);
6473 if (ret == A_OK) {
6474 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6475 fwd_tx_packets,
6476 adapter->prev_fwd_tx_packets);
6477 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6478 fwd_tx_packets,
6479 adapter->prev_fwd_rx_packets);
6480 }
6481 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006482
6483 total_rx += adapter->stats.rx_packets;
6484 total_tx += adapter->stats.tx_packets;
6485
6486 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6487 adapter->prev_tx_packets = adapter->stats.tx_packets;
6488 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306489 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6490 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6492 connected = true;
6493 }
6494
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306495 /* add intra bss forwarded tx and rx packets */
6496 tx_packets += fwd_tx_packets_diff;
6497 rx_packets += fwd_rx_packets_diff;
6498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6500 tx_packets += (uint64_t)ipa_tx_packets;
6501 rx_packets += (uint64_t)ipa_rx_packets;
6502
6503 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006504 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505 return;
6506 }
6507
Yuanyuan Liu13738502016-04-06 17:41:37 -07006508 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509
6510 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6511 hdd_ipa_uc_stat_request(adapter, 2);
6512
Jingxiang Gec64e1932017-08-22 14:38:59 +08006513restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006514 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006515 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006516 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306517 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006518 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006519 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006521
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306522/**
6523 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6524 * @arg: Argument of timer function
6525 *
6526 * Schedule a workqueue in this function where all the processing is done.
6527 *
6528 * Return: None.
6529 */
6530static void __hdd_bus_bw_cbk(void *arg)
6531{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006532 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306533
6534 if (wlan_hdd_validate_context(hdd_ctx))
6535 return;
6536
6537 schedule_work(&hdd_ctx->bus_bw_work);
6538}
6539
6540/**
6541 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6542 * @arg: Argument of timer function
6543 *
6544 * Return: None.
6545 */
6546static void hdd_bus_bw_cbk(void *arg)
6547{
6548 cds_ssr_protect(__func__);
6549 __hdd_bus_bw_cbk(arg);
6550 cds_ssr_unprotect(__func__);
6551}
6552
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006553int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006554{
6555 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306556 INIT_WORK(&hdd_ctx->bus_bw_work,
6557 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006558 hdd_ctx->bus_bw_timer_running = false;
6559 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306560 qdf_timer_init(NULL,
6561 &hdd_ctx->bus_bw_timer,
6562 hdd_bus_bw_cbk, (void *)hdd_ctx,
6563 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006564
6565 return 0;
6566}
6567
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006568void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006569{
Dustin Brownfce08d12017-01-17 16:29:38 -08006570 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006571 hdd_reset_tcp_delack(hdd_ctx);
6572
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006573 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306574 cancel_work_sync(&hdd_ctx->bus_bw_work);
6575 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006576 hdd_ctx->bus_bw_timer_running = false;
6577 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006578}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006579#endif
6580
6581/**
Nirav Shahed34b212016-04-25 10:59:16 +05306582 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6583 * @hdd_ctx: hdd context
6584 *
6585 * Return: 0 for success or error code
6586 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006587static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306588{
6589 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6590 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6591 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006592 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306593 return -ENOMEM;
6594 }
6595 return 0;
6596}
6597
6598/**
6599 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6600 * @hdd_ctx: hdd context
6601 *
6602 * Return: none
6603 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006604void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306605{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306606 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6607 return;
6608
6609 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6610 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306611}
6612
Nirav Shahda008342016-05-17 18:50:40 +05306613static uint8_t *convert_level_to_string(uint32_t level)
6614{
6615 switch (level) {
6616 /* initialize the wlan sub system */
6617 case WLAN_SVC_TP_NONE:
6618 return "NONE";
6619 case WLAN_SVC_TP_LOW:
6620 return "LOW";
6621 case WLAN_SVC_TP_MEDIUM:
6622 return "MED";
6623 case WLAN_SVC_TP_HIGH:
6624 return "HIGH";
6625 default:
6626 return "INVAL";
6627 }
6628}
6629
Nirav Shahed34b212016-04-25 10:59:16 +05306630
6631/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6633 * @hdd_ctx: hdd context
6634 *
6635 * Return: none
6636 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006637void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638{
6639 int i;
6640
6641#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006642 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306643 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006644 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645 hdd_ctx->config->busBandwidthHighThreshold,
6646 hdd_ctx->config->busBandwidthMediumThreshold,
6647 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006648 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306649 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006650 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006651 hdd_ctx->config->tcpDelackThresholdHigh,
6652 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006653 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306654 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655#endif
6656
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006657 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306658 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6659
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006660 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006661
6662 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006663 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006664 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006665 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006666 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6667 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006668 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006669 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6670 convert_level_to_string(
6671 hdd_ctx->hdd_txrx_hist[i].
6672 next_vote_level),
6673 convert_level_to_string(
6674 hdd_ctx->hdd_txrx_hist[i].
6675 next_rx_level),
6676 convert_level_to_string(
6677 hdd_ctx->hdd_txrx_hist[i].
6678 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006680
6681 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682}
6683
6684/**
6685 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6686 * @hdd_ctx: hdd context
6687 *
6688 * Return: none
6689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006690void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006691{
6692 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306693 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6694 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695}
6696
6697/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006698 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006699 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006700 *
6701 * Return: none
6702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006703void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704{
6705
Jeff Johnson9d295242017-08-29 14:39:48 -07006706 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006707 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306708 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006709 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306710 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006711
6712 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306713 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714 adapter = adapter_node->pAdapter;
6715
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006716 hdd_debug("Netif queue operation statistics:");
6717 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306718 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006719 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306720 curr_time = qdf_system_ticks();
6721 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306722 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306723 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306724 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306725 unpause = adapter->total_unpause_time;
6726 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306727 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306728 pause = adapter->total_pause_time;
6729 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006730 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306731 qdf_system_ticks_to_msecs(total),
6732 qdf_system_ticks_to_msecs(pause),
6733 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006734 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006735
Nirav Shahda008342016-05-17 18:50:40 +05306736 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6737 qdf_time_t pause_delta = 0;
6738
6739 if (adapter->pause_map & (1 << i))
6740 pause_delta = delta;
6741
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006742 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006743 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006744 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745 hdd_reason_type_to_string(i),
6746 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306747 adapter->queue_oper_stats[i].unpause_count,
6748 qdf_system_ticks_to_msecs(
6749 adapter->queue_oper_stats[i].total_pause_time +
6750 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751 }
6752
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006753 hdd_debug("Netif queue operation history:");
6754 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306755 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6756
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006757 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006758
6759 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006760 /* using hdd_log to avoid printing function name */
6761 if (adapter->queue_oper_history[i].time == 0)
6762 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006763 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006764 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306765 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766 adapter->queue_oper_history[i].time),
6767 hdd_action_type_to_string(
6768 adapter->queue_oper_history[i].netif_action),
6769 hdd_reason_type_to_string(
6770 adapter->queue_oper_history[i].netif_reason),
6771 adapter->queue_oper_history[i].pause_map);
6772 }
6773
6774 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6775 adapter_node = next;
6776 }
6777
6778
6779}
6780
6781/**
6782 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6783 * @hdd_ctx: hdd context
6784 *
6785 * Return: none
6786 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006787void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788{
Jeff Johnson9d295242017-08-29 14:39:48 -07006789 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306791 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006792
6793 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306794 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795 adapter = adapter_node->pAdapter;
6796
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306797 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306799 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306801 adapter->history_index = 0;
6802 adapter->start_time = adapter->last_time = qdf_system_ticks();
6803 adapter->total_pause_time = 0;
6804 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6806 adapter_node = next;
6807 }
6808}
6809
6810/**
6811 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6812 * @halHandle: Hal handle
6813 * @pContext: Pointer to the context
6814 * @sessionId: Session ID
6815 * @scanId: Scan ID
6816 * @status: Status
6817 *
6818 * This is the callback to be executed when 11d scan is completed to flush out
6819 * the scan results
6820 *
6821 * 11d scan is done during driver load and is a passive scan on all
6822 * channels supported by the device, 11d scans may find some APs on
6823 * frequencies which are forbidden to be used in the regulatory domain
6824 * the device is operating in. If these APs are notified to the supplicant
6825 * it may try to connect to these APs, thus flush out all the scan results
6826 * which are present in SME after 11d scan is done.
6827 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306828 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006829 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306830static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831 uint8_t sessionId, uint32_t scanId,
6832 eCsrScanStatus status)
6833{
6834 ENTER();
6835
6836 sme_scan_flush_result(halHandle);
6837
6838 EXIT();
6839
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306840 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006841}
6842
6843#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6844/**
6845 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6846 * @hdd_ctx: hdd global context
6847 *
6848 * Return: none
6849 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006850static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851{
6852 uint8_t i;
6853
6854 mutex_init(&hdd_ctx->op_ctx.op_lock);
6855 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6856 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6857 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6858 }
6859}
6860#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006861static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862{
6863}
6864#endif
6865
Yingying Tang95409972016-10-20 15:16:15 +08006866#ifdef WLAN_FEATURE_WOW_PULSE
6867/**
6868 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006869 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006870 * @enable: enable or disable this behaviour
6871 *
6872 * Return: int
6873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006874static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006875{
6876 struct hdd_config *pcfg_ini = phddctx->config;
6877 struct wow_pulse_mode wow_pulse_set_info;
6878 QDF_STATUS status;
6879
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006880 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006881
6882 if (false == phddctx->config->wow_pulse_support)
6883 return 0;
6884
6885 /* prepare the request to send to SME */
6886 if (enable == true) {
6887 wow_pulse_set_info.wow_pulse_enable = true;
6888 wow_pulse_set_info.wow_pulse_pin =
6889 pcfg_ini->wow_pulse_pin;
6890 wow_pulse_set_info.wow_pulse_interval_low =
6891 pcfg_ini->wow_pulse_interval_low;
6892 wow_pulse_set_info.wow_pulse_interval_high =
6893 pcfg_ini->wow_pulse_interval_high;
6894 } else {
6895 wow_pulse_set_info.wow_pulse_enable = false;
6896 wow_pulse_set_info.wow_pulse_pin = 0;
6897 wow_pulse_set_info.wow_pulse_interval_low = 0;
6898 wow_pulse_set_info.wow_pulse_interval_high = 0;
6899 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006900 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006901 wow_pulse_set_info.wow_pulse_enable,
6902 wow_pulse_set_info.wow_pulse_pin,
6903 wow_pulse_set_info.wow_pulse_interval_low,
6904 wow_pulse_set_info.wow_pulse_interval_high);
6905
6906 status = sme_set_wow_pulse(&wow_pulse_set_info);
6907 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006908 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006909 return -EIO;
6910 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006911 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006912 return 0;
6913}
6914#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006915static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006916{
6917 return 0;
6918}
6919#endif
6920
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921#ifdef WLAN_FEATURE_FASTPATH
6922/**
6923 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6924 * @hdd_cfg: hdd config
6925 * @context: lower layer context
6926 *
6927 * Return: none
6928 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306929void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006930 void *context)
6931{
6932 if (hdd_cfg->fastpath_enable)
6933 hif_enable_fastpath(context);
6934}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006935#endif
6936
Yuanyuan Liu13738502016-04-06 17:41:37 -07006937#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006938/**
6939 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006940 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941 * @level: thermal level
6942 *
6943 * Change IPA data path to SW path when the thermal throttle level greater
6944 * than 0, and restore the original data path when throttle level is 0
6945 *
6946 * Return: none
6947 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006948static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006949{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006950 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952 /* Change IPA to SW path when throttle level greater than 0 */
6953 if (level > THROTTLE_LEVEL_0)
6954 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6955 else
6956 /* restore original concurrency mode */
6957 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6958}
6959
6960/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306961 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6962 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306963 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006964 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306965 * Get a safe channel to restart SAP. PCL already takes into account the
6966 * unsafe channels. So, the PCL is validated with the ACS range to provide
6967 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006968 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306969 * Return: Channel number to restart SAP in case of success. In case of any
6970 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006971 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306972static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07006973 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006974{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306975 struct sir_pcl_list pcl;
6976 QDF_STATUS status;
6977 uint32_t i, j;
6978 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006979 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306980 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306982 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6983 if (!hdd_ctx) {
6984 hdd_err("invalid HDD context");
6985 return INVALID_CHANNEL_ID;
6986 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306988 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6989 if (!hal_handle) {
6990 hdd_err("invalid HAL handle");
6991 return INVALID_CHANNEL_ID;
6992 }
6993
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006994 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6995 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08006996 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
6997 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306998 if (QDF_IS_STATUS_ERROR(status)) {
6999 hdd_err("Get PCL failed");
7000 return INVALID_CHANNEL_ID;
7001 }
7002
Frank Liudc2cefb2017-06-21 15:38:18 +08007003 /*
7004 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7005 * channel is unsafe channel, the pcl may be empty, instead of return,
7006 * try to choose a safe channel from acs range.
7007 */
7008 if (!pcl.pcl_len)
7009 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307010
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007011 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307012 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7013 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7014
7015 /* PCL already takes unsafe channel into account */
7016 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007017 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307018 if ((pcl.pcl_list[i] >=
7019 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7020 (pcl.pcl_list[i] <=
7021 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007022 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307023 return pcl.pcl_list[i];
7024 }
7025 }
7026
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007027 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307028
7029 /* Try for safe channel from all valid channel */
7030 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007031 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307032 &pcl.pcl_len);
7033 if (QDF_IS_STATUS_ERROR(status)) {
7034 hdd_err("error in getting valid channel list");
7035 return INVALID_CHANNEL_ID;
7036 }
7037
7038 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007039 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307040 found = false;
7041 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007042 if (pcl.pcl_list[i] ==
7043 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007044 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307045 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046 break;
7047 }
7048 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049
7050 if (found)
7051 continue;
7052
7053 if ((pcl.pcl_list[i] >=
7054 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7055 (pcl.pcl_list[i] <=
7056 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007057 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307058 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007059 }
7060 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307061
7062 return INVALID_CHANNEL_ID;
7063}
7064
7065/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007066 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307067 * @adapter: AP adapter
7068 * @channel: Channel
7069 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007070 * Moves the SAP interface by invoking the function which
7071 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307072 *
7073 * Return: None
7074 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007075void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307076{
Jeff Johnson87251032017-08-29 13:31:11 -07007077 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307078 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007079 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307080
7081 if (!adapter) {
7082 hdd_err("invalid adapter");
7083 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007084 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307085
7086 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7087
7088 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7089 if (!hal_handle) {
7090 hdd_err("invalid HAL handle");
7091 return;
7092 }
7093
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007094 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7095
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307096 hdd_ap_ctx->sapConfig.channel = channel;
7097 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7098 hdd_ap_ctx->sapConfig.ch_width_orig;
7099
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007100 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307101 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7102
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007103 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7104 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307105 hdd_ap_ctx->sapConfig.sec_ch,
7106 &hdd_ap_ctx->sapConfig.ch_params);
7107
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007108 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7109 adapter->sessionId, channel,
7110 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007111}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307112
Jeff Johnson9d295242017-08-29 14:39:48 -07007113int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307114{
7115 struct hdd_external_acs_timer_context *timer_context;
7116
7117 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7118
7119 if (QDF_TIMER_STATE_RUNNING ==
7120 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7121 ap.vendor_acs_timer)) {
7122 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7123 }
7124 timer_context = (struct hdd_external_acs_timer_context *)
7125 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7126 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307127 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307128 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307129 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7130 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307131 hdd_notice("Updated ACS config to nl with reason %d", reason);
7132
7133 return 0;
7134}
7135
Agrawal Ashish467dde42016-09-08 18:44:22 +05307136/**
7137 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7138 * @hdd_ctx: hdd context pointer
7139 *
7140 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7141 * and if ACS is enabled, driver will ask userspace to restart the
7142 * sap. User space on LTE coex indication restart driver.
7143 *
7144 * Return - none
7145 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007146void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307147{
7148 QDF_STATUS status;
7149 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007150 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307151 uint32_t i;
7152 bool found = false;
7153 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154
Agrawal Ashish467dde42016-09-08 18:44:22 +05307155 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7156 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7157 adapter_temp = adapter_node->pAdapter;
7158
7159 if (!adapter_temp) {
7160 hdd_err("adapter is NULL, moving to next one");
7161 goto next_adapater;
7162 }
7163
7164 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7165 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007166 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307167 adapter_temp->device_mode,
7168 adapter_temp->sessionCtx.ap.sapConfig.
7169 acs_cfg.acs_mode);
7170 goto next_adapater;
7171 }
7172
7173 found = false;
7174 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007175 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307176 hdd_ctxt->unsafe_channel_list[i]) {
7177 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007178 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307179 adapter_temp->sessionCtx.ap.operatingChannel);
7180 break;
7181 }
7182 }
7183
7184 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007185 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307186 adapter_temp->sessionCtx.ap.operatingChannel);
7187 goto next_adapater;
7188 }
7189
Kapil Gupta8878ad92017-02-13 11:56:04 +05307190 if (hdd_ctxt->config->vendor_acs_support &&
7191 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7192 hdd_update_acs_timer_reason(adapter_temp,
7193 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7194 goto next_adapater;
7195 } else
7196 restart_chan =
7197 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307198 adapter_temp);
7199 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007200 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307201 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007202 /*
7203 * SAP restart due to unsafe channel. While
7204 * restarting the SAP, make sure to clear
7205 * acs_channel, channel to reset to
7206 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307207 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007208 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307209 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7210 adapter_temp->sessionCtx.ap.sapConfig.channel =
7211 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007212 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307213 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7214 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007215 hdd_debug("driver to start sap: %d",
7216 hdd_ctxt->config->sap_internal_restart);
7217 if (hdd_ctxt->config->sap_internal_restart)
7218 hdd_switch_sap_channel(adapter_temp, restart_chan);
7219 else
7220 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307221 }
7222
7223next_adapater:
7224 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7225 adapter_node = next;
7226 }
7227}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007230 * hdd_init_channel_avoidance() - Initialize channel avoidance
7231 * @hdd_ctx: HDD global context
7232 *
7233 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007234 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007235 * down to the lower layers. Then subscribe to subsequent channel
7236 * avoidance events.
7237 *
7238 * Return: None
7239 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007240static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007241{
7242 uint16_t unsafe_channel_count;
7243 int index;
7244
Yuanyuan Liu13738502016-04-06 17:41:37 -07007245 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7246 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007247 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007248 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007249
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007250 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007251 hdd_ctx->unsafe_channel_count);
7252
Anurag Chouhan6d760662016-02-20 16:05:43 +05307253 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007254 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007255
7256 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007257 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007258 hdd_ctx->unsafe_channel_list[index]);
7259
7260 }
7261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262}
Dustin Brown676a2322017-08-15 13:16:13 -07007263
Jeff Johnson9d295242017-08-29 14:39:48 -07007264static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007265 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007266{
7267 uint8_t restart_chan;
7268
7269 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7270 if (!restart_chan) {
7271 hdd_alert("fail to restart SAP");
7272 return;
7273 }
7274
7275 /* SAP restart due to unsafe channel. While restarting
7276 * the SAP, make sure to clear acs_channel, channel to
7277 * reset to 0. Otherwise these settings will override
7278 * the ACS while restart.
7279 */
7280 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7281 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7282
7283 hdd_debug("sending coex indication");
7284
7285 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7286 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7287 hdd_switch_sap_channel(adapter, restart_chan);
7288}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007289
7290int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7291 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7292{
7293 uint32_t size;
7294 uint16_t *unsafe_list;
7295 uint16_t chan_count;
7296
7297 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7298 return -EINVAL;
7299
7300 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7301 NUM_CHANNELS);
7302 if (chan_count) {
7303 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7304 unsafe_list = qdf_mem_malloc(size);
7305 if (!unsafe_list) {
7306 hdd_err("No memory for unsafe chan list size%d",
7307 size);
7308 return -ENOMEM;
7309 }
7310 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7311 } else {
7312 unsafe_list = NULL;
7313 }
7314
7315 *local_unsafe_list = unsafe_list;
7316 *local_unsafe_list_count = chan_count;
7317
7318 return 0;
7319}
7320
7321bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7322 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7323{
7324 int i, j;
7325
7326 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7327 return true;
7328 if (local_unsafe_list_count == 0)
7329 return false;
7330 for (i = 0; i < local_unsafe_list_count; i++) {
7331 for (j = 0; j < local_unsafe_list_count; j++)
7332 if (local_unsafe_list[i] ==
7333 hdd_ctx->unsafe_channel_list[j])
7334 break;
7335 if (j >= local_unsafe_list_count)
7336 break;
7337 }
7338 if (i >= local_unsafe_list_count) {
7339 hdd_info("unsafe chan list same");
7340 return false;
7341 }
7342
7343 return true;
7344}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007346static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347{
7348}
Dustin Brown676a2322017-08-15 13:16:13 -07007349
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007350static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351{
7352}
Dustin Brown676a2322017-08-15 13:16:13 -07007353
Jeff Johnson9d295242017-08-29 14:39:48 -07007354static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007355 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007356{
7357 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7358}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007359#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007360
7361/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007362 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7363 * user space
7364 * @frame_ind: Management frame data to be informed.
7365 *
7366 * This function is used to indicate management frame to
7367 * user space
7368 *
7369 * Return: None
7370 *
7371 */
7372void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7373{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007374 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007375 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007376 int i;
7377
Rajeev Kumard004abc2016-02-17 12:09:56 -08007378 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007379 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007380
7381 if (0 != wlan_hdd_validate_context(hdd_ctx))
7382 return;
7383
7384 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7385 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7386 adapter =
7387 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7388 if (adapter)
7389 break;
7390 }
7391 } else {
7392 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7393 frame_ind->sessionId);
7394 }
7395
7396 if ((NULL != adapter) &&
7397 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7398 __hdd_indicate_mgmt_frame(adapter,
7399 frame_ind->frame_len,
7400 frame_ind->frameBuf,
7401 frame_ind->frameType,
7402 frame_ind->rxChan,
7403 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007404}
7405
Kapil Gupta8878ad92017-02-13 11:56:04 +05307406void hdd_acs_response_timeout_handler(void *context)
7407{
7408 struct hdd_external_acs_timer_context *timer_context =
7409 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007410 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007411 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307412 uint8_t reason;
7413
7414 ENTER();
7415 if (!timer_context) {
7416 hdd_err("invlaid timer context");
7417 return;
7418 }
7419 adapter = timer_context->adapter;
7420 reason = timer_context->reason;
7421
7422
7423 if ((!adapter) ||
7424 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7425 hdd_err("invalid adapter or adapter has invalid magic");
7426 return;
7427 }
7428 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7429 if (wlan_hdd_validate_context(hdd_ctx))
7430 return;
7431
7432 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7433 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7434 else
7435 return;
7436
7437 hdd_err("ACS timeout happened for %s reason %d",
7438 adapter->dev->name, reason);
7439 switch (reason) {
7440 /* SAP init case */
7441 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7442 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7443 false);
7444 wlan_hdd_cfg80211_start_acs(adapter);
7445 break;
7446 /* DFS detected on current channel */
7447 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7448 wlan_sap_update_next_channel(
7449 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7450 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7451 adapter->sessionId);
7452 break;
7453 /* LTE coex event on current channel */
7454 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7455 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7456 break;
7457 default:
7458 hdd_info("invalid reason for timer invoke");
7459
7460 }
7461}
7462
Rajeev Kumard004abc2016-02-17 12:09:56 -08007463/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007464 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7465 * @hdd_ctx: HDD context
7466 *
7467 * Disables all the dual mac features like DBS, Agile DFS etc.
7468 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307469 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007470 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007471static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007472{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007473 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307474 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007475
7476 if (!hdd_ctx) {
7477 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307478 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007479 }
7480
7481 cfg.scan_config = 0;
7482 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007483 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007484
7485 hdd_debug("Disabling all dual mac features...");
7486
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007487 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307488 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007489 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7490 return status;
7491 }
7492
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307493 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007494}
7495
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007496static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007497wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007498{
7499 struct policy_mgr_dual_mac_config cfg = {0};
7500 QDF_STATUS status;
7501
7502 if (!hdd_ctx) {
7503 hdd_err("HDD context is NULL");
7504 return QDF_STATUS_E_FAILURE;
7505 }
7506
7507 cfg.scan_config = 0;
7508 cfg.fw_mode_config = 0;
7509 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7510 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7511 hdd_ctx->hdd_psoc, &cfg.scan_config,
7512 &cfg.fw_mode_config,
7513 hdd_ctx->config->dual_mac_feature_disable);
7514
7515 if (status != QDF_STATUS_SUCCESS) {
7516 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7517 status);
7518 return status;
7519 }
7520
7521 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7522 cfg.scan_config, cfg.fw_mode_config);
7523
7524 status = sme_soc_set_dual_mac_config(cfg);
7525 if (status != QDF_STATUS_SUCCESS) {
7526 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7527 return status;
7528 }
7529
7530 return QDF_STATUS_SUCCESS;
7531}
7532
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007533/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007534 * hdd_override_ini_config - Override INI config
7535 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007536 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007537 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007539 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007540 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007541static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007542{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007543
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007544 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7545 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007546 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007547 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007548 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007549 if (0 == enable_11d || 1 == enable_11d) {
7550 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007551 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552 }
Leo Chang11545d62016-10-17 14:53:50 -07007553
7554 if (!hdd_ipa_is_present(hdd_ctx))
7555 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007556}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007557
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007558/**
7559 * hdd_set_trace_level_for_each - Set trace level for each INI config
7560 * @hdd_ctx - HDD context
7561 *
7562 * Set trace level for each module based on INI config.
7563 *
7564 * Return: None
7565 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007566static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007567{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307568 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7569 hdd_ctx->config->qdf_trace_enable_wdi);
7570 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7571 hdd_ctx->config->qdf_trace_enable_hdd);
7572 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7573 hdd_ctx->config->qdf_trace_enable_sme);
7574 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7575 hdd_ctx->config->qdf_trace_enable_pe);
7576 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7577 hdd_ctx->config->qdf_trace_enable_wma);
7578 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7579 hdd_ctx->config->qdf_trace_enable_sys);
7580 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7581 hdd_ctx->config->qdf_trace_enable_qdf);
7582 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7583 hdd_ctx->config->qdf_trace_enable_sap);
7584 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7585 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7586 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7587 hdd_ctx->config->qdf_trace_enable_bmi);
7588 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7589 hdd_ctx->config->qdf_trace_enable_cfg);
7590 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7591 hdd_ctx->config->qdf_trace_enable_epping);
7592 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7593 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7594 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007595 hdd_ctx->config->qdf_trace_enable_txrx);
7596 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7597 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307598 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7599 hdd_ctx->config->qdf_trace_enable_htc);
7600 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7601 hdd_ctx->config->qdf_trace_enable_hif);
7602 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7603 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7604 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7605 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007606 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7607 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007608 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7609 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007610 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7611 hdd_ctx->config->qdf_trace_enable_regulatory);
7612
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007613 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007614}
7615
7616/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007617 * hdd_context_init() - Initialize HDD context
7618 * @hdd_ctx: HDD context.
7619 *
7620 * Initialize HDD context along with all the feature specific contexts.
7621 *
7622 * return: 0 on success and errno on failure.
7623 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007624static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007625{
7626 int ret;
7627
7628 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7629 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7630
7631 hdd_init_ll_stats_ctx();
7632
7633 init_completion(&hdd_ctx->mc_sus_event_var);
7634 init_completion(&hdd_ctx->ready_to_suspend);
7635
7636 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307637 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007638 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307639
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007640 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7641
7642 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7643
7644 ret = hdd_scan_context_init(hdd_ctx);
7645 if (ret)
7646 goto list_destroy;
7647
Nitesh Shahd1266d72017-01-25 22:07:07 +05307648 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007649
7650 hdd_rx_wake_lock_create(hdd_ctx);
7651
7652 ret = hdd_sap_context_init(hdd_ctx);
7653 if (ret)
7654 goto scan_destroy;
7655
7656 ret = hdd_roc_context_init(hdd_ctx);
7657 if (ret)
7658 goto sap_destroy;
7659
7660 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7661
7662 hdd_init_offloaded_packets_ctx(hdd_ctx);
7663
7664 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7665 hdd_ctx->config);
7666 if (ret)
7667 goto roc_destroy;
7668
7669 return 0;
7670
7671roc_destroy:
7672 hdd_roc_context_destroy(hdd_ctx);
7673
7674sap_destroy:
7675 hdd_sap_context_destroy(hdd_ctx);
7676
7677scan_destroy:
7678 hdd_scan_context_destroy(hdd_ctx);
7679 hdd_rx_wake_lock_destroy(hdd_ctx);
7680 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007681list_destroy:
7682 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007683
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007684 return ret;
7685}
7686
7687/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307688 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7689 * @hdd_ctx: pointer to hdd context
7690 *
7691 * Return: status of initialization
7692 * 0 - success
7693 * negative value - failure
7694 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007695static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307696{
7697 int ret;
7698
7699 if (!hdd_ctx->config->probe_req_ie_whitelist)
7700 return 0;
7701
7702 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7703 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7704 hdd_ctx->config->probe_req_ie_whitelist = false;
7705 return -EINVAL;
7706 }
7707
7708 /* parse ini string probe req oui */
7709 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7710 if (ret) {
7711 hdd_err("parsing error: disable ie whitelisting");
7712 hdd_ctx->config->probe_req_ie_whitelist = false;
7713 }
7714
7715 return ret;
7716}
7717
7718/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007719 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307720 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007721 *
7722 * Allocate and initialize HDD context. HDD context is allocated as part of
7723 * wiphy allocation and then context is initialized.
7724 *
7725 * Return: HDD context on success and ERR_PTR on failure
7726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007727static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007728{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307729 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007730 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007731 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007732 v_CONTEXT_t p_cds_context;
7733
7734 ENTER();
7735
7736 p_cds_context = cds_get_global_context();
7737 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007738 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007739 ret = -EINVAL;
7740 goto err_out;
7741 }
7742
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007743 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007744
7745 if (hdd_ctx == NULL) {
7746 ret = -ENOMEM;
7747 goto err_out;
7748 }
7749
7750 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007751 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307752 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007753
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307754 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007755 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007757 ret = -ENOMEM;
7758 goto err_free_hdd_context;
7759 }
7760
7761 /* Read and parse the qcom_cfg.ini file */
7762 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307763 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307764 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007765 WLAN_INI_FILE);
7766 ret = -EINVAL;
7767 goto err_free_config;
7768 }
7769
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307770 ie_whitelist_attrs_init(hdd_ctx);
7771
Dustin Brown7f939932017-05-18 15:02:17 -07007772 hdd_debug("setting timer multiplier: %u",
7773 hdd_ctx->config->timer_multiplier);
7774 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7775
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007776
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307777 if (hdd_ctx->config->fhostNSOffload)
7778 hdd_ctx->ns_offload_enable = true;
7779
Abhishek Singh5ea86532016-04-27 14:10:53 +05307780 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7781
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007782 hdd_override_ini_config(hdd_ctx);
7783
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007784 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007785
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007786 ret = hdd_context_init(hdd_ctx);
7787
7788 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007789 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007790
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007791 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307792 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007793
Anurag Chouhan6d760662016-02-20 16:05:43 +05307794 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007795 goto skip_multicast_logging;
7796
7797 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7798
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007799 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7800 if (ret)
7801 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307802
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007803 ret = hdd_init_netlink_services(hdd_ctx);
7804 if (ret)
7805 goto err_deinit_txrx_histogram;
7806
Dustin Brown7b3dea22017-07-10 13:02:47 -07007807 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7808 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307809
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007810skip_multicast_logging:
7811 hdd_set_trace_level_for_each(hdd_ctx);
7812
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007813 EXIT();
7814
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007815 return hdd_ctx;
7816
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007817err_deinit_txrx_histogram:
7818 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7819
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007820err_deinit_hdd_context:
7821 hdd_context_deinit(hdd_ctx);
7822
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007823err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307824 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007825
7826err_free_hdd_context:
7827 wiphy_free(hdd_ctx->wiphy);
7828
7829err_out:
7830 return ERR_PTR(ret);
7831}
7832
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007833#ifdef WLAN_OPEN_P2P_INTERFACE
7834/**
7835 * hdd_open_p2p_interface - Open P2P interface
7836 * @hdd_ctx: HDD context
7837 * @rtnl_held: True if RTNL lock held
7838 *
7839 * Open P2P interface during probe. This function called to open the P2P
7840 * interface at probe along with STA interface.
7841 *
7842 * Return: 0 on success and errno on failure
7843 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007844static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007845{
Jeff Johnson9d295242017-08-29 14:39:48 -07007846 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007847 uint8_t *p2p_dev_addr;
7848
7849 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7850 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307851 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007852 hdd_ctx->config->intfMacAddr[0].bytes,
7853 sizeof(tSirMacAddr));
7854
7855 /*
7856 * Generate the P2P Device Address. This consists of
7857 * the device's primary MAC address with the locally
7858 * administered bit set.
7859 */
7860 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7861 } else {
7862 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7863 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007864 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007865 return -ENOSPC;
7866 }
7867
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307868 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307869 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007870 }
7871
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007872 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007873 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007874 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007875
7876 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007877 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007878 return -ENOSPC;
7879 }
7880
7881 return 0;
7882}
7883#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007884static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007885 bool rtnl_held)
7886{
7887 return 0;
7888}
7889#endif
7890
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007891static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007892{
Jeff Johnson9d295242017-08-29 14:39:48 -07007893 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007894 int ret = 0;
7895
7896 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7897 wlan_hdd_get_intf_addr(hdd_ctx),
7898 NET_NAME_UNKNOWN, rtnl_held);
7899 if (adapter == NULL) {
7900 hdd_err("Failed to open 802.11p interface");
7901 ret = -ENOSPC;
7902 }
7903
7904 return ret;
7905}
7906
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007907/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307908 * hdd_start_station_adapter()- Start the Station Adapter
7909 * @adapter: HDD adapter
7910 *
7911 * This function initializes the adapter for the station mode.
7912 *
7913 * Return: 0 on success or errno on failure.
7914 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007915int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307916{
7917 QDF_STATUS status;
7918
7919 ENTER_DEV(adapter->dev);
7920
7921 status = hdd_init_station_mode(adapter);
7922
7923 if (QDF_STATUS_SUCCESS != status) {
7924 hdd_err("Error Initializing station mode: %d", status);
7925 return qdf_status_to_os_return(status);
7926 }
7927
Arun Khandavallifae92942016-08-01 13:31:08 +05307928 hdd_register_tx_flow_control(adapter,
7929 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007930 hdd_tx_resume_cb,
7931 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307932
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307933 EXIT();
7934 return 0;
7935}
7936
7937/**
7938 * hdd_start_ap_adapter()- Start AP Adapter
7939 * @adapter: HDD adapter
7940 *
7941 * This function initializes the adapter for the AP mode.
7942 *
7943 * Return: 0 on success errno on failure.
7944 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007945int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307946{
7947 QDF_STATUS status;
7948
7949 ENTER();
7950
Arun Khandavallicc544b32017-01-30 19:52:16 +05307951 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307952
7953 if (QDF_STATUS_SUCCESS != status) {
7954 hdd_err("Error Initializing the AP mode: %d", status);
7955 return qdf_status_to_os_return(status);
7956 }
7957
Arun Khandavallifae92942016-08-01 13:31:08 +05307958 hdd_register_tx_flow_control(adapter,
7959 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007960 hdd_softap_tx_resume_cb,
7961 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307962
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307963 EXIT();
7964 return 0;
7965}
7966
7967/**
7968 * hdd_start_ftm_adapter()- Start FTM adapter
7969 * @adapter: HDD adapter
7970 *
7971 * This function initializes the adapter for the FTM mode.
7972 *
7973 * Return: 0 on success or errno on failure.
7974 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007975int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307976{
7977 QDF_STATUS qdf_status;
7978
7979 ENTER_DEV(adapter->dev);
7980
7981 qdf_status = hdd_init_tx_rx(adapter);
7982
7983 if (QDF_STATUS_SUCCESS != qdf_status) {
7984 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7985 return qdf_status_to_os_return(qdf_status);
7986 }
7987
7988 return 0;
7989 EXIT();
7990}
7991
7992/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007993 * hdd_open_interfaces - Open all required interfaces
7994 * hdd_ctx: HDD context
7995 * rtnl_held: True if RTNL lock is held
7996 *
7997 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7998 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007999 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008000 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008001static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008002{
Jeff Johnson9d295242017-08-29 14:39:48 -07008003 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008004 int ret;
8005
Ravi Joshia307f632017-07-17 23:41:41 -07008006 /* open monitor mode adapter if con_mode is monitor mode */
8007 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
8008 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
8009 wlan_hdd_get_intf_addr(hdd_ctx),
8010 NET_NAME_UNKNOWN, rtnl_held);
8011 if (!adapter) {
8012 hdd_err("open adapter failed");
8013 return -ENOSPC;
8014 }
8015 return 0;
8016 }
8017
Jeff Johnson957bc272017-02-02 08:54:48 -08008018 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308019 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008020 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008021
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008022 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008023 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008024 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008025
8026 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008027 return -ENOSPC;
8028
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008029 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8030 adapter->fast_roaming_allowed = true;
8031
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008032 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8033 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008034 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008035
8036 /* Open 802.11p Interface */
8037 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008038 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8039 if (ret)
8040 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008041 }
8042
Jeff Johnson957bc272017-02-02 08:54:48 -08008043 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008044
Jeff Johnson957bc272017-02-02 08:54:48 -08008045err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008046 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008047 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008048}
8049
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008050/**
8051 * hdd_update_country_code - Update country code
8052 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008053 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008054 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008055 *
8056 * Return: 0 on success and errno on failure
8057 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008058static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008059{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008060 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008061 return 0;
8062
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008063 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008064}
8065
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308066#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8067/**
8068 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8069 * @cds_cfg: CDS Configuration
8070 * @hdd_ctx: Pointer to hdd context
8071 *
8072 * Return: none
8073 */
8074static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8075 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008076 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308077{
8078 cds_cfg->tx_flow_stop_queue_th =
8079 hdd_ctx->config->TxFlowStopQueueThreshold;
8080 cds_cfg->tx_flow_start_queue_offset =
8081 hdd_ctx->config->TxFlowStartQueueOffset;
8082}
8083#else
8084static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8085 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008086 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308087{
8088}
8089#endif
8090
8091#ifdef FEATURE_WLAN_RA_FILTERING
8092/**
8093 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8094 * @cds_cfg: CDS Configuration
8095 * @hdd_ctx: Pointer to hdd context
8096 *
8097 * Return: none
8098 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308099static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008100 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308101{
8102 cds_cfg->ra_ratelimit_interval =
8103 hdd_ctx->config->RArateLimitInterval;
8104 cds_cfg->is_ra_ratelimit_enabled =
8105 hdd_ctx->config->IsRArateLimitEnabled;
8106}
8107#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308108static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008109 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308110{
8111}
8112#endif
8113
8114/**
8115 * hdd_update_cds_config() - API to update cds configuration parameters
8116 * @hdd_ctx: HDD Context
8117 *
8118 * Return: 0 for Success, errno on failure
8119 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008120static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308121{
8122 struct cds_config_info *cds_cfg;
8123
8124 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8125 if (!cds_cfg) {
8126 hdd_err("failed to allocate cds config");
8127 return -ENOMEM;
8128 }
8129
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008130 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008131 if (!hdd_ctx->config->nMaxPsPoll ||
8132 !hdd_ctx->config->enablePowersaveOffload) {
8133 cds_cfg->powersave_offload_enabled =
8134 hdd_ctx->config->enablePowersaveOffload;
8135 } else {
8136 if ((hdd_ctx->config->enablePowersaveOffload ==
8137 PS_QPOWER_NODEEPSLEEP) ||
8138 (hdd_ctx->config->enablePowersaveOffload ==
8139 PS_LEGACY_NODEEPSLEEP))
8140 cds_cfg->powersave_offload_enabled =
8141 PS_LEGACY_NODEEPSLEEP;
8142 else
8143 cds_cfg->powersave_offload_enabled =
8144 PS_LEGACY_DEEPSLEEP;
8145 hdd_info("Qpower disabled in cds config, %d",
8146 cds_cfg->powersave_offload_enabled);
8147 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308148 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8149 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8150 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8151 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8152 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8153
8154 /* Here ol_ini_info is used to store ini status of arp offload
8155 * ns offload and others. Currently 1st bit is used for arp
8156 * off load and 2nd bit for ns offload currently, rest bits are unused
8157 */
8158 if (hdd_ctx->config->fhostArpOffload)
8159 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8160 if (hdd_ctx->config->fhostNSOffload)
8161 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8162
8163 /*
8164 * Copy the DFS Phyerr Filtering Offload status.
8165 * This parameter reflects the value of the
8166 * dfs_phyerr_filter_offload flag as set in the ini.
8167 */
8168 cds_cfg->dfs_phyerr_filter_offload =
8169 hdd_ctx->config->fDfsPhyerrFilterOffload;
8170 if (hdd_ctx->config->ssdp)
8171 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8172
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308173 cds_cfg->force_target_assert_enabled =
8174 hdd_ctx->config->crash_inject_enabled;
8175
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308176 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8177 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8178
8179 cds_cfg->ap_maxoffload_reorderbuffs =
8180 hdd_ctx->config->apMaxOffloadReorderBuffs;
8181
8182 cds_cfg->ap_disable_intrabss_fwd =
8183 hdd_ctx->config->apDisableIntraBssFwd;
8184
8185 cds_cfg->dfs_pri_multiplier =
8186 hdd_ctx->config->dfsRadarPriMultiplier;
8187 cds_cfg->reorder_offload =
8188 hdd_ctx->config->reorderOffloadSupport;
8189
8190 /* IPA micro controller data path offload resource config item */
8191 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008192 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8193 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008194 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008195 hdd_ctx->config->IpaUcTxBufCount);
8196 hdd_ctx->config->IpaUcTxBufCount =
8197 rounddown_pow_of_two(
8198 hdd_ctx->config->IpaUcTxBufCount);
8199 if (!hdd_ctx->config->IpaUcTxBufCount) {
8200 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308201 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008202 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008203 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008204 hdd_ctx->config->IpaUcTxBufCount);
8205 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308206 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8207 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008208 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8209 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008210 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008211 hdd_ctx->config->IpaUcRxIndRingCount);
8212 hdd_ctx->config->IpaUcRxIndRingCount =
8213 rounddown_pow_of_two(
8214 hdd_ctx->config->IpaUcRxIndRingCount);
8215 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8216 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308217 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008218 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008219 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008220 hdd_ctx->config->IpaUcRxIndRingCount);
8221 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308222 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008223 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308224 cds_cfg->uc_tx_partition_base =
8225 hdd_ctx->config->IpaUcTxPartitionBase;
8226 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8227
8228 cds_cfg->ip_tcp_udp_checksum_offload =
8229 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308230 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308231 cds_cfg->ce_classify_enabled =
8232 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008233 cds_cfg->bpf_packet_filter_enable =
8234 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308235 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8236 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8237 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008238 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008239 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008240 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008241 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308242 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8243 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308244 cds_cfg->auto_power_save_fail_mode =
8245 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308246
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308247 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8248
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308249 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8250 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8251 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008252 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308253 cds_init_ini_config(cds_cfg);
8254 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308255
8256exit:
8257 qdf_mem_free(cds_cfg);
8258 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308259}
8260
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008261/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008262 * hdd_update_user_config() - API to update user configuration
8263 * parameters to obj mgr which are used by multiple components
8264 * @hdd_ctx: HDD Context
8265 *
8266 * Return: 0 for Success, errno on failure
8267 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008268static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008269{
8270 struct wlan_objmgr_psoc_user_config *user_config;
8271
8272 user_config = qdf_mem_malloc(sizeof(*user_config));
8273 if (user_config == NULL) {
8274 hdd_alert("Failed to alloc memory for user_config!");
8275 return -ENOMEM;
8276 }
8277
8278 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8279 user_config->dual_mac_feature_disable =
8280 hdd_ctx->config->dual_mac_feature_disable;
8281 user_config->indoor_channel_support =
8282 hdd_ctx->config->indoor_channel_support;
8283 user_config->is_11d_support_enabled =
8284 hdd_ctx->config->Is11dSupportEnabled;
8285 user_config->is_11h_support_enabled =
8286 hdd_ctx->config->Is11hSupportEnabled;
8287 user_config->optimize_chan_avoid_event =
8288 hdd_ctx->config->goptimize_chan_avoid_event;
8289 user_config->skip_dfs_chnl_in_p2p_search =
8290 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008291 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008292 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8293
8294 qdf_mem_free(user_config);
8295 return 0;
8296}
8297
8298/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008299 * hdd_init_thermal_info - Initialize thermal level
8300 * @hdd_ctx: HDD context
8301 *
8302 * Initialize thermal level at SME layer and set the thermal level callback
8303 * which would be called when a configured thermal threshold is hit.
8304 *
8305 * Return: 0 on success and errno on failure
8306 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008307static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008308{
8309 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308310 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008311
8312 thermal_param.smeThermalMgmtEnabled =
8313 hdd_ctx->config->thermalMitigationEnable;
8314 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8315
Poddar, Siddarth83905022016-04-16 17:56:08 -07008316 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8317 hdd_ctx->config->throttle_dutycycle_level0;
8318 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8319 hdd_ctx->config->throttle_dutycycle_level1;
8320 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8321 hdd_ctx->config->throttle_dutycycle_level2;
8322 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8323 hdd_ctx->config->throttle_dutycycle_level3;
8324
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008325 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8326 hdd_ctx->config->thermalTempMinLevel0;
8327 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8328 hdd_ctx->config->thermalTempMaxLevel0;
8329 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8330 hdd_ctx->config->thermalTempMinLevel1;
8331 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8332 hdd_ctx->config->thermalTempMaxLevel1;
8333 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8334 hdd_ctx->config->thermalTempMinLevel2;
8335 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8336 hdd_ctx->config->thermalTempMaxLevel2;
8337 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8338 hdd_ctx->config->thermalTempMinLevel3;
8339 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8340 hdd_ctx->config->thermalTempMaxLevel3;
8341
8342 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8343
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308344 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308345 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008346
8347 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8348 hdd_set_thermal_level_cb);
8349
8350 return 0;
8351
8352}
8353
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008354#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8355/**
8356 * hdd_hold_rtnl_lock - Hold RTNL lock
8357 *
8358 * Hold RTNL lock
8359 *
8360 * Return: True if held and false otherwise
8361 */
8362static inline bool hdd_hold_rtnl_lock(void)
8363{
8364 rtnl_lock();
8365 return true;
8366}
8367
8368/**
8369 * hdd_release_rtnl_lock - Release RTNL lock
8370 *
8371 * Release RTNL lock
8372 *
8373 * Return: None
8374 */
8375static inline void hdd_release_rtnl_lock(void)
8376{
8377 rtnl_unlock();
8378}
8379#else
8380static inline bool hdd_hold_rtnl_lock(void) { return false; }
8381static inline void hdd_release_rtnl_lock(void) { }
8382#endif
8383
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008384#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008385
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308386/* MAX iwpriv command support */
8387#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308388#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308389#define MAX_PKTLOG_SIZE 16
8390
8391/**
8392 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8393 * @hdd_ctx: hdd context
8394 * @set_value2: pktlog buffer size value
8395 *
8396 *
8397 * Return: 0 for success or error.
8398 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008399static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308400{
8401 struct sir_wifi_start_log start_log = { 0 };
8402 QDF_STATUS status;
8403
8404 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8405 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8406 start_log.ini_triggered = cds_is_packet_log_enabled();
8407 start_log.user_triggered = 1;
8408 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308409 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308410
8411 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8412 if (!QDF_IS_STATUS_SUCCESS(status)) {
8413 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8414 EXIT();
8415 return -EINVAL;
8416 }
8417
8418 return 0;
8419}
8420
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008421/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308422 * hdd_pktlog_clear_buff() - clear pktlog buffer
8423 * @hdd_ctx: hdd context
8424 *
8425 * Return: 0 for success or error.
8426 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008427static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308428{
8429 struct sir_wifi_start_log start_log;
8430 QDF_STATUS status;
8431
8432 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8433 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8434 start_log.ini_triggered = cds_is_packet_log_enabled();
8435 start_log.user_triggered = 1;
8436 start_log.size = 0;
8437 start_log.is_pktlog_buff_clear = true;
8438
8439 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8440 if (!QDF_IS_STATUS_SUCCESS(status)) {
8441 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8442 EXIT();
8443 return -EINVAL;
8444 }
8445
8446 return 0;
8447}
8448
8449
8450/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008451 * hdd_process_pktlog_command() - process pktlog command
8452 * @hdd_ctx: hdd context
8453 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308454 * @set_value2: pktlog buffer size value
8455 *
8456 * This function process pktlog command.
8457 * set_value2 only matters when set_value is 3 (set buff size)
8458 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008459 *
8460 * Return: 0 for success or error.
8461 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008462int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008464{
8465 int ret;
8466 bool enable;
8467 uint8_t user_triggered = 0;
8468
8469 ret = wlan_hdd_validate_context(hdd_ctx);
8470 if (0 != ret)
8471 return ret;
8472
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008473 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008474
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308475 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008476 hdd_err("invalid pktlog value %d", set_value);
8477 return -EINVAL;
8478 }
8479
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308480 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8481 if (set_value2 <= 0) {
8482 hdd_err("invalid pktlog size %d", set_value2);
8483 return -EINVAL;
8484 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8485 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8486 return -EINVAL;
8487 }
8488 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308489 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8490 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308491 }
8492
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008493 /*
8494 * set_value = 0 then disable packetlog
8495 * set_value = 1 enable packetlog forcefully
8496 * set_vlaue = 2 then disable packetlog if disabled through ini or
8497 * enable packetlog with AUTO type.
8498 */
8499 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8500 true : false;
8501
8502 if (1 == set_value) {
8503 enable = true;
8504 user_triggered = 1;
8505 }
8506
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308507 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008508}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008509/**
8510 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8511 * @hdd_ctx: HDD context
8512 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308513 * @user_triggered: triggered through iwpriv
8514 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008515 *
8516 * Return: 0 on success; error number otherwise
8517 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008518int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308519 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008520{
8521 struct sir_wifi_start_log start_log;
8522 QDF_STATUS status;
8523
8524 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8525 start_log.verbose_level =
8526 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008527 start_log.ini_triggered = cds_is_packet_log_enabled();
8528 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308529 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308530 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308531 /*
8532 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8533 * commands. Host uses this flag to decide whether to send pktlog
8534 * disable command to fw without sending pktlog enable command
8535 * previously. For eg, If vendor sends pktlog disable command without
8536 * sending pktlog enable command, then host discards the packet
8537 * but for iwpriv command, host will send it to fw.
8538 */
8539 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008540 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8541 if (!QDF_IS_STATUS_SUCCESS(status)) {
8542 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8543 EXIT();
8544 return -EINVAL;
8545 }
8546
8547 return 0;
8548}
8549#endif /* REMOVE_PKT_LOG */
8550
Komal Seelam92fff912016-03-24 11:51:41 +05308551/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008552 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8553 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308554 * @dev: Device Pointer
8555 * @num: Number of Valid Mac address
8556 *
8557 * Return: Pointer to MAC address buffer
8558 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008559static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8560 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308561{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008562 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308563}
Komal Seelam92fff912016-03-24 11:51:41 +05308564
8565/**
8566 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8567 * @hdd_ctx: HDD Context
8568 * @num: Number of random mac addresses needed
8569 *
8570 * Generate random addresses using bit manipulation on the base mac address
8571 *
8572 * Return: None
8573 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008574void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308575{
8576 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8577 uint32_t iter;
8578 struct hdd_config *ini = hdd_ctx->config;
8579 uint8_t *buf = NULL;
8580 uint8_t macaddr_b3, tmp_br3;
8581 uint8_t *src = ini->intfMacAddr[0].bytes;
8582
8583 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8584 buf = ini->intfMacAddr[iter].bytes;
8585 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8586 macaddr_b3 = buf[3];
8587 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8588 INTF_MACADDR_MASK;
8589 macaddr_b3 += tmp_br3;
8590 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8591 buf[0] |= 0x02;
8592 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008593 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308594 }
8595}
8596
8597/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008598 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308599 * @hdd_ctx: HDD Context
8600 *
8601 * API to get mac addresses from platform driver and update the driver
8602 * structures and configure FW with the base mac address.
8603 * Return: int
8604 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008605static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308606{
8607 uint32_t no_of_mac_addr, iter;
8608 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8609 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8610 uint8_t *addr, *buf;
8611 struct device *dev = hdd_ctx->parent_dev;
8612 struct hdd_config *ini = hdd_ctx->config;
8613 tSirMacAddr mac_addr;
8614 QDF_STATUS status;
8615
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008616 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308617
8618 if (no_of_mac_addr == 0 || !addr) {
8619 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8620 return -EINVAL;
8621 }
8622
8623 if (no_of_mac_addr > max_mac_addr)
8624 no_of_mac_addr = max_mac_addr;
8625
8626 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8627
8628 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8629 buf = ini->intfMacAddr[iter].bytes;
8630 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008631 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308632 }
8633
8634 status = sme_set_custom_mac_addr(mac_addr);
8635
8636 if (!QDF_IS_STATUS_SUCCESS(status))
8637 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008638
Komal Seelam92fff912016-03-24 11:51:41 +05308639 if (no_of_mac_addr < max_mac_addr)
8640 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8641 no_of_mac_addr);
8642 return 0;
8643}
8644
8645/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008646 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8647 * @hdd_ctx: HDD Context
8648 *
8649 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8650 * will generate its own MAC and update it to FW.
8651 *
8652 * Return: 0 for success
8653 * Non-zero error code for failure
8654 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008655static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008656{
8657 tSirMacAddr customMacAddr;
8658 QDF_STATUS status;
8659
8660 qdf_mem_copy(&customMacAddr,
8661 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8662 sizeof(tSirMacAddr));
8663 status = sme_set_custom_mac_addr(customMacAddr);
8664 if (!QDF_IS_STATUS_SUCCESS(status))
8665 return -EAGAIN;
8666 return 0;
8667}
8668
8669/**
Komal Seelam92fff912016-03-24 11:51:41 +05308670 * hdd_initialize_mac_address() - API to get wlan mac addresses
8671 * @hdd_ctx: HDD Context
8672 *
8673 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8674 * is provisioned with mac addresses, driver uses it, else it will use
8675 * wlan_mac.bin to update HW MAC addresses.
8676 *
8677 * Return: None
8678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008679static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308680{
8681 QDF_STATUS status;
8682 int ret;
8683
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008684 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308685 if (ret == 0)
8686 return;
8687
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008688 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8689 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308690
8691 status = hdd_update_mac_config(hdd_ctx);
8692
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008693 if (QDF_IS_STATUS_SUCCESS(status))
8694 return;
8695
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008696 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8697 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008698
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008699 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008700 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008701 if (ret != 0) {
8702 hdd_err("MAC address out-of-sync, ret:%d", ret);
8703 QDF_ASSERT(ret);
8704 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008705 }
Komal Seelam92fff912016-03-24 11:51:41 +05308706}
8707
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008708static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008709{
8710 int vdev_id = 0;
8711 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8712 int value = hdd_ctx->config->smart_chainmask_enabled;
8713 int vpdev = PDEV_CMD;
8714 int ret;
8715
Naveen Rawat247a8682017-06-05 15:00:31 -07008716 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008717 if (ret)
8718 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8719
8720 return ret;
8721}
8722
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008723static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008724{
8725 int vdev_id = 0;
8726 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8727 int value = hdd_ctx->config->alternative_chainmask_enabled;
8728 int vpdev = PDEV_CMD;
8729 int ret;
8730
Naveen Rawat247a8682017-06-05 15:00:31 -07008731 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008732 if (ret)
8733 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8734 ret);
8735
8736 return ret;
8737}
8738
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008739static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008740{
8741 int vdev_id = 0;
8742 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8743 int value = hdd_ctx->config->ani_enabled;
8744 int vpdev = PDEV_CMD;
8745 int ret;
8746
Naveen Rawat247a8682017-06-05 15:00:31 -07008747 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008748 if (ret)
8749 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8750
8751 return ret;
8752}
8753
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008754/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008755 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8756 * @hdd_ctx: HDD context
8757 *
8758 * Pre configurations to be done at lower layer before calling cds enable.
8759 *
8760 * Return: 0 on success and errno on failure.
8761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008762static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008763{
8764 int ret;
8765 QDF_STATUS status;
8766 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008767 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008768
Leo Changfdb45c32016-10-28 11:09:23 -07008769 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008770 /*
8771 * Set 802.11p config
8772 * TODO-OCB: This has been temporarily added here to ensure this
8773 * parameter is set in CSR when we init the channel list. This should
8774 * be removed once the 5.9 GHz channels are added to the regulatory
8775 * domain.
8776 */
8777 hdd_set_dot11p_config(hdd_ctx);
8778
8779 /*
8780 * Note that the cds_pre_enable() sequence triggers the cfg download.
8781 * The cfg download must occur before we update the SME config
8782 * since the SME config operation must access the cfg database
8783 */
8784 status = hdd_set_sme_config(hdd_ctx);
8785
8786 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008787 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008788 ret = qdf_status_to_os_return(status);
8789 goto out;
8790 }
8791
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008792 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8793 if (QDF_STATUS_SUCCESS != status) {
8794 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8795 ret = qdf_status_to_os_return(status);
8796 goto out;
8797 }
8798
Naveen Rawat247a8682017-06-05 15:00:31 -07008799 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008800 hdd_ctx->config->tx_chain_mask_1ss,
8801 PDEV_CMD);
8802 if (0 != ret) {
8803 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8804 goto out;
8805 }
8806
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008807 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8808 if (ret)
8809 goto out;
8810
8811 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8812 if (ret)
8813 goto out;
8814
Jeff Johnson12a744b2017-04-04 08:19:37 -07008815 ret = hdd_set_ani_enabled(hdd_ctx);
8816 if (ret)
8817 goto out;
8818
Naveen Rawat247a8682017-06-05 15:00:31 -07008819 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008820 hdd_ctx->config->arp_ac_category,
8821 PDEV_CMD);
8822 if (0 != ret) {
8823 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8824 hdd_ctx->config->arp_ac_category, ret);
8825 goto out;
8826 }
8827
8828
Prashanth Bhatta07998752016-04-28 12:35:33 -07008829 status = hdd_set_sme_chan_list(hdd_ctx);
8830 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008831 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008832 ret = qdf_status_to_os_return(status);
8833 goto out;
8834 }
8835
8836 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008837 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008838 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008839 ret = -EINVAL;
8840 goto out;
8841 }
8842
Prashanth Bhatta07998752016-04-28 12:35:33 -07008843 /*
8844 * Set the MAC Address Currently this is used by HAL to add self sta.
8845 * Remove this once self sta is added as part of session open.
8846 */
8847 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8848 hdd_ctx->config->intfMacAddr[0].bytes,
8849 sizeof(hdd_ctx->config->intfMacAddr[0]));
8850
8851 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8852 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8853 hal_status, hal_status);
8854 ret = -EINVAL;
8855 goto out;
8856 }
8857
8858 hdd_init_channel_avoidance(hdd_ctx);
8859
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308860 /* update enable sap mandatory chan list */
8861 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8862 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008863out:
8864 return ret;
8865}
8866
8867/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008868 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8869 * @context_ptr - hdd context pointer
8870 * @event_ptr - event structure pointer
8871 *
8872 * This is the p2p listen offload stop event handler, it sends vendor
8873 * event back to supplicant to notify the stop reason.
8874 *
8875 * Return: None
8876 */
8877static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8878 void *event_ptr)
8879{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008880 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008881 struct sir_p2p_lo_event *evt = event_ptr;
8882 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008883 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008884
8885 ENTER();
8886
8887 if (hdd_ctx == NULL) {
8888 hdd_err("Invalid HDD context pointer");
8889 return;
8890 }
8891
Peng Xu5c682812017-08-06 07:39:13 -07008892 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8893 if (!adapter) {
8894 hdd_err("Cannot find adapter by vdev_id = %d",
8895 evt->vdev_id);
8896 return;
8897 }
8898
Peng Xu8fdaa492016-06-22 10:20:47 -07008899 vendor_event =
8900 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008901 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008902 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8903 GFP_KERNEL);
8904
8905 if (!vendor_event) {
8906 hdd_err("cfg80211_vendor_event_alloc failed");
8907 return;
8908 }
8909
8910 if (nla_put_u32(vendor_event,
8911 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8912 evt->reason_code)) {
8913 hdd_err("nla put failed");
8914 kfree_skb(vendor_event);
8915 return;
8916 }
8917
8918 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008919 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8920 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008921}
8922
8923/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308924 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8925 * @hdd_ctx: HDD context
8926 *
8927 * This function sends the adaptive dwell time config configuration to the
8928 * firmware via WMA
8929 *
8930 * Return: 0 - success, < 0 - failure
8931 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008932static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308933{
8934 QDF_STATUS status;
8935 struct adaptive_dwelltime_params dwelltime_params;
8936
8937 dwelltime_params.is_enabled =
8938 hdd_ctx->config->adaptive_dwell_mode_enabled;
8939 dwelltime_params.dwelltime_mode =
8940 hdd_ctx->config->global_adapt_dwelltime_mode;
8941 dwelltime_params.lpf_weight =
8942 hdd_ctx->config->adapt_dwell_lpf_weight;
8943 dwelltime_params.passive_mon_intval =
8944 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8945 dwelltime_params.wifi_act_threshold =
8946 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8947
8948 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8949 &dwelltime_params);
8950
8951 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8952 if (!QDF_IS_STATUS_SUCCESS(status)) {
8953 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8954 return -EAGAIN;
8955 }
8956 return 0;
8957}
8958
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008959int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308960{
8961 QDF_STATUS status;
8962 struct wmi_dbs_scan_sel_params dbs_scan_params;
8963 uint32_t i = 0;
8964 uint8_t count = 0, numentries = 0;
8965 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8966 * CDS_DBS_SCAN_CLIENTS_MAX];
8967
8968 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008969 if (hdd_ctx->config->dual_mac_feature_disable ==
8970 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308971 return -EINVAL;
8972
8973 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8974 dbs_scan_config, &numentries,
8975 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8976 * CDS_DBS_SCAN_CLIENTS_MAX));
8977
8978 hdd_info("numentries %hu", numentries);
8979 if (!numentries) {
8980 hdd_info("Donot send scan_selection_config");
8981 return 0;
8982 }
8983
8984 /* hdd_set_fw_log_params */
8985 dbs_scan_params.num_clients = 0;
8986 while (count < (numentries - 2)) {
8987 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8988 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8989 dbs_scan_params.num_non_dbs_scans[i] =
8990 dbs_scan_config[count + 2];
8991 dbs_scan_params.num_clients++;
8992 hdd_debug("module:%d NDS:%d NNDS:%d",
8993 dbs_scan_params.module_id[i],
8994 dbs_scan_params.num_dbs_scans[i],
8995 dbs_scan_params.num_non_dbs_scans[i]);
8996 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8997 i++;
8998 }
8999
9000 dbs_scan_params.pdev_id = 0;
9001
9002 hdd_debug("clients:%d pdev:%d",
9003 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9004
9005 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9006 &dbs_scan_params);
9007 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9008 if (!QDF_IS_STATUS_SUCCESS(status)) {
9009 hdd_err("Failed to send DBS Scan selection configuration!");
9010 return -EAGAIN;
9011 }
9012 return 0;
9013}
9014
Arun Khandavallid4349a92016-07-25 11:10:43 +05309015#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9016/**
9017 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9018 * @hdd_ctx: HDD context
9019 *
9020 * Set auto shutdown callback to get indications from firmware to indicate
9021 * userspace to shutdown WLAN after a configured amount of inactivity.
9022 *
9023 * Return: 0 on success and errno on failure.
9024 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009025static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309026{
9027 QDF_STATUS status;
9028
9029 if (!hdd_ctx->config->WlanAutoShutdown)
9030 return 0;
9031
9032 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9033 wlan_hdd_auto_shutdown_cb);
9034 if (status != QDF_STATUS_SUCCESS)
9035 hdd_err("Auto shutdown feature could not be enabled: %d",
9036 status);
9037
9038 return qdf_status_to_os_return(status);
9039}
9040#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009041static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309042{
9043 return 0;
9044}
9045#endif
9046
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009047static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009048{
9049 QDF_STATUS status = QDF_STATUS_SUCCESS;
9050
9051 switch (hdd_ctx->config->dual_mac_feature_disable) {
9052 case DISABLE_DBS_CXN_AND_SCAN:
9053 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9054 if (status != QDF_STATUS_SUCCESS)
9055 hdd_err("Failed to disable dual mac features");
9056 break;
9057 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9058 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9059 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9060 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9061 if (status != QDF_STATUS_SUCCESS)
9062 hdd_err("Failed to set dbs scan and fw mode config");
9063 break;
9064 default:
9065 break;
9066 }
9067
9068 return status;
9069}
9070
Arun Khandavallid4349a92016-07-25 11:10:43 +05309071/**
9072 * hdd_features_init() - Init features
9073 * @hdd_ctx: HDD context
9074 * @adapter: Primary adapter context
9075 *
9076 * Initialize features and their feature context after WLAN firmware is up.
9077 *
9078 * Return: 0 on success and errno on failure.
9079 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009080static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309081{
9082 tSirTxPowerLimit hddtxlimit;
9083 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309084 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309085 int ret;
9086
9087 ENTER();
9088
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009089 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309090 if (ret) {
9091 hdd_err("Failed to update country code: %d", ret);
9092 goto out;
9093 }
9094
9095 /* FW capabilities received, Set the Dot11 mode */
9096 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009097 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9098 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309099
Arun Khandavallid4349a92016-07-25 11:10:43 +05309100
9101 if (hdd_ctx->config->fIsImpsEnabled)
9102 hdd_set_idle_ps_config(hdd_ctx, true);
9103 else
9104 hdd_set_idle_ps_config(hdd_ctx, false);
9105
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309106 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009107 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309108
Arun Khandavallid4349a92016-07-25 11:10:43 +05309109 if (hdd_lro_init(hdd_ctx))
9110 hdd_err("Unable to initialize LRO in fw");
9111
9112 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9113 hdd_err("Unable to send adaptive dwelltime setting to FW");
9114
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309115 if (hdd_dbs_scan_selection_init(hdd_ctx))
9116 hdd_err("Unable to send DBS scan selection setting to FW");
9117
Arun Khandavallid4349a92016-07-25 11:10:43 +05309118 ret = hdd_init_thermal_info(hdd_ctx);
9119 if (ret) {
9120 hdd_err("Error while initializing thermal information");
9121 goto deregister_frames;
9122 }
9123
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309124 if (cds_is_packet_log_enabled())
9125 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9126
Arun Khandavallid4349a92016-07-25 11:10:43 +05309127 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9128 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9129 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9130 if (!QDF_IS_STATUS_SUCCESS(status))
9131 hdd_err("Error setting txlimit in sme: %d", status);
9132
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009133 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309134
Arun Khandavallid4349a92016-07-25 11:10:43 +05309135 ret = hdd_register_cb(hdd_ctx);
9136 if (ret) {
9137 hdd_err("Failed to register HDD callbacks!");
9138 goto deregister_frames;
9139 }
9140
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009141 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9142 if (!QDF_IS_STATUS_SUCCESS(status)) {
9143 hdd_err("Failed to set dbs scan and fw mode cfg");
9144 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309145 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009146
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309147 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9148 status = sme_enable_disable_chanavoidind_event(
9149 hdd_ctx->hHal, 0);
9150 if (!QDF_IS_STATUS_SUCCESS(status)) {
9151 hdd_err("Failed to disable Chan Avoidance Indication");
9152 goto deregister_cb;
9153 }
9154 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309155
Manjeet Singha9cae432017-02-28 11:58:22 +05309156 if (hdd_ctx->config->enable_5g_band_pref) {
9157 band_pref_params.rssi_boost_threshold_5g =
9158 hdd_ctx->config->rssi_boost_threshold_5g;
9159 band_pref_params.rssi_boost_factor_5g =
9160 hdd_ctx->config->rssi_boost_factor_5g;
9161 band_pref_params.max_rssi_boost_5g =
9162 hdd_ctx->config->max_rssi_boost_5g;
9163 band_pref_params.rssi_penalize_threshold_5g =
9164 hdd_ctx->config->rssi_penalize_threshold_5g;
9165 band_pref_params.rssi_penalize_factor_5g =
9166 hdd_ctx->config->rssi_penalize_factor_5g;
9167 band_pref_params.max_rssi_penalize_5g =
9168 hdd_ctx->config->max_rssi_penalize_5g;
9169 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9170 }
9171
Arun Khandavallid4349a92016-07-25 11:10:43 +05309172 /* register P2P Listen Offload event callback */
9173 if (wma_is_p2p_lo_capable())
9174 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9175 wlan_hdd_p2p_lo_event_callback);
9176
9177 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9178
9179 if (ret)
9180 goto deregister_cb;
9181
9182 EXIT();
9183 return 0;
9184
9185deregister_cb:
9186 hdd_deregister_cb(hdd_ctx);
9187deregister_frames:
9188 wlan_hdd_cfg80211_deregister_frames(adapter);
9189out:
9190 return -EINVAL;
9191
9192}
9193
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009194/**
9195 * hdd_features_deinit() - Deinit features
9196 * @hdd_ctx: HDD context
9197 *
9198 * De-Initialize features and their feature context.
9199 *
9200 * Return: none.
9201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009202static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009203{
9204 wlan_hdd_tsf_deinit(hdd_ctx);
9205}
9206
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309207/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009208 * hdd_register_bcn_cb() - register scan beacon callback
9209 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309210 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009211 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309212 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009213static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309214{
9215 QDF_STATUS status;
9216
9217 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9218 wlan_cfg80211_inform_bss_frame,
9219 SCAN_CB_TYPE_INFORM_BCN);
9220 if (!QDF_IS_STATUS_SUCCESS(status)) {
9221 hdd_err("failed with status code %08d [x%08x]",
9222 status, status);
9223 return status;
9224 }
9225
9226 return QDF_STATUS_SUCCESS;
9227}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309228
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309229/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309230 * hdd_configure_cds() - Configure cds modules
9231 * @hdd_ctx: HDD context
9232 * @adapter: Primary adapter context
9233 *
9234 * Enable Cds modules after WLAN firmware is up.
9235 *
9236 * Return: 0 on success and errno on failure.
9237 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009238int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309239{
9240 int ret;
9241 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309242
9243 ret = hdd_pre_enable_configure(hdd_ctx);
9244 if (ret) {
9245 hdd_err("Failed to pre-configure cds");
9246 goto out;
9247 }
9248
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009249 /* Always get latest IPA resources allocated from cds_open and configure
9250 * IPA module before configuring them to FW. Sequence required as crash
9251 * observed otherwise.
9252 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009253 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9254 hdd_err("Failed to setup pipes");
9255 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009256 }
9257
Arun Khandavallifae92942016-08-01 13:31:08 +05309258 /*
9259 * Start CDS which starts up the SME/MAC/HAL modules and everything
9260 * else
9261 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009262 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309263
9264 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009265 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309266 goto out;
9267 }
9268
9269 status = hdd_post_cds_enable_config(hdd_ctx);
9270 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009271 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009272 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309273 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309274 status = hdd_register_bcn_cb(hdd_ctx);
9275 if (!QDF_IS_STATUS_SUCCESS(status)) {
9276 hdd_alert("hdd_post_cds_enable_config failed");
9277 goto cds_disable;
9278 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309279
9280 ret = hdd_features_init(hdd_ctx, adapter);
9281 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009282 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309283
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309284 if (hdd_enable_egap(hdd_ctx))
9285 hdd_debug("enhance green ap is not enabled");
9286
Nachiket Kukadedd302662017-07-13 17:31:44 +05309287 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9288 hdd_debug("Failed to set wow pulse");
9289
Arun Khandavallifae92942016-08-01 13:31:08 +05309290 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009291
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009292cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009293 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009294
Arun Khandavallifae92942016-08-01 13:31:08 +05309295out:
9296 return -EINVAL;
9297}
9298
9299/**
9300 * hdd_deconfigure_cds() -De-Configure cds
9301 * @hdd_ctx: HDD context
9302 *
9303 * Deconfigure Cds modules before WLAN firmware is down.
9304 *
9305 * Return: 0 on success and errno on failure.
9306 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009307static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309308{
9309 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009310 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309311
9312 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009313
9314 /* De-init features */
9315 hdd_features_deinit(hdd_ctx);
9316
Arun Khandavallifae92942016-08-01 13:31:08 +05309317 /* De-register the SME callbacks */
9318 hdd_deregister_cb(hdd_ctx);
9319
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009320 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309321 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9322 hdd_err("Failed to Disable the CDS Modules! :%d",
9323 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009324 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309325 }
9326
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309327 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9328 hdd_err("Failed to disconnect pipes");
9329 ret = -EINVAL;
9330 }
9331
Arun Khandavallifae92942016-08-01 13:31:08 +05309332 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009333 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309334}
9335
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009336#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9337static void hdd_deregister_policy_manager_callback(
9338 struct wlan_objmgr_psoc *psoc)
9339{
9340 if (QDF_STATUS_SUCCESS !=
9341 policy_mgr_deregister_hdd_cb(psoc)) {
9342 hdd_err("HDD callback deregister with policy manager failed");
9343 }
9344}
9345#else
9346static void hdd_deregister_policy_manager_callback(
9347 struct wlan_objmgr_psoc *psoc)
9348{
9349}
9350#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309351
9352/**
9353 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9354 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009355 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309356 *
9357 * This function maintains the driver state machine it will be invoked from
9358 * exit, shutdown and con_mode change handler. Depending on the driver state
9359 * shall perform the stopping/closing of the modules.
9360 *
9361 * Return: 0 for success; non-zero for failure
9362 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009363int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309364{
9365 void *hif_ctx;
9366 qdf_device_t qdf_ctx;
9367 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309368 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009369 bool is_idle_stop = !cds_is_driver_unloading() &&
9370 !cds_is_driver_recovering();
9371 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309372
9373 ENTER();
9374
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009375 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9376
Arun Khandavallifae92942016-08-01 13:31:08 +05309377 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9378 if (!qdf_ctx) {
9379 hdd_err("QDF device context NULL");
9380 return -EINVAL;
9381 }
9382
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309383 mutex_lock(&hdd_ctx->iface_change_lock);
9384 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309385
Dustin Brown70111822017-03-30 15:31:40 -07009386 active_threads = cds_return_external_threads_count();
9387 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009388 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009389 active_threads, hdd_ctx->isWiphySuspended);
9390
9391 cds_print_external_threads();
9392
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009393 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009394 mutex_unlock(&hdd_ctx->iface_change_lock);
9395 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009396 hdd_ctx->config->iface_change_wait_time);
9397 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009398 return 0;
9399 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009400 }
9401
Arun Khandavallifae92942016-08-01 13:31:08 +05309402 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9403
9404 switch (hdd_ctx->driver_status) {
9405 case DRIVER_MODULES_UNINITIALIZED:
9406 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309407 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309408 case DRIVER_MODULES_CLOSED:
9409 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309410 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309411 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309412 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309413 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009414 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309415 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309416 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309417 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009418 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309419 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9420 break;
9421 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009422 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309423 break;
9424 default:
9425 hdd_err("Trying to stop wlan in a wrong state: %d",
9426 hdd_ctx->driver_status);
9427 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309428 ret = -EINVAL;
9429 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309430 }
9431
Rajeev Kumarbe021242017-02-16 16:12:23 -08009432 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309433 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9434 hdd_err("Failed to process post CDS disable Modules! :%d",
9435 qdf_status);
9436 ret = -EINVAL;
9437 QDF_ASSERT(0);
9438 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009439 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309440 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009441 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309442 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309443 QDF_ASSERT(0);
9444 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009445
Arun Khandavallifae92942016-08-01 13:31:08 +05309446 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9447 if (!hif_ctx) {
9448 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309449 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309450 }
9451
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309452 hdd_runtime_suspend_context_deinit(hdd_ctx);
9453
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309454 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309455
9456 ol_cds_free();
9457
Dustin Brown70111822017-03-30 15:31:40 -07009458 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309459 ret = pld_power_off(qdf_ctx->dev);
9460 if (ret)
9461 hdd_err("CNSS power down failed put device into Low power mode:%d",
9462 ret);
9463 }
9464 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009465 /*
9466 * Reset total mac phy during module stop such that during
9467 * next module start same psoc is used to populate new service
9468 * ready data
9469 */
9470 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309471
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309472done:
9473 hdd_ctx->stop_modules_in_progress = false;
9474 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309475 EXIT();
9476
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309477 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309478
9479}
9480
9481/**
9482 * hdd_iface_change_callback() - Function invoked when stop modules expires
9483 * @priv: pointer to hdd context
9484 *
9485 * This function is invoked when the timer waiting for the interface change
9486 * expires, it shall cut-down the power to wlan and stop all the modules.
9487 *
9488 * Return: void
9489 */
9490static void hdd_iface_change_callback(void *priv)
9491{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009492 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309493 int ret;
9494 int status = wlan_hdd_validate_context(hdd_ctx);
9495
9496 if (status)
9497 return;
9498
9499 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009500 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009501 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309502 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009503 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309504 EXIT();
9505}
9506
9507/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309508 * hdd_state_info_dump() - prints state information of hdd layer
9509 * @buf: buffer pointer
9510 * @size: size of buffer to be filled
9511 *
9512 * This function is used to dump state information of hdd layer
9513 *
9514 * Return: None
9515 */
9516static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9517{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009518 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309519 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9520 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009521 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009522 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309523 uint16_t len = 0;
9524 char *buf = *buf_ptr;
9525
9526 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9527 if (!hdd_ctx) {
9528 hdd_err("Failed to get hdd context ");
9529 return;
9530 }
9531
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009532 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309533
9534 len += scnprintf(buf + len, *size - len,
9535 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9536 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009537 "\n is_scheduler_suspended %d",
9538 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309539
9540 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9541
9542 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9543 adapter = adapter_node->pAdapter;
9544 if (adapter->dev)
9545 len += scnprintf(buf + len, *size - len,
9546 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009547 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309548 "\n device_mode: %d", adapter->device_mode);
9549 switch (adapter->device_mode) {
9550 case QDF_STA_MODE:
9551 case QDF_P2P_CLIENT_MODE:
9552 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9553 len += scnprintf(buf + len, *size - len,
9554 "\n connState: %d",
9555 hdd_sta_ctx->conn_info.connState);
9556 break;
9557
9558 default:
9559 break;
9560 }
9561 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9562 adapter_node = next;
9563 }
9564
9565 *size -= len;
9566 *buf_ptr += len;
9567}
9568
9569/**
9570 * hdd_register_debug_callback() - registration function for hdd layer
9571 * to print hdd state information
9572 *
9573 * Return: None
9574 */
9575static void hdd_register_debug_callback(void)
9576{
9577 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9578}
9579
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309580/*
9581 * wlan_init_bug_report_lock() - Initialize bug report lock
9582 *
9583 * This function is used to create bug report lock
9584 *
9585 * Return: None
9586 */
9587static void wlan_init_bug_report_lock(void)
9588{
9589 p_cds_contextType p_cds_context;
9590
9591 p_cds_context = cds_get_global_context();
9592 if (!p_cds_context) {
9593 hdd_err("cds context is NULL");
9594 return;
9595 }
9596
9597 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9598}
9599
Mohit Khannaf8f96822017-05-17 17:11:59 -07009600void hdd_dp_trace_init(struct hdd_config *config)
9601{
9602
9603 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9604 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9605 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9606 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9607 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9608 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9609 uint8_t num_entries = 0;
9610
9611 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9612 &num_entries, sizeof(config_params));
9613
9614 /* calculating, num bw timer intervals in a second (1000ms) */
9615 if (config->busBandwidthComputeInterval)
9616 thresh_time_limit =
9617 (1000 / config->busBandwidthComputeInterval);
9618 else
9619 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9620
9621 switch (num_entries) {
9622 case 4:
9623 proto_bitmap = config_params[3];
9624 case 3:
9625 verbosity = config_params[2];
9626 case 2:
9627 thresh = config_params[1];
9628 case 1:
9629 live_mode = config_params[0];
9630 default:
9631 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9632 live_mode, thresh, thresh_time_limit,
9633 verbosity, proto_bitmap);
9634 };
9635
9636 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9637 verbosity, proto_bitmap);
9638
9639}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309640/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009641 * hdd_wlan_startup() - HDD init function
9642 * @dev: Pointer to the underlying device
9643 *
9644 * This is the driver startup code executed once a WLAN device has been detected
9645 *
9646 * Return: 0 for success, < 0 for failure
9647 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309648int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009649{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309650 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009651 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009652 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009653 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309654 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009655 uint32_t num_abg_tx_chains = 0;
9656 uint32_t num_11b_tx_chains = 0;
9657 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009658
9659 ENTER();
9660
Arun Khandavallifae92942016-08-01 13:31:08 +05309661 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009662
9663 if (IS_ERR(hdd_ctx))
9664 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009665
Abhishek Singhe9068f12017-03-31 14:14:52 +05309666 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9667 DEFAULT_PSOC_ID);
9668 if (ret) {
9669 hdd_err("Psoc creation fails!");
9670 QDF_BUG(0);
9671 goto err_hdd_free_context;
9672 }
9673
Arun Khandavallifae92942016-08-01 13:31:08 +05309674 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9675 hdd_iface_change_callback, (void *)hdd_ctx);
9676
9677 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309678#ifdef FEATURE_WLAN_CH_AVOID
9679 mutex_init(&hdd_ctx->avoid_freq_lock);
9680#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309681
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009682 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009683 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309684
Jeff Johnson957bc272017-02-02 08:54:48 -08009685 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309686 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009687 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009688 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009689 }
9690
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309691 wlan_init_bug_report_lock();
9692
Yingying Tang80e15f32016-09-27 18:23:01 +08009693 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009694
Anurag Chouhan6d760662016-02-20 16:05:43 +05309695 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009696
9697 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009698 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309699 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009700 }
9701
Prashanth Bhatta07998752016-04-28 12:35:33 -07009702 ret = hdd_wiphy_init(hdd_ctx);
9703 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009704 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309705 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009706 }
9707
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309708 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009709 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309710
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309711 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009712 goto err_wiphy_unregister;
9713
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309714 wlan_hdd_init_chan_info(hdd_ctx);
9715
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009716 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009717
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009718 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009719
Jeff Johnson957bc272017-02-02 08:54:48 -08009720 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9721 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009722 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009723 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009724 }
9725
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009726 hdd_release_rtnl_lock();
9727 rtnl_held = false;
9728
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009729 wlan_hdd_update_11n_mode(hdd_ctx->config);
9730
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009731#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309732 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309733 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009734 hdd_skip_acs_scan_timer_handler,
9735 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309736 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009737 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009738 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009739#endif
9740
Nitesh Shah61c10d92016-10-19 19:29:15 +05309741 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9742 QDF_TIMER_TYPE_SW,
9743 wlan_hdd_change_tdls_mode,
9744 hdd_ctx);
9745
Prashanth Bhattaab004382016-10-11 16:08:11 -07009746 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009747
Jeff Johnson9afc5012016-09-23 13:56:27 -07009748 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009749
Nirav Shahbd36b062016-07-18 11:12:59 +05309750 if (hdd_ctx->rps)
9751 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009752
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009753 ret = hdd_register_notifiers(hdd_ctx);
9754 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009755 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309756
9757 status = wlansap_global_init();
9758 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009759 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009760
Komal Seelam8634b772016-09-29 12:12:24 +05309761 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009762 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309763 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009764
Arun Khandavallifae92942016-08-01 13:31:08 +05309765 if (hdd_ctx->config->fIsImpsEnabled)
9766 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309767
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309768 if (hdd_ctx->config->sifs_burst_duration) {
9769 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9770 hdd_ctx->config->sifs_burst_duration;
9771
9772 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009773 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309774 set_value, PDEV_CMD);
9775 }
9776
Paul Zhang42dade02017-05-12 19:20:37 +08009777 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009778 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009779 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309780 /* set chip power save failure detected callback */
9781 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9782 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009783
lifeng959a04c2017-05-10 14:21:28 +08009784 if (hdd_ctx->config->max_mpdus_inampdu) {
9785 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009786 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009787 set_value, PDEV_CMD);
9788 }
9789
9790 if (hdd_ctx->config->enable_rts_sifsbursting) {
9791 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009792 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009793 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9794 set_value, PDEV_CMD);
9795 }
9796
Will Huang496b36c2017-07-11 16:38:50 +08009797 if (hdd_ctx->config->sap_get_peer_info) {
9798 set_value = hdd_ctx->config->sap_get_peer_info;
9799 sme_cli_set_command(0,
9800 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9801 set_value, PDEV_CMD);
9802 }
9803
Naveen Rawat247a8682017-06-05 15:00:31 -07009804 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9805 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9806 if (!hdd_ctx->config->enable2x2) {
9807 if (num_11b_tx_chains > 1)
9808 num_11b_tx_chains = 1;
9809 if (num_11ag_tx_chains > 1)
9810 num_11ag_tx_chains = 1;
9811 }
9812 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9813 num_11b_tx_chains);
9814 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9815 num_11ag_tx_chains);
9816 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9817 num_abg_tx_chains, PDEV_CMD);
9818
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309819 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9820 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309821 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309822
Sachin Ahujadddd2632017-03-07 19:07:24 +05309823 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009824 goto success;
9825
Jeff Johnson957bc272017-02-02 08:54:48 -08009826err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009827 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009828
Jeff Johnson46bde382017-02-01 15:31:16 -08009829err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309830 if (rtnl_held)
9831 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009832
Anurag Chouhance6a4052016-09-14 18:20:42 +05309833 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009834
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009835err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009836 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009837
Arun Khandavallifae92942016-08-01 13:31:08 +05309838err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009839 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309840
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009841err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309842 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009843 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309844 if (!QDF_IS_STATUS_SUCCESS(status)) {
9845 hdd_err("Failed to close CDS Scheduler");
9846 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9847 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009848 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009849
Houston Hoffman47a4a052016-11-14 23:22:44 -08009850 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009851 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009852 hdd_exit_netlink_services(hdd_ctx);
9853
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309854 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009855
Dustin Brown20912462017-06-07 13:48:25 -07009856 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9857
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009858err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309859 if (cds_is_fw_down())
9860 hdd_err("Not setting the complete event as fw is down");
9861 else
9862 hdd_start_complete(ret);
9863
Arun Khandavallifae92942016-08-01 13:31:08 +05309864 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9865 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009866 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867 return -EIO;
9868
9869success:
9870 EXIT();
9871 return 0;
9872}
9873
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009874/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309875 * hdd_wlan_update_target_info() - update target type info
9876 * @hdd_ctx: HDD context
9877 * @context: hif context
9878 *
9879 * Update target info received from firmware in hdd context
9880 * Return:None
9881 */
9882
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009883void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309884{
9885 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9886
9887 if (!tgt_info) {
9888 hdd_err("Target info is Null");
9889 return;
9890 }
9891
9892 hdd_ctx->target_type = tgt_info->target_type;
9893}
9894
9895/**
9896 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309897 * @hdd_ctx: HDD context
9898 *
9899 * Register the HDD callbacks to CDS/SME.
9900 *
9901 * Return: 0 for success or Error code for failure
9902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009903int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309904{
9905 QDF_STATUS status;
9906 int ret = 0;
9907
9908 ENTER();
9909
9910 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9911
9912 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9913 hdd_send_oem_data_rsp_msg);
9914
9915 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9916 wlan_hdd_cfg80211_fw_mem_dump_cb);
9917 if (!QDF_IS_STATUS_SUCCESS(status)) {
9918 hdd_err("Failed to register memdump callback");
9919 ret = -EINVAL;
9920 return ret;
9921 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309922 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9923 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309924 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9925 sme_nan_register_callback(hdd_ctx->hHal,
9926 wlan_hdd_cfg80211_nan_callback);
9927 sme_stats_ext_register_callback(hdd_ctx->hHal,
9928 wlan_hdd_cfg80211_stats_ext_callback);
9929
9930 sme_ext_scan_register_callback(hdd_ctx->hHal,
9931 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009932 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9933 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309934
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309935 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9936 hdd_rssi_threshold_breached);
9937
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309938 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9939 wlan_hdd_cfg80211_link_layer_stats_callback);
9940
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309941 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9942
Zhang Qianca38fb12016-12-23 11:10:48 +08009943 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9944 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9945
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309946 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9947 hdd_lost_link_info_cb);
9948 /* print error and not block the startup process */
9949 if (!QDF_IS_STATUS_SUCCESS(status))
9950 hdd_err("set lost link info callback failed");
9951
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309952 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9953
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009954 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009955 hdd_set_connection_in_progress,
9956 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309957
9958 status = sme_congestion_register_callback(hdd_ctx->hHal,
9959 hdd_update_cca_info_cb);
9960 if (!QDF_IS_STATUS_SUCCESS(status))
9961 hdd_err("set congestion callback failed");
9962
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +05309963 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
9964 hdd_bt_activity_cb);
9965 if (!QDF_IS_STATUS_SUCCESS(status))
9966 hdd_err("set bt activity info callback failed");
9967
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309968 EXIT();
9969
9970 return ret;
9971}
9972
9973/**
9974 * hdd_deregister_cb() - De-Register HDD callbacks.
9975 * @hdd_ctx: HDD context
9976 *
9977 * De-Register the HDD callbacks to CDS/SME.
9978 *
9979 * Return: void
9980 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009981void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309982{
9983 QDF_STATUS status;
9984
9985 ENTER();
9986
9987 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9988 if (!QDF_IS_STATUS_SUCCESS(status))
9989 hdd_err("De-register of dcc stats callback failed: %d",
9990 status);
9991
9992 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309993 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9994
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309995 sme_stats_ext_register_callback(hdd_ctx->hHal,
9996 wlan_hdd_cfg80211_stats_ext_callback);
9997
9998 sme_nan_deregister_callback(hdd_ctx->hHal);
9999 status = sme_reset_tsfcb(hdd_ctx->hHal);
10000 if (!QDF_IS_STATUS_SUCCESS(status))
10001 hdd_err("Failed to de-register tsfcb the callback:%d",
10002 status);
10003 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10004 if (!QDF_IS_STATUS_SUCCESS(status))
10005 hdd_err("Failed to de-register the fw mem dump callback: %d",
10006 status);
10007
10008 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10009 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10010
10011 EXIT();
10012}
10013
10014/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010015 * hdd_softap_sta_deauth() - handle deauth req from HDD
10016 * @adapter: Pointer to the HDD
10017 * @enable: bool value
10018 *
10019 * This to take counter measure to handle deauth req from HDD
10020 *
10021 * Return: None
10022 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010023QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010024 struct tagCsrDelStaParams *pDelStaParams)
10025{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010026 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010027
10028 ENTER();
10029
Jeff Johnson36e74c42017-09-18 08:15:42 -070010030 hdd_debug("hdd_softap_sta_deauth:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010031 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10032
10033 /* Ignore request to deauth bcmc station */
10034 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010035 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010036
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010037 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010038 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10039 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010040
10041 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010042 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010043}
10044
10045/**
10046 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10047 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010048 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010049 *
10050 * This to take counter measure to handle deauth req from HDD
10051 *
10052 * Return: None
10053 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010054void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010055 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010056{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010057 ENTER();
10058
Jeff Johnson36e74c42017-09-18 08:15:42 -070010059 hdd_debug("hdd_softap_sta_disassoc:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010060 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10061
10062 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010063 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010064 return;
10065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010066 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010067 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010068}
10069
Jeff Johnson9d295242017-08-29 14:39:48 -070010070void hdd_softap_tkip_mic_fail_counter_measure(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010071 bool enable)
10072{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010073 ENTER();
10074
Jeff Johnson36e74c42017-09-18 08:15:42 -070010075 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%pK, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010076 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010078 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10079 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010080}
10081
10082/**
10083 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10084 * @hdd_ctx: HDD Context
10085 *
10086 * API to find if there is any STA or P2P-Client is connected
10087 *
10088 * Return: true if connected; false otherwise
10089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010090QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010091{
10092 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10093}
10094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010095/**
10096 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10097 * @adapter: HDD adapter pointer
10098 *
10099 * This function loop through each adapter and disable roaming on each STA
10100 * device mode except the input adapter.
10101 *
10102 * Note: On the input adapter roaming is not enabled yet hence no need to
10103 * disable.
10104 *
10105 * Return: None
10106 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010107void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010108{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010109 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010110 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010111 hdd_adapter_list_node_t *adapterNode = NULL;
10112 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010113 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010114
10115 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010116 hdd_ctx->config->isRoamOffloadScanEnabled &&
10117 QDF_STA_MODE == adapter->device_mode &&
10118 policy_mgr_is_sta_active_connection_exists(
10119 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010120 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121 adapter->sessionId);
10122 /*
10123 * Loop through adapter and disable roaming for each STA device
10124 * mode except the input adapter.
10125 */
10126 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10127
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010128 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010129 adapterIdx = adapterNode->pAdapter;
10130
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010131 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010132 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010133 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010134 adapterIdx->sessionId);
10135 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10136 (adapterIdx),
10137 adapterIdx->sessionId, 0);
10138 }
10139
10140 status = hdd_get_next_adapter(hdd_ctx,
10141 adapterNode,
10142 &pNext);
10143 adapterNode = pNext;
10144 }
10145 }
10146}
10147
10148/**
10149 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10150 * @adapter: HDD adapter pointer
10151 *
10152 * This function loop through each adapter and enable roaming on each STA
10153 * device mode except the input adapter.
10154 * Note: On the input adapter no need to enable roaming because link got
10155 * disconnected on this.
10156 *
10157 * Return: None
10158 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010159void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010160{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010161 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010162 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010163 hdd_adapter_list_node_t *adapterNode = NULL;
10164 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010165 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010166
10167 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010168 hdd_ctx->config->isRoamOffloadScanEnabled &&
10169 QDF_STA_MODE == adapter->device_mode &&
10170 policy_mgr_is_sta_active_connection_exists(
10171 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010172 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010173 adapter->sessionId);
10174 /*
10175 * Loop through adapter and enable roaming for each STA device
10176 * mode except the input adapter.
10177 */
10178 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10179
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010180 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010181 adapterIdx = adapterNode->pAdapter;
10182
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010183 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010184 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010185 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010186 adapterIdx->sessionId);
10187 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10188 (adapterIdx),
10189 adapterIdx->sessionId,
10190 REASON_CONNECT);
10191 }
10192
10193 status = hdd_get_next_adapter(hdd_ctx,
10194 adapterNode,
10195 &pNext);
10196 adapterNode = pNext;
10197 }
10198 }
10199}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010200
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010201/**
10202 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10203 * @skb: sk buffer pointer
10204 *
10205 * Sends the bcast message to SVC multicast group with generic nl socket
10206 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10207 *
10208 * Return: None
10209 */
10210static void nl_srv_bcast_svc(struct sk_buff *skb)
10211{
10212#ifdef CNSS_GENL
10213 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10214#else
10215 nl_srv_bcast(skb);
10216#endif
10217}
10218
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010219void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010220{
10221 struct sk_buff *skb;
10222 struct nlmsghdr *nlh;
10223 tAniMsgHdr *ani_hdr;
10224 void *nl_data = NULL;
10225 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010226 struct radio_index_tlv *radio_info;
10227 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010228
10229 if (in_interrupt() || irqs_disabled() || in_atomic())
10230 flags = GFP_ATOMIC;
10231
10232 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10233
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010234 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010235 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010236
10237 nlh = (struct nlmsghdr *)skb->data;
10238 nlh->nlmsg_pid = 0; /* from kernel */
10239 nlh->nlmsg_flags = 0;
10240 nlh->nlmsg_seq = 0;
10241 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10242
10243 ani_hdr = NLMSG_DATA(nlh);
10244 ani_hdr->type = type;
10245
10246 switch (type) {
10247 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010248 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010249 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010250 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010251 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010252 ani_hdr->length = 0;
10253 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010254 break;
10255 case WLAN_SVC_WLAN_STATUS_IND:
10256 case WLAN_SVC_WLAN_VERSION_IND:
10257 case WLAN_SVC_DFS_CAC_START_IND:
10258 case WLAN_SVC_DFS_CAC_END_IND:
10259 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10260 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10261 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010262 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010263 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010264 ani_hdr->length = len;
10265 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10266 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10267 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268 break;
10269
10270 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010271 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010272 type);
10273 kfree_skb(skb);
10274 return;
10275 }
10276
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010277 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010278 * Add radio index at the end of the svc event in TLV format
10279 * to maintain the backward compatibility with userspace
10280 * applications.
10281 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010282
10283 tlv_len = 0;
10284
10285 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10286 < WLAN_NL_MAX_PAYLOAD) {
10287 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10288 sizeof(*ani_hdr) + len);
10289 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10290 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10291 radio_info->radio = radio;
10292 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010293 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010294 "Added radio index tlv - radio index %d",
10295 radio_info->radio);
10296 }
10297
10298 nlh->nlmsg_len += tlv_len;
10299 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10300
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010301 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010302}
10303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010304#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10305void wlan_hdd_auto_shutdown_cb(void)
10306{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010307 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010308
10309 if (!hdd_ctx)
10310 return;
10311
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010312 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010313 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10314 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010315}
10316
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010317void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010318{
10319 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010320 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010321 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010322 bool ap_connected = false, sta_connected = false;
10323 tHalHandle hal_handle;
10324
10325 hal_handle = hdd_ctx->hHal;
10326 if (hal_handle == NULL)
10327 return;
10328
10329 if (hdd_ctx->config->WlanAutoShutdown == 0)
10330 return;
10331
10332 if (enable == false) {
10333 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010334 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010335 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010336 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010337 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010338 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010339 return;
10340 }
10341
10342 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010343 if (policy_mgr_concurrent_open_sessions_running(
10344 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010345 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010347 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010348 adapter = adapterNode->pAdapter;
10349 if (adapter
10350 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010351 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010352 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10353 conn_info.connState ==
10354 eConnectionState_Associated) {
10355 sta_connected = true;
10356 break;
10357 }
10358 }
10359 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010360 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10362 bApActive == true) {
10363 ap_connected = true;
10364 break;
10365 }
10366 }
10367 status = hdd_get_next_adapter(hdd_ctx,
10368 adapterNode,
10369 &pNext);
10370 adapterNode = pNext;
10371 }
10372 }
10373
10374 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010375 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010376 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010377 }
Jeff Johnson68755312017-02-10 11:46:55 -080010378
10379 if (sme_set_auto_shutdown_timer(hal_handle,
10380 hdd_ctx->config->WlanAutoShutdown)
10381 != QDF_STATUS_SUCCESS)
10382 hdd_err("Failed to start wlan auto shutdown timer");
10383 else
10384 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10385 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010386}
10387#endif
10388
Jeff Johnson9d295242017-08-29 14:39:48 -070010389struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010390 bool check_start_bss)
10391{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010392 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010393 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010394 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010395 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10396
10397 con_sap_adapter = NULL;
10398
10399 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010400 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010402 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10403 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010404 adapter != this_sap_adapter) {
10405 if (check_start_bss) {
10406 if (test_bit(SOFTAP_BSS_STARTED,
10407 &adapter->event_flags)) {
10408 con_sap_adapter = adapter;
10409 break;
10410 }
10411 } else {
10412 con_sap_adapter = adapter;
10413 break;
10414 }
10415 }
10416 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10417 adapterNode = pNext;
10418 }
10419
10420 return con_sap_adapter;
10421}
10422
10423#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010424static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010425{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010426 return adapter->device_mode == QDF_STA_MODE ||
10427 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010428}
10429
Jeff Johnson9d295242017-08-29 14:39:48 -070010430static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010431{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010432 return adapter->device_mode == QDF_SAP_MODE ||
10433 adapter->device_mode == QDF_P2P_GO_MODE;
10434}
10435
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010436static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010437{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010438 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010439 hdd_adapter_list_node_t *node;
10440
10441 status = hdd_get_front_adapter(hdd_ctx, &node);
10442 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson9d295242017-08-29 14:39:48 -070010443 struct hdd_adapter *adapter = node->pAdapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010444
10445 if (adapter &&
10446 hdd_adapter_is_sta(adapter) &&
10447 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10448 conn_info.connState == eConnectionState_Associated) {
10449 return true;
10450 }
10451
10452 if (adapter &&
10453 hdd_adapter_is_ap(adapter) &&
10454 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10455 return true;
10456 }
10457
10458 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10459 }
10460
10461 return false;
10462}
10463
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010464static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010465{
10466 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010467
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010468 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010469 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010470 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471
Dustin Brown5ec6b552017-03-31 12:11:40 -070010472 return is_running;
10473}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010474
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010475static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010476{
10477 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10478 hdd_ctx->bus_bw_timer_running = true;
10479 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10480 hdd_ctx->config->busBandwidthComputeInterval);
10481 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10482}
10483
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010484void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010485{
10486 ENTER();
10487
10488 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10489 hdd_debug("Bandwidth compute timer already started");
10490 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010491 }
10492
Dustin Brown5ec6b552017-03-31 12:11:40 -070010493 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10494
10495 EXIT();
10496}
10497
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010498void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010499{
10500 ENTER();
10501
10502 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10503 hdd_debug("Bandwidth compute timer already started");
10504 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010505 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010506
10507 if (hdd_any_adapter_is_assoc(hdd_ctx))
10508 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10509
10510 EXIT();
10511}
10512
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010513static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010514{
10515 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10516
10517 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10518 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10519 hdd_ctx->bus_bw_timer_running = false;
10520 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10521
10522 hdd_reset_tcp_delack(hdd_ctx);
10523}
10524
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010525void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010526{
10527 ENTER();
10528
10529 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10530 hdd_debug("Bandwidth compute timer already stopped");
10531 return;
10532 }
10533
10534 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10535
10536 EXIT();
10537}
10538
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010539void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010540{
10541 ENTER();
10542
10543 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10544 hdd_debug("Bandwidth compute timer already stopped");
10545 return;
10546 }
10547
10548 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10549 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10550
10551 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010552}
10553#endif
10554
10555/**
10556 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10557 * and sta's operating channel.
10558 * @sta_adapter: Describe the first argument to foobar.
10559 * @ap_adapter: Describe the second argument to foobar.
10560 * @roam_profile: Roam profile of AP to which STA wants to connect.
10561 * @concurrent_chnl_same: If both SAP and STA channels are same then
10562 * set this flag to true else false.
10563 *
10564 * This function checks the sap's operating channel and sta's operating channel.
10565 * if both are same then it will return false else it will restart the sap in
10566 * sta's channel and return true.
10567 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010568 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010569 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010570QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10571 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010572 tCsrRoamProfile *roam_profile,
10573 tScanResultHandle *scan_cache,
10574 bool *concurrent_chnl_same)
10575{
Jeff Johnson87251032017-08-29 13:31:11 -070010576 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010577 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010578 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010579 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010580 *concurrent_chnl_same = true;
10581
10582 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10583 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010584 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010585 scan_cache,
10586 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010587 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010588 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010589 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10590 if (hdd_ap_ctx->operatingChannel != channel_id) {
10591 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010592 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010593 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010594 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010595 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10596 if (hdd_ap_ctx->operatingChannel != channel_id) {
10597 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010598 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010599 }
10600 }
10601 } else {
10602 /*
10603 * Lets handle worst case scenario here, Scan cache lookup is
10604 * failed so we have to stop the SAP to avoid any channel
10605 * discrepancy between SAP's channel and STA's channel.
10606 * Return the status as failure so caller function could know
10607 * that scan look up is failed.
10608 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010609 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010610 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010612 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010613}
10614
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615/**
10616 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10617 * @ap_adapter: SAP adapter
10618 *
10619 * This function will process the stopping of sap adapter.
10620 *
10621 * Return: None
10622 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010623void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010624{
Jeff Johnson87251032017-08-29 13:31:11 -070010625 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010626 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010627 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010628 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010629
10630 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010631 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010632 return;
10633 }
10634
10635 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10636 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010637 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010638 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010640 mutex_lock(&hdd_ctx->sap_lock);
10641 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010642 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010643 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10644 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010645 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010646 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010647 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010648 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010649 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010650 qdf_stop_bss_event,
10651 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010652 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010653 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010654 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655 return;
10656 }
10657 }
10658 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010659 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10660 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010661 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010662 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010663 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010664 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010665 }
10666 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010667}
10668
10669/**
10670 * wlan_hdd_start_sap() - this function starts bss of SAP.
10671 * @ap_adapter: SAP adapter
10672 *
10673 * This function will process the starting of sap adapter.
10674 *
10675 * Return: None
10676 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010677void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010678{
Jeff Johnson87251032017-08-29 13:31:11 -070010679 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010680 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010681 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010682 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683 tsap_Config_t *sap_config;
10684
10685 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010686 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010687 return;
10688 }
10689
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010690 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010691 hdd_err("SoftAp role has not been enabled");
10692 return;
10693 }
10694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010695 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10696 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10697 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10698 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010700 mutex_lock(&hdd_ctx->sap_lock);
10701 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10702 goto end;
10703
10704 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010705 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010706 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10707 goto end;
10708 }
10709
Wei Song2f76f642016-11-18 16:32:53 +080010710 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010711 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10712 &hdd_ap_ctx->sapConfig,
10713 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010714 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010715 goto end;
10716
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010717 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010718 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010719 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010720 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010721 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722 goto end;
10723 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010724 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010725 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010726 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010727 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10728 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010729 ap_adapter->sessionId);
10730 hostapd_state->bCommit = true;
10731
10732end:
10733 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010734 /* SAP context and beacon cleanup will happen during driver unload
10735 * in hdd_stop_adapter
10736 */
10737 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10738
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010739}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740
10741/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010742 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10743 * mac scan config
10744 * @status: Status of set antenna mode
10745 *
10746 * Callback on setting the dual mac configuration
10747 *
10748 * Return: None
10749 */
10750void wlan_hdd_soc_set_antenna_mode_cb(
10751 enum set_antenna_mode_status status)
10752{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010753 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010754
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010755 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010756
10757 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10758 if (0 != wlan_hdd_validate_context(hdd_ctx))
10759 return;
10760
10761 /* Signal the completion of set dual mac config */
10762 complete(&hdd_ctx->set_antenna_mode_cmpl);
10763}
10764
10765/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010766 * hdd_get_fw_version() - Get FW version
10767 * @hdd_ctx: pointer to HDD context.
10768 * @major_spid: FW version - major spid.
10769 * @minor_spid: FW version - minor spid
10770 * @ssid: FW version - ssid
10771 * @crmid: FW version - crmid
10772 *
10773 * This function is called to get the firmware build version stored
10774 * as part of the HDD context
10775 *
10776 * Return: None
10777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010778void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779 uint32_t *major_spid, uint32_t *minor_spid,
10780 uint32_t *siid, uint32_t *crmid)
10781{
10782 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10783 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10784 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10785 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10786}
10787
10788#ifdef QCA_CONFIG_SMP
10789/**
10790 * wlan_hdd_get_cpu() - get cpu_index
10791 *
10792 * Return: cpu_index
10793 */
10794int wlan_hdd_get_cpu(void)
10795{
10796 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010798 put_cpu();
10799 return cpu_index;
10800}
10801#endif
10802
10803/**
10804 * hdd_get_fwpath() - get framework path
10805 *
10806 * This function is used to get the string written by
10807 * userspace to start the wlan driver
10808 *
10809 * Return: string
10810 */
10811const char *hdd_get_fwpath(void)
10812{
10813 return fwpath.string;
10814}
10815
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010816static int hdd_qdf_print_init(void)
10817{
10818 int qdf_print_idx;
10819 QDF_STATUS status;
10820
10821 status = qdf_print_setup();
10822 if (status != QDF_STATUS_SUCCESS) {
10823 pr_err("qdf_print_setup failed\n");
10824 return -EINVAL;
10825 }
10826
10827 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10828
10829 if (qdf_print_idx < 0) {
10830 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10831 qdf_print_idx);
10832 return -EINVAL;
10833 }
10834
10835 qdf_set_pidx(qdf_print_idx);
10836
10837 return 0;
10838}
10839
10840static void hdd_qdf_print_deinit(void)
10841{
10842 int qdf_print_idx;
10843
10844 qdf_print_idx = qdf_get_pidx();
10845 qdf_print_ctrl_cleanup(qdf_print_idx);
10846}
10847
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010848/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010849 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010850 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010851 * This function initilizes CDS global context with the help of cds_init. This
10852 * has to be the first function called after probe to get a valid global
10853 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010854 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010855 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010856 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010857int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010858{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010859 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010860 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010861
Houston Hoffman9e06e542016-12-12 12:06:26 -080010862 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010863#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10864 wlan_logging_sock_init_svc();
10865#endif
10866
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010867 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010868 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010869 ret = -ENOMEM;
10870 goto err_out;
10871 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010872
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010873 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010874 hdd_qdf_print_init();
10875
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010876 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010877
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010878err_out:
10879 return ret;
10880}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010881
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010882/**
10883 * hdd_deinit() - Deinitialize Driver
10884 *
10885 * This function frees CDS global context with the help of cds_deinit. This
10886 * has to be the last function call in remove callback to free the global
10887 * context.
10888 */
10889void hdd_deinit(void)
10890{
Dustin Brownedce4a52017-05-10 11:59:15 -070010891 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010892 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010893
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010894 hdd_qdf_print_deinit();
10895
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010896#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10897 wlan_logging_sock_deinit_svc();
10898#endif
10899}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010900
Yue Ma6e7b1a02017-04-03 14:17:46 -070010901#ifdef QCA_WIFI_NAPIER_EMULATION
10902#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10903#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010904#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010905#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010906
Sachin Ahujadddd2632017-03-07 19:07:24 +053010907static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10908 struct file *file)
10909{
10910 return 0;
10911}
10912
10913static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10914 const char __user *user_buf,
10915 size_t count,
10916 loff_t *f_pos)
10917{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010918 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010919 static const char wlan_off_str[] = "OFF";
10920 static const char wlan_on_str[] = "ON";
10921 int ret;
10922 unsigned long rc;
10923
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010924 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010925 pr_err("Failed to read buffer\n");
10926 return -EINVAL;
10927 }
10928
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010929 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010930 pr_debug("Wifi turning off from UI\n");
10931 goto exit;
10932 }
10933
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010934 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010935 pr_err("Invalid value received from framework");
10936 goto exit;
10937 }
10938
10939 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010940 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010941 rc = wait_for_completion_timeout(&wlan_start_comp,
10942 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10943 if (!rc) {
10944 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10945 ret = -EINVAL;
10946 hdd_start_complete(ret);
10947 return ret;
10948 }
10949
10950 hdd_start_complete(0);
10951 }
10952
10953exit:
10954 return count;
10955}
10956
10957
10958const struct file_operations wlan_hdd_state_fops = {
10959 .owner = THIS_MODULE,
10960 .open = wlan_hdd_state_ctrl_param_open,
10961 .write = wlan_hdd_state_ctrl_param_write,
10962};
10963
10964static int wlan_hdd_state_ctrl_param_create(void)
10965{
10966 unsigned int wlan_hdd_state_major = 0;
10967 int ret;
10968 struct device *dev;
10969
10970 device = MKDEV(wlan_hdd_state_major, 0);
10971
10972 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10973 if (ret) {
10974 pr_err("Failed to register qcwlanstate");
10975 goto dev_alloc_err;
10976 }
10977 wlan_hdd_state_major = MAJOR(device);
10978
10979 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10980 if (IS_ERR(class)) {
10981 pr_err("wlan_hdd_state class_create error");
10982 goto class_err;
10983 }
10984
10985 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10986 if (IS_ERR(dev)) {
10987 pr_err("wlan_hdd_statedevice_create error");
10988 goto err_class_destroy;
10989 }
10990
10991 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10992 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10993 if (ret) {
10994 pr_err("Failed to add cdev error");
10995 goto cdev_add_err;
10996 }
10997
10998 pr_info("wlan_hdd_state %s major(%d) initialized",
10999 WLAN_MODULE_NAME, wlan_hdd_state_major);
11000
11001 return 0;
11002
11003cdev_add_err:
11004 device_destroy(class, device);
11005err_class_destroy:
11006 class_destroy(class);
11007class_err:
11008 unregister_chrdev_region(device, dev_num);
11009dev_alloc_err:
11010 return -ENODEV;
11011}
11012
11013static void wlan_hdd_state_ctrl_param_destroy(void)
11014{
11015 cdev_del(&wlan_hdd_state_cdev);
11016 device_destroy(class, device);
11017 class_destroy(class);
11018 unregister_chrdev_region(device, dev_num);
11019
11020 pr_info("Device node unregistered");
11021}
11022
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011023/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011024 * component_init - API to init cld component's
11025 *
11026 * Return: None
11027 */
11028static void component_init(void)
11029{
11030 pmo_init();
11031}
11032
11033/**
11034 * component_deinit - API to deinit cld component's
11035 *
11036 * Return: None
11037 */
11038static void component_deinit(void)
11039{
11040 pmo_deinit();
11041}
11042
11043/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011044 * __hdd_module_init - Module init helper
11045 *
11046 * Module init helper function used by both module and static driver.
11047 *
11048 * Return: 0 for success, errno on failure
11049 */
11050static int __hdd_module_init(void)
11051{
11052 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011053
Dustin Brownab482ac2017-06-09 17:00:44 -070011054 pr_err("%s: Loading driver v%s (%s)%s\n",
11055 WLAN_MODULE_NAME,
11056 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011057 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011058 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011059
Sachin Ahujadddd2632017-03-07 19:07:24 +053011060 ret = wlan_hdd_state_ctrl_param_create();
11061 if (ret) {
11062 pr_err("wlan_hdd_state_create:%x\n", ret);
11063 goto err_dev_state;
11064 }
11065
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011066 pld_init();
11067
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011068 ret = hdd_init();
11069 if (ret) {
11070 pr_err("hdd_init failed %x\n", ret);
11071 goto err_hdd_init;
11072 }
11073
Rajeev Kumar97767a02016-11-30 11:20:40 -080011074 dispatcher_init();
11075
Mukul Sharmad75a6672017-06-22 15:40:53 +053011076 /* Ensure to call post objmgr init */
11077 component_init();
11078
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011079 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011080
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011081 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011082
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011083 ret = wlan_hdd_register_driver();
11084 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011085 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11086 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011087 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011088 }
11089
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011090 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011091
11092 return 0;
11093out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011094 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011095 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011096 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011097
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011098err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011099 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011100 wlan_hdd_state_ctrl_param_destroy();
11101err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011102 return ret;
11103}
11104
11105/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011106 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
11107 *
11108 * Block the unloading of the driver until the cds recovery is completed
11109 *
11110 * Return: None
11111 */
11112static void hdd_wait_for_recovery_completion(void)
11113{
11114 int retry = 0;
11115
11116 /* Wait for recovery to complete */
11117 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011118 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011119 msleep(1000);
11120 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011121 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011122 QDF_BUG(0);
11123 }
11124 }
11125}
11126
11127/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011128 * __hdd_module_exit - Module exit helper
11129 *
11130 * Module exit helper function used by both module and static driver.
11131 */
11132static void __hdd_module_exit(void)
11133{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011134
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011135 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11136 QWLAN_VERSIONSTR);
11137
bings6028ee82017-03-29 07:51:40 +080011138 cds_set_unload_in_progress(true);
11139
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011140 hdd_wait_for_recovery_completion();
11141
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011142 wlan_hdd_unregister_driver();
11143
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011144 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011145
Mukul Sharmad75a6672017-06-22 15:40:53 +053011146 /* Ensure to call prior to objmgr deinit */
11147 component_deinit();
11148
Rajeev Kumar97767a02016-11-30 11:20:40 -080011149 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011150 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011151 pld_deinit();
11152
Sachin Ahujadddd2632017-03-07 19:07:24 +053011153 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011154}
11155
Arun Khandavallifae92942016-08-01 13:31:08 +053011156#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011157/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011158 * wlan_boot_cb() - Wlan boot callback
11159 * @kobj: object whose directory we're creating the link in.
11160 * @attr: attribute the user is interacting with
11161 * @buff: the buffer containing the user data
11162 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011163 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011164 * This callback is invoked when the fs is ready to start the
11165 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011166 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011167 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011168 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011169static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011170 struct kobj_attribute *attr,
11171 const char *buf,
11172 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011173{
Arun Khandavallifae92942016-08-01 13:31:08 +053011174
Arun Khandavallifae92942016-08-01 13:31:08 +053011175 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011176 pr_err("%s: wlan driver already initialized\n", __func__);
11177 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011178 }
11179
Arun Khandavallifae92942016-08-01 13:31:08 +053011180 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011181 pr_err("%s: wlan driver initialization failed\n", __func__);
11182 return -EIO;
11183 }
11184
11185 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011186
11187 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011188}
Arun Khandavallifae92942016-08-01 13:31:08 +053011189
11190/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011191 * hdd_sysfs_cleanup() - cleanup sysfs
11192 *
11193 * Return: None
11194 *
11195 */
11196static void hdd_sysfs_cleanup(void)
11197{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011198 /* remove from group */
11199 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11200 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11201 wlan_loader->attr_group);
11202
11203 /* unlink the object from parent */
11204 kobject_del(wlan_loader->boot_wlan_obj);
11205
11206 /* free the object */
11207 kobject_put(wlan_loader->boot_wlan_obj);
11208
11209 kfree(wlan_loader->attr_group);
11210 kfree(wlan_loader);
11211
11212 wlan_loader = NULL;
11213}
11214
11215/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011216 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11217 * ready
11218 *
11219 * This is creates the syfs entry boot_wlan. Which shall be invoked
11220 * when the filesystem is ready.
11221 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011222 * QDF API cannot be used here since this function is called even before
11223 * initializing WLAN driver.
11224 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011225 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011226 */
11227static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011228{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011229 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011230
11231 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011232 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011233 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011234
11235 wlan_loader->boot_wlan_obj = NULL;
11236 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11237 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011238 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011239 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011240
11241 wlan_loader->loaded_state = 0;
11242 wlan_loader->attr_group->attrs = attrs;
11243
11244 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11245 kernel_kobj);
11246 if (!wlan_loader->boot_wlan_obj) {
11247 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011248 goto error_return;
11249 }
11250
11251 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11252 wlan_loader->attr_group);
11253 if (ret) {
11254 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11255 goto error_return;
11256 }
11257
11258 return 0;
11259
11260error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011261 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011262
11263 return ret;
11264}
11265
11266/**
11267 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11268 *
11269 * Return: 0 on success or errno on failure
11270 */
11271static int wlan_deinit_sysfs(void)
11272{
Arun Khandavallifae92942016-08-01 13:31:08 +053011273 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011274 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011275 return -EINVAL;
11276 }
11277
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011278 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011279 return 0;
11280}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011281
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011282#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011283
11284#ifdef MODULE
11285/**
11286 * __hdd_module_init - Module init helper
11287 *
11288 * Module init helper function used by both module and static driver.
11289 *
11290 * Return: 0 for success, errno on failure
11291 */
11292static int hdd_module_init(void)
11293{
Arun Khandavallifae92942016-08-01 13:31:08 +053011294 if (__hdd_module_init()) {
11295 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011296 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011297 }
11298
Dustin Brownab482ac2017-06-09 17:00:44 -070011299 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011300}
11301#else
11302static int __init hdd_module_init(void)
11303{
11304 int ret = -EINVAL;
11305
11306 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011307 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011308 pr_err("Failed to create sysfs entry for loading wlan");
11309
11310 return ret;
11311}
11312#endif
11313
11314
11315#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011316/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011317 * hdd_module_exit() - Exit function
11318 *
11319 * This is the driver exit point (invoked when module is unloaded using rmmod)
11320 *
11321 * Return: None
11322 */
11323static void __exit hdd_module_exit(void)
11324{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011325 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011326}
Arun Khandavallifae92942016-08-01 13:31:08 +053011327#else
11328static void __exit hdd_module_exit(void)
11329{
11330 __hdd_module_exit();
11331 wlan_deinit_sysfs();
11332}
11333#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011334
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011335static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11336{
11337 return param_set_copystring(kmessage, kp);
11338}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011339
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011340/**
11341 * is_con_mode_valid() check con mode is valid or not
11342 * @mode: global con mode
11343 *
11344 * Return: TRUE on success FALSE on failure
11345 */
11346static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11347{
11348 switch (mode) {
11349 case QDF_GLOBAL_MONITOR_MODE:
11350 case QDF_GLOBAL_FTM_MODE:
11351 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011352 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011353 return true;
11354 default:
11355 return false;
11356 }
11357}
11358
11359/**
11360 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11361 * @mode: global con mode
11362 *
11363 * Return: adapter mode
11364 */
11365static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11366 enum tQDF_GLOBAL_CON_MODE mode)
11367{
11368
11369 switch (mode) {
11370 case QDF_GLOBAL_MISSION_MODE:
11371 return QDF_STA_MODE;
11372 case QDF_GLOBAL_MONITOR_MODE:
11373 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011374 case QDF_GLOBAL_EPPING_MODE:
11375 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011376 case QDF_GLOBAL_FTM_MODE:
11377 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011378 case QDF_GLOBAL_QVIT_MODE:
11379 return QDF_QVIT_MODE;
11380 default:
11381 return QDF_MAX_NO_OF_MODE;
11382 }
11383}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011384
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011385static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011386 enum tQDF_GLOBAL_CON_MODE curr_mode)
11387{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011388 int driver_status;
11389
11390 driver_status = hdd_ctx->driver_status;
11391
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011392 switch (curr_mode) {
11393 case QDF_GLOBAL_MISSION_MODE:
11394 case QDF_GLOBAL_MONITOR_MODE:
11395 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011396 if (driver_status != DRIVER_MODULES_CLOSED) {
11397 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11398 hdd_stop_all_adapters(hdd_ctx);
11399 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011400 hdd_deinit_all_adapters(hdd_ctx, false);
11401 hdd_close_all_adapters(hdd_ctx, false);
11402 break;
11403 case QDF_GLOBAL_EPPING_MODE:
11404 epping_disable();
11405 epping_close();
11406 break;
11407 default:
11408 return;
11409 }
11410}
11411
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011412static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011413 enum tQDF_GLOBAL_CON_MODE mode)
11414{
Jeff Johnson9d295242017-08-29 14:39:48 -070011415 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011416 int ret = 0;
11417 bool rtnl_held;
11418 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11419 QDF_STATUS status;
11420
11421 if (!qdf_dev) {
11422 hdd_err("qdf device context is Null return!");
11423 return -EINVAL;
11424 }
11425
11426 rtnl_held = hdd_hold_rtnl_lock();
11427 switch (mode) {
11428 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011429 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11430 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011431 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011432 break;
11433 case QDF_GLOBAL_FTM_MODE:
11434 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11435 wlan_hdd_get_intf_addr(hdd_ctx),
11436 NET_NAME_UNKNOWN, rtnl_held);
11437 if (adapter == NULL)
11438 ret = -EINVAL;
11439 break;
11440 case QDF_GLOBAL_MONITOR_MODE:
11441 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11442 wlan_hdd_get_intf_addr(hdd_ctx),
11443 NET_NAME_UNKNOWN, rtnl_held);
11444 if (adapter == NULL)
11445 ret = -EINVAL;
11446 break;
11447 case QDF_GLOBAL_EPPING_MODE:
11448 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011449 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011450 hdd_err("Failed to open in eeping mode: %d", status);
11451 ret = -EINVAL;
11452 break;
11453 }
11454 ret = epping_enable(qdf_dev->dev);
11455 if (ret) {
11456 hdd_err("Failed to enable in epping mode : %d", ret);
11457 epping_close();
11458 }
11459 break;
11460 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011461 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011462 ret = -ENOTSUPP;
11463 break;
11464 }
11465 hdd_release_rtnl_lock();
11466 rtnl_held = false;
11467 return ret;
11468}
11469
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011470/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011471 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011472 * @kmessage: con mode name on which driver to be bring up
11473 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011474 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011475 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011476 * This function is invoked when user updates con mode using sys entry,
11477 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011478 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011479 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011480 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011481static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011482 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011483{
11484 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011485 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011486 enum tQDF_GLOBAL_CON_MODE curr_mode;
11487 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011488
Dustin Brownab6029b2017-05-24 13:04:19 -070011489 hdd_info("con_mode handler: %s", kmessage);
11490
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011491 ret = wlan_hdd_validate_context(hdd_ctx);
11492 if (ret)
11493 return ret;
11494
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011495 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011496
11497 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011498
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011499 if (!(is_con_mode_valid(con_mode))) {
11500 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011501 ret = -EINVAL;
11502 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011503 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011504
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011505 curr_mode = hdd_get_conparam();
11506 if (curr_mode == con_mode) {
11507 hdd_err("curr mode: %d is same as user triggered mode %d",
11508 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011509 ret = 0;
11510 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011511 }
11512
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011513 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011514 if (ret) {
11515 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011516 goto reset_flags;
11517 }
11518
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011519 /* Cleanup present mode before switching to new mode */
11520 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11521
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011522 hdd_set_conparam(con_mode);
11523
11524 /* Register for new con_mode & then kick_start modules again */
11525 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11526 if (ret) {
11527 hdd_err("Failed to register for new mode");
11528 goto reset_flags;
11529 }
11530
11531 adapter_mode = hdd_get_adpter_mode(con_mode);
11532 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11533 hdd_err("invalid adapter");
11534 ret = -EINVAL;
11535 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011536 }
11537
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011538 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011539 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011540 hdd_err("Failed to get adapter:%d", adapter_mode);
11541 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011542 }
11543
11544 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11545 if (ret) {
11546 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011547 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011548 }
11549
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011550 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11551 con_mode == QDF_GLOBAL_FTM_MODE) {
11552 if (hdd_start_adapter(adapter)) {
11553 hdd_err("Failed to start %s adapter", kmessage);
11554 ret = -EINVAL;
11555 goto reset_flags;
11556 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011557 }
11558
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011559 hdd_info("Mode successfully changed to %s", kmessage);
11560 ret = 0;
11561
11562reset_flags:
11563 cds_set_load_in_progress(false);
11564 return ret;
11565}
11566
11567
11568static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11569{
11570 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011571 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011572
11573 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11574 ret = wlan_hdd_validate_context(hdd_ctx);
11575 if (ret)
11576 return ret;
11577
11578 cds_ssr_protect(__func__);
11579 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11580 cds_ssr_unprotect(__func__);
11581
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011582 return ret;
11583}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011584
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011585static int con_mode_handler_ftm(const char *kmessage,
11586 struct kernel_param *kp)
11587{
11588 int ret;
11589
11590 ret = param_set_int(kmessage, kp);
11591
11592 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11593 pr_err("Only FTM mode supported!");
11594 return -ENOTSUPP;
11595 }
11596
11597 hdd_set_conparam(con_mode_ftm);
11598 con_mode = con_mode_ftm;
11599
11600 return ret;
11601}
11602
Ravi Joshia307f632017-07-17 23:41:41 -070011603static int con_mode_handler_monitor(const char *kmessage,
11604 struct kernel_param *kp)
11605{
11606 int ret;
11607
11608 ret = param_set_int(kmessage, kp);
11609
11610 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
11611 pr_err("Only Monitor mode supported!");
11612 return -ENOTSUPP;
11613 }
11614
11615 hdd_set_conparam(con_mode_monitor);
11616 con_mode = con_mode_monitor;
11617
11618 return ret;
11619}
11620
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011621/**
11622 * hdd_get_conparam() - driver exit point
11623 *
11624 * This is the driver exit point (invoked when module is unloaded using rmmod)
11625 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011626 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011627 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011628enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011629{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011630 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011631}
11632
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011633void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011634{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011635 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011636}
11637
Komal Seelamc11bb222016-01-27 18:57:10 +053011638/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011639 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11640 * @hdd_ctx: HDD context
11641 *
11642 * Cleans up the pre cac interface, if it exists
11643 *
11644 * Return: None
11645 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011646void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011647{
11648 uint8_t session_id;
11649 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011650 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011651
11652 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11653 if (QDF_IS_STATUS_ERROR(status)) {
11654 hdd_err("failed to get pre cac vdev id");
11655 return;
11656 }
11657
11658 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11659 if (!precac_adapter) {
11660 hdd_err("invalid pre cac adapater");
11661 return;
11662 }
11663
11664 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11665 wlan_hdd_sap_pre_cac_failure,
11666 (void *)precac_adapter);
11667 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11668
11669}
11670
11671/**
Komal Seelamec702b02016-02-24 18:42:16 +053011672 * hdd_update_ol_config - API to update ol configuration parameters
11673 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011674 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011675 * Return: void
11676 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011677static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011678{
Komal Seelamec702b02016-02-24 18:42:16 +053011679 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011680 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011681
Komal Seelamec702b02016-02-24 18:42:16 +053011682 if (!ol_ctx)
11683 return;
11684
11685 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11686 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11687 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11688 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011689 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011690
11691 ol_init_ini_config(ol_ctx, &cfg);
11692}
11693
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011694#ifdef FEATURE_RUNTIME_PM
11695/**
11696 * hdd_populate_runtime_cfg() - populate runtime configuration
11697 * @hdd_ctx: hdd context
11698 * @cfg: pointer to the configuration memory being populated
11699 *
11700 * Return: void
11701 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011702static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011703 struct hif_config_info *cfg)
11704{
11705 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11706 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11707}
11708#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011709static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011710 struct hif_config_info *cfg)
11711{
11712}
11713#endif
11714
Komal Seelamec702b02016-02-24 18:42:16 +053011715/**
11716 * hdd_update_hif_config - API to update HIF configuration parameters
11717 * @hdd_ctx: HDD Context
11718 *
11719 * Return: void
11720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011721static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011722{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011723 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011724 struct hif_config_info cfg;
11725
11726 if (!scn)
11727 return;
11728
11729 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011730 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011731 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011732
11733 if (hdd_ctx->config->prevent_link_down)
11734 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011735}
11736
11737/**
11738 * hdd_update_config() - Initialize driver per module ini parameters
11739 * @hdd_ctx: HDD Context
11740 *
11741 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011742 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011743 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011744int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011745{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011746 int ret;
11747
Komal Seelamec702b02016-02-24 18:42:16 +053011748 hdd_update_ol_config(hdd_ctx);
11749 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011750 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11751 ret = hdd_update_cds_config_ftm(hdd_ctx);
11752 else
11753 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011754 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011755
11756 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011757}
11758
Mukul Sharma9d797a02017-01-05 20:26:03 +053011759#ifdef FEATURE_WLAN_RA_FILTERING
11760/**
11761 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11762 * @psoc_cfg: pmo psoc Configuration
11763 * @hdd_ctx: Pointer to hdd context
11764 *
11765 * Return: none
11766 */
11767static inline void hdd_ra_populate_pmo_config(
11768 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011769 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011770{
11771 psoc_cfg->ra_ratelimit_interval =
11772 hdd_ctx->config->RArateLimitInterval;
11773 psoc_cfg->ra_ratelimit_enable =
11774 hdd_ctx->config->IsRArateLimitEnabled;
11775}
11776#else
11777static inline void hdd_ra_populate_pmo_config(
11778 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011779 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011780{
11781}
11782#endif
11783/**
11784 * hdd_update_pmo_config - API to update pmo configuration parameters
11785 * @hdd_ctx: HDD context
11786 *
11787 * Return: void
11788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011789static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011790{
11791 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11792 struct pmo_psoc_cfg psoc_cfg;
11793 QDF_STATUS status;
11794
11795 /*
11796 * Value of hdd_ctx->wowEnable can be,
11797 * 0 - Disable both magic pattern match and pattern byte match.
11798 * 1 - Enable magic pattern match on all interfaces.
11799 * 2 - Enable pattern byte match on all interfaces.
11800 * 3 - Enable both magic patter and pattern byte match on
11801 * all interfaces.
11802 */
11803 psoc_cfg.magic_ptrn_enable =
11804 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11805 psoc_cfg.ptrn_match_enable_all_vdev =
11806 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11807 psoc_cfg.bpf_enable =
11808 hdd_ctx->config->bpf_packet_filter_enable;
11809 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011810 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011811 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11812 if (hdd_ctx->config->fhostNSOffload)
11813 psoc_cfg.ns_offload_enable_dynamic = true;
11814 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11815 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11816 psoc_cfg.active_mode_offload =
11817 hdd_ctx->config->active_mode_offload;
11818 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11819 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011820 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11821 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11822 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11823 psoc_cfg.power_save_mode =
11824 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011825 psoc_cfg.auto_power_save_fail_mode =
11826 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011827
11828 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011829 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11830 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011831 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11832 if (status != QDF_STATUS_SUCCESS) {
11833 hdd_err("failed pmo psoc configuration");
11834 return -EINVAL;
11835 }
11836
11837 return 0;
11838}
11839
Abhishek Singhb20db962017-03-03 21:28:46 +053011840#ifdef FEATURE_WLAN_SCAN_PNO
11841static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11842 struct hdd_config *cfg)
11843{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011844 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
11845
Abhishek Singhb20db962017-03-03 21:28:46 +053011846 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11847 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11848 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11849 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11850 pno_cfg->channel_prediction_full_scan =
11851 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070011852 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
11853 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
11854 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
11855 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053011856}
11857#else
11858static inline void
11859hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11860 struct hdd_config *cfg)
11861{
11862 return;
11863}
11864#endif
11865
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011866void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11867 struct hdd_config *cfg)
11868{
11869 uint8_t i = 0;
11870
11871 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11872 if (!ie_whitelist->white_list)
11873 return;
11874
11875 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11876 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11877 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11878 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11879 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11880 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11881 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11882 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11883
11884 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11885 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11886 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11887}
11888
Abhishek Singh257a9482017-03-06 16:52:39 +053011889/**
11890 * hdd_update_scan_config - API to update scan configuration parameters
11891 * @hdd_ctx: HDD context
11892 *
11893 * Return: 0 if success else err
11894 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011895static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011896{
11897 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11898 struct scan_user_cfg scan_cfg;
11899 struct hdd_config *cfg = hdd_ctx->config;
11900 QDF_STATUS status;
11901
11902 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11903 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11904 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11905 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11906 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11907 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11908 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011909 /* convert to ms */
11910 scan_cfg.scan_cache_aging_time =
11911 cfg->scanAgingTimeout * 1000;
11912 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11913 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11914 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11915 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011916 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011917 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011918
Abhishek Singhb20db962017-03-03 21:28:46 +053011919 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011920 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011921
Abhishek Singh257a9482017-03-06 16:52:39 +053011922 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11923 if (status != QDF_STATUS_SUCCESS) {
11924 hdd_err("failed pmo psoc configuration");
11925 return -EINVAL;
11926 }
11927
11928 return 0;
11929}
Abhishek Singh257a9482017-03-06 16:52:39 +053011930
Frank Liud4b2fa02017-03-29 11:46:48 +080011931#ifdef CONVERGED_TDLS_ENABLE
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011932static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080011933{
11934 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11935 struct tdls_start_params tdls_cfg;
11936 struct tdls_user_config *config = &tdls_cfg.config;
11937 struct hdd_config *cfg = hdd_ctx->config;
11938 QDF_STATUS status;
11939
11940 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11941 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11942 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11943 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11944 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11945 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11946 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11947 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11948 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11949 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11950 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11951 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11952 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11953 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11954 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11955 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11956 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11957 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11958 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11959 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11960 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11961 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11962 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11963 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11964 (cfg->fEnableTDLSImplicitTrigger ?
11965 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11966 (cfg->fTDLSExternalControl ?
11967 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11968
11969 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11970 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11971 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11972 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011973 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011974 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011975 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11976 tdls_cfg.tdls_evt_cb_data = psoc;
11977 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11978 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11979 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011980 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11981 tdls_cfg.tdls_wmm_cb_data = psoc;
11982 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11983 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011984 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011985
11986 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11987 if (status != QDF_STATUS_SUCCESS) {
11988 hdd_err("failed pmo psoc configuration");
11989 return -EINVAL;
11990 }
11991
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011992 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011993 /* disable napier specific tdls data path */
11994 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011995
Frank Liud4b2fa02017-03-29 11:46:48 +080011996 return 0;
11997}
11998#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011999static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012000{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012001 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012002 /* disable napier specific tdls data path */
12003 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080012004 return 0;
12005}
12006#endif
12007
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012008int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012009{
12010 int ret;
12011
12012 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012013 if (ret)
12014 return ret;
12015 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012016 if (ret)
12017 return ret;
12018 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012019
12020 return ret;
12021}
12022
Agrawal Ashish65634612016-08-18 13:24:32 +053012023/**
12024 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12025 * @mode : cfg80211 DFS mode
12026 *
12027 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12028 */
12029enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12030{
12031 switch (mode) {
12032 case DFS_MODE_ENABLE:
12033 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012034 case DFS_MODE_DISABLE:
12035 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012036 case DFS_MODE_DEPRIORITIZE:
12037 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012038 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012039 hdd_debug("ACS dfs mode is NONE");
12040 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012041 }
12042}
12043
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012044/**
12045 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12046 * @hddctx: pointer to hdd context
12047 * @set_value: enable/disable
12048 *
12049 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12050 * Host(even though it is duplicate). When Host send vendor command
12051 * disable,FW doesn't perform any action. Whenever any change in
12052 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12053 *
12054 * return - 0 on success, appropriate error values on failure.
12055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012056int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012057{
12058 QDF_STATUS status;
12059
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012060 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012061 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012062
12063 if (!hddctx->config->goptimize_chan_avoid_event) {
12064 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12065 return -EINVAL;
12066 }
12067
12068 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12069 if (!QDF_IS_STATUS_SUCCESS(status)) {
12070 hdd_err("Failed to send chan avoid command to SME");
12071 return -EINVAL;
12072 }
12073 return 0;
12074}
Agrawal Ashish65634612016-08-18 13:24:32 +053012075
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012076/**
12077 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12078 * @value: value to set
12079 *
12080 * This function will set the passed value to roaming in progress flag.
12081 *
12082 * Return: None
12083 */
12084void hdd_set_roaming_in_progress(bool value)
12085{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012086 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012087
12088 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12089 if (!hdd_ctx) {
12090 hdd_err("HDD context is NULL");
12091 return;
12092 }
12093
12094 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012095 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012096}
12097
12098/**
12099 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012100 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012101 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012102 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012103 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012104bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012105{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012106 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012107 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012108
12109 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12110 if (!hdd_ctx) {
12111 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012112 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012113 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012114 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12115 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012116 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12117 hdd_ctx->roaming_in_progress);
12118
12119 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012120}
12121
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012122/**
12123 * hdd_is_connection_in_progress() - check if connection is in
12124 * progress
12125 * @session_id: session id
12126 * @reason: scan reject reason
12127 *
12128 * Go through each adapter and check if Connection is in progress
12129 *
12130 * Return: true if connection is in progress else false
12131 */
12132bool hdd_is_connection_in_progress(uint8_t *session_id,
12133 enum scan_reject_states *reason)
12134{
12135 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012136 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012137 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012138 QDF_STATUS status = 0;
12139 uint8_t sta_id = 0;
12140 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012141 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012142
12143 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12144 if (!hdd_ctx) {
12145 hdd_err("HDD context is NULL");
12146 return false;
12147 }
12148
12149 if (true == hdd_ctx->btCoexModeSet) {
12150 hdd_info("BTCoex Mode operation in progress");
12151 return true;
12152 }
12153 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12154 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
12155 adapter = adapter_node->pAdapter;
12156 if (!adapter)
12157 goto end;
12158
12159 hdd_info("Adapter with device mode %s(%d) exists",
12160 hdd_device_mode_to_string(adapter->device_mode),
12161 adapter->device_mode);
12162 if (((QDF_STA_MODE == adapter->device_mode)
12163 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12164 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12165 && (eConnectionState_Connecting ==
12166 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12167 conn_info.connState)) {
Jeff Johnson36e74c42017-09-18 08:15:42 -070012168 hdd_err("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012169 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12170 adapter->sessionId);
12171 if (session_id && reason) {
12172 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012173 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012174 }
12175 return true;
12176 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012177 /*
12178 * sme_neighbor_middle_of_roaming is for LFR2
12179 * hdd_is_roaming_in_progress is for LFR3
12180 */
12181 if (((QDF_STA_MODE == adapter->device_mode) &&
12182 sme_neighbor_middle_of_roaming(
12183 WLAN_HDD_GET_HAL_CTX(adapter),
12184 adapter->sessionId)) ||
12185 hdd_is_roaming_in_progress(adapter)) {
Jeff Johnson36e74c42017-09-18 08:15:42 -070012186 hdd_err("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012187 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12188 adapter->sessionId);
12189 if (session_id && reason) {
12190 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012191 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012192 }
12193 return true;
12194 }
12195 if ((QDF_STA_MODE == adapter->device_mode) ||
12196 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12197 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12198 hdd_sta_ctx =
12199 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12200 if ((eConnectionState_Associated ==
12201 hdd_sta_ctx->conn_info.connState)
12202 && (false ==
12203 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12204 sta_mac = (uint8_t *)
12205 &(adapter->macAddressCurrent.bytes[0]);
12206 hdd_err("client " MAC_ADDRESS_STR
12207 " is in middle of WPS/EAPOL exchange.",
12208 MAC_ADDR_ARRAY(sta_mac));
12209 if (session_id && reason) {
12210 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012211 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012212 }
12213 return true;
12214 }
12215 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12216 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12217 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12218 sta_id++) {
12219 if (!((adapter->aStaInfo[sta_id].isUsed)
12220 && (OL_TXRX_PEER_STATE_CONN ==
12221 adapter->aStaInfo[sta_id].tlSTAState)))
12222 continue;
12223
12224 sta_mac = (uint8_t *)
12225 &(adapter->aStaInfo[sta_id].
12226 macAddrSTA.bytes[0]);
12227 hdd_err("client " MAC_ADDRESS_STR
12228 " of SAP/GO is in middle of WPS/EAPOL exchange",
12229 MAC_ADDR_ARRAY(sta_mac));
12230 if (session_id && reason) {
12231 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012232 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012233 }
12234 return true;
12235 }
12236 if (hdd_ctx->connection_in_progress) {
12237 hdd_err("AP/GO: connection is in progress");
12238 return true;
12239 }
12240 }
12241end:
12242 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12243 adapter_node = next;
12244 }
12245 return false;
12246}
12247
12248/**
12249 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012250 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012251 *
12252 * Return: None
12253 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012254void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012255{
Jeff Johnson87251032017-08-29 13:31:11 -070012256 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012257 hdd_hostapd_state_t *hostapd_state;
12258 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012259 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012260 tsap_Config_t *sap_config;
12261 void *sap_ctx;
12262
12263 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12264 sap_config = &hdd_ap_ctx->sapConfig;
12265 sap_ctx = hdd_ap_ctx->sapContext;
12266
12267 mutex_lock(&hdd_ctx->sap_lock);
12268 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12269 wlan_hdd_del_station(ap_adapter);
12270 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12271 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12272 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12273 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12274 qdf_status =
12275 qdf_wait_single_event(&hostapd_state->
12276 qdf_stop_bss_event,
12277 SME_CMD_TIMEOUT_VALUE);
12278
12279 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12280 cds_err("SAP Stop Failed");
12281 goto end;
12282 }
12283 }
12284 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012285 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012286 ap_adapter->device_mode, ap_adapter->sessionId);
12287 cds_err("SAP Stop Success");
12288
12289 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12290 cds_err("SAP Not able to set AP IEs");
12291 wlansap_reset_sap_config_add_ie(sap_config,
12292 eUPDATE_IE_ALL);
12293 goto end;
12294 }
12295
12296 qdf_event_reset(&hostapd_state->qdf_event);
12297 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12298 sap_config,
12299 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12300 cds_err("SAP Start Bss fail");
12301 wlansap_reset_sap_config_add_ie(sap_config,
12302 eUPDATE_IE_ALL);
12303 goto end;
12304 }
12305
12306 cds_info("Waiting for SAP to start");
12307 qdf_status =
12308 qdf_wait_single_event(&hostapd_state->qdf_event,
12309 SME_CMD_TIMEOUT_VALUE);
12310 wlansap_reset_sap_config_add_ie(sap_config,
12311 eUPDATE_IE_ALL);
12312 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12313 cds_err("SAP Start failed");
12314 goto end;
12315 }
12316 cds_err("SAP Start Success");
12317 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12318 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012319 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12320 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012321 ap_adapter->sessionId);
12322 hostapd_state->bCommit = true;
12323 }
12324end:
12325 mutex_unlock(&hdd_ctx->sap_lock);
12326 return;
12327}
12328
12329/**
12330 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12331 * with non dfs acs
12332 *
12333 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12334 *
12335 * Return: None
12336 */
12337void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12338{
Jeff Johnson9d295242017-08-29 14:39:48 -070012339 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012340 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012341 cds_context_type *cds_ctx;
12342
12343 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12344 if (!hdd_ctx) {
12345 cds_err("HDD context is NULL");
12346 return;
12347 }
12348
12349 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12350 if (!cds_ctx) {
12351 cds_err("Invalid CDS Context");
12352 return;
12353 }
12354
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012355 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12356 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012357 cds_info("Concurrency mode is not SAP");
12358 return;
12359 }
12360
12361 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012362 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12363 &ap_adapter->event_flags) &&
12364 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12365 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012366
12367 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12368 ap_adapter->sessionCtx.ap.sapConfig.channel =
12369 AUTO_CHANNEL_SELECT;
12370 ap_adapter->sessionCtx.ap.sapConfig.
12371 acs_cfg.acs_mode = true;
12372
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012373 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012374 }
12375}
12376
12377/**
12378 * hdd_set_connection_in_progress() - to set the connection in
12379 * progress flag
12380 * @value: value to set
12381 *
12382 * This function will set the passed value to connection in progress flag.
12383 * If value is previously being set to true then no need to set it again.
12384 *
12385 * Return: true if value is being set correctly and false otherwise.
12386 */
12387bool hdd_set_connection_in_progress(bool value)
12388{
12389 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012390 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012391
12392 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12393 if (!hdd_ctx) {
12394 cds_err("HDD context is NULL");
12395 return false;
12396 }
12397
12398 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12399 /*
12400 * if the value is set to true previously and if someone is
12401 * trying to make it true again then it could be some race
12402 * condition being triggered. Avoid this situation by returning
12403 * false
12404 */
12405 if (hdd_ctx->connection_in_progress && value)
12406 status = false;
12407 else
12408 hdd_ctx->connection_in_progress = value;
12409 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12410 return status;
12411}
12412
Jeff Johnson9d295242017-08-29 14:39:48 -070012413int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012414{
12415 if (!adapter) {
12416 hdd_err("Invalid adapter");
12417 return -EINVAL;
12418 }
12419 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012420 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012421 WMA_VDEV_MCC_SET_TIME_QUOTA,
12422 set_value, VDEV_CMD);
12423 return 0;
12424
12425}
12426
Jeff Johnson9d295242017-08-29 14:39:48 -070012427int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012428{
12429 if (!adapter) {
12430 hdd_err("Invalid adapter");
12431 return -EINVAL;
12432 }
12433
12434 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012435 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012436 WMA_VDEV_MCC_SET_TIME_LATENCY,
12437 set_value, VDEV_CMD);
12438 return 0;
12439}
12440
Jeff Johnson9d295242017-08-29 14:39:48 -070012441struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012442 *psoc, uint8_t vdev_id)
12443{
Jeff Johnson9d295242017-08-29 14:39:48 -070012444 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012445 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012446
12447 /*
12448 * Currently PSOC is not being used. But this logic will
12449 * change once we have the converged implementation of
12450 * HDD context per PSOC in place. This would break if
12451 * multiple vdev objects reuse the vdev id.
12452 */
12453 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12454 if (!adapter)
12455 hdd_err("Get adapter by vdev id failed");
12456
12457 return adapter;
12458}
12459
Jeff Johnson9d295242017-08-29 14:39:48 -070012460int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012461 int8_t *rssi, int8_t *snr)
12462{
12463 QDF_STATUS status;
12464 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12465 tCsrRoamProfile *profile = &wext_state->roamProfile;
12466
12467 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12468 profile, bssid, rssi, snr);
12469 if (QDF_STATUS_SUCCESS != status) {
12470 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12471 return -EINVAL;
12472 }
12473
12474 return 0;
12475}
12476
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012477/* Register the module init/exit functions */
12478module_init(hdd_module_init);
12479module_exit(hdd_module_exit);
12480
12481MODULE_LICENSE("Dual BSD/GPL");
12482MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12483MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012485module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12486 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012487
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012488module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12489 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12490
Ravi Joshia307f632017-07-17 23:41:41 -070012491module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
12492 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12493
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012494module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12495 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12496
12497module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12498
12499module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12500
12501module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);