blob: 0d810fb38d05e3a5c8465b6218e55a869d3d275a [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"
Dhanashri Atreb08959a2016-03-01 17:28:03 -080087#include "cdp_txrx_flow_ctrl_v2.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#endif /* FEATURE_WLAN_CH_AVOID */
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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800124
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530125#ifdef CNSS_GENL
126#include <net/cnss_nl.h>
127#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800128#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800130#ifdef MODULE
131#define WLAN_MODULE_NAME module_name(THIS_MODULE)
132#else
133#define WLAN_MODULE_NAME "wlan"
134#endif
135
136#ifdef TIMER_MANAGER
137#define TIMER_MANAGER_STR " +TIMER_MANAGER"
138#else
139#define TIMER_MANAGER_STR ""
140#endif
141
142#ifdef MEMORY_DEBUG
143#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
144#else
145#define MEMORY_DEBUG_STR ""
146#endif
147
Sachin Ahujadddd2632017-03-07 19:07:24 +0530148int wlan_start_ret_val;
149static DECLARE_COMPLETION(wlan_start_comp);
150static unsigned int dev_num = 1;
151static struct cdev wlan_hdd_state_cdev;
152static struct class *class;
153static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530154#ifndef MODULE
155static struct gwlan_loader *wlan_loader;
156static ssize_t wlan_boot_cb(struct kobject *kobj,
157 struct kobj_attribute *attr,
158 const char *buf, size_t count);
159struct gwlan_loader {
160 bool loaded_state;
161 struct kobject *boot_wlan_obj;
162 struct attribute_group *attr_group;
163};
164
165static struct kobj_attribute wlan_boot_attribute =
166 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
167
168static struct attribute *attrs[] = {
169 &wlan_boot_attribute.attr,
170 NULL,
171};
172
173#define MODULE_INITIALIZED 1
174#endif
175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176/* the Android framework expects this param even though we don't use it */
177#define BUF_LEN 20
178static char fwpath_buffer[BUF_LEN];
179static struct kparam_string fwpath = {
180 .string = fwpath_buffer,
181 .maxlen = BUF_LEN,
182};
183
184static char *country_code;
185static int enable_11d = -1;
186static int enable_dfs_chan_scan = -1;
187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800188/*
189 * spinlock for synchronizing asynchronous request/response
190 * (full description of use in wlan_hdd_main.h)
191 */
192DEFINE_SPINLOCK(hdd_context_lock);
193
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800194#define WLAN_NLINK_CESIUM 30
195
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530196static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197
198#define WOW_MAX_FILTER_LISTS 1
199#define WOW_MAX_FILTERS_PER_LIST 4
200#define WOW_MIN_PATTERN_SIZE 6
201#define WOW_MAX_PATTERN_SIZE 64
202
203#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
204static const struct wiphy_wowlan_support wowlan_support_reg_init = {
205 .flags = WIPHY_WOWLAN_ANY |
206 WIPHY_WOWLAN_MAGIC_PKT |
207 WIPHY_WOWLAN_DISCONNECT |
208 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
209 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
210 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
211 WIPHY_WOWLAN_4WAY_HANDSHAKE |
212 WIPHY_WOWLAN_RFKILL_RELEASE,
213 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
214 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
215 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
216};
217#endif
218
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700219static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
220 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
221 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
222 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
223 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
224 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
225 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
226 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
227 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
228 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
229 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
232 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
233 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
234 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
235 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
236 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
254};
255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800256/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530257struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258
259struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700261static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#endif
263
Sachin Ahujadddd2632017-03-07 19:07:24 +0530264void hdd_start_complete(int ret)
265{
266 wlan_start_ret_val = ret;
267
268 complete(&wlan_start_comp);
269}
270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800271/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530272 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
273 * @hdd_ctx: pointer to hdd_context_t
274 *
275 * Return: none
276 */
Jeff Johnson590e2012016-10-05 16:16:24 -0700277static void hdd_set_rps_cpu_mask(hdd_context_t *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530278{
279 hdd_adapter_t *adapter;
280 hdd_adapter_list_node_t *adapter_node, *next;
281 QDF_STATUS status = QDF_STATUS_SUCCESS;
282
283 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
284 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
285 adapter = adapter_node->pAdapter;
286 if (NULL != adapter)
287 hdd_send_rps_ind(adapter);
288 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
289 adapter_node = next;
290 }
291}
292
293/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
295 * @vdev_id: vdev_id
296 * @action: action type
297 * @reason: reason type
298 *
299 * Return: none
300 */
301void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
302 enum netif_action_type action, enum netif_reason_type reason)
303{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530304 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305 hdd_adapter_t *adapter;
306
307 if (!hdd_ctx) {
308 hdd_err("hdd ctx is NULL");
309 return;
310 }
311 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
312
313 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314}
315
316/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700317 * Store WLAN driver version and timestamp info in global variables such that
318 * crash debugger can extract them from driver debug symbol and crashdump for
319 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800320 */
321uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700322
323#ifndef BUILD_TIMESTAMP
324#define BUILD_TIMESTAMP ""
325#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700326uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800327
328/**
329 * hdd_device_mode_to_string() - return string conversion of device mode
330 * @device_mode: device mode
331 *
332 * This utility function helps log string conversion of device mode.
333 *
334 * Return: string conversion of device mode, if match found;
335 * "Unknown" otherwise.
336 */
337const char *hdd_device_mode_to_string(uint8_t device_mode)
338{
339 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800340 CASE_RETURN_STRING(QDF_STA_MODE);
341 CASE_RETURN_STRING(QDF_SAP_MODE);
342 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
343 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
344 CASE_RETURN_STRING(QDF_FTM_MODE);
345 CASE_RETURN_STRING(QDF_IBSS_MODE);
346 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
347 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700348 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800349 default:
350 return "Unknown";
351 }
352}
353
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530354/**
355 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
356 * @adapter: HDD adapter
357 * @chan_number: Channel number
358 * @chan_bw: Bandwidth
359 *
360 * Checks if the given bandwidth is valid for the given channel number.
361 *
362 * Return: 0 for success, non-zero for failure
363 */
364int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
365 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800366 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530367{
368 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
369 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
370 bool found = false;
371 tHalHandle hal;
372
373 hal = WLAN_HDD_GET_HAL_CTX(adapter);
374 if (!hal) {
375 hdd_err("Invalid HAL context");
376 return -EINVAL;
377 }
378
379 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
380 hdd_err("No valid channel list");
381 return -EOPNOTSUPP;
382 }
383
384 for (i = 0; i < len; i++) {
385 if (chan[i] == chan_number) {
386 found = true;
387 break;
388 }
389 }
390
391 if (found == false) {
392 hdd_err("Channel not in driver's valid channel list");
393 return -EOPNOTSUPP;
394 }
395
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700396 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
397 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530398 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
399 return -EINVAL;
400 }
401
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700402 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530403 if (chan_bw == CH_WIDTH_80MHZ) {
404 hdd_err("BW80 not possible in 2.4GHz band");
405 return -EINVAL;
406 }
407 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
408 (chan_bw != CH_WIDTH_MAX)) {
409 hdd_err("Only BW20 possible on channel 14");
410 return -EINVAL;
411 }
412 }
413
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700414 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530415 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
416 (chan_bw != CH_WIDTH_MAX)) {
417 hdd_err("Only BW20 possible on channel 165");
418 return -EINVAL;
419 }
420 }
421
422 return 0;
423}
424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425static int __hdd_netdev_notifier_call(struct notifier_block *nb,
426 unsigned long state, void *data)
427{
428#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
429 struct netdev_notifier_info *dev_notif_info = data;
430 struct net_device *dev = dev_notif_info->dev;
431#else
432 struct net_device *dev = data;
433#endif
434 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
435 hdd_context_t *hdd_ctx;
436
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800437 ENTER_DEV(dev);
438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 /* Make sure that this callback corresponds to our device. */
440 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
441 return NOTIFY_DONE;
442
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530443 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700445 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446 return NOTIFY_DONE;
447 }
448
449 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700450 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451 return NOTIFY_DONE;
452 }
453
454 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
455 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800456 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530457 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 return NOTIFY_DONE;
459 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530460 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800461 return NOTIFY_DONE;
462
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800463 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800464 dev->name, state);
465
466 switch (state) {
467 case NETDEV_REGISTER:
468 break;
469
470 case NETDEV_UNREGISTER:
471 break;
472
473 case NETDEV_UP:
474 sme_ch_avoid_update_req(hdd_ctx->hHal);
475 break;
476
477 case NETDEV_DOWN:
478 break;
479
480 case NETDEV_CHANGE:
481 if (true == adapter->isLinkUpSvcNeeded)
482 complete(&adapter->linkup_event_var);
483 break;
484
485 case NETDEV_GOING_DOWN:
486 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530487 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
488 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489 } else {
hqueaa33ee2017-05-04 17:56:35 +0800490 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800491 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492 }
493 break;
494
495 default:
496 break;
497 }
498
499 return NOTIFY_DONE;
500}
501
502/**
503 * hdd_netdev_notifier_call() - netdev notifier callback function
504 * @nb: pointer to notifier block
505 * @state: state
506 * @ndev: ndev pointer
507 *
508 * Return: 0 on success, error number otherwise.
509 */
510static int hdd_netdev_notifier_call(struct notifier_block *nb,
511 unsigned long state,
512 void *ndev)
513{
514 int ret;
515
516 cds_ssr_protect(__func__);
517 ret = __hdd_netdev_notifier_call(nb, state, ndev);
518 cds_ssr_unprotect(__func__);
519
520 return ret;
521}
522
523struct notifier_block hdd_netdev_notifier = {
524 .notifier_call = hdd_netdev_notifier_call,
525};
526
527/* variable to hold the insmod parameters */
528static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800529
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530530static int con_mode_ftm;
531
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800532/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800533static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800534
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530535/**
536 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
537 * @ch_width: NL channel width
538 *
539 * Converts the NL channel width to the driver's internal representation
540 *
541 * Return: Converted channel width. In case of non matching NL channel width,
542 * CH_WIDTH_MAX will be returned.
543 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800544enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530545{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800546 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700547
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800548 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530549 switch (ch_width) {
550 case NL80211_CHAN_WIDTH_20_NOHT:
551 case NL80211_CHAN_WIDTH_20:
552 return CH_WIDTH_20MHZ;
553 case NL80211_CHAN_WIDTH_40:
554 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530555 case NL80211_CHAN_WIDTH_80:
556 return CH_WIDTH_80MHZ;
557 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800558 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
559 return CH_WIDTH_80P80MHZ;
560 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
561 return CH_WIDTH_160MHZ;
562 else
563 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530564 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800565 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
566 return CH_WIDTH_160MHZ;
567 else
568 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530569 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800570 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530571 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800572 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530573 default:
574 hdd_err("Invalid channel width %d, setting to default",
575 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800576 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530577 }
578}
579
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530580/* wlan_hdd_find_opclass() - Find operating class for a channel
581 * @hal: handler to HAL
582 * @channel: channel id
583 * @bw_offset: bandwidth offset
584 *
585 * Function invokes sme api to find the operating class
586 *
587 * Return: operating class
588 */
589uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
590 uint8_t bw_offset)
591{
592 uint8_t opclass = 0;
593
594 sme_get_opclass(hal, channel, bw_offset, &opclass);
595 return opclass;
596}
597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800598/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530599 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530600 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 * @bitmask: Bitmask of log levels to be enabled
602 *
603 * Called immediately after the cfg.ini is read in order to configure
604 * the desired trace levels.
605 *
606 * Return: None
607 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530608int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800609{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530610 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530611 int qdf_print_idx = -1;
612 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800613 /*
614 * if the bitmask is the default value, then a bitmask was not
615 * specified in cfg.ini, so leave the logging level alone (it
616 * will remain at the "compiled in" default value)
617 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700618 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530619 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800620
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530621 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530623 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530624 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530625 QDF_TRACE_LEVEL_NONE, 0);
626
627 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530628 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800629 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530630 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800631 while (0 != bitmask) {
632 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530633 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530634 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530635 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530636 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 level++;
640 bitmask >>= 1;
641 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530642 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800643}
644
645/**
Chris Guo1751acf2017-07-03 14:09:01 +0800646 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
647 * @hdd_ctx: HDD context pointer
648 *
649 * Return: 0 if the context is valid. Error code otherwise
650 */
651int wlan_hdd_validate_context_in_loading(hdd_context_t *hdd_ctx)
652{
653 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
654 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
655 return -ENODEV;
656 }
657
658 if (cds_is_driver_recovering()) {
659 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
660 (void *)_RET_IP_, cds_get_driver_state());
661 return -EAGAIN;
662 }
663
664 if (hdd_ctx->start_modules_in_progress ||
665 hdd_ctx->stop_modules_in_progress) {
666 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
667 (void *)_RET_IP_);
668 return -EAGAIN;
669 }
670
671 return 0;
672}
673
674
675/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676 * wlan_hdd_validate_context() - check the HDD context
677 * @hdd_ctx: HDD context pointer
678 *
679 * Return: 0 if the context is valid. Error code otherwise
680 */
681int wlan_hdd_validate_context(hdd_context_t *hdd_ctx)
682{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530684 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685 return -ENODEV;
686 }
687
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800688 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800689 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530690 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 return -EAGAIN;
692 }
693
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700694 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530696
697 if (hdd_ctx->start_modules_in_progress ||
698 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800699 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530700 (void *)_RET_IP_);
701 return -EAGAIN;
702 }
703
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530704 if (cds_is_driver_in_bad_state()) {
705 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
706 (void *)_RET_IP_, cds_get_driver_state());
707 return -ENODEV;
708 }
709
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800710 return 0;
711}
712
Dustin Brownf13b8c32017-05-19 17:23:08 -0700713int hdd_validate_adapter(hdd_adapter_t *adapter)
714{
715 if (!adapter) {
716 hdd_err("adapter is null");
717 return -EINVAL;
718 }
719
720 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
721 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
722 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
723 return -EINVAL;
724 }
725
726 if (!adapter->dev) {
727 hdd_err("adapter net_device is null");
728 return -EINVAL;
729 }
730
731 if (!(adapter->dev->flags & IFF_UP)) {
732 hdd_info("adapter net_device is not up");
733 return -EAGAIN;
734 }
735
736 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
737 hdd_info("adapter session is not open");
738 return -EAGAIN;
739 }
740
741 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
742 hdd_err("bad adapter session Id: %u", adapter->sessionId);
743 return -EINVAL;
744 }
745
746 return 0;
747}
748
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530750 * wlan_hdd_validate_modules_state() - Check modules status
751 * @hdd_ctx: HDD context pointer
752 *
753 * Check's the driver module's state and returns true if the
754 * modules are enabled returns false if modules are closed.
755 *
756 * Return: True if modules are enabled or false.
757 */
758bool wlan_hdd_validate_modules_state(hdd_context_t *hdd_ctx)
759{
760 mutex_lock(&hdd_ctx->iface_change_lock);
761 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
762 mutex_unlock(&hdd_ctx->iface_change_lock);
763 hdd_notice("Modules not enabled, Present status: %d",
764 hdd_ctx->driver_status);
765 return false;
766 }
767 mutex_unlock(&hdd_ctx->iface_change_lock);
768 return true;
769}
770
771/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
773 * @hdd_adapter_t Hdd adapter.
774 *
775 * This function sets the IBSS power save config parameters to WMA
776 * which will send it to firmware if FW supports IBSS power save
777 * before vdev start.
778 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530779 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800780 * on failure.
781 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530782QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783{
784 int ret;
785 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
786
787 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700788 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530789 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800790 }
791
Naveen Rawat247a8682017-06-05 15:00:31 -0700792 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
794 hdd_ctx->config->ibssATIMWinSize,
795 VDEV_CMD);
796 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700797 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530798 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 }
800
Naveen Rawat247a8682017-06-05 15:00:31 -0700801 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
803 hdd_ctx->config->isIbssPowerSaveAllowed,
804 VDEV_CMD);
805 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700806 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
807 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530808 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809 }
810
Naveen Rawat247a8682017-06-05 15:00:31 -0700811 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
813 hdd_ctx->config->
814 isIbssPowerCollapseAllowed, VDEV_CMD);
815 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700816 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
817 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530818 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 }
820
Naveen Rawat247a8682017-06-05 15:00:31 -0700821 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
823 hdd_ctx->config->isIbssAwakeOnTxRx,
824 VDEV_CMD);
825 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700826 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530827 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 }
829
Naveen Rawat247a8682017-06-05 15:00:31 -0700830 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
832 hdd_ctx->config->ibssInactivityCount,
833 VDEV_CMD);
834 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700835 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530836 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 }
838
Naveen Rawat247a8682017-06-05 15:00:31 -0700839 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
841 hdd_ctx->config->ibssTxSpEndInactivityTime,
842 VDEV_CMD);
843 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700844 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
845 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530846 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 }
848
Naveen Rawat247a8682017-06-05 15:00:31 -0700849 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
851 hdd_ctx->config->ibssPsWarmupTime,
852 VDEV_CMD);
853 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700854 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
855 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530856 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 }
858
Naveen Rawat247a8682017-06-05 15:00:31 -0700859 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
861 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
862 VDEV_CMD);
863 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700864 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
865 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530866 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 }
868
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530869 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870}
871
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872#define INTF_MACADDR_MASK 0x7
873
874/**
875 * hdd_update_macaddr() - update mac address
876 * @config: hdd configuration
877 * @hw_macaddr: mac address
878 *
879 * Mac address for multiple virtual interface is found as following
880 * i) The mac address of the first interface is just the actual hw mac address.
881 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
882 * define the mac address for the remaining interfaces and locally
883 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
884 * supported virtual interfaces, right now this is 0x07 (meaning 8
885 * interface).
886 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
887 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
888 *
889 * Return: None
890 */
891void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530892 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893{
894 int8_t i;
895 uint8_t macaddr_b3, tmp_br3;
896
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530897 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530898 QDF_MAC_ADDR_SIZE);
899 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530900 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530901 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 macaddr_b3 = config->intfMacAddr[i].bytes[3];
903 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
904 INTF_MACADDR_MASK;
905 macaddr_b3 += tmp_br3;
906
907 /* XOR-ing bit-24 of the mac address. This will give enough
908 * mac address range before collision
909 */
910 macaddr_b3 ^= (1 << 7);
911
912 /* Set locally administered bit */
913 config->intfMacAddr[i].bytes[0] |= 0x02;
914 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800915 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 MAC_ADDRESS_STR, i,
917 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
918 }
919}
920
921static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
922 struct wma_tgt_services *cfg)
923{
924 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925
926 /* Set up UAPSD */
927 config->apUapsdEnabled &= cfg->uapsd;
928
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800929 /* 11AX mode support */
930 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
931 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
932 config->dot11Mode = eHDD_DOT11_MODE_11ac;
933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934 /* 11AC mode support */
935 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
936 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
937 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938
939 /* ARP offload: override user setting if invalid */
940 config->fhostArpOffload &= cfg->arp_offload;
941
942#ifdef FEATURE_WLAN_SCAN_PNO
943 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800944 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 if (cfg->pno_offload)
946 config->PnoOffload = true;
947#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948#ifdef FEATURE_WLAN_TDLS
949 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530950 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
951 cfg->en_tdls_offchan;
952 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
953 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700954 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700956 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959#ifdef WLAN_FEATURE_ROAM_OFFLOAD
960 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
961#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700962 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963
964}
965
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700966/**
967 * hdd_update_vdev_nss() - sets the vdev nss
968 * @hdd_ctx: HDD context
969 *
970 * Sets the Nss per vdev type based on INI
971 *
972 * Return: None
973 */
974static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
975{
976 struct hdd_config *cfg_ini = hdd_ctx->config;
977 uint8_t max_supp_nss = 1;
978
Naveen Rawat10b1c152017-01-18 11:16:06 -0800979 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700980 max_supp_nss = 2;
981
982 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
983 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
984
985 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
986 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
987}
988
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530989/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +0530990 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
991 * @hdd_ctx: HDD context
992 *
993 * Updates wiphy vhtcap fields
994 *
995 * Return: None
996 */
997static void hdd_update_wiphy_vhtcap(hdd_context_t *hdd_ctx)
998{
999 struct ieee80211_supported_band *band_5g =
1000 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1001 uint32_t val;
1002
1003 if (!band_5g) {
1004 hdd_debug("5GHz band disabled, skipping capability population");
1005 return;
1006 }
1007
1008 val = hdd_ctx->config->txBFCsnValue;
1009 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1010
1011 val = NUM_OF_SOUNDING_DIMENSIONS;
1012 band_5g->vht_cap.cap |=
1013 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1014
1015 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1016 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1017}
1018
1019/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301020 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1021 * @hdd_ctx: HDD context
1022 *
1023 * Sets the DBS capability as per INI and firmware capability
1024 *
1025 * Return: None
1026 */
1027static void hdd_update_hw_dbs_capable(hdd_context_t *hdd_ctx)
1028{
1029 struct hdd_config *cfg_ini = hdd_ctx->config;
1030 uint8_t hw_dbs_capable = 0;
1031
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001032 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1033 ((cfg_ini->dual_mac_feature_disable ==
1034 ENABLE_DBS_CXN_AND_SCAN) ||
1035 (cfg_ini->dual_mac_feature_disable ==
1036 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301037 hw_dbs_capable = 1;
1038
1039 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1040}
1041
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
1043 struct wma_tgt_ht_cap *cfg)
1044{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301045 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 uint32_t value, val32;
1047 uint16_t val16;
1048 struct hdd_config *pconfig = hdd_ctx->config;
1049 tSirMacHTCapabilityInfo *phtCapInfo;
1050 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1051 uint8_t enable_tx_stbc;
1052
1053 /* check and update RX STBC */
1054 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1055 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1056
1057 /* get the MPDU density */
1058 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1059
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301060 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001061 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001062 value = 0;
1063 }
1064
1065 /*
1066 * MPDU density:
1067 * override user's setting if value is larger
1068 * than the one supported by target
1069 */
1070 if (value > cfg->mpdu_density) {
1071 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1072 cfg->mpdu_density);
1073
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301074 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001075 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 }
1077
1078 /* get the HT capability info */
1079 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301080 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001081 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001082 return;
1083 }
1084 val16 = (uint16_t) val32;
1085 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1086
1087 /* Set the LDPC capability */
1088 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1089
1090 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1091 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1092
1093 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1094 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1095
1096 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1097 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1098
1099 enable_tx_stbc = pconfig->enableTxSTBC;
1100
1101 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1102 pconfig->enable2x2 = 1;
1103 } else {
1104 pconfig->enable2x2 = 0;
1105 enable_tx_stbc = 0;
1106
1107 /* 1x1 */
1108 /* Update Rx Highest Long GI data Rate */
1109 if (sme_cfg_set_int(hdd_ctx->hHal,
1110 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001111 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301112 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001113 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 }
1115
1116 /* Update Tx Highest Long GI data Rate */
1117 if (sme_cfg_set_int
1118 (hdd_ctx->hHal,
1119 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001120 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301121 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001122 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 }
1124 }
1125 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1126 enable_tx_stbc = 0;
1127 phtCapInfo->txSTBC = enable_tx_stbc;
1128
1129 val32 = val16;
1130 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301131 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001132 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001133#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1134 value = SIZE_OF_SUPPORTED_MCS_SET;
1135 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301136 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001137 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138
1139 if (pconfig->enable2x2) {
1140 for (value = 0; value < cfg->num_rf_chains; value++)
1141 mcs_set[value] =
1142 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1143
1144 status =
1145 sme_cfg_set_str(hdd_ctx->hHal,
1146 WNI_CFG_SUPPORTED_MCS_SET,
1147 mcs_set,
1148 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301149 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001150 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 }
1152 }
1153#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1154}
1155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
1157 struct wma_tgt_vht_cap *cfg)
1158{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301159 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 uint32_t value = 0;
1161 struct hdd_config *pconfig = hdd_ctx->config;
1162 struct wiphy *wiphy = hdd_ctx->wiphy;
1163 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001164 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001165 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001166 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001167 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001168
Dustin Brown5e06bd32016-10-04 12:49:10 -07001169 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001170 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001171 return;
1172 }
1173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001174 /* Get the current MPDU length */
1175 status =
1176 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1177 &value);
1178
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301179 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001180 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 value = 0;
1182 }
1183
1184 /*
1185 * VHT max MPDU length:
1186 * override if user configured value is too high
1187 * that the target cannot support
1188 */
1189 if (value > cfg->vht_max_mpdu) {
1190 status = sme_cfg_set_int(hdd_ctx->hHal,
1191 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1192 cfg->vht_max_mpdu);
1193
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001194 if (status == QDF_STATUS_E_FAILURE)
1195 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196 }
1197
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001198 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1199 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1200
1201 if (pconfig->enable2x2)
1202 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1203
1204 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1205 QDF_STATUS_E_FAILURE) {
1206 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1207 }
1208
1209 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1210 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1211 if (pconfig->enable2x2)
1212 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1213
1214 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1215 QDF_STATUS_E_FAILURE) {
1216 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1217 }
1218
1219 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1220 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1221 if (pconfig->enable2x2)
1222 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1223
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001224 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001225 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1226
1227 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1228 QDF_STATUS_E_FAILURE) {
1229 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1230 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001232 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 &value);
1234
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301235 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001236 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 value = 0;
1238 }
1239
jiad4a7a33c2017-08-08 15:32:24 +08001240 /* Set HW RX LDPC capability */
1241 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1242 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243 status = sme_cfg_set_int(hdd_ctx->hHal,
1244 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001245 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001246
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001247 if (status == QDF_STATUS_E_FAILURE)
1248 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 }
1250
1251 /* Get current GI 80 value */
1252 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1253 &value);
1254
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301255 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001256 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 value = 0;
1258 }
1259
1260 /* set the Guard interval 80MHz */
1261 if (value && !cfg->vht_short_gi_80) {
1262 status = sme_cfg_set_int(hdd_ctx->hHal,
1263 WNI_CFG_VHT_SHORT_GI_80MHZ,
1264 cfg->vht_short_gi_80);
1265
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001266 if (status == QDF_STATUS_E_FAILURE)
1267 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001268 }
1269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270 /* Get VHT TX STBC cap */
1271 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1272
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301273 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001274 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001275 value = 0;
1276 }
1277
1278 /* VHT TX STBC cap */
1279 if (value && !cfg->vht_tx_stbc) {
1280 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1281 cfg->vht_tx_stbc);
1282
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001283 if (status == QDF_STATUS_E_FAILURE)
1284 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 }
1286
1287 /* Get VHT RX STBC cap */
1288 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1289
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301290 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001291 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 value = 0;
1293 }
1294
1295 /* VHT RX STBC cap */
1296 if (value && !cfg->vht_rx_stbc) {
1297 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1298 cfg->vht_rx_stbc);
1299
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001300 if (status == QDF_STATUS_E_FAILURE)
1301 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 }
1303
1304 /* Get VHT SU Beamformer cap */
1305 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1306 &value);
1307
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301308 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001309 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001310 value = 0;
1311 }
1312
1313 /* set VHT SU Beamformer cap */
1314 if (value && !cfg->vht_su_bformer) {
1315 status = sme_cfg_set_int(hdd_ctx->hHal,
1316 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1317 cfg->vht_su_bformer);
1318
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001319 if (status == QDF_STATUS_E_FAILURE)
1320 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 }
1322
1323 /* check and update SU BEAMFORMEE capabality */
1324 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1325 pconfig->enableTxBF = cfg->vht_su_bformee;
1326
1327 status = sme_cfg_set_int(hdd_ctx->hHal,
1328 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1329 pconfig->enableTxBF);
1330
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001331 if (status == QDF_STATUS_E_FAILURE)
1332 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001333
1334 /* Get VHT MU Beamformer cap */
1335 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1336 &value);
1337
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301338 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001339 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 value = 0;
1341 }
1342
1343 /* set VHT MU Beamformer cap */
1344 if (value && !cfg->vht_mu_bformer) {
1345 status = sme_cfg_set_int(hdd_ctx->hHal,
1346 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1347 cfg->vht_mu_bformer);
1348
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001349 if (status == QDF_STATUS_E_FAILURE)
1350 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 }
1352
1353 /* Get VHT MU Beamformee cap */
1354 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1355 &value);
1356
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301357 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001358 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359 value = 0;
1360 }
1361
1362 /* set VHT MU Beamformee cap */
1363 if (value && !cfg->vht_mu_bformee) {
1364 status = sme_cfg_set_int(hdd_ctx->hHal,
1365 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1366 cfg->vht_mu_bformee);
1367
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001368 if (status == QDF_STATUS_E_FAILURE)
1369 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 }
1371
1372 /* Get VHT MAX AMPDU Len exp */
1373 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1374 &value);
1375
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301376 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001377 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378 value = 0;
1379 }
1380
1381 /*
1382 * VHT max AMPDU len exp:
1383 * override if user configured value is too high
1384 * that the target cannot support.
1385 * Even though Rome publish ampdu_len=7, it can
1386 * only support 4 because of some h/w bug.
1387 */
1388
1389 if (value > cfg->vht_max_ampdu_len_exp) {
1390 status = sme_cfg_set_int(hdd_ctx->hHal,
1391 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1392 cfg->vht_max_ampdu_len_exp);
1393
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001394 if (status == QDF_STATUS_E_FAILURE)
1395 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 }
1397
1398 /* Get VHT TXOP PS CAP */
1399 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1400
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301401 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001402 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 value = 0;
1404 }
1405
1406 /* set VHT TXOP PS cap */
1407 if (value && !cfg->vht_txop_ps) {
1408 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1409 cfg->vht_txop_ps);
1410
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001411 if (status == QDF_STATUS_E_FAILURE)
1412 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 }
1414
1415 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1416 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1417 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1418 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1419 else
1420 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1421
1422
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001423 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1424 status = sme_cfg_set_int(hdd_ctx->hHal,
1425 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1426 VHT_CAP_160_AND_80P80_SUPP);
1427 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001428 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 band_5g->vht_cap.cap |=
1430 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001431 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1432 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1433 status = sme_cfg_set_int(hdd_ctx->hHal,
1434 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1435 VHT_CAP_160_SUPP);
1436 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001437 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 band_5g->vht_cap.cap |=
1439 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001440 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1441 }
1442 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1443 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301444 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001445 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301446 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001447 &value);
1448 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301449 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001450 value = 0;
1451 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301452 /* set the Guard interval 160MHz */
1453 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001454 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301455 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1456 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001457
1458 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301459 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001460 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461
1462 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1463 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1464
1465 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1466 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1467 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1468 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1469
1470 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1471 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1472
1473 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1474 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1475 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1476 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1477 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1478 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1479
1480 band_5g->vht_cap.cap |=
1481 (cfg->vht_max_ampdu_len_exp <<
1482 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1483
1484 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1485 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1486 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1487 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1488 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1489 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1490 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1491 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1492
1493 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1494 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1495
1496}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001498/**
1499 * hdd_generate_macaddr_auto() - Auto-generate mac address
1500 * @hdd_ctx: Pointer to the HDD context
1501 *
1502 * Auto-generate mac address using device serial number.
1503 * Keep the first 3 bytes of OUI as before and replace
1504 * the last 3 bytes with the lower 3 bytes of serial number.
1505 *
1506 * Return: 0 for success
1507 * Non zero failure code for errors
1508 */
1509static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1510{
1511 unsigned int serialno = 0;
1512 struct qdf_mac_addr mac_addr = {
1513 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1514 };
1515
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001516 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001517 if (serialno == 0)
1518 return -EINVAL;
1519
1520 serialno &= 0x00ffffff;
1521
1522 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1523 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1524 mac_addr.bytes[5] = serialno & 0xff;
1525
1526 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1527 return 0;
1528}
1529
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301530/**
1531 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1532 * configuration to cfg_ini in HDD
1533 * @hdd_ctx: Pointer to hdd_ctx
1534 * @cfg: target configuration
1535 *
1536 * Return: None
1537 */
1538#ifdef FEATURE_WLAN_RA_FILTERING
1539static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1540 struct wma_tgt_cfg *cfg)
1541{
1542 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1543}
1544#else
1545static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1546 struct wma_tgt_cfg *cfg)
1547{
1548}
1549#endif
1550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551void hdd_update_tgt_cfg(void *context, void *param)
1552{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001553 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1555 struct wma_tgt_cfg *cfg = param;
1556 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001557 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301558 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301559
Yue Mae3e86ab2017-05-08 10:48:24 -07001560 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301561 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1562 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1563 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1564 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1565 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001566 /* Restore pdev to MAC/WMA contexts */
1567 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001568 } else {
1569 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1570 if (ret) {
1571 hdd_err("pdev creation fails!");
1572 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301573 } else
1574 hdd_debug("New pdev has been created with pdev_id = %u",
1575 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301576 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001577
Naveen Rawat64e477e2016-05-20 10:34:56 -07001578 if (cds_cfg) {
1579 if (hdd_ctx->config->enable_sub_20_channel_width !=
1580 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1581 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1582 cds_cfg->sub_20_channel_width =
1583 WLAN_SUB_20_CH_WIDTH_NONE;
1584 } else {
1585 cds_cfg->sub_20_channel_width =
1586 hdd_ctx->config->enable_sub_20_channel_width;
1587 }
1588 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589
1590 /* first store the INI band capability */
1591 temp_band_cap = hdd_ctx->config->nBandCapability;
1592
1593 hdd_ctx->config->nBandCapability = cfg->band_cap;
1594
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001595 /*
1596 * now overwrite the target band capability with INI
1597 * setting if INI setting is a subset
1598 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599
1600 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1601 (temp_band_cap != eCSR_BAND_ALL))
1602 hdd_ctx->config->nBandCapability = temp_band_cap;
1603 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1604 (temp_band_cap != eCSR_BAND_ALL) &&
1605 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001606 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 }
1608
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301609 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1611 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1612 }
1613
1614 /* This can be extended to other configurations like ht, vht cap... */
1615
Anurag Chouhanc5548422016-02-24 18:33:27 +05301616 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001618 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001620 static struct qdf_mac_addr default_mac_addr = {
1621 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1622 };
1623 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1624 &default_mac_addr)) {
1625 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1626 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1627 MAC_ADDRESS_STR,
1628 MAC_ADDR_ARRAY(hdd_ctx->config->
1629 intfMacAddr[0].bytes));
1630 } else {
1631 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1632 MAC_ADDRESS_STR,
1633 MAC_ADDR_ARRAY(hdd_ctx->config->
1634 intfMacAddr[0].bytes));
1635 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001636 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 }
1638
1639 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001640 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641
1642 hdd_ctx->max_intf_count = cfg->max_intf_count;
1643
Jeff Johnsonc875e242016-09-23 18:12:34 -07001644 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001645 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001646
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1648 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1649
1650 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001653 if (cfg->services.en_11ax) {
1654 hdd_info("11AX: 11ax is enabled - update HDD config");
1655 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1656 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001657
1658 hdd_update_vdev_nss(hdd_ctx);
1659
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301660 hdd_update_hw_dbs_capable(hdd_ctx);
1661
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001662 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001663 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001664 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001665 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001666
Nitesh Shahe50711f2017-04-26 16:30:45 +05301667 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1668 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1669 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001670 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001671 hdd_ctx->current_antenna_mode);
1672
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001673 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1674 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301675 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301676
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301677 if ((hdd_ctx->config->txBFCsnValue >
1678 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1679 !cfg->tx_bfee_8ss_enabled)
1680 hdd_ctx->config->txBFCsnValue =
1681 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1682
1683 if (sme_cfg_set_int(hdd_ctx->hHal,
1684 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1685 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1686 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1687
1688
1689 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1690 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1691 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301692
1693 /*
1694 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1695 */
1696 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301697 /*
1698 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1699 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1700 * configure the STA mode wow pattern.
1701 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301702 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301703 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301704
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301705 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1706
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001707 /* Configure NAN datapath features */
1708 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001709 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001710}
1711
Arif Hussaincd151632017-02-11 16:57:19 -08001712bool hdd_dfs_indicate_radar(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1715 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301716 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301717 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718
Arif Hussaincd151632017-02-11 16:57:19 -08001719 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
1720 hdd_info("skip tx block hdd_ctx=%p, disableDFSChSwitch=%d",
1721 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301722 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001723 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724
Arif Hussaincd151632017-02-11 16:57:19 -08001725 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1726 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1727 adapter = adapterNode->pAdapter;
1728 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1729
1730 if ((QDF_SAP_MODE == adapter->device_mode ||
1731 QDF_P2P_GO_MODE == adapter->device_mode) &&
1732 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1733 ap_ctx->operatingChannel))) {
1734 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1735 true;
1736 hdd_info("tx blocked for session: %d",
1737 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301738 }
Arif Hussaincd151632017-02-11 16:57:19 -08001739 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1740 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301742
1743 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001745
1746/**
1747 * hdd_is_valid_mac_address() - validate MAC address
1748 * @pMacAddr: Pointer to the input MAC address
1749 *
1750 * This function validates whether the given MAC address is valid or not
1751 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1752 * where X is the hexa decimal digit character and separated by ':'
1753 * This algorithm works even if MAC address is not separated by ':'
1754 *
1755 * This code checks given input string mac contains exactly 12 hexadecimal
1756 * digits and a separator colon : appears in the input string only after
1757 * an even number of hex digits.
1758 *
1759 * Return: 1 for valid and 0 for invalid
1760 */
1761bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1762{
1763 int xdigit = 0;
1764 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766 while (*pMacAddr) {
1767 if (isxdigit(*pMacAddr)) {
1768 xdigit++;
1769 } else if (':' == *pMacAddr) {
1770 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1771 break;
1772
1773 ++separator;
1774 } else {
1775 /* Invalid MAC found */
1776 return 0;
1777 }
1778 ++pMacAddr;
1779 }
1780 return xdigit == 12 && (separator == 5 || separator == 0);
1781}
1782
1783/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301784 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1785 * @dev: Handle to struct net_device to be updated.
1786 *
1787 * Return: None
1788 */
1789static void hdd_mon_mode_ether_setup(struct net_device *dev)
1790{
1791 dev->header_ops = NULL;
1792 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1793 dev->hard_header_len = ETH_HLEN;
1794 dev->mtu = ETH_DATA_LEN;
1795 dev->addr_len = ETH_ALEN;
1796 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1797 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1798 dev->priv_flags |= IFF_TX_SKB_SHARING;
1799
1800 memset(dev->broadcast, 0xFF, ETH_ALEN);
1801}
1802
1803/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001804 * __hdd__mon_open() - HDD Open function
1805 * @dev: Pointer to net_device structure
1806 *
1807 * This is called in response to ifconfig up
1808 *
1809 * Return: 0 for success; non-zero for failure
1810 */
1811static int __hdd_mon_open(struct net_device *dev)
1812{
1813 int ret;
1814
1815 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301816 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001817 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001818
1819 if (!ret)
1820 ret = hdd_enable_monitor_mode(dev);
1821
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001822 return ret;
1823}
1824
1825/**
1826 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1827 * @dev: Pointer to net_device structure
1828 *
1829 * This is called in response to ifconfig up
1830 *
1831 * Return: 0 for success; non-zero for failure
1832 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001833static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001834{
1835 int ret;
1836
1837 cds_ssr_protect(__func__);
1838 ret = __hdd_mon_open(dev);
1839 cds_ssr_unprotect(__func__);
1840
1841 return ret;
1842}
1843
1844/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301845 * hdd_start_adapter() - Wrapper function for device specific adapter
1846 * @adapter: pointer to HDD adapter
1847 *
1848 * This function is called to start the device specific adapter for
1849 * the mode passed in the adapter's device_mode.
1850 *
1851 * Return: 0 for success; non-zero for failure
1852 */
1853int hdd_start_adapter(hdd_adapter_t *adapter)
1854{
1855
1856 int ret;
1857 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1858
1859 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001860 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301861
1862 switch (device_mode) {
1863 case QDF_P2P_CLIENT_MODE:
1864 case QDF_P2P_DEVICE_MODE:
1865 case QDF_OCB_MODE:
1866 case QDF_STA_MODE:
1867 case QDF_MONITOR_MODE:
1868 ret = hdd_start_station_adapter(adapter);
1869 if (ret)
1870 goto err_start_adapter;
1871 break;
1872 case QDF_P2P_GO_MODE:
1873 case QDF_SAP_MODE:
1874 ret = hdd_start_ap_adapter(adapter);
1875 if (ret)
1876 goto err_start_adapter;
1877 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301878 case QDF_IBSS_MODE:
1879 /*
1880 * For IBSS interface is initialized as part of
1881 * hdd_init_station_mode()
1882 */
1883 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301884 case QDF_FTM_MODE:
1885 ret = hdd_start_ftm_adapter(adapter);
1886 if (ret)
1887 goto err_start_adapter;
1888 break;
1889 default:
1890 hdd_err("Invalid session type %d", device_mode);
1891 QDF_ASSERT(0);
1892 goto err_start_adapter;
1893 }
1894 if (hdd_set_fw_params(adapter))
1895 hdd_err("Failed to set the FW params for the adapter!");
1896
1897 /*
1898 * Action frame registered in one adapter which will
1899 * applicable to all interfaces
1900 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301901 ret = wlan_hdd_cfg80211_register_frames(adapter);
1902 if (ret < 0) {
1903 hdd_err("Failed to register frames - ret %d", ret);
1904 goto err_start_adapter;
1905 }
1906
Arun Khandavallifae92942016-08-01 13:31:08 +05301907 EXIT();
1908 return 0;
1909err_start_adapter:
1910 return -EINVAL;
1911}
1912
1913/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301914 * hdd_enable_power_management() - API to Enable Power Management
1915 *
1916 * API invokes Bus Interface Layer power management functionality
1917 *
1918 * Return: None
1919 */
1920static void hdd_enable_power_management(void)
1921{
1922 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1923
1924 if (!hif_ctx) {
1925 hdd_err("Bus Interface Context is Invalid");
1926 return;
1927 }
1928
1929 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1930}
1931
1932/**
1933 * hdd_disable_power_management() - API to disable Power Management
1934 *
1935 * API disable Bus Interface Layer Power management functionality
1936 *
1937 * Return: None
1938 */
1939static void hdd_disable_power_management(void)
1940{
1941 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1942
1943 if (!hif_ctx) {
1944 hdd_err("Bus Interface Context is Invalid");
1945 return;
1946 }
1947
1948 hif_disable_power_management(hif_ctx);
1949}
1950
1951/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301952 * hdd_update_hw_sw_info() - API to update the HW/SW information
1953 *
1954 * API to update the HW and SW information in the driver
1955 *
1956 * Return: None
1957 */
1958static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1959{
1960 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07001961 size_t target_hw_name_len;
1962 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301963
1964 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1965 if (!hif_sc) {
1966 hdd_err("HIF context is NULL");
1967 return;
1968 }
1969
1970 /*
1971 * target hw version/revision would only be retrieved after firmware
1972 * download
1973 */
Dustin Brown6f17a022017-07-19 13:40:55 -07001974 hif_get_hw_info(hif_sc,
1975 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301976 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07001977 &target_hw_name);
1978
1979 if (hdd_ctx->target_hw_name)
1980 qdf_mem_free(hdd_ctx->target_hw_name);
1981
1982 target_hw_name_len = strlen(target_hw_name) + 1;
1983 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
1984 if (hdd_ctx->target_hw_name)
1985 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
1986 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301987
1988 /* Get the wlan hw/fw version */
1989 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301990}
1991
1992/**
gbian62edd7e2017-03-07 13:12:13 +08001993 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1994 * @hdd_ctx: Pointer to hdd context
1995 *
1996 * Return: none
1997 */
1998static void
1999hdd_update_cds_ac_specs_params(hdd_context_t *hdd_ctx)
2000{
2001 uint8_t num_entries = 0;
2002 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2003 uint8_t *tx_sched_wrr_ac;
2004 int i;
2005 cds_context_type *cds_ctx;
2006
2007 if (NULL == hdd_ctx)
2008 return;
2009
2010 if (NULL == hdd_ctx->config) {
2011 /* Do nothing if hdd_ctx is invalid */
2012 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2013 return;
2014 }
2015
2016 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2017
2018 if (!cds_ctx) {
2019 hdd_err("Invalid CDS Context");
2020 return;
2021 }
2022
2023 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2024 switch (i) {
2025 case OL_TX_WMM_AC_BE:
2026 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2027 break;
2028 case OL_TX_WMM_AC_BK:
2029 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2030 break;
2031 case OL_TX_WMM_AC_VI:
2032 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2033 break;
2034 case OL_TX_WMM_AC_VO:
2035 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2036 break;
2037 default:
2038 tx_sched_wrr_ac = NULL;
2039 break;
2040 }
2041
2042 hdd_string_to_u8_array(tx_sched_wrr_ac,
2043 tx_sched_wrr_param,
2044 &num_entries,
2045 sizeof(tx_sched_wrr_param));
2046
2047 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2048 cds_ctx->ac_specs[i].wrr_skip_weight =
2049 tx_sched_wrr_param[0];
2050 cds_ctx->ac_specs[i].credit_threshold =
2051 tx_sched_wrr_param[1];
2052 cds_ctx->ac_specs[i].send_limit =
2053 tx_sched_wrr_param[2];
2054 cds_ctx->ac_specs[i].credit_reserve =
2055 tx_sched_wrr_param[3];
2056 cds_ctx->ac_specs[i].discard_weight =
2057 tx_sched_wrr_param[4];
2058 }
2059
2060 num_entries = 0;
2061 }
2062}
2063
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002064#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002065static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2066 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2067{
2068 hdd_adapter_t *adapter = NULL;
2069 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2070
2071 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2072 if (!adapter) {
2073 hdd_err("Adapter is NULL");
2074 return PM_MAX_NUM_OF_MODE;
2075 }
2076
2077 return policy_mgr_convert_device_mode_to_qdf_type(
2078 adapter->device_mode);
2079}
2080
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002081static void hdd_register_policy_manager_callback(
2082 struct wlan_objmgr_psoc *psoc)
2083{
2084 struct policy_mgr_hdd_cbacks hdd_cbacks;
2085 hdd_cbacks.sap_restart_chan_switch_cb =
2086 sap_restart_chan_switch_cb;
2087 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2088 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002089 hdd_cbacks.get_mode_for_non_connected_vdev =
2090 wlan_hdd_get_mode_for_non_connected_vdev;
2091
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002092 if (QDF_STATUS_SUCCESS !=
2093 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2094 hdd_err("HDD callback registration with policy manager failed");
2095 }
2096}
2097#else
2098static void hdd_register_policy_manager_callback(
2099 struct wlan_objmgr_psoc *psoc)
2100{
2101}
2102#endif
2103
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002104#ifdef WLAN_FEATURE_NAN_CONVERGENCE
2105static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2106{
2107 struct nan_callbacks cb_obj = {0};
2108
2109 cb_obj.ndi_open = hdd_ndi_open;
2110 cb_obj.ndi_close = hdd_ndi_close;
2111 cb_obj.ndi_start = hdd_ndi_start;
2112 cb_obj.ndi_delete = hdd_ndi_delete;
2113 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2114 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2115
Naveen Rawat37f62c82017-03-26 22:24:43 -07002116 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2117 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002118 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002119
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002120 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2121}
2122#else
2123static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2124{
2125}
2126#endif
2127
gbian62edd7e2017-03-07 13:12:13 +08002128/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302129 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2130 * @hdd_ctx: HDD context
2131 * @adapter: HDD adapter
2132 * @reinit: flag to indicate from SSR or normal path
2133 *
2134 * This function maintains the driver state machine it will be invoked from
2135 * startup, reinit and change interface. Depending on the driver state shall
2136 * perform the opening of the modules.
2137 *
2138 * Return: 0 for success; non-zero for failure
2139 */
2140int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
2141 bool reinit)
2142{
2143 int ret;
2144 qdf_device_t qdf_dev;
2145 QDF_STATUS status;
2146 p_cds_contextType p_cds_context;
2147 bool unint = false;
2148 void *hif_ctx;
2149
2150 ENTER();
2151
2152 p_cds_context = cds_get_global_context();
2153 if (!p_cds_context) {
2154 hdd_err("Global Context is NULL");
2155 QDF_ASSERT(0);
2156 return -EINVAL;
2157 }
2158
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002159 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302160 hdd_ctx->driver_status, reinit);
2161
2162 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2163 if (!qdf_dev) {
2164 hdd_err("QDF Device Context is Invalid return");
2165 return -EINVAL;
2166 }
2167
2168 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302169 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302170
2171 if (QDF_TIMER_STATE_RUNNING ==
2172 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2173
2174 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002175 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302176 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2177 }
2178
2179 switch (hdd_ctx->driver_status) {
2180 case DRIVER_MODULES_UNINITIALIZED:
2181 unint = true;
2182 /* Fall through dont add break here */
2183 case DRIVER_MODULES_CLOSED:
2184 if (!reinit && !unint) {
2185 ret = pld_power_on(qdf_dev->dev);
2186 if (ret) {
2187 hdd_err("Failed to Powerup the device: %d", ret);
2188 goto release_lock;
2189 }
2190 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002191
2192 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2193 hdd_ctx->config->enable_fw_log);
2194
Arun Khandavallifae92942016-08-01 13:31:08 +05302195 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2196 qdf_dev->bus_type,
2197 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2198 HIF_ENABLE_TYPE_PROBE);
2199 if (ret) {
2200 hdd_err("Failed to open hif: %d", ret);
2201 goto power_down;
2202 }
2203
2204 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302205 if (!hif_ctx) {
2206 hdd_err("hif context is null!!");
2207 goto power_down;
2208 }
2209
Arun Khandavallifae92942016-08-01 13:31:08 +05302210 status = ol_cds_init(qdf_dev, hif_ctx);
2211 if (status != QDF_STATUS_SUCCESS) {
2212 hdd_err("No Memory to Create BMI Context :%d", status);
2213 goto hif_close;
2214 }
2215
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002216 ret = hdd_update_config(hdd_ctx);
2217 if (ret) {
2218 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302219 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002220 }
2221
gbian62edd7e2017-03-07 13:12:13 +08002222 hdd_update_cds_ac_specs_params(hdd_ctx);
2223
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302224 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302225 if (!QDF_IS_STATUS_SUCCESS(status)) {
2226 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302227 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302228 }
2229
Mukul Sharma9d797a02017-01-05 20:26:03 +05302230 /* initalize components configurations after psoc open */
2231 ret = hdd_update_components_config(hdd_ctx);
2232 if (ret) {
2233 hdd_err("Failed to update components configs :%d",
2234 ret);
2235 goto close;
2236 }
2237
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002238 /*
2239 * NAN compoenet requires certian operations like, open adapter,
2240 * close adapter, etc. to be initiated by HDD, for those
2241 * register HDD callbacks with UMAC's NAN componenet.
2242 */
2243 hdd_nan_register_callbacks(hdd_ctx);
2244
Arun Khandavallifae92942016-08-01 13:31:08 +05302245 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2246
2247 status = cds_pre_enable(hdd_ctx->pcds_context);
2248 if (!QDF_IS_STATUS_SUCCESS(status)) {
2249 hdd_err("Failed to pre-enable CDS: %d", status);
2250 goto close;
2251 }
2252
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002253 hdd_register_policy_manager_callback(
2254 hdd_ctx->hdd_psoc);
2255
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302256 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302257 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302258
Arun Khandavallifae92942016-08-01 13:31:08 +05302259 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2260 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2261 hdd_ftm_mc_process_msg);
2262 break;
2263 }
2264 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002265 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302266 break;
2267 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302268
2269 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002270 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2271 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002272 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002273 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302274 }
2275
Arun Khandavallifae92942016-08-01 13:31:08 +05302276 /* Fall through dont add break here */
2277 case DRIVER_MODULES_OPENED:
2278 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002279 hdd_alert("adapter is Null");
2280 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302281 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302282 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2283 hdd_err("in ftm mode, no need to configure cds modules");
2284 break;
2285 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302286 if (hdd_configure_cds(hdd_ctx, adapter)) {
2287 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002288 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302289 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302290 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302291 hdd_info("Driver Modules Successfully Enabled");
2292 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2293 break;
2294 case DRIVER_MODULES_ENABLED:
2295 hdd_info("Driver modules already Enabled");
2296 break;
2297 default:
2298 hdd_err("WLAN start invoked in wrong state! :%d\n",
2299 hdd_ctx->driver_status);
2300 goto release_lock;
2301 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302302 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302303 mutex_unlock(&hdd_ctx->iface_change_lock);
2304 EXIT();
2305 return 0;
2306
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002307post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002308 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002309
Arun Khandavallifae92942016-08-01 13:31:08 +05302310close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002311 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302312 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302313
2314ol_cds_free:
2315 ol_cds_free();
2316
2317hif_close:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302318 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302319power_down:
2320 if (!reinit && !unint)
2321 pld_power_off(qdf_dev->dev);
2322release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302323 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302324 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302325 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002326
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 return -EINVAL;
2328}
2329
Naveen Rawat910726a2017-03-06 11:42:51 -08002330#ifdef WIFI_POS_CONVERGED
2331static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2332{
2333 int ret = os_if_wifi_pos_register_nl();
2334
2335 if (ret)
2336 hdd_err("os_if_wifi_pos_register_nl failed");
2337
2338 return ret;
2339}
2340
2341static int hdd_deactivate_wifi_pos(void)
2342{
2343 int ret = os_if_wifi_pos_deregister_nl();
2344
2345 if (ret)
2346 hdd_err("os_if_wifi_pos_deregister_nl failed");
2347
2348 return ret;
2349}
2350
2351/**
2352 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2353 * @hdd_ctx: hdd context
2354 *
2355 * Return: status of operation
2356 */
2357static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2358{
2359 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2360 struct hdd_config *cfg = hdd_ctx->config;
2361
2362 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2363 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2364 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2365 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2366 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2367 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2368 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2369 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2370}
2371#else
2372static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2373{
2374 return oem_activate_service(hdd_ctx);
2375}
2376
2377static int hdd_deactivate_wifi_pos(void)
2378{
2379 return 0;
2380}
2381
2382static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2383{
2384}
2385#endif
2386
Arun Khandavallifae92942016-08-01 13:31:08 +05302387/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388 * __hdd_open() - HDD Open function
2389 * @dev: Pointer to net_device structure
2390 *
2391 * This is called in response to ifconfig up
2392 *
2393 * Return: 0 for success; non-zero for failure
2394 */
2395static int __hdd_open(struct net_device *dev)
2396{
2397 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2398 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2399 int ret;
2400
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002401 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302402 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302403 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404
2405 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302406 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002407 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302408
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002409
Arun Khandavallifae92942016-08-01 13:31:08 +05302410 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2411 if (ret) {
2412 hdd_err("Failed to start WLAN modules return");
2413 return -ret;
2414 }
2415
2416
2417 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2418 ret = hdd_start_adapter(adapter);
2419 if (ret) {
2420 hdd_err("Failed to start adapter :%d",
2421 adapter->device_mode);
2422 return ret;
2423 }
2424 }
2425
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002426 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2427 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002428 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 /* Enable TX queues only when we are connected */
2430 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302431 WLAN_START_ALL_NETIF_QUEUE,
2432 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 }
2434
Naveen Rawat286def52016-09-23 15:38:02 -07002435 /* Enable carrier and transmit queues for NDI */
2436 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002437 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002438 wlan_hdd_netif_queue_control(adapter,
2439 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2440 WLAN_CONTROL_PATH);
2441 }
2442
Naveen Rawat910726a2017-03-06 11:42:51 -08002443 hdd_populate_wifi_pos_cfg(hdd_ctx);
2444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002445 return ret;
2446}
2447
Arun Khandavallifae92942016-08-01 13:31:08 +05302448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002449/**
2450 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2451 * @dev: Pointer to net_device structure
2452 *
2453 * This is called in response to ifconfig up
2454 *
2455 * Return: 0 for success; non-zero for failure
2456 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002457static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458{
2459 int ret;
2460
2461 cds_ssr_protect(__func__);
2462 ret = __hdd_open(dev);
2463 cds_ssr_unprotect(__func__);
2464
2465 return ret;
2466}
2467
2468/**
2469 * __hdd_stop() - HDD stop function
2470 * @dev: Pointer to net_device structure
2471 *
2472 * This is called in response to ifconfig down
2473 *
2474 * Return: 0 for success; non-zero for failure
2475 */
2476static int __hdd_stop(struct net_device *dev)
2477{
2478 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2479 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2480 int ret;
2481
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002482 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002483
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302484 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485 adapter->sessionId, adapter->device_mode));
2486
2487 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302488 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002489 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002490
2491 /* Nothing to be done if the interface is not opened */
2492 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002493 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002494 return -ENODEV;
2495 }
2496
2497 /* Make sure the interface is marked as closed */
2498 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002499 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302500 wlan_hdd_netif_queue_control(adapter,
2501 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2502 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002503
2504 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002505 * NAN data interface is different in some sense. The traffic on NDI is
2506 * bursty in nature and depends on the need to transfer. The service
2507 * layer may down the interface after the usage and up again when
2508 * required. In some sense, the NDI is expected to be available
2509 * (like SAP) iface until NDI delete request is issued by the service
2510 * layer. Skip BSS termination and adapter deletion for NAN Data
2511 * interface (NDI).
2512 */
2513 if (WLAN_HDD_IS_NDI(adapter))
2514 return 0;
2515
2516 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002517 * The interface is marked as down for outside world (aka kernel)
2518 * But the driver is pretty much alive inside. The driver needs to
2519 * tear down the existing connection on the netdev (session)
2520 * cleanup the data pipes and wait until the control plane is stabilized
2521 * for this interface. The call also needs to wait until the above
2522 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002523 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002524 * That is intentional to be able to scan if it is a STA/P2P interface
2525 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302526 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527
2528 /* DeInit the adapter. This ensures datapath cleanup as well */
2529 hdd_deinit_adapter(hdd_ctx, adapter, true);
2530
Arun Khandavallifae92942016-08-01 13:31:08 +05302531
2532 /*
2533 * Find if any iface is up. If any iface is up then can't put device to
2534 * sleep/power save mode
2535 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302536 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002537 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302538 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302539 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302540 }
2541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002542 EXIT();
2543 return 0;
2544}
2545
2546/**
2547 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2548 * @dev: pointer to net_device structure
2549 *
2550 * This is called in response to ifconfig down
2551 *
2552 * Return: 0 for success and error number for failure
2553 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002554static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002555{
2556 int ret;
2557
2558 cds_ssr_protect(__func__);
2559 ret = __hdd_stop(dev);
2560 cds_ssr_unprotect(__func__);
2561
2562 return ret;
2563}
2564
2565/**
2566 * __hdd_uninit() - HDD uninit function
2567 * @dev: Pointer to net_device structure
2568 *
2569 * This is called during the netdev unregister to uninitialize all data
2570 * associated with the device
2571 *
2572 * Return: None
2573 */
2574static void __hdd_uninit(struct net_device *dev)
2575{
2576 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2577
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002578 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002579
2580 do {
2581 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002582 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 break;
2584 }
2585
2586 if (NULL == adapter->pHddCtx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002587 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588 break;
2589 }
2590
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002591 if (dev != adapter->dev)
2592 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593
2594 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2595
2596 /* after uninit our adapter structure will no longer be valid */
2597 adapter->dev = NULL;
2598 adapter->magic = 0;
2599 } while (0);
2600
2601 EXIT();
2602}
2603
2604/**
2605 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2606 * @dev: pointer to net_device structure
2607 *
2608 * This is called during the netdev unregister to uninitialize all data
2609 * associated with the device
2610 *
2611 * Return: none
2612 */
2613static void hdd_uninit(struct net_device *dev)
2614{
2615 cds_ssr_protect(__func__);
2616 __hdd_uninit(dev);
2617 cds_ssr_unprotect(__func__);
2618}
2619
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002620static int hdd_open_cesium_nl_sock(void)
2621{
2622#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2623 struct netlink_kernel_cfg cfg = {
2624 .groups = WLAN_NLINK_MCAST_GRP_ID,
2625 .input = NULL
2626 };
2627#endif
2628 int ret = 0;
2629
2630#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2631 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2632#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2633 THIS_MODULE,
2634#endif
2635 &cfg);
2636#else
2637 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2638 WLAN_NLINK_MCAST_GRP_ID,
2639 NULL, NULL, THIS_MODULE);
2640#endif
2641
2642 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002643 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002644 ret = -ECONNREFUSED;
2645 }
2646
2647 return ret;
2648}
2649
2650static void hdd_close_cesium_nl_sock(void)
2651{
2652 if (NULL != cesium_nl_srv_sock) {
2653 netlink_kernel_release(cesium_nl_srv_sock);
2654 cesium_nl_srv_sock = NULL;
2655 }
2656}
2657
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002658/**
2659 * __hdd_set_mac_address() - set the user specified mac address
2660 * @dev: Pointer to the net device.
2661 * @addr: Pointer to the sockaddr.
2662 *
2663 * This function sets the user specified mac address using
2664 * the command ifconfig wlanX hw ether <mac adress>.
2665 *
2666 * Return: 0 for success, non zero for failure
2667 */
2668static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2669{
2670 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2671 hdd_context_t *hdd_ctx;
2672 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302673 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 int ret;
2675
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002676 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002677
2678 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2679 ret = wlan_hdd_validate_context(hdd_ctx);
2680 if (0 != ret)
2681 return ret;
2682
2683 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2684 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2685
2686 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302687 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688}
2689
2690/**
2691 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2692 * function from SSR
2693 * @dev: pointer to net_device structure
2694 * @addr: Pointer to the sockaddr
2695 *
2696 * This function sets the user specified mac address using
2697 * the command ifconfig wlanX hw ether <mac adress>.
2698 *
2699 * Return: 0 for success.
2700 */
2701static int hdd_set_mac_address(struct net_device *dev, void *addr)
2702{
2703 int ret;
2704
2705 cds_ssr_protect(__func__);
2706 ret = __hdd_set_mac_address(dev, addr);
2707 cds_ssr_unprotect(__func__);
2708
2709 return ret;
2710}
2711
2712uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2713{
2714 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002715
Anurag Chouhan6d760662016-02-20 16:05:43 +05302716 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002717 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2718 break;
2719 }
2720
Anurag Chouhan6d760662016-02-20 16:05:43 +05302721 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 return NULL;
2723
2724 hdd_ctx->config->intfAddrMask |= (1 << i);
2725 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2726}
2727
2728void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2729{
2730 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002731
Anurag Chouhan6d760662016-02-20 16:05:43 +05302732 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002733 if (!memcmp(releaseAddr,
2734 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2735 6)) {
2736 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2737 break;
2738 }
2739 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740}
2741
2742#ifdef WLAN_FEATURE_PACKET_FILTERING
2743/**
2744 * __hdd_set_multicast_list() - set the multicast address list
2745 * @dev: Pointer to the WLAN device.
2746 * @skb: Pointer to OS packet (sk_buff).
2747 *
2748 * This funciton sets the multicast address list.
2749 *
2750 * Return: None
2751 */
2752static void __hdd_set_multicast_list(struct net_device *dev)
2753{
2754 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755 int i = 0, status;
2756 struct netdev_hw_addr *ha;
2757 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302758 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2759 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2760 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002762 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302763 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302764 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302767 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302768 goto out;
2769
Dustin Brownc788acb2017-08-01 17:43:51 -07002770 status = hdd_validate_adapter(adapter);
2771 if (status)
2772 goto out;
2773
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302774 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2775 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002776 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302777 goto out;
2778 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302780 /* Delete already configured multicast address list */
2781 if (adapter->mc_addr_list.mc_cnt > 0) {
2782 hdd_info("clear previously configured MC address list");
2783 hdd_disable_and_flush_mc_addr_list(adapter,
2784 pmo_mc_list_change_notify);
2785 }
2786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002788 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302789 hdd_disable_and_flush_mc_addr_list(adapter,
2790 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 } else {
2792 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302793 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002794 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302795 pmo_ucfg_max_mc_addr_supported(psoc));
2796 hdd_disable_and_flush_mc_addr_list(adapter,
2797 pmo_mc_list_change_notify);
2798 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002800 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002801 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302802 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803 if (i == mc_count)
2804 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302805 memset(&(mc_list_request->mc_addr[i].bytes),
2806 0, ETH_ALEN);
2807 memcpy(&(mc_list_request->mc_addr[i].bytes),
2808 ha->addr, ETH_ALEN);
2809 hdd_info("mlist[%d] = %pM", i,
2810 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811 i++;
2812 }
2813 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302814
2815 mc_list_request->psoc = psoc;
2816 mc_list_request->vdev_id = adapter->sessionId;
2817 mc_list_request->count = mc_count;
2818 status = hdd_cache_mc_addr_list(mc_list_request);
2819 if (status == 0) {
2820 hdd_enable_mc_addr_filtering(adapter,
2821 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302823 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302825out:
2826 if (mc_list_request)
2827 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302828 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002829}
2830
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302831
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832/**
2833 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2834 * @dev: pointer to net_device
2835 *
2836 * Return: none
2837 */
2838static void hdd_set_multicast_list(struct net_device *dev)
2839{
2840 cds_ssr_protect(__func__);
2841 __hdd_set_multicast_list(dev);
2842 cds_ssr_unprotect(__func__);
2843}
2844#endif
2845
2846/**
2847 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2848 * @dev: Pointer to the WLAN device.
2849 * @skb: Pointer to OS packet (sk_buff).
2850 *
2851 * This function is registered with the Linux OS for network
2852 * core to decide which queue to use first.
2853 *
2854 * Return: ac, Queue Index/access category corresponding to UP in IP header
2855 */
2856static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2857#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2858 , void *accel_priv
2859#endif
2860#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2861 , select_queue_fallback_t fallback
2862#endif
2863)
2864{
2865 return hdd_wmm_select_queue(dev, skb);
2866}
2867
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002868static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869 .ndo_open = hdd_open,
2870 .ndo_stop = hdd_stop,
2871 .ndo_uninit = hdd_uninit,
2872 .ndo_start_xmit = hdd_hard_start_xmit,
2873 .ndo_tx_timeout = hdd_tx_timeout,
2874 .ndo_get_stats = hdd_get_stats,
2875 .ndo_do_ioctl = hdd_ioctl,
2876 .ndo_set_mac_address = hdd_set_mac_address,
2877 .ndo_select_queue = hdd_select_queue,
2878#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880#endif
2881};
2882
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002883/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002884static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002885 .ndo_open = hdd_mon_open,
2886 .ndo_stop = hdd_stop,
2887 .ndo_get_stats = hdd_get_stats,
2888};
2889
2890/**
2891 * hdd_set_station_ops() - update net_device ops for monitor mode
2892 * @pWlanDev: Handle to struct net_device to be updated.
2893 * Return: None
2894 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895void hdd_set_station_ops(struct net_device *pWlanDev)
2896{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002897 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2898 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2899 else
2900 pWlanDev->netdev_ops = &wlan_drv_ops;
2901}
2902
Komal Seelama89be8d2016-09-29 11:09:26 +05302903#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302904/**
2905 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2906 * @hdd_ctx: HDD context
2907 *
2908 * Return: None
2909 */
2910static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2911{
2912 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2913
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002914 qdf_runtime_lock_init(&ctx->roc);
2915 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05302916}
2917
2918/**
2919 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2920 * @hdd_ctx: HDD Context
2921 *
2922 * Return: None
2923 */
2924static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2925{
2926 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2927
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002928 qdf_runtime_lock_deinit(&ctx->roc);
2929 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302930
2931 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302932}
2933
Komal Seelama89be8d2016-09-29 11:09:26 +05302934static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2935{
2936 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2937
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002938 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302939}
2940
2941static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2942{
2943 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2944
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002945 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302946}
2947#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302948static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2949static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302950static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2951static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2952#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002953/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002954 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2955 * @hdd_ctx: global hdd context
2956 * @macAddr: mac address to assign to the interface
2957 * @name: User-visible name of the interface
2958 *
2959 * hdd adapter pointer would point to the netdev->priv space, this function
2960 * would retrive the pointer, and setup the hdd adapter configuration.
2961 *
2962 * Return: the pointer to hdd adapter, otherwise NULL
2963 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002964static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2965 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002966 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 const char *name)
2968{
2969 struct net_device *pWlanDev = NULL;
2970 hdd_adapter_t *adapter = NULL;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05302971 hdd_station_ctx_t *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002972 /*
2973 * cfg80211 initialization and registration....
2974 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002975 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2976#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2977 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002978#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002979 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2980 hdd_mon_mode_ether_setup : ether_setup),
2981 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982
2983 if (pWlanDev != NULL) {
2984
2985 /* Save the pointer to the net_device in the HDD adapter */
2986 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2987
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302988 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05302989 sta_ctx = &adapter->sessionCtx.station;
2990 qdf_mem_set(sta_ctx->conn_info.staId,
2991 sizeof(sta_ctx->conn_info.staId),
2992 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993 adapter->dev = pWlanDev;
2994 adapter->pHddCtx = hdd_ctx;
2995 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302996 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002997
2998 init_completion(&adapter->session_open_comp_var);
2999 init_completion(&adapter->session_close_comp_var);
3000 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303001 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003002 init_completion(&adapter->linkup_event_var);
3003 init_completion(&adapter->cancel_rem_on_chan_var);
3004 init_completion(&adapter->rem_on_chan_ready_event);
3005 init_completion(&adapter->sta_authorized_event);
3006 init_completion(&adapter->offchannel_tx_event);
3007 init_completion(&adapter->tx_action_cnf_event);
3008#ifdef FEATURE_WLAN_TDLS
3009 init_completion(&adapter->tdls_add_station_comp);
3010 init_completion(&adapter->tdls_del_station_comp);
3011 init_completion(&adapter->tdls_mgmt_comp);
3012 init_completion(&adapter->tdls_link_establish_req_comp);
3013#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003014 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015 init_completion(&adapter->change_country_code);
3016
3017
3018 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303019 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020
3021 adapter->offloads_configured = false;
3022 adapter->isLinkUpSvcNeeded = false;
3023 adapter->higherDtimTransition = true;
3024 /* Init the net_device structure */
3025 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3026
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303027 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003028 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303029 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030 sizeof(tSirMacAddr));
3031 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003032
3033 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3034 pWlanDev->features |=
3035 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3036 pWlanDev->features |= NETIF_F_RXCSUM;
3037
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003038 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3039
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 hdd_set_station_ops(adapter->dev);
3041
3042 pWlanDev->destructor = free_netdev;
3043 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003044 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045 adapter->wdev.wiphy = hdd_ctx->wiphy;
3046 adapter->wdev.netdev = pWlanDev;
3047 /* set pWlanDev's parent to underlying device */
3048 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3049 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303050 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303052 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053 }
3054
3055 return adapter;
3056}
3057
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003058static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003060 struct net_device *dev = adapter->dev;
3061 int ret;
3062
3063 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003064
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003065 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003066 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3067
3068 ret = dev_alloc_name(dev, dev->name);
3069 if (ret < 0) {
3070 hdd_err(
3071 "unable to get dev name: %s, err = 0x%x",
3072 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303073 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 }
3075 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003076
3077 ret = register_netdevice(dev);
3078 if (ret) {
3079 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3080 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303081 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 }
3083 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003084 ret = register_netdev(dev);
3085 if (ret) {
3086 hdd_err("register_netdev(%s) failed, err = 0x%x",
3087 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303088 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 }
3090 }
3091 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3092
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003093 EXIT();
3094
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303095 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096}
3097
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003098QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003099{
3100 hdd_adapter_t *adapter = pContext;
3101
3102 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003103 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303104 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 }
3106
3107 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003108 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303109 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 }
3111
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003112 /*
3113 * For NAN Data interface, the close session results in the final
3114 * indication to the userspace
3115 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003116 if (adapter->device_mode == QDF_NDI_MODE)
3117 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 /*
3122 * We can be blocked while waiting for scheduled work to be
3123 * flushed, and the adapter structure can potentially be freed, in
3124 * which case the magic will have been reset. So make sure the
3125 * magic is still good, and hence the adapter structure is still
3126 * valid, before signaling completion
3127 */
3128 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3129 complete(&adapter->session_close_comp_var);
3130
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303131 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132}
3133
Krunal Soni8c37e322016-02-03 16:08:37 -08003134/**
3135 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3136 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003137 *
3138 * This routine will check the mode of adapter and if it is required then it
3139 * will initialize the TDLS operations
3140 *
3141 * Return: QDF_STATUS
3142 */
3143#ifdef FEATURE_WLAN_TDLS
Dustin Brownd28772b2017-03-17 14:16:07 -07003144static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003145{
Dustin Brownd28772b2017-03-17 14:16:07 -07003146 if (adapter->device_mode == QDF_IBSS_MODE)
3147 return QDF_STATUS_SUCCESS;
3148
3149 if (wlan_hdd_tdls_init(adapter)) {
3150 hdd_err("wlan_hdd_tdls_init failed");
3151 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003152 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003153 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3154
Krunal Soni8c37e322016-02-03 16:08:37 -08003155 return QDF_STATUS_SUCCESS;
3156}
3157#else
Dustin Brownd28772b2017-03-17 14:16:07 -07003158static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003159{
3160 return QDF_STATUS_SUCCESS;
3161}
3162#endif
3163
Dustin Brownd28772b2017-03-17 14:16:07 -07003164int hdd_vdev_ready(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165{
Dustin Brownd28772b2017-03-17 14:16:07 -07003166 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167
Dustin Brownd28772b2017-03-17 14:16:07 -07003168 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003169 if (QDF_IS_STATUS_ERROR(status))
3170 return qdf_status_to_os_return(status);
3171
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003172 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003173 if (QDF_IS_STATUS_ERROR(status))
3174 return qdf_status_to_os_return(status);
3175
3176 if (wma_capability_enhanced_mcast_filter())
3177 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3178 else
3179 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003180
3181 return qdf_status_to_os_return(status);
3182}
3183
3184int hdd_vdev_destroy(hdd_adapter_t *adapter)
3185{
3186 QDF_STATUS status;
3187 int errno;
3188 hdd_context_t *hdd_ctx;
3189 unsigned long rc;
3190
3191 hdd_info("destroying vdev %d", adapter->sessionId);
3192
3193 /* vdev created sanity check */
3194 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3195 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3196 return -EINVAL;
3197 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003198 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003199 /* do vdev logical destroy via objmgr */
3200 errno = hdd_objmgr_destroy_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003201 if (errno) {
3202 hdd_err("failed to destroy objmgr vdev: %d", errno);
3203 return errno;
3204 }
3205
Yue Maf9782842017-05-08 12:49:49 -07003206 /*
3207 * In SSR case, there is no need to destroy vdev in firmware since
3208 * it has already asserted. vdev can be released directly.
3209 */
3210 if (cds_is_driver_recovering())
3211 goto release_vdev;
3212
Dustin Brownd28772b2017-03-17 14:16:07 -07003213 /* close sme session (destroy vdev in firmware via legacy API) */
3214 INIT_COMPLETION(adapter->session_close_comp_var);
3215 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3216 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3217 hdd_sme_close_session_callback, adapter);
3218 if (QDF_IS_STATUS_ERROR(status)) {
3219 hdd_err("failed to close sme session: %d", status);
3220 return qdf_status_to_os_return(status);
3221 }
3222
3223 /* block on a completion variable until sme session is closed */
3224 rc = wait_for_completion_timeout(
3225 &adapter->session_close_comp_var,
3226 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3227 if (!rc) {
3228 hdd_err("timed out waiting for close sme session: %ld", rc);
3229 if (adapter->device_mode == QDF_NDI_MODE)
3230 hdd_ndp_session_end_handler(adapter);
3231 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3232 return -ETIMEDOUT;
3233 }
3234
Yue Maf9782842017-05-08 12:49:49 -07003235release_vdev:
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003236 /* now that sme session is closed, allow physical vdev destroy */
3237 errno = hdd_objmgr_release_vdev(adapter);
3238 if (errno) {
3239 hdd_err("failed to release objmgr vdev: %d", errno);
3240 return errno;
3241 }
3242
Dustin Brownd28772b2017-03-17 14:16:07 -07003243 hdd_info("vdev destroyed successfully");
3244
3245 return 0;
3246}
3247
3248int hdd_vdev_create(hdd_adapter_t *adapter)
3249{
3250 QDF_STATUS status;
3251 int errno;
3252 hdd_context_t *hdd_ctx;
3253 uint32_t type;
3254 uint32_t sub_type;
3255 unsigned long rc;
3256
3257 hdd_info("creating new vdev");
3258
3259 /* determine vdev (sub)type */
3260 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303261 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003262 hdd_err("failed to get vdev type: %d", status);
3263 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003265
3266 /* do vdev create via objmgr */
3267 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003268 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003269 if (errno) {
3270 hdd_err("failed to create objmgr vdev: %d", errno);
3271 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003273
3274 /* Open a SME session (prepare vdev in firmware via legacy API) */
3275 INIT_COMPLETION(adapter->session_open_comp_var);
3276 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3277 (uint8_t *)&adapter->macAddressCurrent,
3278 adapter->sessionId, type, sub_type);
3279 if (QDF_IS_STATUS_ERROR(status)) {
3280 hdd_err("failed to open sme session: %d", status);
3281 errno = qdf_status_to_os_return(status);
3282 goto objmgr_vdev_destroy;
3283 }
3284
3285 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 rc = wait_for_completion_timeout(
3287 &adapter->session_open_comp_var,
3288 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3289 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003290 hdd_err("timed out waiting for open sme session: %ld", rc);
3291 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303292 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3293 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003294 }
3295
3296 /* firmware ready for component communication, raise vdev_ready event */
3297 errno = hdd_vdev_ready(adapter);
3298 if (errno) {
3299 hdd_err("failed to dispatch vdev ready event: %d", errno);
3300 goto hdd_vdev_destroy;
3301 }
3302
3303 hdd_info("vdev %d created successfully", adapter->sessionId);
3304
3305 return 0;
3306
3307 /*
3308 * Due to legacy constraints, we need to destroy in the same order as
3309 * create. So, split error handling into 2 cases to accommodate.
3310 */
3311
3312objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003313 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003314
3315 return errno;
3316
3317hdd_vdev_destroy:
3318 QDF_BUG(!hdd_vdev_destroy(adapter));
3319
3320 return errno;
3321}
3322
3323QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
3324{
3325 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
3326 hdd_context_t *hdd_ctx;
3327 QDF_STATUS status;
3328 int ret_val;
3329
3330 ret_val = hdd_vdev_create(adapter);
3331 if (ret_val) {
3332 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303333 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 }
3335
Dustin Brownd28772b2017-03-17 14:16:07 -07003336 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3337 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3338 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003339 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003342 status = hdd_register_wext(adapter->dev);
3343 if (QDF_IS_STATUS_ERROR(status)) {
3344 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 goto error_register_wext;
3346 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003347 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303349 qdf_mem_set(pHddStaCtx->conn_info.staId,
3350 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3351
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003352 /* set fast roaming capability in sme session */
3353 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3354 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355 /* Set the default operation channel */
3356 pHddStaCtx->conn_info.operationChannel =
3357 hdd_ctx->config->OperatingChannel;
3358
3359 /* Make the default Auth Type as OPEN */
3360 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3361
3362 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303363 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003364 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 status, status);
3366 goto error_init_txrx;
3367 }
3368
3369 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3370
3371 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303372 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003373 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374 status, status);
3375 goto error_wmm_init;
3376 }
3377
3378 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3379
Naveen Rawat247a8682017-06-05 15:00:31 -07003380 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 WMI_PDEV_PARAM_BURST_ENABLE,
3382 hdd_ctx->config->enableSifsBurst,
3383 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003384 if (ret_val)
3385 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386
Dustin Brownd28772b2017-03-17 14:16:07 -07003387 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003388 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003391 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303392 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003393
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394error_tdls_init:
3395 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3396 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003397error_wmm_init:
3398 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3399 hdd_deinit_tx_rx(adapter);
3400error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003401 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003402error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003403 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 return status;
3406}
3407
3408void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
3409{
3410 hdd_cfg80211_state_t *cfgState;
3411
3412 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3413
3414 if (NULL != cfgState->buf) {
3415 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417 rc = wait_for_completion_timeout(
3418 &adapter->tx_action_cnf_event,
3419 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3420 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003421 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303422 /*
3423 * Inform tx status as FAILURE to upper layer and free
3424 * cfgState->buf
3425 */
3426 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427 }
3428 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429}
3430
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303431/**
3432 * hdd_station_adapter_deinit() - De-initialize the station adapter
3433 * @hdd_ctx: global hdd context
3434 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003435 * @rtnl_held: Used to indicate whether or not the caller is holding
3436 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303437 *
3438 * This function De-initializes the STA/P2P/OCB adapter.
3439 *
3440 * Return: None.
3441 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003442static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
3443 hdd_adapter_t *adapter,
3444 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303445{
3446 ENTER_DEV(adapter->dev);
3447
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303448 if (adapter->dev) {
3449 if (rtnl_held)
3450 adapter->dev->wireless_handlers = NULL;
3451 else {
3452 rtnl_lock();
3453 adapter->dev->wireless_handlers = NULL;
3454 rtnl_unlock();
3455 }
3456 }
3457
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303458 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3459 hdd_deinit_tx_rx(adapter);
3460 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3461 }
3462
3463 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3464 hdd_wmm_adapter_close(adapter);
3465 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3466 }
3467
3468 hdd_cleanup_actionframe(hdd_ctx, adapter);
3469 wlan_hdd_tdls_exit(adapter);
3470
3471 EXIT();
3472}
3473
3474/**
3475 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3476 * @hdd_ctx: global hdd context
3477 * @adapter: HDD adapter
3478 * @rtnl_held: the rtnl lock hold flag
3479 * This function De-initializes the AP/P2PGo adapter.
3480 *
3481 * Return: None.
3482 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003483static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
3484 hdd_adapter_t *adapter,
3485 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303486{
3487 ENTER_DEV(adapter->dev);
3488
3489 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3490 hdd_wmm_adapter_close(adapter);
3491 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3492 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003493 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303494
3495 hdd_cleanup_actionframe(hdd_ctx, adapter);
3496
3497 hdd_unregister_hostapd(adapter, rtnl_held);
3498
3499 EXIT();
3500}
3501
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3503 bool rtnl_held)
3504{
3505 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003508 case QDF_STA_MODE:
3509 case QDF_P2P_CLIENT_MODE:
3510 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303512 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513 break;
3514 }
3515
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003516 case QDF_SAP_MODE:
3517 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 {
3519
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303520 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003521 break;
3522 }
3523
3524 default:
3525 break;
3526 }
3527
3528 EXIT();
3529}
3530
Jeff Johnson590e2012016-10-05 16:16:24 -07003531static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3532 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533{
3534 struct net_device *pWlanDev = NULL;
3535
3536 if (adapter)
3537 pWlanDev = adapter->dev;
3538 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003539 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 return;
3541 }
3542
Rajeev Kumardca5f812016-02-04 17:28:06 -08003543 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303544
3545 if (adapter->scan_info.default_scan_ies) {
3546 qdf_mem_free(adapter->scan_info.default_scan_ies);
3547 adapter->scan_info.default_scan_ies = NULL;
3548 }
3549
Komal Seelama89be8d2016-09-29 11:09:26 +05303550 hdd_adapter_runtime_suspend_denit(adapter);
3551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 /*
3553 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3554 * the driver is almost closed and cannot handle either control
3555 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003556 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3557 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003558 * is not right. Setting this flag helps hdd_stop() to recognize that
3559 * the interface is closed and restricts any operations on that
3560 */
3561 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3562
3563 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003564 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003566 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003568 /*
3569 * Note that the adapter is no longer valid at this point
3570 * since the memory has been reclaimed
3571 */
3572 }
3573}
3574
Jeff Johnson590e2012016-10-05 16:16:24 -07003575static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3576 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577{
3578 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3579 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303580 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003581
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303583 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 adapter = adapterNode->pAdapter;
3585 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303586 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303588 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 }
3590 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3591 adapterNode = pNext;
3592 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303593 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003595
Arun Khandavalli2358d522016-05-16 18:05:37 +05303596#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3597/**
3598 * hdd_set_fw_log_params() - Set log parameters to FW
3599 * @hdd_ctx: HDD Context
3600 * @adapter: HDD Adapter
3601 *
3602 * This function set the FW Debug log level based on the INI.
3603 *
3604 * Return: None
3605 */
3606static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3607 hdd_adapter_t *adapter)
3608{
3609 uint8_t count = 0, numentries = 0,
3610 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3611 uint32_t value = 0;
3612 int ret;
3613
Arun Khandavallifae92942016-08-01 13:31:08 +05303614 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3615 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003616 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303617 return;
3618 }
3619
Arun Khandavallifae92942016-08-01 13:31:08 +05303620 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303621 hdd_ctx->fw_log_settings.dl_type =
3622 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003623 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303624 WMI_DBGLOG_TYPE,
3625 hdd_ctx->config->enableFwLogType,
3626 DBG_CMD);
3627 if (ret != 0)
3628 hdd_err("Failed to enable FW log type ret %d",
3629 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303630
3631 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303632 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003633 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303634 WMI_DBGLOG_LOG_LEVEL,
3635 hdd_ctx->config->enableFwLogLevel,
3636 DBG_CMD);
3637 if (ret != 0)
3638 hdd_err("Failed to enable FW log level ret %d",
3639 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303640
3641 hdd_string_to_u8_array(
3642 hdd_ctx->config->enableFwModuleLogLevel,
3643 moduleloglevel,
3644 &numentries,
3645 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3646
3647 while (count < numentries) {
3648 /*
3649 * FW module log level input string looks like
3650 * below:
3651 * gFwDebugModuleLoglevel=<FW Module ID>,
3652 * <Log Level>,...
3653 * For example:
3654 * gFwDebugModuleLoglevel=
3655 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3656 * Above input string means :
3657 * For FW module ID 1 enable log level 0
3658 * For FW module ID 2 enable log level 1
3659 * For FW module ID 3 enable log level 2
3660 * For FW module ID 4 enable log level 3
3661 * For FW module ID 5 enable log level 4
3662 * For FW module ID 6 enable log level 5
3663 * For FW module ID 7 enable log level 6
3664 */
3665
Nishank Aggarwale239d962017-03-03 12:26:02 +05303666 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3667 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3668 hdd_err("Module id %d and dbglog level %d input length is more than max",
3669 moduleloglevel[count],
3670 moduleloglevel[count + 1]);
3671 return;
3672 }
3673
3674 value = moduleloglevel[count] << 16;
3675 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003676 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303677 WMI_DBGLOG_MOD_LOG_LEVEL,
3678 value, DBG_CMD);
3679 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303680 hdd_err("Failed to enable FW module log level %d ret %d",
3681 value, ret);
3682
3683 count += 2;
3684 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303685
Arun Khandavalli2358d522016-05-16 18:05:37 +05303686}
3687#else
3688static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3689 hdd_adapter_t *adapter)
3690{
3691}
3692
3693#endif
3694
3695/**
3696 * hdd_set_fw_params() - Set parameters to firmware
3697 * @adapter: HDD adapter
3698 *
3699 * This function Sets various parameters to fw once the
3700 * adapter is started.
3701 *
3702 * Return: 0 on success or errno on failure
3703 */
3704int hdd_set_fw_params(hdd_adapter_t *adapter)
3705{
3706 int ret;
3707 hdd_context_t *hdd_ctx;
3708
3709 ENTER_DEV(adapter->dev);
3710
3711 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3712 if (!hdd_ctx)
3713 return -EINVAL;
3714
Dustin Brown732ab9c2017-06-15 13:24:09 -07003715 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3716 hdd_debug("FTM Mode is active; nothing to do");
3717 return 0;
3718 }
3719
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303720 ret = sme_cli_set_command(adapter->sessionId,
3721 WMI_PDEV_PARAM_DTIM_SYNTH,
3722 hdd_ctx->config->enable_lprx, PDEV_CMD);
3723 if (ret) {
3724 hdd_err("Failed to set LPRx");
3725 goto error;
3726 }
3727
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303728 if (adapter->device_mode == QDF_STA_MODE) {
3729 sme_set_smps_cfg(adapter->sessionId,
3730 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3731 hdd_ctx->config->upper_brssi_thresh);
3732
3733 sme_set_smps_cfg(adapter->sessionId,
3734 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3735 hdd_ctx->config->lower_brssi_thresh);
3736
3737 sme_set_smps_cfg(adapter->sessionId,
3738 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3739 hdd_ctx->config->enable_dtim_1chrx);
3740 }
3741
Dustin Brown732ab9c2017-06-15 13:24:09 -07003742 if (hdd_ctx->config->enable2x2) {
3743 hdd_debug("configuring 2x2 mode fw params");
3744
Naveen Rawat247a8682017-06-05 15:00:31 -07003745 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003746 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3747 hdd_ctx->config->enable_cck_tx_fir_override,
3748 PDEV_CMD);
3749 if (ret) {
3750 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3751 ret);
3752 goto error;
3753 }
3754 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303755#define HDD_DTIM_1CHAIN_RX_ID 0x5
3756#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003757 hdd_debug("configuring 1x1 mode fw params");
3758
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003759 /*
3760 * Disable DTIM 1 chain Rx when in 1x1,
3761 * we are passing two value
3762 * as param_id << 29 | param_value.
3763 * Below param_value = 0(disable)
3764 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003765 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003766 WMI_STA_SMPS_PARAM_CMDID,
3767 HDD_DTIM_1CHAIN_RX_ID <<
3768 HDD_SMPS_PARAM_VALUE_S,
3769 VDEV_CMD);
3770 if (ret) {
3771 hdd_err("DTIM 1 chain set failed %d", ret);
3772 goto error;
3773 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303774
Naveen Rawat247a8682017-06-05 15:00:31 -07003775 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003776 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3777 hdd_ctx->config->txchainmask1x1,
3778 PDEV_CMD);
3779 if (ret) {
3780 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3781 ret);
3782 goto error;
3783 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303784
Naveen Rawat247a8682017-06-05 15:00:31 -07003785 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003786 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3787 hdd_ctx->config->rxchainmask1x1,
3788 PDEV_CMD);
3789 if (ret) {
3790 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3791 ret);
3792 goto error;
3793 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303794#undef HDD_DTIM_1CHAIN_RX_ID
3795#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003796 }
3797
Naveen Rawat247a8682017-06-05 15:00:31 -07003798 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003799 WMI_PDEV_PARAM_HYST_EN,
3800 hdd_ctx->config->enableMemDeepSleep,
3801 PDEV_CMD);
3802 if (ret) {
3803 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3804 goto error;
3805 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303806
Naveen Rawat247a8682017-06-05 15:00:31 -07003807 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003808 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3809 hdd_ctx->config->rts_profile,
3810 VDEV_CMD);
3811 if (ret) {
3812 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3813 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303814 }
3815
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003816 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3817
3818 ret = wma_cli_set_command(adapter->sessionId,
3819 GEN_VDEV_PARAM_AMSDU,
3820 hdd_ctx->config->max_amsdu_num,
3821 GEN_CMD);
3822 if (ret != 0) {
3823 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3824 goto error;
3825 }
3826
Arun Khandavalli2358d522016-05-16 18:05:37 +05303827 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303828 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003829
Arun Khandavalli2358d522016-05-16 18:05:37 +05303830 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303831
Arun Khandavalli2358d522016-05-16 18:05:37 +05303832error:
3833 return -EINVAL;
3834}
3835
Ryan Hsu07495ea2016-01-21 15:25:39 -08003836/**
3837 * hdd_open_adapter() - open and setup the hdd adatper
3838 * @hdd_ctx: global hdd context
3839 * @session_type: type of the interface to be created
3840 * @iface_name: User-visible name of the interface
3841 * @macAddr: MAC address to assign to the interface
3842 * @name_assign_type: the name of assign type of the netdev
3843 * @rtnl_held: the rtnl lock hold flag
3844 *
3845 * This function open and setup the hdd adpater according to the device
3846 * type request, assign the name, the mac address assigned, and then prepared
3847 * the hdd related parameters, queue, lock and ready to start.
3848 *
3849 * Return: the pointer of hdd adapter, otherwise NULL.
3850 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3852 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003853 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003854 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855{
3856 hdd_adapter_t *adapter = NULL;
3857 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303858 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861
3862 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3863 /*
3864 * Max limit reached on the number of vdevs configured by the
3865 * host. Return error
3866 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303867 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3868 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 return NULL;
3870 }
3871
3872 if (macAddr == NULL) {
3873 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303874 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875 return NULL;
3876 }
3877 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303878 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303879 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3880 " already exists",
3881 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882 return NULL;
3883 }
3884
3885 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003886 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003887 /* Reset locally administered bit if the device mode is STA */
3888 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3889 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003890 case QDF_P2P_CLIENT_MODE:
3891 case QDF_P2P_DEVICE_MODE:
3892 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003893 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303894 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003895 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3896 name_assign_type,
3897 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898
3899 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303900 hdd_err("failed to allocate adapter for session %d",
3901 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 return NULL;
3903 }
3904
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003905 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003907 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303909 else if (QDF_MONITOR_MODE == session_type)
3910 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 else
3912 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3913
3914 adapter->device_mode = session_type;
3915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 /*
3918 * Workqueue which gets scheduled in IPv4 notification
3919 * callback
3920 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3922 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923
3924#ifdef WLAN_NS_OFFLOAD
3925 /*
3926 * Workqueue which gets scheduled in IPv6
3927 * notification callback.
3928 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3930 hdd_ipv6_notifier_work_queue);
3931#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303933 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303935 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 }
3937
3938 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003939 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303941 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3942 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303943
Ravi Joshi1a292562017-05-18 16:28:54 -07003944 /* Initialize NAN Data Interface */
3945 if (QDF_NDI_MODE == session_type) {
3946 status = hdd_init_nan_data_mode(adapter);
3947 if (QDF_STATUS_SUCCESS != status)
3948 goto err_free_netdev;
3949 }
3950
3951 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003953 case QDF_P2P_GO_MODE:
3954 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003955 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3956 name_assign_type,
3957 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003959 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303960 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 return NULL;
3962 }
3963
3964 adapter->wdev.iftype =
3965 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003966 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 NL80211_IFTYPE_P2P_GO;
3968 adapter->device_mode = session_type;
3969
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003970 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303971 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3973 goto err_free_netdev;
3974 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003975 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303977 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3978 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303980 case QDF_FTM_MODE:
3981 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3982 name_assign_type,
3983 "wlan0");
3984 if (NULL == adapter) {
3985 hdd_err("Failed to allocate adapter for FTM mode");
3986 return NULL;
3987 }
3988 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3989 adapter->device_mode = session_type;
3990 status = hdd_register_interface(adapter, rtnl_held);
3991 if (QDF_STATUS_SUCCESS != status) {
3992 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3993 goto err_free_netdev;
3994 }
3995 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003996 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303997 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303998 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3999 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304000 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004002 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304003 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 return NULL;
4005 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006
hqueaa33ee2017-05-04 17:56:35 +08004007 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4010 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4011
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304012 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 /* Add it to the hdd's session list. */
4014 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304015 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304017 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 } else {
4019 pHddAdapterNode->pAdapter = adapter;
4020 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4021 }
4022 }
4023
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304024 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 if (NULL != adapter) {
4026 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4027 adapter = NULL;
4028 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004029 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304030 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 return NULL;
4033 }
4034
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304035 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004036 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4037 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 /* Adapter successfully added. Increment the vdev count */
4040 hdd_ctx->current_intf_count++;
4041
Jeff Johnson5880d792016-08-15 13:32:30 -07004042 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 hdd_ctx->current_intf_count);
4044
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004045 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046 }
4047
Rajeev Kumardca5f812016-02-04 17:28:06 -08004048 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004049 hdd_err("Interface %s wow debug_fs init failed",
4050 netdev_name(adapter->dev));
4051
4052 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4053 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054
4055 return adapter;
4056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304059 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060
4061 return NULL;
4062}
4063
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304064QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004065 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066{
4067 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304068 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069
4070 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304071 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004072 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 status);
4074 return status;
4075 }
4076
4077 while (pCurrent->pAdapter != adapter) {
4078 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304079 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 break;
4081
4082 pCurrent = pNext;
4083 }
4084 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304085 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004086 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004087 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304088 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004089
4090 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004091 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4092 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304095 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004096 adapterNode = NULL;
4097
Dustin Brown5ec6b552017-03-31 12:11:40 -07004098 /* conditionally restart the bw timer */
4099 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101 /* Adapter removed. Decrement vdev count */
4102 if (hdd_ctx->current_intf_count != 0)
4103 hdd_ctx->current_intf_count--;
4104
4105 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304106 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304108
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304109 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110}
4111
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004112/**
4113 * hdd_close_all_adapters - Close all open adapters
4114 * @hdd_ctx: Hdd context
4115 * rtnl_held: True if RTNL lock held
4116 *
4117 * Close all open adapters.
4118 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304119 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004120 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304121QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004122{
4123 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304124 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125
4126 ENTER();
4127
4128 do {
4129 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304130 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304131 wlan_hdd_release_intf_addr(hdd_ctx,
4132 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004134 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304135 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304136 /* Adapter removed. Decrement vdev count */
4137 if (hdd_ctx->current_intf_count != 0)
4138 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304140 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141
4142 EXIT();
4143
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304144 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145}
4146
4147void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
4148{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304149 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004153 case QDF_STA_MODE:
4154 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 {
4156 hdd_station_ctx_t *pHddStaCtx =
4157 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004158 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159 break;
4160 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004161 case QDF_SAP_MODE:
4162 case QDF_P2P_GO_MODE:
4163 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004164 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004165 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 break;
4167 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004168 case QDF_FTM_MODE:
4169 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170 default:
4171 /*
4172 * wlan_hdd_reset_prob_rspies should not have been called
4173 * for these kind of devices
4174 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004175 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 pHostapdAdapter->device_mode);
4177 return;
4178 }
4179
Anurag Chouhanc5548422016-02-24 18:33:27 +05304180 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4182 updateIE.ieBufferlength = 0;
4183 updateIE.pAdditionIEBuffer = NULL;
4184 updateIE.append = true;
4185 updateIE.notify = false;
4186 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4187 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304188 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004189 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 }
4191}
4192
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304193QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 const bool bCloseSession)
4195{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304196 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4198 union iwreq_data wrqu;
4199 tSirUpdateIE updateIE;
4200 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004201 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202
4203 ENTER();
4204
Sachin Ahuja988fd102016-09-15 17:16:25 +05304205 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004206 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304207 wlan_hdd_netif_queue_control(adapter,
4208 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4209 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004211 case QDF_STA_MODE:
4212 case QDF_P2P_CLIENT_MODE:
4213 case QDF_IBSS_MODE:
4214 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004215 case QDF_NDI_MODE:
4216 if ((QDF_NDI_MODE == adapter->device_mode) ||
4217 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4219 hdd_is_connecting(
4220 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004221 INIT_COMPLETION(adapter->disconnect_comp_var);
4222 /*
4223 * For NDI do not use pWextState from sta_ctx, if needed
4224 * extract from ndi_ctx.
4225 */
4226 if (QDF_NDI_MODE == adapter->device_mode)
4227 qdf_ret_status = sme_roam_disconnect(
4228 hdd_ctx->hHal,
4229 adapter->sessionId,
4230 eCSR_DISCONNECT_REASON_NDI_DELETE);
4231 else if (pWextState->roamProfile.BSSType ==
4232 eCSR_BSS_TYPE_START_IBSS)
4233 qdf_ret_status = sme_roam_disconnect(
4234 hdd_ctx->hHal,
4235 adapter->sessionId,
4236 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004237 else if (QDF_STA_MODE == adapter->device_mode)
4238 qdf_ret_status =
4239 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004241 qdf_ret_status = sme_roam_disconnect(
4242 hdd_ctx->hHal,
4243 adapter->sessionId,
4244 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004245 /* success implies disconnect command got
4246 * queued up successfully
4247 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004248 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4249 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004250 rc = wait_for_completion_timeout(
4251 &adapter->disconnect_comp_var,
4252 msecs_to_jiffies
4253 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004254 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004255 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004256 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004257 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4258 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 memset(&wrqu, '\0', sizeof(wrqu));
4260 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4261 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4262 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4263 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304264 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004265 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304266 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004267
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304268 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269
4270#ifdef WLAN_OPEN_SOURCE
4271 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4272#endif
4273
4274 hdd_deregister_tx_flow_control(adapter);
4275
4276#ifdef WLAN_NS_OFFLOAD
4277#ifdef WLAN_OPEN_SOURCE
4278 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4279#endif
4280#endif
4281
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304282 if (adapter->device_mode == QDF_STA_MODE)
4283 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4284 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 /*
4286 * It is possible that the caller of this function does not
4287 * wish to close the session
4288 */
Krunal Soni985b8132017-02-10 18:49:08 -08004289 if (true == bCloseSession) {
4290 if (0 != wlan_hdd_try_disconnect(adapter)) {
4291 hdd_err("Error: Can't disconnect adapter");
4292 return QDF_STATUS_E_FAILURE;
4293 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004294 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004295 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 break;
4297
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004298 case QDF_SAP_MODE:
4299 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004301 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4303
4304 hdd_deregister_tx_flow_control(adapter);
4305
Kapil Guptac1224bf2017-06-22 21:22:40 +05304306 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 mutex_lock(&hdd_ctx->sap_lock);
4308 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304309 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304310 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311
4312 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 status = wlansap_stop_bss(
4314 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304316 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 hdd_hostapd_state_t *hostapd_state =
4318 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304319 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304320 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304321 qdf_status =
4322 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004323 qdf_stop_bss_event,
4324 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004325
Anurag Chouhance0dc992016-02-16 18:18:03 +05304326 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004327 hdd_err("failure waiting for wlansap_stop_bss %d",
4328 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004329 }
4330 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004331 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332 }
4333 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004334 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4335 adapter->device_mode,
4336 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337
Anurag Chouhanc5548422016-02-24 18:33:27 +05304338 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004339 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 updateIE.smeSessionId = adapter->sessionId;
4341 updateIE.ieBufferlength = 0;
4342 updateIE.pAdditionIEBuffer = NULL;
4343 updateIE.append = false;
4344 updateIE.notify = false;
4345 /* Probe bcn reset */
4346 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4347 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304348 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004349 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 }
4351 /* Assoc resp reset */
4352 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4353 &updateIE,
4354 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304355 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004356 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 }
4358 /* Reset WNI_CFG_PROBE_RSP Flags */
4359 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004361 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4362 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304363 /*
4364 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4365 */
4366 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4367 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4368
Peng Xu66162de2016-02-11 17:01:20 -08004369 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004370 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004371 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004373 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004374 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004375 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004376 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 break;
4378 default:
4379 break;
4380 }
4381
4382 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304383 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384}
4385
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304386/**
4387 * hdd_deinit_all_adapters - deinit all adapters
4388 * @hdd_ctx: HDD context
4389 * @rtnl_held: True if RTNL lock held
4390 *
4391 */
4392void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
4393{
4394 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4395 QDF_STATUS status;
4396 hdd_adapter_t *adapter;
4397
4398 ENTER();
4399
4400 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4401
4402 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4403 adapter = adapter_node->pAdapter;
4404 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4405 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4406 adapter_node = next;
4407 }
4408
4409 EXIT();
4410}
4411
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304412QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413{
4414 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304415 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 hdd_adapter_t *adapter;
4417
4418 ENTER();
4419
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304420 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4423
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304424 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 adapter = adapterNode->pAdapter;
4426 hdd_stop_adapter(hdd_ctx, adapter, true);
4427 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4428 adapterNode = pNext;
4429 }
4430
4431 EXIT();
4432
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304433 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434}
4435
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304436QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437{
4438 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304439 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440 hdd_adapter_t *adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004441 hdd_station_ctx_t *pHddStaCtx;
4442 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
4444 ENTER();
4445
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304446 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4449
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304450 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004452 hdd_notice("Disabling queues for adapter type: %d",
4453 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304454
4455 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004456 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304457 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004458 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304459
Arun Khandavallicc544b32017-01-30 19:52:16 +05304460 if (hdd_ctx->config->sap_internal_restart &&
4461 adapter->device_mode == QDF_SAP_MODE) {
4462 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304463 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304464 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004465 if (test_bit(SOFTAP_BSS_STARTED,
4466 &adapter->event_flags)) {
4467 hdd_sap_indicate_disconnect_for_sta(adapter);
4468 hdd_cleanup_actionframe(hdd_ctx, adapter);
4469 hdd_sap_destroy_events(adapter);
4470 }
4471 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4472 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304473 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304474 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004476 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004477
4478 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4479
4480 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004481 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4482 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4484 hdd_wmm_adapter_close(adapter);
4485 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4486 }
4487
Wu Gao3545e642017-07-14 19:24:41 +08004488 if (adapter->device_mode == QDF_SAP_MODE) {
4489 /*
4490 * If adapter is SAP, set session ID to invalid
4491 * since SAP session will be cleanup during SSR.
4492 */
Wu Gao36717432016-11-21 15:09:48 +08004493 wlansap_set_invalid_session(
4494 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4495
Wu Gao3545e642017-07-14 19:24:41 +08004496 wlansap_cleanup_cac_timer(
4497 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4498 }
4499
Yue Mad5b4b9f2017-05-26 16:23:40 -07004500 /* Delete peers if any for STA and P2P client modes */
4501 if (adapter->device_mode == QDF_STA_MODE ||
4502 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4503 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4504 qdf_copy_macaddr(&peerMacAddr,
4505 &pHddStaCtx->conn_info.bssId);
4506
4507 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4508 peerMacAddr.bytes);
4509 }
4510
Yue Maf9782842017-05-08 12:49:49 -07004511 /* Destroy vdev which will be recreated during reinit. */
4512 hdd_vdev_destroy(adapter);
4513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4515 adapterNode = pNext;
4516 }
4517
4518 EXIT();
4519
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304520 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521}
4522
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304523bool hdd_check_for_opened_interfaces(hdd_context_t *hdd_ctx)
4524{
4525 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4526 QDF_STATUS status;
4527 bool close_modules = true;
4528
Arun Khandavalliba479c42017-07-26 21:29:40 +05304529 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4530 hdd_info("FTM mode, don't close the module");
4531 return false;
4532 }
4533
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304534 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4535 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4536 if (test_bit(DEVICE_IFACE_OPENED,
4537 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004538 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304539 close_modules = false;
4540 break;
4541 }
4542 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4543 adapter_node = next;
4544 }
4545
4546 return close_modules;
4547}
4548
Arun Khandavallifae92942016-08-01 13:31:08 +05304549/**
4550 * hdd_is_interface_up()- Checkfor interface up before ssr
4551 * @hdd_ctx: HDD context
4552 *
4553 * check if there are any wlan interfaces before SSR accordingly start
4554 * the interface.
4555 *
4556 * Return: 0 if interface was opened else false
4557 */
4558static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4559{
4560 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4561 return true;
4562 else
4563 return false;
4564}
4565
Anurag Chouhanc4092922016-09-08 15:56:11 +05304566#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004567 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304568struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4569 struct ieee80211_channel *channel,
4570 const u8 *bssid, const u8 *ssid,
4571 size_t ssid_len)
4572{
4573 return cfg80211_get_bss(wiphy, channel, bssid,
4574 ssid, ssid_len,
4575 WLAN_CAPABILITY_ESS,
4576 WLAN_CAPABILITY_ESS);
4577}
4578#else
4579struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4580 struct ieee80211_channel *channel,
4581 const u8 *bssid, const u8 *ssid,
4582 size_t ssid_len)
4583{
4584 return cfg80211_get_bss(wiphy, channel, bssid,
4585 ssid, ssid_len,
4586 IEEE80211_BSS_TYPE_ESS,
4587 IEEE80211_PRIVACY_ANY);
4588}
4589#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304590
Abhishek Singha84d3952016-09-13 13:45:05 +05304591#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304592#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4593 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4594/**
4595 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4596 * @timeout_reason: reason for connect timeout
4597 *
4598 * This function is used to convert host timeout
4599 * reason enum to kernel specific enum.
4600 *
4601 * Return: nl timeout enum
4602 */
4603static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4604 tSirResultCodes timeout_reason)
4605{
4606 switch (timeout_reason) {
4607 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4608 return NL80211_TIMEOUT_SCAN;
4609 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4610 return NL80211_TIMEOUT_AUTH;
4611 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4612 return NL80211_TIMEOUT_ASSOC;
4613 default:
4614 return NL80211_TIMEOUT_UNSPECIFIED;
4615 }
4616}
4617
4618/**
4619 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4620 * @dev: network device
4621 * @bssid: bssid to which we want to associate
4622 * @timeout_reason: reason for connect timeout
4623 *
4624 * This API is used to send connection timeout reason to supplicant
4625 *
4626 * Return: void
4627 */
4628static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4629 const u8 *bssid,
4630 tSirResultCodes timeout_reason)
4631{
4632 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004633
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304634 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4635
4636 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4637 nl_timeout_reason);
4638}
4639
4640/**
4641 * __hdd_connect_bss() - API to send connection status to supplicant
4642 * @dev: network device
4643 * @bssid: bssid to which we want to associate
4644 * @req_ie: Request Information Element
4645 * @req_ie_len: len of the req IE
4646 * @resp_ie: Response IE
4647 * @resp_ie_len: len of ht response IE
4648 * @status: status
4649 * @gfp: Kernel Flag
4650 * @timeout_reason: reason for connect timeout
4651 *
4652 * Return: void
4653 */
4654static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4655 struct cfg80211_bss *bss, const u8 *req_ie,
4656 size_t req_ie_len, const u8 *resp_ie,
4657 size_t resp_ie_len, int status, gfp_t gfp,
4658 tSirResultCodes timeout_reason)
4659{
4660 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004661
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304662 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4663
4664 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4665 resp_ie, resp_ie_len, status, gfp,
4666 nl_timeout_reason);
4667}
4668#else
4669#if defined CFG80211_CONNECT_TIMEOUT
4670static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4671 const u8 *bssid,
4672 tSirResultCodes timeout_reason)
4673{
4674 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4675}
4676#endif
4677
4678static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4679 struct cfg80211_bss *bss, const u8 *req_ie,
4680 size_t req_ie_len, const u8 *resp_ie,
4681 size_t resp_ie_len, int status, gfp_t gfp,
4682 tSirResultCodes timeout_reason)
4683{
4684 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4685 resp_ie, resp_ie_len, status, gfp);
4686}
4687#endif
4688
Abhishek Singha84d3952016-09-13 13:45:05 +05304689/**
4690 * hdd_connect_bss() - API to send connection status to supplicant
4691 * @dev: network device
4692 * @bssid: bssid to which we want to associate
4693 * @req_ie: Request Information Element
4694 * @req_ie_len: len of the req IE
4695 * @resp_ie: Response IE
4696 * @resp_ie_len: len of ht response IE
4697 * @status: status
4698 * @gfp: Kernel Flag
4699 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304700 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304701 *
4702 * The API is a wrapper to send connection status to supplicant
4703 *
4704 * Return: Void
4705 */
4706#if defined CFG80211_CONNECT_TIMEOUT
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,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304711 bool connect_timeout,
4712 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304713{
4714 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304715 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304716 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304717 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4718 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304719}
4720#else
4721static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4722 struct cfg80211_bss *bss, const u8 *req_ie,
4723 size_t req_ie_len, const u8 *resp_ie,
4724 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304725 bool connect_timeout,
4726 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304727{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304728 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4729 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304730}
4731#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304732
4733/**
4734 * hdd_connect_result() - API to send connection status to supplicant
4735 * @dev: network device
4736 * @bssid: bssid to which we want to associate
4737 * @roam_info: information about connected bss
4738 * @req_ie: Request Information Element
4739 * @req_ie_len: len of the req IE
4740 * @resp_ie: Response IE
4741 * @resp_ie_len: len of ht response IE
4742 * @status: status
4743 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304744 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304745 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304746 *
4747 * The API is a wrapper to send connection status to supplicant
4748 * and allow runtime suspend
4749 *
4750 * Return: Void
4751 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304752void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4753 tCsrRoamInfo *roam_info, const u8 *req_ie,
4754 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304755 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304756 bool connect_timeout,
4757 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304758{
4759 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4760 struct cfg80211_bss *bss = NULL;
4761
4762 if (WLAN_STATUS_SUCCESS == status) {
4763 struct ieee80211_channel *chan;
4764 int freq;
4765 int chan_no = roam_info->pBssDesc->channelId;
4766
4767 if (chan_no <= 14)
4768 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004769 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304770 else
4771 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004772 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304773
4774 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4775 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4776 roam_info->u.pConnectedProfile->SSID.ssId,
4777 roam_info->u.pConnectedProfile->SSID.length);
4778 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304779
Abhishek Singha84d3952016-09-13 13:45:05 +05304780 hdd_connect_bss(dev, bssid, bss, req_ie,
4781 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304782 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304783
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004784 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004785 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304786}
4787#else
4788void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4789 tCsrRoamInfo *roam_info, const u8 *req_ie,
4790 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304791 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304792 bool connect_timeout,
4793 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304794{
Komal Seelama89be8d2016-09-29 11:09:26 +05304795 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4796
Anurag Chouhanc4092922016-09-08 15:56:11 +05304797 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4798 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004799
4800 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004801 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304802}
4803#endif
4804
4805
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304806QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004807{
4808 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304809 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810 hdd_adapter_t *adapter;
4811#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304812 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813#endif
4814 eConnectionState connState;
4815
4816 ENTER();
4817
4818 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304819 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820 adapter = adapterNode->pAdapter;
4821
Arun Khandavallifae92942016-08-01 13:31:08 +05304822 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304823 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304824
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 hdd_wmm_init(adapter);
4826
Dustin Browna7e6a5c2017-07-07 12:52:24 -07004827 adapter->scan_info.mScanPending = false;
4828
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004830 case QDF_STA_MODE:
4831 case QDF_P2P_CLIENT_MODE:
4832 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833
4834 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4835 ->conn_info.connState;
4836
4837 hdd_init_station_mode(adapter);
4838 /* Open the gates for HDD to receive Wext commands */
4839 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004841 /* Indicate disconnect event to supplicant
4842 * if associated previously
4843 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004845 eConnectionState_IbssConnected == connState ||
4846 eConnectionState_NotConnected == connState ||
4847 eConnectionState_IbssDisconnected == connState ||
4848 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004850
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004851 memset(&wrqu, '\0', sizeof(wrqu));
4852 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4853 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4854 wireless_send_event(adapter->dev, SIOCGIWAP,
4855 &wrqu, NULL);
4856 adapter->sessionCtx.station.
4857 hdd_ReassocScenario = false;
4858
4859 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304860 wlan_hdd_cfg80211_indicate_disconnect(
4861 adapter->dev, false,
4862 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 } else if (eConnectionState_Connecting == connState) {
4864 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004865 * Indicate connect failure to supplicant if we
4866 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004867 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304868 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304869 NULL, 0, NULL, 0,
4870 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004871 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872 }
4873
4874 hdd_register_tx_flow_control(adapter,
4875 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08004876 hdd_tx_resume_cb,
4877 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878
4879 break;
4880
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004881 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004882 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05304883 hdd_init_ap_mode(adapter, true);
4884
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 break;
4886
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004887 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004889 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004890 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4891#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004892 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893 /* event supplicant to restart */
4894 cfg80211_del_sta(adapter->dev,
4895 (const u8 *)&bcastMac.bytes[0],
4896 GFP_KERNEL);
4897#endif
4898 break;
4899
4900 default:
4901 break;
4902 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304903get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004904 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4905 adapterNode = pNext;
4906 }
4907
4908 EXIT();
4909
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304910 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911}
4912
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304913QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 hdd_adapter_list_node_t **padapterNode)
4915{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304916 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004917
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004918 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304919 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4920 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004921 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922 return status;
4923}
4924
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304925QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004926 hdd_adapter_list_node_t *adapterNode,
4927 hdd_adapter_list_node_t **pNextAdapterNode)
4928{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304929 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004930
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004931 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304932 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4933 (qdf_list_node_t *) adapterNode,
4934 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004936 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004937 return status;
4938}
4939
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304940QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004941 hdd_adapter_list_node_t *adapterNode)
4942{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304943 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004944
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004945 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304946 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004947 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004948 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004949 return status;
4950}
4951
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304952QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004953 hdd_adapter_list_node_t **padapterNode)
4954{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304955 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004956
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004957 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304958 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4959 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004960 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961 return status;
4962}
4963
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304964QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004965 hdd_adapter_list_node_t *adapterNode)
4966{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304967 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004968
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004969 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304970 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4971 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004972 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973 return status;
4974}
4975
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304976QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 hdd_adapter_list_node_t *adapterNode)
4978{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304979 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004980
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004981 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304982 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4983 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004984 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 return status;
4986}
4987
4988hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4989 tSirMacAddr macAddr)
4990{
4991 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4992 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304993 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004994
4995 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4996
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304997 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998 adapter = adapterNode->pAdapter;
4999
5000 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305001 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005002 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005003 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5006 adapterNode = pNext;
5007 }
5008
5009 return NULL;
5010
5011}
5012
5013hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
5014 uint32_t vdev_id)
5015{
5016 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5017 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305018 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305020 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005021
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305022 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 adapter = adapterNode->pAdapter;
5024
5025 if (adapter->sessionId == vdev_id)
5026 return adapter;
5027
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305028 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5030 adapterNode = pNext;
5031 }
5032
Jeff Johnson5880d792016-08-15 13:32:30 -07005033 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034
5035 return NULL;
5036}
5037
Abhishek Singh7996eb72015-12-30 17:24:02 +05305038/**
5039 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5040 * the sessionid
5041 * @hdd_ctx: hdd context.
5042 * @sme_session_id: sme session is for the adapter to get.
5043 *
5044 * This function is used to get the adapter with provided session id
5045 *
5046 * Return: adapter pointer if found
5047 *
5048 */
5049hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
5050 uint32_t sme_session_id)
5051{
5052 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5053 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305054 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305055
5056
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305057 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305058
5059 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305060 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305061 adapter = adapter_node->pAdapter;
5062
5063 if (adapter &&
5064 adapter->sessionId == sme_session_id)
5065 return adapter;
5066
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305067 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305068 hdd_get_next_adapter(hdd_ctx,
5069 adapter_node, &next);
5070 adapter_node = next;
5071 }
5072 return NULL;
5073}
5074
Naveen Rawat4edb6822017-04-12 10:09:17 -07005075hdd_adapter_t *hdd_get_adapter_by_iface_name(hdd_context_t *hdd_ctx,
5076 const char *iface_name)
5077{
5078 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5079 hdd_adapter_t *adapter;
5080 QDF_STATUS qdf_status;
5081
5082 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5083
5084 while ((NULL != adapter_node) &&
5085 (QDF_STATUS_SUCCESS == qdf_status)) {
5086 adapter = adapter_node->pAdapter;
5087
5088 if (adapter &&
5089 !qdf_str_cmp(adapter->dev->name, iface_name))
5090 return adapter;
5091
5092 qdf_status =
5093 hdd_get_next_adapter(hdd_ctx,
5094 adapter_node, &next);
5095 adapter_node = next;
5096 }
5097 return NULL;
5098}
5099
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005100/**
5101 * hdd_get_adapter() - to get adapter matching the mode
5102 * @hdd_ctx: hdd context
5103 * @mode: adapter mode
5104 *
5105 * This routine will return the pointer to adapter matching
5106 * with the passed mode.
5107 *
5108 * Return: pointer to adapter or null
5109 */
5110hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
5111 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112{
5113 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5114 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305115 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116
5117 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5118
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305119 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 adapter = adapterNode->pAdapter;
5121
5122 if (adapter && (mode == adapter->device_mode))
5123 return adapter;
5124
5125 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5126 adapterNode = pNext;
5127 }
5128
5129 return NULL;
5130
5131}
5132
5133/**
5134 * hdd_get_operating_channel() - return operating channel of the device mode
5135 * @hdd_ctx: Pointer to the HDD context.
5136 * @mode: Device mode for which operating channel is required.
5137 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005138 * QDF_STA_MODE,
5139 * QDF_P2P_CLIENT_MODE,
5140 * QDF_SAP_MODE,
5141 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 *
5143 * This API returns the operating channel of the requested device mode
5144 *
5145 * Return: channel number. "0" id the requested device is not found OR it is
5146 * not connected.
5147 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005148uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
5149 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005150{
5151 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305152 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153 hdd_adapter_t *adapter;
5154 uint8_t operatingChannel = 0;
5155
5156 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5157
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305158 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 adapter = adapterNode->pAdapter;
5160
5161 if (mode == adapter->device_mode) {
5162 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005163 case QDF_STA_MODE:
5164 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 if (hdd_conn_is_connected
5166 (WLAN_HDD_GET_STATION_CTX_PTR
5167 (adapter))) {
5168 operatingChannel =
5169 (WLAN_HDD_GET_STATION_CTX_PTR
5170 (adapter))->conn_info.
5171 operationChannel;
5172 }
5173 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005174 case QDF_SAP_MODE:
5175 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 /* softap connection info */
5177 if (test_bit
5178 (SOFTAP_BSS_STARTED,
5179 &adapter->event_flags))
5180 operatingChannel =
5181 (WLAN_HDD_GET_AP_CTX_PTR
5182 (adapter))->operatingChannel;
5183 break;
5184 default:
5185 break;
5186 }
5187
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005188 /* Found the device of interest. break the loop */
5189 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 }
5191
5192 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5193 adapterNode = pNext;
5194 }
5195 return operatingChannel;
5196}
5197
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305198static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 hdd_ctx)
5200{
5201 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305202 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 hdd_adapter_t *adapter;
5204
5205 ENTER();
5206
5207 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5208
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305209 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005211 if ((adapter->device_mode == QDF_STA_MODE) ||
5212 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5213 (adapter->device_mode == QDF_IBSS_MODE) ||
5214 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5215 (adapter->device_mode == QDF_SAP_MODE) ||
5216 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 wlan_hdd_cfg80211_deregister_frames(adapter);
5218 hdd_unregister_wext(adapter->dev);
5219 }
5220 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5221 adapterNode = pNext;
5222 }
5223
5224 EXIT();
5225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305226 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227}
5228
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305229QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230{
5231 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305232 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 hdd_adapter_t *adapter;
5234
5235 ENTER();
5236
5237 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5238
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305239 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005241 if ((adapter->device_mode == QDF_STA_MODE) ||
5242 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5243 (adapter->device_mode == QDF_IBSS_MODE) ||
5244 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5245 (adapter->device_mode == QDF_SAP_MODE) ||
5246 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305247 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5248 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 }
5250 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5251 adapterNode = pNext;
5252 }
5253
5254 EXIT();
5255
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305256 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257}
5258
Dustin Brownf27bce82016-11-03 12:52:27 -07005259/**
5260 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5261 * adapters
5262 * @hdd_ctx: The HDD context containing the adapters to operate on
5263 *
5264 * return: QDF_STATUS_SUCCESS
5265 */
5266static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
5267{
5268 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5269 QDF_STATUS status;
5270 hdd_adapter_t *adapter;
5271 int err;
5272
5273 ENTER();
5274
5275 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5276
5277 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5278 adapter = adapter_node->pAdapter;
5279 if ((adapter->device_mode == QDF_STA_MODE) ||
5280 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5281 (adapter->device_mode == QDF_IBSS_MODE) ||
5282 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5283 (adapter->device_mode == QDF_SAP_MODE) ||
5284 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5285 err = wlan_hdd_sched_scan_stop(adapter->dev);
5286 if (err)
5287 hdd_err("Unable to stop scheduled scan");
5288 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005289 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5290 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005291 adapter_node = next_node;
5292 }
5293
5294 EXIT();
5295
5296 return QDF_STATUS_SUCCESS;
5297}
5298
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299#ifdef WLAN_NS_OFFLOAD
5300/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005301 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302 * @hdd_ctx: Pointer to hdd context
5303 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005304 * Unregister for IPv6 address change notifications.
5305 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005306 * Return: None
5307 */
5308static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5309{
5310 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311}
5312
5313/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005314 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 * @hdd_ctx: Pointer to hdd context
5316 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005317 * Register for IPv6 address change notifications.
5318 *
5319 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005321static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322{
5323 int ret;
5324
5325 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5326 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005327 if (ret) {
5328 hdd_err("Failed to register IPv6 notifier: %d", ret);
5329 goto out;
5330 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005331
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005332 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005333out:
5334 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335}
5336#else
5337/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005338 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005339 * @hdd_ctx: Pointer to hdd context
5340 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005341 * Unregister for IPv6 address change notifications.
5342 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 * Return: None
5344 */
5345static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5346{
5347}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005348
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005350 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351 * @hdd_ctx: Pointer to hdd context
5352 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005353 * Register for IPv6 address change notifications.
5354 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 * Return: None
5356 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005357static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005359 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360}
5361#endif
5362
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305363#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
5364/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005365 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305366 * @hdd_ctx: HDD context
5367 *
5368 * Activates the logging service
5369 *
5370 * Return: Zero in case of success, negative value otherwise
5371 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005372static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305373{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005374 int ret;
5375 struct hdd_config *config = hdd_ctx->config;
5376
5377 if (!config->wlanLoggingEnable)
5378 return 0;
5379
Srinivas Girigowda8187e792017-03-03 11:50:59 -08005380 ret = wlan_logging_sock_activate_svc(config->wlanLoggingToConsole,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005381 config->wlanLoggingNumBuf);
5382 if (ret)
5383 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
5384 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305385}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005386
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305387/**
5388 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
5389 * @hdd_ctx: HDD context
5390 *
5391 * Deactivates the logging service
5392 *
5393 * Return: 0 on deactivating the logging service
5394 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005395static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305396{
5397 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
5398 return wlan_logging_sock_deactivate_svc();
5399
5400 return 0;
5401}
5402#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005403static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305404{
5405 return 0;
5406}
5407
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005408static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305409{
5410 return 0;
5411}
5412#endif
5413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005415 * hdd_register_notifiers - Register netdev notifiers.
5416 * @hdd_ctx: HDD context
5417 *
5418 * Register netdev notifiers like IPv4 and IPv6.
5419 *
5420 * Return: 0 on success and errno on failure
5421 */
5422static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
5423{
5424 int ret;
5425
5426 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5427 if (ret) {
5428 hdd_err("register_netdevice_notifier failed: %d", ret);
5429 goto out;
5430 }
5431
5432 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5433 if (ret)
5434 goto unregister_notifier;
5435
5436 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5437 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5438 if (ret) {
5439 hdd_err("Failed to register IPv4 notifier: %d", ret);
5440 goto unregister_ip6_notifier;
5441 }
5442
5443 return 0;
5444
5445unregister_ip6_notifier:
5446 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5447unregister_notifier:
5448 unregister_netdevice_notifier(&hdd_netdev_notifier);
5449out:
5450 return ret;
5451
5452}
5453
5454/**
5455 * hdd_unregister_notifiers - Unregister netdev notifiers.
5456 * @hdd_ctx: HDD context
5457 *
5458 * Unregister netdev notifiers like IPv4 and IPv6.
5459 *
5460 * Return: None.
5461 */
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305462void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005463{
5464 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5465
5466 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5467
5468 unregister_netdevice_notifier(&hdd_netdev_notifier);
5469}
5470
5471/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005472 * hdd_exit_netlink_services - Exit netlink services
5473 * @hdd_ctx: HDD context
5474 *
5475 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5476 * nl service.
5477 *
5478 * Return: None.
5479 */
5480static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
5481{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005482 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005483 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005484 ptt_sock_deactivate_svc();
5485
5486 nl_srv_exit();
5487}
5488
5489/**
5490 * hdd_init_netlink_services- Init netlink services
5491 * @hdd_ctx: HDD context
5492 *
5493 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5494 * nl service.
5495 *
5496 * Return: 0 on success and errno on failure.
5497 */
5498static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
5499{
5500 int ret;
5501
Ryan Hsuceddceb2016-04-28 10:20:14 -07005502 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005503 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005504 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005505 goto out;
5506 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005507 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005508
Naveen Rawat910726a2017-03-06 11:42:51 -08005509 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005510 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005511 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005512 goto err_nl_srv;
5513 }
5514
5515 ret = ptt_sock_activate_svc();
5516 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005517 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005518 goto err_nl_srv;
5519 }
5520
5521 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005522 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005523 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005524
5525 ret = cnss_diag_activate_service();
5526 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005527 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005528 goto err_close_cesium;
5529 }
5530
5531 return 0;
5532
5533err_close_cesium:
5534 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005535 ptt_sock_deactivate_svc();
5536err_nl_srv:
5537 nl_srv_exit();
5538out:
5539 return ret;
5540}
5541
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005542/**
5543 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5544 * @hdd_ctx: HDD context.
5545 *
5546 * Destroy RX wakelock.
5547 *
5548 * Return: None.
5549 */
5550static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
5551{
5552 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5553}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005554
5555/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005556 * hdd_rx_wake_lock_create() - Create RX wakelock
5557 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005558 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005559 * Create RX wakelock.
5560 *
5561 * Return: None.
5562 */
5563static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
5564{
5565 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5566}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005567
5568/**
5569 * hdd_roc_context_init() - Init ROC context
5570 * @hdd_ctx: HDD context.
5571 *
5572 * Initialize ROC context.
5573 *
5574 * Return: 0 on success and errno on failure.
5575 */
5576static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
5577{
5578 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5579 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5580
5581 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5582
5583 return 0;
5584}
5585
5586/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305587 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5588 * @hdd_ctx: HDD context.
5589 *
5590 * Free memory allocations made in ROC Req Queue nodes.
5591 *
5592 * Return: None.
5593 */
5594static void hdd_destroy_roc_req_q(hdd_context_t *hdd_ctx)
5595{
5596 hdd_roc_req_t *hdd_roc_req;
5597 QDF_STATUS status;
5598
5599 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5600
5601 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5602 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5603 (qdf_list_node_t **) &hdd_roc_req);
5604
5605 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305606 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5607 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305608 QDF_ASSERT(0);
5609 return;
5610 }
5611
5612 if (hdd_roc_req->pRemainChanCtx)
5613 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5614
5615 qdf_mem_free(hdd_roc_req);
5616 }
5617
5618 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5619}
5620
5621/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005622 * hdd_roc_context_destroy() - Destroy ROC context
5623 * @hdd_ctx: HDD context.
5624 *
5625 * Destroy roc list and flush the pending roc work.
5626 *
5627 * Return: None.
5628 */
5629static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
5630{
5631 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305632 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005633 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005634}
5635
5636/**
Houston Hoffman160db392016-10-10 17:37:51 -07005637 * hdd_context_deinit() - Deinitialize HDD context
5638 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005639 *
Houston Hoffman160db392016-10-10 17:37:51 -07005640 * Deinitialize HDD context along with all the feature specific contexts but
5641 * do not free hdd context itself. Caller of this API is supposed to free
5642 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005643 *
Houston Hoffman160db392016-10-10 17:37:51 -07005644 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005645 */
Houston Hoffman160db392016-10-10 17:37:51 -07005646static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005647{
Houston Hoffman160db392016-10-10 17:37:51 -07005648 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005649
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005650 hdd_roc_context_destroy(hdd_ctx);
5651
5652 hdd_sap_context_destroy(hdd_ctx);
5653
5654 hdd_rx_wake_lock_destroy(hdd_ctx);
5655
5656 hdd_tdls_context_destroy(hdd_ctx);
5657
5658 hdd_scan_context_destroy(hdd_ctx);
5659
5660 qdf_list_destroy(&hdd_ctx->hddAdapters);
5661
Houston Hoffman160db392016-10-10 17:37:51 -07005662 return 0;
5663}
5664
5665/**
5666 * hdd_context_destroy() - Destroy HDD context
5667 * @hdd_ctx: HDD context to be destroyed.
5668 *
5669 * Free config and HDD context as well as destroy all the resources.
5670 *
5671 * Return: None
5672 */
5673static void hdd_context_destroy(hdd_context_t *hdd_ctx)
5674{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305675
5676 hdd_logging_sock_deactivate_svc(hdd_ctx);
Houston Hoffman160db392016-10-10 17:37:51 -07005677
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305678 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5679
Houston Hoffman160db392016-10-10 17:37:51 -07005680 hdd_context_deinit(hdd_ctx);
5681
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305682 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005683 hdd_ctx->config = NULL;
5684
5685 wiphy_free(hdd_ctx->wiphy);
5686}
5687
5688/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305689 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5690 *
5691 * This function is used to destroy bug report lock
5692 *
5693 * Return: None
5694 */
5695static void wlan_destroy_bug_report_lock(void)
5696{
5697 p_cds_contextType p_cds_context;
5698
5699 p_cds_context = cds_get_global_context();
5700 if (!p_cds_context) {
5701 hdd_err("cds context is NULL");
5702 return;
5703 }
5704
5705 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5706}
5707
5708/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709 * hdd_wlan_exit() - HDD WLAN exit function
5710 * @hdd_ctx: Pointer to the HDD Context
5711 *
5712 * This is the driver exit point (invoked during rmmod)
5713 *
5714 * Return: None
5715 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005716static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717{
5718 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305719 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305721 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005722
5723 ENTER();
5724
Arun Khandavallifae92942016-08-01 13:31:08 +05305725 if (QDF_TIMER_STATE_RUNNING ==
5726 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005727 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305728 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729 }
5730
Arun Khandavallifae92942016-08-01 13:31:08 +05305731 if (!QDF_IS_STATUS_SUCCESS
5732 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5733 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005734
Arun Khandavallifae92942016-08-01 13:31:08 +05305735
5736 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005737
Nitesh Shah61c10d92016-10-19 19:29:15 +05305738 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5739
Prashanth Bhattaab004382016-10-11 16:08:11 -07005740 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741
5742#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305743 if (QDF_TIMER_STATE_RUNNING ==
5744 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5745 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746 }
5747
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305748 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305749 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005750 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005752 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5753 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5754 hdd_ctx->last_acs_channel_list = NULL;
5755 hdd_ctx->num_of_channels = 0;
5756 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005757#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758
Arun Khandavallifae92942016-08-01 13:31:08 +05305759 mutex_lock(&hdd_ctx->iface_change_lock);
5760 driver_status = hdd_ctx->driver_status;
5761 mutex_unlock(&hdd_ctx->iface_change_lock);
5762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 /*
5764 * Powersave Offload Case
5765 * Disable Idle Power Save Mode
5766 */
5767 hdd_set_idle_ps_config(hdd_ctx, false);
5768
Arun Khandavallifae92942016-08-01 13:31:08 +05305769 if (driver_status != DRIVER_MODULES_CLOSED) {
5770 hdd_unregister_wext_all_adapters(hdd_ctx);
5771 /*
5772 * Cancel any outstanding scan requests. We are about to close
5773 * all of our adapters, but an adapter structure is what SME
5774 * passes back to our callback function. Hence if there
5775 * are any outstanding scan requests then there is a
5776 * race condition between when the adapter is closed and
5777 * when the callback is invoked. We try to resolve that
5778 * race condition here by canceling any outstanding scans
5779 * before we close the adapters.
5780 * Note that the scans may be cancelled in an asynchronous
5781 * manner, so ideally there needs to be some kind of
5782 * synchronization. Rather than introduce a new
5783 * synchronization here, we will utilize the fact that we are
5784 * about to Request Full Power, and since that is synchronized,
5785 * the expectation is that by the time Request Full Power has
5786 * completed, all scans will be cancelled
5787 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005788 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305789 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005790 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305791 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005792 }
5793
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305794 wlan_destroy_bug_report_lock();
5795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005796 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305797 * Close the scheduler before calling cds_close to make sure
5798 * no thread is scheduled after the each module close is
5799 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305801 qdf_status = cds_sched_close(p_cds_context);
5802 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305803 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305804 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005806
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005807 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305808
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305809 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5810 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5811 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813 /*
5814 * Close CDS
5815 * This frees pMac(HAL) context. There should not be any call
5816 * that requires pMac access after this.
5817 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005818
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005819 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005820 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005821
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005822 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005823
5824 hdd_ipa_cleanup(hdd_ctx);
5825
5826 /* Free up RoC request queue and flush workqueue */
5827 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305829 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305830 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305831 /*
5832 * If there is re_init failure wiphy would have already de-registered
5833 * check the wiphy status before un-registering again
5834 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305835 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305836 wiphy_unregister(wiphy);
5837 wlan_hdd_cfg80211_deinit(wiphy);
5838 hdd_lpass_notify_stop(hdd_ctx);
5839 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005840
Arun Khandavallifae92942016-08-01 13:31:08 +05305841 hdd_exit_netlink_services(hdd_ctx);
5842 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05305843#ifdef FEATURE_WLAN_CH_AVOID
5844 mutex_destroy(&hdd_ctx->avoid_freq_lock);
5845#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05305846
5847 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5848 if (driver_status)
5849 hdd_err("Pdev delete failed");
5850
5851 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
5852 if (driver_status)
5853 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07005854
5855 qdf_mem_free(hdd_ctx->target_hw_name);
5856
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005857 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858}
5859
5860void __hdd_wlan_exit(void)
5861{
5862 hdd_context_t *hdd_ctx;
5863
5864 ENTER();
5865
Anurag Chouhan6d760662016-02-20 16:05:43 +05305866 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005867 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005868 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869 EXIT();
5870 return;
5871 }
5872
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005873 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305874 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005875
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005876 /* Do all the cleanup before deregistering the driver */
5877 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005879 EXIT();
5880}
5881
5882#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005883/**
5884 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5885 * @data: pointer to hdd_context_t
5886 *
5887 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5888 * Then new ACS request will do a fresh scan without reusing the cached
5889 * scan information.
5890 *
5891 * Return: void
5892 */
Tang Yingying523322d2017-01-17 23:28:43 +08005893static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005894{
5895 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5896
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005897 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005899 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5900 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5901 hdd_ctx->last_acs_channel_list = NULL;
5902 hdd_ctx->num_of_channels = 0;
5903 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904
5905 if (!hdd_ctx->hHal)
5906 return;
5907 sme_scan_flush_result(hdd_ctx->hHal);
5908}
5909#endif
5910
5911#ifdef QCA_HT_2040_COEX
5912/**
5913 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5914 * @adapter: pointer to adapter
5915 * @staId: station id
5916 * @macAddrSTA: station MAC address
5917 * @channel_type: channel type
5918 *
5919 * This function notifies FW with HT20/HT40 mode
5920 *
5921 * Return: 0 if successful, error number otherwise
5922 */
5923int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305924 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925{
5926 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305927 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005928 hdd_context_t *hdd_ctx = NULL;
5929
5930 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5931
5932 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305933 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936 if (!hdd_ctx->hHal)
5937 return -EINVAL;
5938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305939 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005940 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305941 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005942 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943 return -EINVAL;
5944 }
5945
5946 return 0;
5947}
5948#endif
5949
5950/**
5951 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5952 * @state: state
5953 *
5954 * This function notifies FW with modem power status
5955 *
5956 * Return: 0 if successful, error number otherwise
5957 */
5958int hdd_wlan_notify_modem_power_state(int state)
5959{
5960 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305961 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962 hdd_context_t *hdd_ctx;
5963
Anurag Chouhan6d760662016-02-20 16:05:43 +05305964 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305966 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005967 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005969 if (!hdd_ctx->hHal)
5970 return -EINVAL;
5971
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305972 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5973 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005974 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005975 state);
5976 return -EINVAL;
5977 }
5978 return 0;
5979}
5980
5981/**
5982 *
5983 * hdd_post_cds_enable_config() - HDD post cds start config helper
5984 * @adapter - Pointer to the HDD
5985 *
5986 * Return: None
5987 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305988QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005989{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305990 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005991
5992 /*
5993 * Send ready indication to the HDD. This will kick off the MAC
5994 * into a 'running' state and should kick off an initial scan.
5995 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305996 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5997 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005998 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5999 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306000 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006001 }
6002
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306003 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004}
6005
6006/* wake lock APIs for HDD */
6007void hdd_prevent_suspend(uint32_t reason)
6008{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306009 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010}
6011
6012void hdd_allow_suspend(uint32_t reason)
6013{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306014 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015}
6016
6017void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6018{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306019 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6020 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006021}
6022
6023/**
6024 * hdd_exchange_version_and_caps() - exchange version and capability with target
6025 * @hdd_ctx: Pointer to HDD context
6026 *
6027 * This is the HDD function to exchange version and capability information
6028 * between Host and Target
6029 *
6030 * This function gets reported version of FW.
6031 * It also finds the version of target headers used to compile the host;
6032 * It compares the above two and prints a warning if they are different;
6033 * It gets the SW and HW version string;
6034 * Finally, it exchanges capabilities between host and target i.e. host
6035 * and target exchange a msg indicating the features they support through a
6036 * bitmap
6037 *
6038 * Return: None
6039 */
6040void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
6041{
6042
6043 tSirVersionType versionCompiled;
6044 tSirVersionType versionReported;
6045 tSirVersionString versionString;
6046 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306047 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048
6049 memset(&versionCompiled, 0, sizeof(versionCompiled));
6050 memset(&versionReported, 0, sizeof(versionReported));
6051
6052 /* retrieve and display WCNSS version information */
6053 do {
6054
6055 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
6056 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306057 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006058 hdd_err("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059 break;
6060 }
6061
6062 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
6063 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306064 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006065 hdd_err("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006066 break;
6067 }
6068
6069 if ((versionCompiled.major != versionReported.major) ||
6070 (versionCompiled.minor != versionReported.minor) ||
6071 (versionCompiled.version != versionReported.version) ||
6072 (versionCompiled.revision != versionReported.revision)) {
6073 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
6074 "Host expected %u.%u.%u.%u\n",
6075 WLAN_MODULE_NAME,
6076 (int)versionReported.major,
6077 (int)versionReported.minor,
6078 (int)versionReported.version,
6079 (int)versionReported.revision,
6080 (int)versionCompiled.major,
6081 (int)versionCompiled.minor,
6082 (int)versionCompiled.version,
6083 (int)versionCompiled.revision);
6084 } else {
6085 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
6086 WLAN_MODULE_NAME,
6087 (int)versionReported.major,
6088 (int)versionReported.minor,
6089 (int)versionReported.version,
6090 (int)versionReported.revision);
6091 }
6092
6093 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
6094 versionString,
6095 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306096 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006097 hdd_err("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098 break;
6099 }
6100
6101 pr_info("%s: WCNSS software version %s\n",
6102 WLAN_MODULE_NAME, versionString);
6103
6104 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
6105 versionString,
6106 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306107 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006108 hdd_err("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109 break;
6110 }
6111
6112 pr_info("%s: WCNSS hardware version %s\n",
6113 WLAN_MODULE_NAME, versionString);
6114
6115 /*
6116 * 1.Check if FW version is greater than 0.1.1.0. Only then
6117 * send host-FW capability exchange message
6118 * 2.Host-FW capability exchange message is only present on
6119 * target 1.1 so send the message only if it the target is 1.1
6120 * minor numbers for different target branches:
6121 * 0 -> (1.0)Mainline Build
6122 * 1 -> (1.1)Mainline Build
6123 * 2->(1.04) Stability Build
6124 */
6125 if (((versionReported.major > 0) || (versionReported.minor > 1)
6126 || ((versionReported.minor >= 1)
6127 && (versionReported.version >= 1)))
6128 && ((versionReported.major == 1)
6129 && (versionReported.minor >= 1)))
6130 fwFeatCapsMsgSupported = 1;
6131
6132 if (fwFeatCapsMsgSupported) {
6133 /*
6134 * Indicate if IBSS heartbeat monitoring needs to be
6135 * offloaded
6136 */
6137 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
6138 sme_disable_feature_capablity
6139 (IBSS_HEARTBEAT_OFFLOAD);
6140 }
6141
6142 sme_feature_caps_exchange(hdd_ctx->hHal);
6143 }
6144
6145 } while (0);
6146
6147}
6148
6149/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306150QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006152
Amar Singhal6f8592b2017-04-26 14:31:58 -07006153 return sme_init_chan_list(hdd_ctx->hHal,
6154 hdd_ctx->reg.alpha2,
6155 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156}
6157
6158/**
6159 * hdd_is_5g_supported() - check if hardware supports 5GHz
6160 * @hdd_ctx: Pointer to the hdd context
6161 *
6162 * HDD function to know if hardware supports 5GHz
6163 *
6164 * Return: true if hardware supports 5GHz
6165 */
6166bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
6167{
zdingf54169a2016-10-12 17:08:45 +08006168 if (!hdd_ctx || !hdd_ctx->config)
6169 return true;
6170
6171 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
6172 return true;
6173 else
6174 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175}
6176
Amar Singhale4f28ee2015-10-21 14:36:56 -07006177static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178{
6179 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006180 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006181
6182 wiphy = hdd_ctx->wiphy;
6183
6184 /*
6185 * The channel information in
6186 * wiphy needs to be initialized before wiphy registration
6187 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006188 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6189 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006190 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006191 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006192 }
6193
6194#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6195 wiphy->wowlan = &wowlan_support_reg_init;
6196#else
6197 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6198 WIPHY_WOWLAN_MAGIC_PKT |
6199 WIPHY_WOWLAN_DISCONNECT |
6200 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6201 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6202 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6203 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6204 WIPHY_WOWLAN_RFKILL_RELEASE;
6205
6206 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6207 WOW_MAX_FILTERS_PER_LIST);
6208 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6209 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6210#endif
6211
6212 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006213 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306214 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006215 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306216 return ret_val;
6217 }
6218
Amar Singhal5cccafe2017-02-15 12:42:58 -08006219 if (!hdd_ctx->reg_offload)
6220 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221
Amar Singhale4f28ee2015-10-21 14:36:56 -07006222 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223}
6224
Ravi Joshie2331e82015-07-01 18:18:54 -07006225/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006226 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006227 * @hdd_ctx - handle to hdd context
6228 * @tx_packets - transmit packet count
6229 * @rx_packets - receive packet count
6230 *
6231 * The function controls the bus bandwidth and dynamic control of
6232 * tcp delayed ack configuration
6233 *
6234 * Returns: None
6235 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07006237static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
6238 const uint64_t tx_packets,
6239 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006242 uint64_t temp_rx = 0;
6243 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006244 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006245 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006246 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006247 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006248 uint16_t index = 0;
6249 bool vote_level_change = false;
6250 bool rx_level_change = false;
6251 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006254 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006256 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006257 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006258 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006259 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006260 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006263 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6264 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006266 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006267 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306268 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306269 if (hdd_ctx->hbw_requested) {
6270 pld_remove_pm_qos(hdd_ctx->parent_dev);
6271 hdd_ctx->hbw_requested = false;
6272 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306273 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006274 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306275 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306276 if (!hdd_ctx->hbw_requested) {
6277 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6278 hdd_ctx->hbw_requested = true;
6279 }
6280
Nirav Shah3bbfa512016-05-12 16:43:49 +05306281 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006282 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306283 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006284 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006286
6287 /* fine-tuning parameters for RX Flows */
6288 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006291
Ravi Joshifed83572016-10-07 16:20:37 -07006292 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6293 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6294 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6295 next_rx_level = WLAN_SVC_TP_HIGH;
6296 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006297 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006298 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006299 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006300 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006302 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006303 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006304 next_rx_level, temp_rx);
6305 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006306 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006307 /* Send throughput indication only if it is enabled.
6308 * Disabling tcp_del_ack will revert the tcp stack behavior
6309 * to default delayed ack. Note that this will disable the
6310 * dynamic delayed ack mechanism across the system
6311 */
6312 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306313 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6314 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 &next_rx_level,
6316 sizeof(next_rx_level));
6317 }
6318
Mohit Khannae71e2262015-11-10 09:37:24 -08006319 /* fine-tuning parameters for TX Flows */
6320 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6321 hdd_ctx->prev_tx = tx_packets;
6322 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6323 next_tx_level = WLAN_SVC_TP_HIGH;
6324 else
6325 next_tx_level = WLAN_SVC_TP_LOW;
6326
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006327 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006328 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6329 next_tx_level, temp_tx);
6330 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006331 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306332 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6333 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006334 &next_tx_level,
6335 sizeof(next_tx_level));
6336 }
6337
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006338 index = hdd_ctx->hdd_txrx_hist_idx;
6339
6340 if (vote_level_change || tx_level_change || rx_level_change) {
6341 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6342 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6343 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6344 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6345 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6346 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6347 hdd_ctx->hdd_txrx_hist_idx++;
6348 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6349 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350}
6351
6352#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306353static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306355 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
6356 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306358 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306359 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6360 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 uint64_t total_tx = 0, total_rx = 0;
6362 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306363 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306364 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006365 bool connected = false;
6366 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6367
Prashanth Bhattaab004382016-10-11 16:08:11 -07006368 if (wlan_hdd_validate_context(hdd_ctx))
6369 return;
6370
Jingxiang Gec64e1932017-08-22 14:38:59 +08006371 if (hdd_ctx->isWiphySuspended)
6372 goto restart_timer;
6373
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306375 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376 status =
6377 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6378
6379 if (adapterNode->pAdapter == NULL)
6380 continue;
6381 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306382 /*
6383 * Validate magic so we don't end up accessing
6384 * an invalid adapter.
6385 */
6386 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6387 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006389 if ((adapter->device_mode == QDF_STA_MODE ||
6390 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6392 != eConnectionState_Associated) {
6393
6394 continue;
6395 }
6396
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006397 if ((adapter->device_mode == QDF_SAP_MODE ||
6398 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6400
6401 continue;
6402 }
6403
6404 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6405 adapter->prev_tx_packets);
6406 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6407 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306408
6409 if (adapter->device_mode == QDF_SAP_MODE ||
6410 adapter->device_mode == QDF_P2P_GO_MODE ||
6411 adapter->device_mode == QDF_IBSS_MODE) {
6412
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006413 ret = cdp_get_intra_bss_fwd_pkts_count(
6414 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306415 adapter->sessionId,
6416 &fwd_tx_packets, &fwd_rx_packets);
6417 if (ret == A_OK) {
6418 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6419 fwd_tx_packets,
6420 adapter->prev_fwd_tx_packets);
6421 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6422 fwd_tx_packets,
6423 adapter->prev_fwd_rx_packets);
6424 }
6425 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426
6427 total_rx += adapter->stats.rx_packets;
6428 total_tx += adapter->stats.tx_packets;
6429
6430 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6431 adapter->prev_tx_packets = adapter->stats.tx_packets;
6432 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306433 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6434 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006435 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6436 connected = true;
6437 }
6438
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306439 /* add intra bss forwarded tx and rx packets */
6440 tx_packets += fwd_tx_packets_diff;
6441 rx_packets += fwd_rx_packets_diff;
6442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006443 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6444 tx_packets += (uint64_t)ipa_tx_packets;
6445 rx_packets += (uint64_t)ipa_rx_packets;
6446
6447 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006448 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449 return;
6450 }
6451
Yuanyuan Liu13738502016-04-06 17:41:37 -07006452 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006453
6454 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6455 hdd_ipa_uc_stat_request(adapter, 2);
6456
Jingxiang Gec64e1932017-08-22 14:38:59 +08006457restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006458 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006459 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006460 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306461 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006462 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006463 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006464}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006465
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306466/**
6467 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6468 * @arg: Argument of timer function
6469 *
6470 * Schedule a workqueue in this function where all the processing is done.
6471 *
6472 * Return: None.
6473 */
6474static void __hdd_bus_bw_cbk(void *arg)
6475{
6476 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
6477
6478 if (wlan_hdd_validate_context(hdd_ctx))
6479 return;
6480
6481 schedule_work(&hdd_ctx->bus_bw_work);
6482}
6483
6484/**
6485 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6486 * @arg: Argument of timer function
6487 *
6488 * Return: None.
6489 */
6490static void hdd_bus_bw_cbk(void *arg)
6491{
6492 cds_ssr_protect(__func__);
6493 __hdd_bus_bw_cbk(arg);
6494 cds_ssr_unprotect(__func__);
6495}
6496
Prashanth Bhattaab004382016-10-11 16:08:11 -07006497int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
6498{
6499 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306500 INIT_WORK(&hdd_ctx->bus_bw_work,
6501 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006502 hdd_ctx->bus_bw_timer_running = false;
6503 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306504 qdf_timer_init(NULL,
6505 &hdd_ctx->bus_bw_timer,
6506 hdd_bus_bw_cbk, (void *)hdd_ctx,
6507 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006508
6509 return 0;
6510}
6511
6512void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
6513{
Dustin Brownfce08d12017-01-17 16:29:38 -08006514 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006515 hdd_reset_tcp_delack(hdd_ctx);
6516
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006517 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306518 cancel_work_sync(&hdd_ctx->bus_bw_work);
6519 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006520 hdd_ctx->bus_bw_timer_running = false;
6521 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006522}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523#endif
6524
6525/**
Nirav Shahed34b212016-04-25 10:59:16 +05306526 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6527 * @hdd_ctx: hdd context
6528 *
6529 * Return: 0 for success or error code
6530 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07006531static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306532{
6533 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6534 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6535 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006536 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306537 return -ENOMEM;
6538 }
6539 return 0;
6540}
6541
6542/**
6543 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6544 * @hdd_ctx: hdd context
6545 *
6546 * Return: none
6547 */
6548void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
6549{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306550 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6551 return;
6552
6553 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6554 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306555}
6556
Nirav Shahda008342016-05-17 18:50:40 +05306557static uint8_t *convert_level_to_string(uint32_t level)
6558{
6559 switch (level) {
6560 /* initialize the wlan sub system */
6561 case WLAN_SVC_TP_NONE:
6562 return "NONE";
6563 case WLAN_SVC_TP_LOW:
6564 return "LOW";
6565 case WLAN_SVC_TP_MEDIUM:
6566 return "MED";
6567 case WLAN_SVC_TP_HIGH:
6568 return "HIGH";
6569 default:
6570 return "INVAL";
6571 }
6572}
6573
Nirav Shahed34b212016-04-25 10:59:16 +05306574
6575/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006576 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6577 * @hdd_ctx: hdd context
6578 *
6579 * Return: none
6580 */
6581void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
6582{
6583 int i;
6584
6585#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006586 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306587 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006588 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589 hdd_ctx->config->busBandwidthHighThreshold,
6590 hdd_ctx->config->busBandwidthMediumThreshold,
6591 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006592 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306593 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006594 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595 hdd_ctx->config->tcpDelackThresholdHigh,
6596 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006597 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306598 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599#endif
6600
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006601 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306602 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6603
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006604 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006605
6606 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006607 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006608 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006609 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006610 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6611 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006612 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006613 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6614 convert_level_to_string(
6615 hdd_ctx->hdd_txrx_hist[i].
6616 next_vote_level),
6617 convert_level_to_string(
6618 hdd_ctx->hdd_txrx_hist[i].
6619 next_rx_level),
6620 convert_level_to_string(
6621 hdd_ctx->hdd_txrx_hist[i].
6622 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006623 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006624
6625 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626}
6627
6628/**
6629 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6630 * @hdd_ctx: hdd context
6631 *
6632 * Return: none
6633 */
6634void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
6635{
6636 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306637 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6638 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639}
6640
6641/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006642 * wlan_hdd_display_netif_queue_history() - display netif queue history
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643 * @pHddCtx: hdd context
6644 *
6645 * Return: none
6646 */
6647void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
6648{
6649
6650 hdd_adapter_t *adapter = NULL;
6651 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306652 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306654 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655
6656 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306657 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658 adapter = adapter_node->pAdapter;
6659
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006660 hdd_debug("Netif queue operation statistics:");
6661 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306662 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006663 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306664 curr_time = qdf_system_ticks();
6665 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306666 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306667 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306668 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306669 unpause = adapter->total_unpause_time;
6670 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306671 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306672 pause = adapter->total_pause_time;
6673 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006674 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306675 qdf_system_ticks_to_msecs(total),
6676 qdf_system_ticks_to_msecs(pause),
6677 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006678 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679
Nirav Shahda008342016-05-17 18:50:40 +05306680 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6681 qdf_time_t pause_delta = 0;
6682
6683 if (adapter->pause_map & (1 << i))
6684 pause_delta = delta;
6685
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006686 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006687 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006688 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689 hdd_reason_type_to_string(i),
6690 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306691 adapter->queue_oper_stats[i].unpause_count,
6692 qdf_system_ticks_to_msecs(
6693 adapter->queue_oper_stats[i].total_pause_time +
6694 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695 }
6696
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006697 hdd_debug("Netif queue operation history:");
6698 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306699 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6700
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006701 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006702
6703 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006704 /* using hdd_log to avoid printing function name */
6705 if (adapter->queue_oper_history[i].time == 0)
6706 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006707 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006708 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306709 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710 adapter->queue_oper_history[i].time),
6711 hdd_action_type_to_string(
6712 adapter->queue_oper_history[i].netif_action),
6713 hdd_reason_type_to_string(
6714 adapter->queue_oper_history[i].netif_reason),
6715 adapter->queue_oper_history[i].pause_map);
6716 }
6717
6718 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6719 adapter_node = next;
6720 }
6721
6722
6723}
6724
6725/**
6726 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6727 * @hdd_ctx: hdd context
6728 *
6729 * Return: none
6730 */
6731void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
6732{
6733 hdd_adapter_t *adapter = NULL;
6734 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306735 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736
6737 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306738 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 adapter = adapter_node->pAdapter;
6740
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306741 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306743 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306745 adapter->history_index = 0;
6746 adapter->start_time = adapter->last_time = qdf_system_ticks();
6747 adapter->total_pause_time = 0;
6748 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006749 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6750 adapter_node = next;
6751 }
6752}
6753
6754/**
6755 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6756 * @halHandle: Hal handle
6757 * @pContext: Pointer to the context
6758 * @sessionId: Session ID
6759 * @scanId: Scan ID
6760 * @status: Status
6761 *
6762 * This is the callback to be executed when 11d scan is completed to flush out
6763 * the scan results
6764 *
6765 * 11d scan is done during driver load and is a passive scan on all
6766 * channels supported by the device, 11d scans may find some APs on
6767 * frequencies which are forbidden to be used in the regulatory domain
6768 * the device is operating in. If these APs are notified to the supplicant
6769 * it may try to connect to these APs, thus flush out all the scan results
6770 * which are present in SME after 11d scan is done.
6771 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306772 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306774static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775 uint8_t sessionId, uint32_t scanId,
6776 eCsrScanStatus status)
6777{
6778 ENTER();
6779
6780 sme_scan_flush_result(halHandle);
6781
6782 EXIT();
6783
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306784 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006785}
6786
6787#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6788/**
6789 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6790 * @hdd_ctx: hdd global context
6791 *
6792 * Return: none
6793 */
6794static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6795{
6796 uint8_t i;
6797
6798 mutex_init(&hdd_ctx->op_ctx.op_lock);
6799 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6800 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6801 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6802 }
6803}
6804#else
6805static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6806{
6807}
6808#endif
6809
Yingying Tang95409972016-10-20 15:16:15 +08006810#ifdef WLAN_FEATURE_WOW_PULSE
6811/**
6812 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6813 * @phddctx: hdd_context_t structure pointer
6814 * @enable: enable or disable this behaviour
6815 *
6816 * Return: int
6817 */
6818static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6819{
6820 struct hdd_config *pcfg_ini = phddctx->config;
6821 struct wow_pulse_mode wow_pulse_set_info;
6822 QDF_STATUS status;
6823
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006824 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006825
6826 if (false == phddctx->config->wow_pulse_support)
6827 return 0;
6828
6829 /* prepare the request to send to SME */
6830 if (enable == true) {
6831 wow_pulse_set_info.wow_pulse_enable = true;
6832 wow_pulse_set_info.wow_pulse_pin =
6833 pcfg_ini->wow_pulse_pin;
6834 wow_pulse_set_info.wow_pulse_interval_low =
6835 pcfg_ini->wow_pulse_interval_low;
6836 wow_pulse_set_info.wow_pulse_interval_high =
6837 pcfg_ini->wow_pulse_interval_high;
6838 } else {
6839 wow_pulse_set_info.wow_pulse_enable = false;
6840 wow_pulse_set_info.wow_pulse_pin = 0;
6841 wow_pulse_set_info.wow_pulse_interval_low = 0;
6842 wow_pulse_set_info.wow_pulse_interval_high = 0;
6843 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006844 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006845 wow_pulse_set_info.wow_pulse_enable,
6846 wow_pulse_set_info.wow_pulse_pin,
6847 wow_pulse_set_info.wow_pulse_interval_low,
6848 wow_pulse_set_info.wow_pulse_interval_high);
6849
6850 status = sme_set_wow_pulse(&wow_pulse_set_info);
6851 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006852 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006853 return -EIO;
6854 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006855 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006856 return 0;
6857}
6858#else
6859static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6860{
6861 return 0;
6862}
6863#endif
6864
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006865#ifdef WLAN_FEATURE_FASTPATH
6866/**
6867 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6868 * @hdd_cfg: hdd config
6869 * @context: lower layer context
6870 *
6871 * Return: none
6872 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306873void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874 void *context)
6875{
6876 if (hdd_cfg->fastpath_enable)
6877 hif_enable_fastpath(context);
6878}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006879#endif
6880
Yuanyuan Liu13738502016-04-06 17:41:37 -07006881#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882/**
6883 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006884 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006885 * @level: thermal level
6886 *
6887 * Change IPA data path to SW path when the thermal throttle level greater
6888 * than 0, and restore the original data path when throttle level is 0
6889 *
6890 * Return: none
6891 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006892static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006894 hdd_context_t *hdd_ctx = context;
6895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 /* Change IPA to SW path when throttle level greater than 0 */
6897 if (level > THROTTLE_LEVEL_0)
6898 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6899 else
6900 /* restore original concurrency mode */
6901 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6902}
6903
6904/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306905 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6906 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306907 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306909 * Get a safe channel to restart SAP. PCL already takes into account the
6910 * unsafe channels. So, the PCL is validated with the ACS range to provide
6911 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306913 * Return: Channel number to restart SAP in case of success. In case of any
6914 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306916static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6917 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006918{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306919 struct sir_pcl_list pcl;
6920 QDF_STATUS status;
6921 uint32_t i, j;
6922 tHalHandle *hal_handle;
6923 hdd_context_t *hdd_ctx;
6924 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306926 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6927 if (!hdd_ctx) {
6928 hdd_err("invalid HDD context");
6929 return INVALID_CHANNEL_ID;
6930 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306932 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6933 if (!hal_handle) {
6934 hdd_err("invalid HAL handle");
6935 return INVALID_CHANNEL_ID;
6936 }
6937
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006938 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6939 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08006940 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
6941 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306942 if (QDF_IS_STATUS_ERROR(status)) {
6943 hdd_err("Get PCL failed");
6944 return INVALID_CHANNEL_ID;
6945 }
6946
Frank Liudc2cefb2017-06-21 15:38:18 +08006947 /*
6948 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
6949 * channel is unsafe channel, the pcl may be empty, instead of return,
6950 * try to choose a safe channel from acs range.
6951 */
6952 if (!pcl.pcl_len)
6953 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306954
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006955 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306956 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6957 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6958
6959 /* PCL already takes unsafe channel into account */
6960 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006961 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306962 if ((pcl.pcl_list[i] >=
6963 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6964 (pcl.pcl_list[i] <=
6965 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006966 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306967 return pcl.pcl_list[i];
6968 }
6969 }
6970
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006971 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306972
6973 /* Try for safe channel from all valid channel */
6974 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006975 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306976 &pcl.pcl_len);
6977 if (QDF_IS_STATUS_ERROR(status)) {
6978 hdd_err("error in getting valid channel list");
6979 return INVALID_CHANNEL_ID;
6980 }
6981
6982 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006983 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306984 found = false;
6985 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006986 if (pcl.pcl_list[i] ==
6987 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006988 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306989 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990 break;
6991 }
6992 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306993
6994 if (found)
6995 continue;
6996
6997 if ((pcl.pcl_list[i] >=
6998 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6999 (pcl.pcl_list[i] <=
7000 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007001 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307002 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007003 }
7004 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307005
7006 return INVALID_CHANNEL_ID;
7007}
7008
7009/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007010 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307011 * @adapter: AP adapter
7012 * @channel: Channel
7013 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007014 * Moves the SAP interface by invoking the function which
7015 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307016 *
7017 * Return: None
7018 */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007019void hdd_switch_sap_channel(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307020{
7021 hdd_ap_ctx_t *hdd_ap_ctx;
7022 tHalHandle *hal_handle;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007023 hdd_context_t *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307024
7025 if (!adapter) {
7026 hdd_err("invalid adapter");
7027 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007028 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307029
7030 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7031
7032 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7033 if (!hal_handle) {
7034 hdd_err("invalid HAL handle");
7035 return;
7036 }
7037
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007038 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7039
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307040 hdd_ap_ctx->sapConfig.channel = channel;
7041 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7042 hdd_ap_ctx->sapConfig.ch_width_orig;
7043
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007044 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307045 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7046
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007047 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7048 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049 hdd_ap_ctx->sapConfig.sec_ch,
7050 &hdd_ap_ctx->sapConfig.ch_params);
7051
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007052 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7053 adapter->sessionId, channel,
7054 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307056
7057int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
7058{
7059 struct hdd_external_acs_timer_context *timer_context;
7060
7061 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7062
7063 if (QDF_TIMER_STATE_RUNNING ==
7064 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7065 ap.vendor_acs_timer)) {
7066 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7067 }
7068 timer_context = (struct hdd_external_acs_timer_context *)
7069 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7070 timer_context->reason = reason;
7071 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7072 WLAN_VENDOR_ACS_WAIT_TIME);
7073 /* Update config to application */
7074 hdd_cfg80211_update_acs_config(adapter, reason);
7075 hdd_notice("Updated ACS config to nl with reason %d", reason);
7076
7077 return 0;
7078}
7079
Agrawal Ashish467dde42016-09-08 18:44:22 +05307080/**
7081 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7082 * @hdd_ctx: hdd context pointer
7083 *
7084 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7085 * and if ACS is enabled, driver will ask userspace to restart the
7086 * sap. User space on LTE coex indication restart driver.
7087 *
7088 * Return - none
7089 */
7090void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
7091{
7092 QDF_STATUS status;
7093 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
7094 hdd_adapter_t *adapter_temp;
7095 uint32_t i;
7096 bool found = false;
7097 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098
Agrawal Ashish467dde42016-09-08 18:44:22 +05307099 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7100 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7101 adapter_temp = adapter_node->pAdapter;
7102
7103 if (!adapter_temp) {
7104 hdd_err("adapter is NULL, moving to next one");
7105 goto next_adapater;
7106 }
7107
7108 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7109 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007110 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307111 adapter_temp->device_mode,
7112 adapter_temp->sessionCtx.ap.sapConfig.
7113 acs_cfg.acs_mode);
7114 goto next_adapater;
7115 }
7116
7117 found = false;
7118 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007119 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307120 hdd_ctxt->unsafe_channel_list[i]) {
7121 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007122 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307123 adapter_temp->sessionCtx.ap.operatingChannel);
7124 break;
7125 }
7126 }
7127
7128 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007129 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307130 adapter_temp->sessionCtx.ap.operatingChannel);
7131 goto next_adapater;
7132 }
7133
Kapil Gupta8878ad92017-02-13 11:56:04 +05307134 if (hdd_ctxt->config->vendor_acs_support &&
7135 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7136 hdd_update_acs_timer_reason(adapter_temp,
7137 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7138 goto next_adapater;
7139 } else
7140 restart_chan =
7141 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307142 adapter_temp);
7143 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007144 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307145 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007146 /*
7147 * SAP restart due to unsafe channel. While
7148 * restarting the SAP, make sure to clear
7149 * acs_channel, channel to reset to
7150 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307151 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007152 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307153 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7154 adapter_temp->sessionCtx.ap.sapConfig.channel =
7155 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007156 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307157 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7158 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007159 hdd_switch_sap_channel(adapter_temp, restart_chan);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307160 }
7161
7162next_adapater:
7163 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7164 adapter_node = next;
7165 }
7166}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007168/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169 * hdd_init_channel_avoidance() - Initialize channel avoidance
7170 * @hdd_ctx: HDD global context
7171 *
7172 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007173 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007174 * down to the lower layers. Then subscribe to subsequent channel
7175 * avoidance events.
7176 *
7177 * Return: None
7178 */
7179static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7180{
7181 uint16_t unsafe_channel_count;
7182 int index;
7183
Yuanyuan Liu13738502016-04-06 17:41:37 -07007184 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7185 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007187 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007188
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007189 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007190 hdd_ctx->unsafe_channel_count);
7191
Anurag Chouhan6d760662016-02-20 16:05:43 +05307192 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007193 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007194
7195 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007196 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197 hdd_ctx->unsafe_channel_list[index]);
7198
7199 }
7200
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007201}
7202#else
7203static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7204{
7205}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007206static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007207{
7208}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007209#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007210
7211/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007212 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7213 * user space
7214 * @frame_ind: Management frame data to be informed.
7215 *
7216 * This function is used to indicate management frame to
7217 * user space
7218 *
7219 * Return: None
7220 *
7221 */
7222void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7223{
7224 hdd_context_t *hdd_ctx = NULL;
7225 hdd_adapter_t *adapter = NULL;
7226 void *cds_context = NULL;
7227 int i;
7228
7229 /* Get the global VOSS context.*/
7230 cds_context = cds_get_global_context();
7231 if (!cds_context) {
7232 hdd_err("Global CDS context is Null");
7233 return;
7234 }
7235 /* Get the HDD context.*/
7236 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
7237
7238 if (0 != wlan_hdd_validate_context(hdd_ctx))
7239 return;
7240
7241 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7242 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7243 adapter =
7244 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7245 if (adapter)
7246 break;
7247 }
7248 } else {
7249 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7250 frame_ind->sessionId);
7251 }
7252
7253 if ((NULL != adapter) &&
7254 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7255 __hdd_indicate_mgmt_frame(adapter,
7256 frame_ind->frame_len,
7257 frame_ind->frameBuf,
7258 frame_ind->frameType,
7259 frame_ind->rxChan,
7260 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007261}
7262
Kapil Gupta8878ad92017-02-13 11:56:04 +05307263static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
7264 hdd_context_t *hdd_ctx)
7265{
7266 uint8_t restart_chan = 0;
7267
7268 restart_chan =
7269 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7270 if (!restart_chan) {
7271 hdd_alert("fail to restart SAP");
7272 } else {
7273 /* SAP restart due to unsafe channel. While restarting
7274 * the SAP, make sure to clear acs_channel, channel to
7275 * reset to 0. Otherwise these settings will override
7276 * the ACS while restart.
7277 */
7278 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7279 adapter->sessionCtx.ap.sapConfig.channel =
7280 AUTO_CHANNEL_SELECT;
7281 hdd_info("sending coex indication");
7282 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7283 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007284 hdd_switch_sap_channel(adapter, restart_chan);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307285 }
7286}
7287
7288void hdd_acs_response_timeout_handler(void *context)
7289{
7290 struct hdd_external_acs_timer_context *timer_context =
7291 (struct hdd_external_acs_timer_context *)context;
7292 hdd_adapter_t *adapter;
7293 hdd_context_t *hdd_ctx;
7294 uint8_t reason;
7295
7296 ENTER();
7297 if (!timer_context) {
7298 hdd_err("invlaid timer context");
7299 return;
7300 }
7301 adapter = timer_context->adapter;
7302 reason = timer_context->reason;
7303
7304
7305 if ((!adapter) ||
7306 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7307 hdd_err("invalid adapter or adapter has invalid magic");
7308 return;
7309 }
7310 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7311 if (wlan_hdd_validate_context(hdd_ctx))
7312 return;
7313
7314 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7315 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7316 else
7317 return;
7318
7319 hdd_err("ACS timeout happened for %s reason %d",
7320 adapter->dev->name, reason);
7321 switch (reason) {
7322 /* SAP init case */
7323 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7324 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7325 false);
7326 wlan_hdd_cfg80211_start_acs(adapter);
7327 break;
7328 /* DFS detected on current channel */
7329 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7330 wlan_sap_update_next_channel(
7331 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7332 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7333 adapter->sessionId);
7334 break;
7335 /* LTE coex event on current channel */
7336 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7337 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7338 break;
7339 default:
7340 hdd_info("invalid reason for timer invoke");
7341
7342 }
7343}
7344
Rajeev Kumard004abc2016-02-17 12:09:56 -08007345/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7347 * @hdd_ctx: HDD context
7348 *
7349 * Disables all the dual mac features like DBS, Agile DFS etc.
7350 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307351 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007352 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307353static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007355 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307356 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007357
7358 if (!hdd_ctx) {
7359 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307360 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007361 }
7362
7363 cfg.scan_config = 0;
7364 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007365 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007366
7367 hdd_debug("Disabling all dual mac features...");
7368
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007369 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307370 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007371 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7372 return status;
7373 }
7374
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307375 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007376}
7377
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007378static QDF_STATUS
7379wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_context_t *hdd_ctx)
7380{
7381 struct policy_mgr_dual_mac_config cfg = {0};
7382 QDF_STATUS status;
7383
7384 if (!hdd_ctx) {
7385 hdd_err("HDD context is NULL");
7386 return QDF_STATUS_E_FAILURE;
7387 }
7388
7389 cfg.scan_config = 0;
7390 cfg.fw_mode_config = 0;
7391 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7392 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7393 hdd_ctx->hdd_psoc, &cfg.scan_config,
7394 &cfg.fw_mode_config,
7395 hdd_ctx->config->dual_mac_feature_disable);
7396
7397 if (status != QDF_STATUS_SUCCESS) {
7398 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7399 status);
7400 return status;
7401 }
7402
7403 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7404 cfg.scan_config, cfg.fw_mode_config);
7405
7406 status = sme_soc_set_dual_mac_config(cfg);
7407 if (status != QDF_STATUS_SUCCESS) {
7408 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7409 return status;
7410 }
7411
7412 return QDF_STATUS_SUCCESS;
7413}
7414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007416 * hdd_override_ini_config - Override INI config
7417 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007419 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007421 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007422 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007423static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007424{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007425
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007426 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7427 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007428 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007429 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007430 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007431 if (0 == enable_11d || 1 == enable_11d) {
7432 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007433 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007434 }
Leo Chang11545d62016-10-17 14:53:50 -07007435
7436 if (!hdd_ipa_is_present(hdd_ctx))
7437 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007438}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007439
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007440/**
7441 * hdd_set_trace_level_for_each - Set trace level for each INI config
7442 * @hdd_ctx - HDD context
7443 *
7444 * Set trace level for each module based on INI config.
7445 *
7446 * Return: None
7447 */
7448static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
7449{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307450 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7451 hdd_ctx->config->qdf_trace_enable_wdi);
7452 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7453 hdd_ctx->config->qdf_trace_enable_hdd);
7454 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7455 hdd_ctx->config->qdf_trace_enable_sme);
7456 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7457 hdd_ctx->config->qdf_trace_enable_pe);
7458 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7459 hdd_ctx->config->qdf_trace_enable_wma);
7460 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7461 hdd_ctx->config->qdf_trace_enable_sys);
7462 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7463 hdd_ctx->config->qdf_trace_enable_qdf);
7464 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7465 hdd_ctx->config->qdf_trace_enable_sap);
7466 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7467 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7468 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7469 hdd_ctx->config->qdf_trace_enable_bmi);
7470 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7471 hdd_ctx->config->qdf_trace_enable_cfg);
7472 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7473 hdd_ctx->config->qdf_trace_enable_epping);
7474 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7475 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7476 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05307477 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307478 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7479 hdd_ctx->config->qdf_trace_enable_htc);
7480 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7481 hdd_ctx->config->qdf_trace_enable_hif);
7482 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7483 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7484 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7485 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007486 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7487 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007488 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7489 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007490 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7491 hdd_ctx->config->qdf_trace_enable_regulatory);
7492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007494}
7495
7496/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007497 * hdd_context_init() - Initialize HDD context
7498 * @hdd_ctx: HDD context.
7499 *
7500 * Initialize HDD context along with all the feature specific contexts.
7501 *
7502 * return: 0 on success and errno on failure.
7503 */
7504static int hdd_context_init(hdd_context_t *hdd_ctx)
7505{
7506 int ret;
7507
7508 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7509 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7510
7511 hdd_init_ll_stats_ctx();
7512
7513 init_completion(&hdd_ctx->mc_sus_event_var);
7514 init_completion(&hdd_ctx->ready_to_suspend);
7515
7516 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307517 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007518 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307519
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007520 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7521
7522 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7523
7524 ret = hdd_scan_context_init(hdd_ctx);
7525 if (ret)
7526 goto list_destroy;
7527
Nitesh Shahd1266d72017-01-25 22:07:07 +05307528 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007529
7530 hdd_rx_wake_lock_create(hdd_ctx);
7531
7532 ret = hdd_sap_context_init(hdd_ctx);
7533 if (ret)
7534 goto scan_destroy;
7535
7536 ret = hdd_roc_context_init(hdd_ctx);
7537 if (ret)
7538 goto sap_destroy;
7539
7540 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7541
7542 hdd_init_offloaded_packets_ctx(hdd_ctx);
7543
7544 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7545 hdd_ctx->config);
7546 if (ret)
7547 goto roc_destroy;
7548
7549 return 0;
7550
7551roc_destroy:
7552 hdd_roc_context_destroy(hdd_ctx);
7553
7554sap_destroy:
7555 hdd_sap_context_destroy(hdd_ctx);
7556
7557scan_destroy:
7558 hdd_scan_context_destroy(hdd_ctx);
7559 hdd_rx_wake_lock_destroy(hdd_ctx);
7560 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007561list_destroy:
7562 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007563
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007564 return ret;
7565}
7566
7567/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307568 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7569 * @hdd_ctx: pointer to hdd context
7570 *
7571 * Return: status of initialization
7572 * 0 - success
7573 * negative value - failure
7574 */
7575static int ie_whitelist_attrs_init(hdd_context_t *hdd_ctx)
7576{
7577 int ret;
7578
7579 if (!hdd_ctx->config->probe_req_ie_whitelist)
7580 return 0;
7581
7582 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7583 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7584 hdd_ctx->config->probe_req_ie_whitelist = false;
7585 return -EINVAL;
7586 }
7587
7588 /* parse ini string probe req oui */
7589 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7590 if (ret) {
7591 hdd_err("parsing error: disable ie whitelisting");
7592 hdd_ctx->config->probe_req_ie_whitelist = false;
7593 }
7594
7595 return ret;
7596}
7597
7598/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007599 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307600 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007601 *
7602 * Allocate and initialize HDD context. HDD context is allocated as part of
7603 * wiphy allocation and then context is initialized.
7604 *
7605 * Return: HDD context on success and ERR_PTR on failure
7606 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007607static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007608{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307609 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007610 int ret = 0;
7611 hdd_context_t *hdd_ctx;
7612 v_CONTEXT_t p_cds_context;
7613
7614 ENTER();
7615
7616 p_cds_context = cds_get_global_context();
7617 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007618 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007619 ret = -EINVAL;
7620 goto err_out;
7621 }
7622
7623 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
7624
7625 if (hdd_ctx == NULL) {
7626 ret = -ENOMEM;
7627 goto err_out;
7628 }
7629
7630 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007631 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307632 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007633
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307634 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007635 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007636 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007637 ret = -ENOMEM;
7638 goto err_free_hdd_context;
7639 }
7640
7641 /* Read and parse the qcom_cfg.ini file */
7642 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307643 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307644 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007645 WLAN_INI_FILE);
7646 ret = -EINVAL;
7647 goto err_free_config;
7648 }
7649
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307650 ie_whitelist_attrs_init(hdd_ctx);
7651
Dustin Brown7f939932017-05-18 15:02:17 -07007652 hdd_debug("setting timer multiplier: %u",
7653 hdd_ctx->config->timer_multiplier);
7654 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7655
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007656
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307657 if (hdd_ctx->config->fhostNSOffload)
7658 hdd_ctx->ns_offload_enable = true;
7659
Abhishek Singh5ea86532016-04-27 14:10:53 +05307660 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7661
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007662 hdd_override_ini_config(hdd_ctx);
7663
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007664 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007665
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007666 ret = hdd_context_init(hdd_ctx);
7667
7668 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007669 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007670
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007671 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307672 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007673
Anurag Chouhan6d760662016-02-20 16:05:43 +05307674 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007675 goto skip_multicast_logging;
7676
7677 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7678
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007679 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7680 if (ret)
7681 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307682
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007683 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7684 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307685 goto err_free_histogram;
7686
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007687skip_multicast_logging:
7688 hdd_set_trace_level_for_each(hdd_ctx);
7689
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007690 EXIT();
7691
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007692 return hdd_ctx;
7693
Nirav Shahed34b212016-04-25 10:59:16 +05307694err_free_histogram:
7695 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7696
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007697err_deinit_hdd_context:
7698 hdd_context_deinit(hdd_ctx);
7699
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007700err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307701 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007702
7703err_free_hdd_context:
7704 wiphy_free(hdd_ctx->wiphy);
7705
7706err_out:
7707 return ERR_PTR(ret);
7708}
7709
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007710#ifdef WLAN_OPEN_P2P_INTERFACE
7711/**
7712 * hdd_open_p2p_interface - Open P2P interface
7713 * @hdd_ctx: HDD context
7714 * @rtnl_held: True if RTNL lock held
7715 *
7716 * Open P2P interface during probe. This function called to open the P2P
7717 * interface at probe along with STA interface.
7718 *
7719 * Return: 0 on success and errno on failure
7720 */
7721static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7722{
7723 hdd_adapter_t *adapter;
7724 uint8_t *p2p_dev_addr;
7725
7726 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7727 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307728 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007729 hdd_ctx->config->intfMacAddr[0].bytes,
7730 sizeof(tSirMacAddr));
7731
7732 /*
7733 * Generate the P2P Device Address. This consists of
7734 * the device's primary MAC address with the locally
7735 * administered bit set.
7736 */
7737 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7738 } else {
7739 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7740 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007741 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007742 return -ENOSPC;
7743 }
7744
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307745 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307746 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007747 }
7748
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007749 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007750 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007751 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007752
7753 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007754 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007755 return -ENOSPC;
7756 }
7757
7758 return 0;
7759}
7760#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307761static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007762 bool rtnl_held)
7763{
7764 return 0;
7765}
7766#endif
7767
Jeff Johnson957bc272017-02-02 08:54:48 -08007768static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7769{
7770 hdd_adapter_t *adapter;
7771 int ret = 0;
7772
7773 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7774 wlan_hdd_get_intf_addr(hdd_ctx),
7775 NET_NAME_UNKNOWN, rtnl_held);
7776 if (adapter == NULL) {
7777 hdd_err("Failed to open 802.11p interface");
7778 ret = -ENOSPC;
7779 }
7780
7781 return ret;
7782}
7783
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007784/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307785 * hdd_start_station_adapter()- Start the Station Adapter
7786 * @adapter: HDD adapter
7787 *
7788 * This function initializes the adapter for the station mode.
7789 *
7790 * Return: 0 on success or errno on failure.
7791 */
7792int hdd_start_station_adapter(hdd_adapter_t *adapter)
7793{
7794 QDF_STATUS status;
7795
7796 ENTER_DEV(adapter->dev);
7797
7798 status = hdd_init_station_mode(adapter);
7799
7800 if (QDF_STATUS_SUCCESS != status) {
7801 hdd_err("Error Initializing station mode: %d", status);
7802 return qdf_status_to_os_return(status);
7803 }
7804
Arun Khandavallifae92942016-08-01 13:31:08 +05307805 hdd_register_tx_flow_control(adapter,
7806 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007807 hdd_tx_resume_cb,
7808 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307809
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307810 EXIT();
7811 return 0;
7812}
7813
7814/**
7815 * hdd_start_ap_adapter()- Start AP Adapter
7816 * @adapter: HDD adapter
7817 *
7818 * This function initializes the adapter for the AP mode.
7819 *
7820 * Return: 0 on success errno on failure.
7821 */
7822int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7823{
7824 QDF_STATUS status;
7825
7826 ENTER();
7827
Arun Khandavallicc544b32017-01-30 19:52:16 +05307828 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307829
7830 if (QDF_STATUS_SUCCESS != status) {
7831 hdd_err("Error Initializing the AP mode: %d", status);
7832 return qdf_status_to_os_return(status);
7833 }
7834
Arun Khandavallifae92942016-08-01 13:31:08 +05307835 hdd_register_tx_flow_control(adapter,
7836 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007837 hdd_softap_tx_resume_cb,
7838 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307839
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307840 EXIT();
7841 return 0;
7842}
7843
7844/**
7845 * hdd_start_ftm_adapter()- Start FTM adapter
7846 * @adapter: HDD adapter
7847 *
7848 * This function initializes the adapter for the FTM mode.
7849 *
7850 * Return: 0 on success or errno on failure.
7851 */
7852int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7853{
7854 QDF_STATUS qdf_status;
7855
7856 ENTER_DEV(adapter->dev);
7857
7858 qdf_status = hdd_init_tx_rx(adapter);
7859
7860 if (QDF_STATUS_SUCCESS != qdf_status) {
7861 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7862 return qdf_status_to_os_return(qdf_status);
7863 }
7864
7865 return 0;
7866 EXIT();
7867}
7868
7869/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007870 * hdd_open_interfaces - Open all required interfaces
7871 * hdd_ctx: HDD context
7872 * rtnl_held: True if RTNL lock is held
7873 *
7874 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7875 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007876 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007877 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007878static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007879{
Jeff Johnson957bc272017-02-02 08:54:48 -08007880 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007881 int ret;
7882
Jeff Johnson957bc272017-02-02 08:54:48 -08007883 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307884 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007885 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007886
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007887 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007888 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007889 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007890
7891 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007892 return -ENOSPC;
7893
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007894 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7895 adapter->fast_roaming_allowed = true;
7896
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007897 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7898 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007899 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007900
7901 /* Open 802.11p Interface */
7902 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007903 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7904 if (ret)
7905 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007906 }
7907
Jeff Johnson957bc272017-02-02 08:54:48 -08007908 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007909
Jeff Johnson957bc272017-02-02 08:54:48 -08007910err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007911 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007912 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007913}
7914
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007915/**
7916 * hdd_update_country_code - Update country code
7917 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007918 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007919 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007920 *
7921 * Return: 0 on success and errno on failure
7922 */
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007923static int hdd_update_country_code(hdd_context_t *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007924{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007925 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007926 return 0;
7927
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007928 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007929}
7930
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307931#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7932/**
7933 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7934 * @cds_cfg: CDS Configuration
7935 * @hdd_ctx: Pointer to hdd context
7936 *
7937 * Return: none
7938 */
7939static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7940 *cds_cfg,
7941 hdd_context_t *hdd_ctx)
7942{
7943 cds_cfg->tx_flow_stop_queue_th =
7944 hdd_ctx->config->TxFlowStopQueueThreshold;
7945 cds_cfg->tx_flow_start_queue_offset =
7946 hdd_ctx->config->TxFlowStartQueueOffset;
7947}
7948#else
7949static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7950 *cds_cfg,
7951 hdd_context_t *hdd_ctx)
7952{
7953}
7954#endif
7955
7956#ifdef FEATURE_WLAN_RA_FILTERING
7957/**
7958 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
7959 * @cds_cfg: CDS Configuration
7960 * @hdd_ctx: Pointer to hdd context
7961 *
7962 * Return: none
7963 */
Anand Kumar3b92a912016-12-05 12:01:26 +05307964static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307965 hdd_context_t *hdd_ctx)
7966{
7967 cds_cfg->ra_ratelimit_interval =
7968 hdd_ctx->config->RArateLimitInterval;
7969 cds_cfg->is_ra_ratelimit_enabled =
7970 hdd_ctx->config->IsRArateLimitEnabled;
7971}
7972#else
Anand Kumar3b92a912016-12-05 12:01:26 +05307973static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307974 hdd_context_t *hdd_ctx)
7975{
7976}
7977#endif
7978
7979/**
7980 * hdd_update_cds_config() - API to update cds configuration parameters
7981 * @hdd_ctx: HDD Context
7982 *
7983 * Return: 0 for Success, errno on failure
7984 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007985static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307986{
7987 struct cds_config_info *cds_cfg;
7988
7989 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
7990 if (!cds_cfg) {
7991 hdd_err("failed to allocate cds config");
7992 return -ENOMEM;
7993 }
7994
Srinivas Girigowda35b00312017-06-27 21:52:03 -07007995 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08007996 if (!hdd_ctx->config->nMaxPsPoll ||
7997 !hdd_ctx->config->enablePowersaveOffload) {
7998 cds_cfg->powersave_offload_enabled =
7999 hdd_ctx->config->enablePowersaveOffload;
8000 } else {
8001 if ((hdd_ctx->config->enablePowersaveOffload ==
8002 PS_QPOWER_NODEEPSLEEP) ||
8003 (hdd_ctx->config->enablePowersaveOffload ==
8004 PS_LEGACY_NODEEPSLEEP))
8005 cds_cfg->powersave_offload_enabled =
8006 PS_LEGACY_NODEEPSLEEP;
8007 else
8008 cds_cfg->powersave_offload_enabled =
8009 PS_LEGACY_DEEPSLEEP;
8010 hdd_info("Qpower disabled in cds config, %d",
8011 cds_cfg->powersave_offload_enabled);
8012 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308013 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8014 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8015 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8016 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8017 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8018
8019 /* Here ol_ini_info is used to store ini status of arp offload
8020 * ns offload and others. Currently 1st bit is used for arp
8021 * off load and 2nd bit for ns offload currently, rest bits are unused
8022 */
8023 if (hdd_ctx->config->fhostArpOffload)
8024 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8025 if (hdd_ctx->config->fhostNSOffload)
8026 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8027
8028 /*
8029 * Copy the DFS Phyerr Filtering Offload status.
8030 * This parameter reflects the value of the
8031 * dfs_phyerr_filter_offload flag as set in the ini.
8032 */
8033 cds_cfg->dfs_phyerr_filter_offload =
8034 hdd_ctx->config->fDfsPhyerrFilterOffload;
8035 if (hdd_ctx->config->ssdp)
8036 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8037
8038 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8039 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8040
8041 cds_cfg->ap_maxoffload_reorderbuffs =
8042 hdd_ctx->config->apMaxOffloadReorderBuffs;
8043
8044 cds_cfg->ap_disable_intrabss_fwd =
8045 hdd_ctx->config->apDisableIntraBssFwd;
8046
8047 cds_cfg->dfs_pri_multiplier =
8048 hdd_ctx->config->dfsRadarPriMultiplier;
8049 cds_cfg->reorder_offload =
8050 hdd_ctx->config->reorderOffloadSupport;
8051
8052 /* IPA micro controller data path offload resource config item */
8053 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008054 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8055 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008056 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008057 hdd_ctx->config->IpaUcTxBufCount);
8058 hdd_ctx->config->IpaUcTxBufCount =
8059 rounddown_pow_of_two(
8060 hdd_ctx->config->IpaUcTxBufCount);
8061 if (!hdd_ctx->config->IpaUcTxBufCount) {
8062 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308063 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008064 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008065 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008066 hdd_ctx->config->IpaUcTxBufCount);
8067 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308068 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8069 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008070 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8071 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008072 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008073 hdd_ctx->config->IpaUcRxIndRingCount);
8074 hdd_ctx->config->IpaUcRxIndRingCount =
8075 rounddown_pow_of_two(
8076 hdd_ctx->config->IpaUcRxIndRingCount);
8077 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8078 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308079 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008080 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008081 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008082 hdd_ctx->config->IpaUcRxIndRingCount);
8083 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308084 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008085 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308086 cds_cfg->uc_tx_partition_base =
8087 hdd_ctx->config->IpaUcTxPartitionBase;
8088 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8089
8090 cds_cfg->ip_tcp_udp_checksum_offload =
8091 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308092 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308093 cds_cfg->ce_classify_enabled =
8094 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008095 cds_cfg->bpf_packet_filter_enable =
8096 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308097 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8098 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8099 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008100 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008101 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008102 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008103 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308104 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8105 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308106 cds_cfg->auto_power_save_fail_mode =
8107 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308108
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308109 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8110
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308111 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8112 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8113 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008114 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308115 cds_init_ini_config(cds_cfg);
8116 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308117
8118exit:
8119 qdf_mem_free(cds_cfg);
8120 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308121}
8122
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008123/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008124 * hdd_update_user_config() - API to update user configuration
8125 * parameters to obj mgr which are used by multiple components
8126 * @hdd_ctx: HDD Context
8127 *
8128 * Return: 0 for Success, errno on failure
8129 */
8130static int hdd_update_user_config(hdd_context_t *hdd_ctx)
8131{
8132 struct wlan_objmgr_psoc_user_config *user_config;
8133
8134 user_config = qdf_mem_malloc(sizeof(*user_config));
8135 if (user_config == NULL) {
8136 hdd_alert("Failed to alloc memory for user_config!");
8137 return -ENOMEM;
8138 }
8139
8140 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8141 user_config->dual_mac_feature_disable =
8142 hdd_ctx->config->dual_mac_feature_disable;
8143 user_config->indoor_channel_support =
8144 hdd_ctx->config->indoor_channel_support;
8145 user_config->is_11d_support_enabled =
8146 hdd_ctx->config->Is11dSupportEnabled;
8147 user_config->is_11h_support_enabled =
8148 hdd_ctx->config->Is11hSupportEnabled;
8149 user_config->optimize_chan_avoid_event =
8150 hdd_ctx->config->goptimize_chan_avoid_event;
8151 user_config->skip_dfs_chnl_in_p2p_search =
8152 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008153 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008154 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8155
8156 qdf_mem_free(user_config);
8157 return 0;
8158}
8159
8160/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008161 * hdd_init_thermal_info - Initialize thermal level
8162 * @hdd_ctx: HDD context
8163 *
8164 * Initialize thermal level at SME layer and set the thermal level callback
8165 * which would be called when a configured thermal threshold is hit.
8166 *
8167 * Return: 0 on success and errno on failure
8168 */
8169static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
8170{
8171 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308172 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008173
8174 thermal_param.smeThermalMgmtEnabled =
8175 hdd_ctx->config->thermalMitigationEnable;
8176 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8177
Poddar, Siddarth83905022016-04-16 17:56:08 -07008178 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8179 hdd_ctx->config->throttle_dutycycle_level0;
8180 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8181 hdd_ctx->config->throttle_dutycycle_level1;
8182 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8183 hdd_ctx->config->throttle_dutycycle_level2;
8184 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8185 hdd_ctx->config->throttle_dutycycle_level3;
8186
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008187 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8188 hdd_ctx->config->thermalTempMinLevel0;
8189 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8190 hdd_ctx->config->thermalTempMaxLevel0;
8191 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8192 hdd_ctx->config->thermalTempMinLevel1;
8193 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8194 hdd_ctx->config->thermalTempMaxLevel1;
8195 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8196 hdd_ctx->config->thermalTempMinLevel2;
8197 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8198 hdd_ctx->config->thermalTempMaxLevel2;
8199 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8200 hdd_ctx->config->thermalTempMinLevel3;
8201 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8202 hdd_ctx->config->thermalTempMaxLevel3;
8203
8204 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8205
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308206 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308207 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008208
8209 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8210 hdd_set_thermal_level_cb);
8211
8212 return 0;
8213
8214}
8215
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008216#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8217/**
8218 * hdd_hold_rtnl_lock - Hold RTNL lock
8219 *
8220 * Hold RTNL lock
8221 *
8222 * Return: True if held and false otherwise
8223 */
8224static inline bool hdd_hold_rtnl_lock(void)
8225{
8226 rtnl_lock();
8227 return true;
8228}
8229
8230/**
8231 * hdd_release_rtnl_lock - Release RTNL lock
8232 *
8233 * Release RTNL lock
8234 *
8235 * Return: None
8236 */
8237static inline void hdd_release_rtnl_lock(void)
8238{
8239 rtnl_unlock();
8240}
8241#else
8242static inline bool hdd_hold_rtnl_lock(void) { return false; }
8243static inline void hdd_release_rtnl_lock(void) { }
8244#endif
8245
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008246#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008247
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308248/* MAX iwpriv command support */
8249#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308250#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308251#define MAX_PKTLOG_SIZE 16
8252
8253/**
8254 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8255 * @hdd_ctx: hdd context
8256 * @set_value2: pktlog buffer size value
8257 *
8258 *
8259 * Return: 0 for success or error.
8260 */
8261static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
8262{
8263 struct sir_wifi_start_log start_log = { 0 };
8264 QDF_STATUS status;
8265
8266 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8267 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8268 start_log.ini_triggered = cds_is_packet_log_enabled();
8269 start_log.user_triggered = 1;
8270 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308271 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308272
8273 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8274 if (!QDF_IS_STATUS_SUCCESS(status)) {
8275 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8276 EXIT();
8277 return -EINVAL;
8278 }
8279
8280 return 0;
8281}
8282
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008283/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308284 * hdd_pktlog_clear_buff() - clear pktlog buffer
8285 * @hdd_ctx: hdd context
8286 *
8287 * Return: 0 for success or error.
8288 */
8289static int hdd_pktlog_clear_buff(hdd_context_t *hdd_ctx)
8290{
8291 struct sir_wifi_start_log start_log;
8292 QDF_STATUS status;
8293
8294 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8295 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8296 start_log.ini_triggered = cds_is_packet_log_enabled();
8297 start_log.user_triggered = 1;
8298 start_log.size = 0;
8299 start_log.is_pktlog_buff_clear = true;
8300
8301 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8302 if (!QDF_IS_STATUS_SUCCESS(status)) {
8303 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8304 EXIT();
8305 return -EINVAL;
8306 }
8307
8308 return 0;
8309}
8310
8311
8312/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008313 * hdd_process_pktlog_command() - process pktlog command
8314 * @hdd_ctx: hdd context
8315 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308316 * @set_value2: pktlog buffer size value
8317 *
8318 * This function process pktlog command.
8319 * set_value2 only matters when set_value is 3 (set buff size)
8320 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008321 *
8322 * Return: 0 for success or error.
8323 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308324int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
8325 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008326{
8327 int ret;
8328 bool enable;
8329 uint8_t user_triggered = 0;
8330
8331 ret = wlan_hdd_validate_context(hdd_ctx);
8332 if (0 != ret)
8333 return ret;
8334
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008335 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008336
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308337 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008338 hdd_err("invalid pktlog value %d", set_value);
8339 return -EINVAL;
8340 }
8341
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308342 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8343 if (set_value2 <= 0) {
8344 hdd_err("invalid pktlog size %d", set_value2);
8345 return -EINVAL;
8346 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8347 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8348 return -EINVAL;
8349 }
8350 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308351 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8352 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308353 }
8354
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008355 /*
8356 * set_value = 0 then disable packetlog
8357 * set_value = 1 enable packetlog forcefully
8358 * set_vlaue = 2 then disable packetlog if disabled through ini or
8359 * enable packetlog with AUTO type.
8360 */
8361 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8362 true : false;
8363
8364 if (1 == set_value) {
8365 enable = true;
8366 user_triggered = 1;
8367 }
8368
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308369 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008370}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008371/**
8372 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8373 * @hdd_ctx: HDD context
8374 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308375 * @user_triggered: triggered through iwpriv
8376 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008377 *
8378 * Return: 0 on success; error number otherwise
8379 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008380int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308381 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008382{
8383 struct sir_wifi_start_log start_log;
8384 QDF_STATUS status;
8385
8386 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8387 start_log.verbose_level =
8388 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008389 start_log.ini_triggered = cds_is_packet_log_enabled();
8390 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308391 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308392 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308393 /*
8394 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8395 * commands. Host uses this flag to decide whether to send pktlog
8396 * disable command to fw without sending pktlog enable command
8397 * previously. For eg, If vendor sends pktlog disable command without
8398 * sending pktlog enable command, then host discards the packet
8399 * but for iwpriv command, host will send it to fw.
8400 */
8401 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008402 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8403 if (!QDF_IS_STATUS_SUCCESS(status)) {
8404 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8405 EXIT();
8406 return -EINVAL;
8407 }
8408
8409 return 0;
8410}
8411#endif /* REMOVE_PKT_LOG */
8412
Komal Seelam92fff912016-03-24 11:51:41 +05308413/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008414 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8415 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308416 * @dev: Device Pointer
8417 * @num: Number of Valid Mac address
8418 *
8419 * Return: Pointer to MAC address buffer
8420 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008421static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8422 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308423{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008424 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308425}
Komal Seelam92fff912016-03-24 11:51:41 +05308426
8427/**
8428 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8429 * @hdd_ctx: HDD Context
8430 * @num: Number of random mac addresses needed
8431 *
8432 * Generate random addresses using bit manipulation on the base mac address
8433 *
8434 * Return: None
8435 */
Nachiket Kukadee4d86442017-06-23 16:57:00 +05308436void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308437{
8438 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8439 uint32_t iter;
8440 struct hdd_config *ini = hdd_ctx->config;
8441 uint8_t *buf = NULL;
8442 uint8_t macaddr_b3, tmp_br3;
8443 uint8_t *src = ini->intfMacAddr[0].bytes;
8444
8445 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8446 buf = ini->intfMacAddr[iter].bytes;
8447 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8448 macaddr_b3 = buf[3];
8449 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8450 INTF_MACADDR_MASK;
8451 macaddr_b3 += tmp_br3;
8452 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8453 buf[0] |= 0x02;
8454 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008455 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308456 }
8457}
8458
8459/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008460 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308461 * @hdd_ctx: HDD Context
8462 *
8463 * API to get mac addresses from platform driver and update the driver
8464 * structures and configure FW with the base mac address.
8465 * Return: int
8466 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008467static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308468{
8469 uint32_t no_of_mac_addr, iter;
8470 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8471 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8472 uint8_t *addr, *buf;
8473 struct device *dev = hdd_ctx->parent_dev;
8474 struct hdd_config *ini = hdd_ctx->config;
8475 tSirMacAddr mac_addr;
8476 QDF_STATUS status;
8477
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008478 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308479
8480 if (no_of_mac_addr == 0 || !addr) {
8481 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8482 return -EINVAL;
8483 }
8484
8485 if (no_of_mac_addr > max_mac_addr)
8486 no_of_mac_addr = max_mac_addr;
8487
8488 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8489
8490 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8491 buf = ini->intfMacAddr[iter].bytes;
8492 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008493 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308494 }
8495
8496 status = sme_set_custom_mac_addr(mac_addr);
8497
8498 if (!QDF_IS_STATUS_SUCCESS(status))
8499 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008500
Komal Seelam92fff912016-03-24 11:51:41 +05308501 if (no_of_mac_addr < max_mac_addr)
8502 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8503 no_of_mac_addr);
8504 return 0;
8505}
8506
8507/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008508 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8509 * @hdd_ctx: HDD Context
8510 *
8511 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8512 * will generate its own MAC and update it to FW.
8513 *
8514 * Return: 0 for success
8515 * Non-zero error code for failure
8516 */
8517static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
8518{
8519 tSirMacAddr customMacAddr;
8520 QDF_STATUS status;
8521
8522 qdf_mem_copy(&customMacAddr,
8523 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8524 sizeof(tSirMacAddr));
8525 status = sme_set_custom_mac_addr(customMacAddr);
8526 if (!QDF_IS_STATUS_SUCCESS(status))
8527 return -EAGAIN;
8528 return 0;
8529}
8530
8531/**
Komal Seelam92fff912016-03-24 11:51:41 +05308532 * hdd_initialize_mac_address() - API to get wlan mac addresses
8533 * @hdd_ctx: HDD Context
8534 *
8535 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8536 * is provisioned with mac addresses, driver uses it, else it will use
8537 * wlan_mac.bin to update HW MAC addresses.
8538 *
8539 * Return: None
8540 */
8541static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
8542{
8543 QDF_STATUS status;
8544 int ret;
8545
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008546 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308547 if (ret == 0)
8548 return;
8549
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008550 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8551 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308552
8553 status = hdd_update_mac_config(hdd_ctx);
8554
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008555 if (QDF_IS_STATUS_SUCCESS(status))
8556 return;
8557
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008558 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8559 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008560
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008561 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008562 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008563 if (ret != 0) {
8564 hdd_err("MAC address out-of-sync, ret:%d", ret);
8565 QDF_ASSERT(ret);
8566 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008567 }
Komal Seelam92fff912016-03-24 11:51:41 +05308568}
8569
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008570static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
8571{
8572 int vdev_id = 0;
8573 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8574 int value = hdd_ctx->config->smart_chainmask_enabled;
8575 int vpdev = PDEV_CMD;
8576 int ret;
8577
Naveen Rawat247a8682017-06-05 15:00:31 -07008578 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008579 if (ret)
8580 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8581
8582 return ret;
8583}
8584
8585static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
8586{
8587 int vdev_id = 0;
8588 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8589 int value = hdd_ctx->config->alternative_chainmask_enabled;
8590 int vpdev = PDEV_CMD;
8591 int ret;
8592
Naveen Rawat247a8682017-06-05 15:00:31 -07008593 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008594 if (ret)
8595 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8596 ret);
8597
8598 return ret;
8599}
8600
Jeff Johnson12a744b2017-04-04 08:19:37 -07008601static int hdd_set_ani_enabled(hdd_context_t *hdd_ctx)
8602{
8603 int vdev_id = 0;
8604 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8605 int value = hdd_ctx->config->ani_enabled;
8606 int vpdev = PDEV_CMD;
8607 int ret;
8608
Naveen Rawat247a8682017-06-05 15:00:31 -07008609 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008610 if (ret)
8611 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8612
8613 return ret;
8614}
8615
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008616/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008617 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8618 * @hdd_ctx: HDD context
8619 *
8620 * Pre configurations to be done at lower layer before calling cds enable.
8621 *
8622 * Return: 0 on success and errno on failure.
8623 */
8624static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
8625{
8626 int ret;
8627 QDF_STATUS status;
8628 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008629 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008630
Leo Changfdb45c32016-10-28 11:09:23 -07008631 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008632 /*
8633 * Set 802.11p config
8634 * TODO-OCB: This has been temporarily added here to ensure this
8635 * parameter is set in CSR when we init the channel list. This should
8636 * be removed once the 5.9 GHz channels are added to the regulatory
8637 * domain.
8638 */
8639 hdd_set_dot11p_config(hdd_ctx);
8640
8641 /*
8642 * Note that the cds_pre_enable() sequence triggers the cfg download.
8643 * The cfg download must occur before we update the SME config
8644 * since the SME config operation must access the cfg database
8645 */
8646 status = hdd_set_sme_config(hdd_ctx);
8647
8648 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008649 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008650 ret = qdf_status_to_os_return(status);
8651 goto out;
8652 }
8653
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008654 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8655 if (QDF_STATUS_SUCCESS != status) {
8656 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8657 ret = qdf_status_to_os_return(status);
8658 goto out;
8659 }
8660
Naveen Rawat247a8682017-06-05 15:00:31 -07008661 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008662 hdd_ctx->config->tx_chain_mask_1ss,
8663 PDEV_CMD);
8664 if (0 != ret) {
8665 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8666 goto out;
8667 }
8668
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008669 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8670 if (ret)
8671 goto out;
8672
8673 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8674 if (ret)
8675 goto out;
8676
Jeff Johnson12a744b2017-04-04 08:19:37 -07008677 ret = hdd_set_ani_enabled(hdd_ctx);
8678 if (ret)
8679 goto out;
8680
Naveen Rawat247a8682017-06-05 15:00:31 -07008681 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008682 hdd_ctx->config->arp_ac_category,
8683 PDEV_CMD);
8684 if (0 != ret) {
8685 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8686 hdd_ctx->config->arp_ac_category, ret);
8687 goto out;
8688 }
8689
8690
Prashanth Bhatta07998752016-04-28 12:35:33 -07008691 status = hdd_set_sme_chan_list(hdd_ctx);
8692 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008693 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008694 ret = qdf_status_to_os_return(status);
8695 goto out;
8696 }
8697
8698 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008699 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008700 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008701 ret = -EINVAL;
8702 goto out;
8703 }
8704
Prashanth Bhatta07998752016-04-28 12:35:33 -07008705 /*
8706 * Set the MAC Address Currently this is used by HAL to add self sta.
8707 * Remove this once self sta is added as part of session open.
8708 */
8709 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8710 hdd_ctx->config->intfMacAddr[0].bytes,
8711 sizeof(hdd_ctx->config->intfMacAddr[0]));
8712
8713 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8714 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8715 hal_status, hal_status);
8716 ret = -EINVAL;
8717 goto out;
8718 }
8719
8720 hdd_init_channel_avoidance(hdd_ctx);
8721
8722out:
8723 return ret;
8724}
8725
8726/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008727 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8728 * @context_ptr - hdd context pointer
8729 * @event_ptr - event structure pointer
8730 *
8731 * This is the p2p listen offload stop event handler, it sends vendor
8732 * event back to supplicant to notify the stop reason.
8733 *
8734 * Return: None
8735 */
8736static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8737 void *event_ptr)
8738{
8739 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8740 struct sir_p2p_lo_event *evt = event_ptr;
8741 struct sk_buff *vendor_event;
Peng Xu5c682812017-08-06 07:39:13 -07008742 hdd_adapter_t *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008743
8744 ENTER();
8745
8746 if (hdd_ctx == NULL) {
8747 hdd_err("Invalid HDD context pointer");
8748 return;
8749 }
8750
Peng Xu5c682812017-08-06 07:39:13 -07008751 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8752 if (!adapter) {
8753 hdd_err("Cannot find adapter by vdev_id = %d",
8754 evt->vdev_id);
8755 return;
8756 }
8757
Peng Xu8fdaa492016-06-22 10:20:47 -07008758 vendor_event =
8759 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008760 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008761 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8762 GFP_KERNEL);
8763
8764 if (!vendor_event) {
8765 hdd_err("cfg80211_vendor_event_alloc failed");
8766 return;
8767 }
8768
8769 if (nla_put_u32(vendor_event,
8770 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8771 evt->reason_code)) {
8772 hdd_err("nla put failed");
8773 kfree_skb(vendor_event);
8774 return;
8775 }
8776
8777 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008778 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8779 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008780}
8781
8782/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308783 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8784 * @hdd_ctx: HDD context
8785 *
8786 * This function sends the adaptive dwell time config configuration to the
8787 * firmware via WMA
8788 *
8789 * Return: 0 - success, < 0 - failure
8790 */
8791static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8792{
8793 QDF_STATUS status;
8794 struct adaptive_dwelltime_params dwelltime_params;
8795
8796 dwelltime_params.is_enabled =
8797 hdd_ctx->config->adaptive_dwell_mode_enabled;
8798 dwelltime_params.dwelltime_mode =
8799 hdd_ctx->config->global_adapt_dwelltime_mode;
8800 dwelltime_params.lpf_weight =
8801 hdd_ctx->config->adapt_dwell_lpf_weight;
8802 dwelltime_params.passive_mon_intval =
8803 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8804 dwelltime_params.wifi_act_threshold =
8805 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8806
8807 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8808 &dwelltime_params);
8809
8810 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8811 if (!QDF_IS_STATUS_SUCCESS(status)) {
8812 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8813 return -EAGAIN;
8814 }
8815 return 0;
8816}
8817
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308818int hdd_dbs_scan_selection_init(hdd_context_t *hdd_ctx)
8819{
8820 QDF_STATUS status;
8821 struct wmi_dbs_scan_sel_params dbs_scan_params;
8822 uint32_t i = 0;
8823 uint8_t count = 0, numentries = 0;
8824 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8825 * CDS_DBS_SCAN_CLIENTS_MAX];
8826
8827 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008828 if (hdd_ctx->config->dual_mac_feature_disable ==
8829 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308830 return -EINVAL;
8831
8832 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8833 dbs_scan_config, &numentries,
8834 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8835 * CDS_DBS_SCAN_CLIENTS_MAX));
8836
8837 hdd_info("numentries %hu", numentries);
8838 if (!numentries) {
8839 hdd_info("Donot send scan_selection_config");
8840 return 0;
8841 }
8842
8843 /* hdd_set_fw_log_params */
8844 dbs_scan_params.num_clients = 0;
8845 while (count < (numentries - 2)) {
8846 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8847 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8848 dbs_scan_params.num_non_dbs_scans[i] =
8849 dbs_scan_config[count + 2];
8850 dbs_scan_params.num_clients++;
8851 hdd_debug("module:%d NDS:%d NNDS:%d",
8852 dbs_scan_params.module_id[i],
8853 dbs_scan_params.num_dbs_scans[i],
8854 dbs_scan_params.num_non_dbs_scans[i]);
8855 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8856 i++;
8857 }
8858
8859 dbs_scan_params.pdev_id = 0;
8860
8861 hdd_debug("clients:%d pdev:%d",
8862 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
8863
8864 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
8865 &dbs_scan_params);
8866 hdd_debug("Sending DBS Scan Selection Configuration to fw");
8867 if (!QDF_IS_STATUS_SUCCESS(status)) {
8868 hdd_err("Failed to send DBS Scan selection configuration!");
8869 return -EAGAIN;
8870 }
8871 return 0;
8872}
8873
Arun Khandavallid4349a92016-07-25 11:10:43 +05308874#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8875/**
8876 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8877 * @hdd_ctx: HDD context
8878 *
8879 * Set auto shutdown callback to get indications from firmware to indicate
8880 * userspace to shutdown WLAN after a configured amount of inactivity.
8881 *
8882 * Return: 0 on success and errno on failure.
8883 */
8884static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8885{
8886 QDF_STATUS status;
8887
8888 if (!hdd_ctx->config->WlanAutoShutdown)
8889 return 0;
8890
8891 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8892 wlan_hdd_auto_shutdown_cb);
8893 if (status != QDF_STATUS_SUCCESS)
8894 hdd_err("Auto shutdown feature could not be enabled: %d",
8895 status);
8896
8897 return qdf_status_to_os_return(status);
8898}
8899#else
8900static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8901{
8902 return 0;
8903}
8904#endif
8905
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008906static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(hdd_context_t *hdd_ctx)
8907{
8908 QDF_STATUS status = QDF_STATUS_SUCCESS;
8909
8910 switch (hdd_ctx->config->dual_mac_feature_disable) {
8911 case DISABLE_DBS_CXN_AND_SCAN:
8912 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
8913 if (status != QDF_STATUS_SUCCESS)
8914 hdd_err("Failed to disable dual mac features");
8915 break;
8916 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
8917 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
8918 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
8919 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
8920 if (status != QDF_STATUS_SUCCESS)
8921 hdd_err("Failed to set dbs scan and fw mode config");
8922 break;
8923 default:
8924 break;
8925 }
8926
8927 return status;
8928}
8929
Arun Khandavallid4349a92016-07-25 11:10:43 +05308930/**
8931 * hdd_features_init() - Init features
8932 * @hdd_ctx: HDD context
8933 * @adapter: Primary adapter context
8934 *
8935 * Initialize features and their feature context after WLAN firmware is up.
8936 *
8937 * Return: 0 on success and errno on failure.
8938 */
8939static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8940{
8941 tSirTxPowerLimit hddtxlimit;
8942 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05308943 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05308944 int ret;
8945
8946 ENTER();
8947
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008948 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308949 if (ret) {
8950 hdd_err("Failed to update country code: %d", ret);
8951 goto out;
8952 }
8953
8954 /* FW capabilities received, Set the Dot11 mode */
8955 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008956 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8957 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308958
Arun Khandavallid4349a92016-07-25 11:10:43 +05308959
8960 if (hdd_ctx->config->fIsImpsEnabled)
8961 hdd_set_idle_ps_config(hdd_ctx, true);
8962 else
8963 hdd_set_idle_ps_config(hdd_ctx, false);
8964
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308965 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008966 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308967
Arun Khandavallid4349a92016-07-25 11:10:43 +05308968 if (hdd_lro_init(hdd_ctx))
8969 hdd_err("Unable to initialize LRO in fw");
8970
8971 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8972 hdd_err("Unable to send adaptive dwelltime setting to FW");
8973
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308974 if (hdd_dbs_scan_selection_init(hdd_ctx))
8975 hdd_err("Unable to send DBS scan selection setting to FW");
8976
Arun Khandavallid4349a92016-07-25 11:10:43 +05308977 ret = hdd_init_thermal_info(hdd_ctx);
8978 if (ret) {
8979 hdd_err("Error while initializing thermal information");
8980 goto deregister_frames;
8981 }
8982
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308983 if (cds_is_packet_log_enabled())
8984 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8985
Arun Khandavallid4349a92016-07-25 11:10:43 +05308986 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
8987 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
8988 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
8989 if (!QDF_IS_STATUS_SUCCESS(status))
8990 hdd_err("Error setting txlimit in sme: %d", status);
8991
Yu Wangf5d5b5f2017-05-25 22:38:32 +08008992 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308993
Arun Khandavallid4349a92016-07-25 11:10:43 +05308994 ret = hdd_register_cb(hdd_ctx);
8995 if (ret) {
8996 hdd_err("Failed to register HDD callbacks!");
8997 goto deregister_frames;
8998 }
8999
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009000 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9001 if (!QDF_IS_STATUS_SUCCESS(status)) {
9002 hdd_err("Failed to set dbs scan and fw mode cfg");
9003 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309004 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009005
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309006 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9007 status = sme_enable_disable_chanavoidind_event(
9008 hdd_ctx->hHal, 0);
9009 if (!QDF_IS_STATUS_SUCCESS(status)) {
9010 hdd_err("Failed to disable Chan Avoidance Indication");
9011 goto deregister_cb;
9012 }
9013 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309014
Manjeet Singha9cae432017-02-28 11:58:22 +05309015 if (hdd_ctx->config->enable_5g_band_pref) {
9016 band_pref_params.rssi_boost_threshold_5g =
9017 hdd_ctx->config->rssi_boost_threshold_5g;
9018 band_pref_params.rssi_boost_factor_5g =
9019 hdd_ctx->config->rssi_boost_factor_5g;
9020 band_pref_params.max_rssi_boost_5g =
9021 hdd_ctx->config->max_rssi_boost_5g;
9022 band_pref_params.rssi_penalize_threshold_5g =
9023 hdd_ctx->config->rssi_penalize_threshold_5g;
9024 band_pref_params.rssi_penalize_factor_5g =
9025 hdd_ctx->config->rssi_penalize_factor_5g;
9026 band_pref_params.max_rssi_penalize_5g =
9027 hdd_ctx->config->max_rssi_penalize_5g;
9028 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9029 }
9030
Arun Khandavallid4349a92016-07-25 11:10:43 +05309031 /* register P2P Listen Offload event callback */
9032 if (wma_is_p2p_lo_capable())
9033 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9034 wlan_hdd_p2p_lo_event_callback);
9035
9036 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9037
9038 if (ret)
9039 goto deregister_cb;
9040
9041 EXIT();
9042 return 0;
9043
9044deregister_cb:
9045 hdd_deregister_cb(hdd_ctx);
9046deregister_frames:
9047 wlan_hdd_cfg80211_deregister_frames(adapter);
9048out:
9049 return -EINVAL;
9050
9051}
9052
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009053/**
9054 * hdd_features_deinit() - Deinit features
9055 * @hdd_ctx: HDD context
9056 *
9057 * De-Initialize features and their feature context.
9058 *
9059 * Return: none.
9060 */
9061static void hdd_features_deinit(hdd_context_t *hdd_ctx)
9062{
9063 wlan_hdd_tsf_deinit(hdd_ctx);
9064}
9065
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309066/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009067 * hdd_register_bcn_cb() - register scan beacon callback
9068 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309069 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009070 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309071 */
9072static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
9073{
9074 QDF_STATUS status;
9075
9076 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9077 wlan_cfg80211_inform_bss_frame,
9078 SCAN_CB_TYPE_INFORM_BCN);
9079 if (!QDF_IS_STATUS_SUCCESS(status)) {
9080 hdd_err("failed with status code %08d [x%08x]",
9081 status, status);
9082 return status;
9083 }
9084
9085 return QDF_STATUS_SUCCESS;
9086}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309087
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309088/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309089 * hdd_configure_cds() - Configure cds modules
9090 * @hdd_ctx: HDD context
9091 * @adapter: Primary adapter context
9092 *
9093 * Enable Cds modules after WLAN firmware is up.
9094 *
9095 * Return: 0 on success and errno on failure.
9096 */
9097int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
9098{
9099 int ret;
9100 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309101
9102 ret = hdd_pre_enable_configure(hdd_ctx);
9103 if (ret) {
9104 hdd_err("Failed to pre-configure cds");
9105 goto out;
9106 }
9107
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009108 /* Always get latest IPA resources allocated from cds_open and configure
9109 * IPA module before configuring them to FW. Sequence required as crash
9110 * observed otherwise.
9111 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009112 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9113 hdd_err("Failed to setup pipes");
9114 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009115 }
9116
Arun Khandavallifae92942016-08-01 13:31:08 +05309117 /*
9118 * Start CDS which starts up the SME/MAC/HAL modules and everything
9119 * else
9120 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309121 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309122
9123 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009124 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309125 goto out;
9126 }
9127
9128 status = hdd_post_cds_enable_config(hdd_ctx);
9129 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009130 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009131 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309132 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309133 status = hdd_register_bcn_cb(hdd_ctx);
9134 if (!QDF_IS_STATUS_SUCCESS(status)) {
9135 hdd_alert("hdd_post_cds_enable_config failed");
9136 goto cds_disable;
9137 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309138
9139 ret = hdd_features_init(hdd_ctx, adapter);
9140 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009141 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309142
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309143 if (hdd_enable_egap(hdd_ctx))
9144 hdd_debug("enhance green ap is not enabled");
9145
Nachiket Kukadedd302662017-07-13 17:31:44 +05309146 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9147 hdd_debug("Failed to set wow pulse");
9148
Arun Khandavallifae92942016-08-01 13:31:08 +05309149 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009150
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009151cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309152 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009153
Arun Khandavallifae92942016-08-01 13:31:08 +05309154out:
9155 return -EINVAL;
9156}
9157
9158/**
9159 * hdd_deconfigure_cds() -De-Configure cds
9160 * @hdd_ctx: HDD context
9161 *
9162 * Deconfigure Cds modules before WLAN firmware is down.
9163 *
9164 * Return: 0 on success and errno on failure.
9165 */
Jeff Johnson590e2012016-10-05 16:16:24 -07009166static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309167{
9168 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009169 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309170
9171 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009172
9173 /* De-init features */
9174 hdd_features_deinit(hdd_ctx);
9175
Arun Khandavallifae92942016-08-01 13:31:08 +05309176 /* De-register the SME callbacks */
9177 hdd_deregister_cb(hdd_ctx);
9178
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309179 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309180 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9181 hdd_err("Failed to Disable the CDS Modules! :%d",
9182 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009183 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309184 }
9185
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309186 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9187 hdd_err("Failed to disconnect pipes");
9188 ret = -EINVAL;
9189 }
9190
Arun Khandavallifae92942016-08-01 13:31:08 +05309191 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009192 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309193}
9194
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009195#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9196static void hdd_deregister_policy_manager_callback(
9197 struct wlan_objmgr_psoc *psoc)
9198{
9199 if (QDF_STATUS_SUCCESS !=
9200 policy_mgr_deregister_hdd_cb(psoc)) {
9201 hdd_err("HDD callback deregister with policy manager failed");
9202 }
9203}
9204#else
9205static void hdd_deregister_policy_manager_callback(
9206 struct wlan_objmgr_psoc *psoc)
9207{
9208}
9209#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309210
9211/**
9212 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9213 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009214 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309215 *
9216 * This function maintains the driver state machine it will be invoked from
9217 * exit, shutdown and con_mode change handler. Depending on the driver state
9218 * shall perform the stopping/closing of the modules.
9219 *
9220 * Return: 0 for success; non-zero for failure
9221 */
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009222int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309223{
9224 void *hif_ctx;
9225 qdf_device_t qdf_ctx;
9226 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309227 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009228 bool is_idle_stop = !cds_is_driver_unloading() &&
9229 !cds_is_driver_recovering();
9230 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309231
9232 ENTER();
9233
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009234 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9235
Arun Khandavallifae92942016-08-01 13:31:08 +05309236 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9237 if (!qdf_ctx) {
9238 hdd_err("QDF device context NULL");
9239 return -EINVAL;
9240 }
9241
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309242 mutex_lock(&hdd_ctx->iface_change_lock);
9243 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309244
Dustin Brown70111822017-03-30 15:31:40 -07009245 active_threads = cds_return_external_threads_count();
9246 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009247 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009248 active_threads, hdd_ctx->isWiphySuspended);
9249
9250 cds_print_external_threads();
9251
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009252 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009253 mutex_unlock(&hdd_ctx->iface_change_lock);
9254 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009255 hdd_ctx->config->iface_change_wait_time);
9256 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009257 return 0;
9258 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009259 }
9260
Arun Khandavallifae92942016-08-01 13:31:08 +05309261 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9262
9263 switch (hdd_ctx->driver_status) {
9264 case DRIVER_MODULES_UNINITIALIZED:
9265 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309266 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309267 case DRIVER_MODULES_CLOSED:
9268 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309269 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309270 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309271 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309272 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009273 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309274 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309275 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309276 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009277 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309278 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9279 break;
9280 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009281 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309282 break;
9283 default:
9284 hdd_err("Trying to stop wlan in a wrong state: %d",
9285 hdd_ctx->driver_status);
9286 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309287 ret = -EINVAL;
9288 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309289 }
9290
Rajeev Kumarbe021242017-02-16 16:12:23 -08009291 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309292 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9293 hdd_err("Failed to process post CDS disable Modules! :%d",
9294 qdf_status);
9295 ret = -EINVAL;
9296 QDF_ASSERT(0);
9297 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309298 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309299 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009300 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309301 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309302 QDF_ASSERT(0);
9303 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009304
Arun Khandavallifae92942016-08-01 13:31:08 +05309305 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9306 if (!hif_ctx) {
9307 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309308 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309309 }
9310
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309311 hdd_runtime_suspend_context_deinit(hdd_ctx);
9312
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309313 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309314
9315 ol_cds_free();
9316
Dustin Brown70111822017-03-30 15:31:40 -07009317 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309318 ret = pld_power_off(qdf_ctx->dev);
9319 if (ret)
9320 hdd_err("CNSS power down failed put device into Low power mode:%d",
9321 ret);
9322 }
9323 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009324 /*
9325 * Reset total mac phy during module stop such that during
9326 * next module start same psoc is used to populate new service
9327 * ready data
9328 */
9329 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309330
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309331done:
9332 hdd_ctx->stop_modules_in_progress = false;
9333 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309334 EXIT();
9335
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309336 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309337
9338}
9339
9340/**
9341 * hdd_iface_change_callback() - Function invoked when stop modules expires
9342 * @priv: pointer to hdd context
9343 *
9344 * This function is invoked when the timer waiting for the interface change
9345 * expires, it shall cut-down the power to wlan and stop all the modules.
9346 *
9347 * Return: void
9348 */
9349static void hdd_iface_change_callback(void *priv)
9350{
9351 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
9352 int ret;
9353 int status = wlan_hdd_validate_context(hdd_ctx);
9354
9355 if (status)
9356 return;
9357
9358 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009359 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009360 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309361 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009362 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309363 EXIT();
9364}
9365
9366/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309367 * hdd_state_info_dump() - prints state information of hdd layer
9368 * @buf: buffer pointer
9369 * @size: size of buffer to be filled
9370 *
9371 * This function is used to dump state information of hdd layer
9372 *
9373 * Return: None
9374 */
9375static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9376{
9377 hdd_context_t *hdd_ctx;
9378 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9379 QDF_STATUS status;
9380 hdd_station_ctx_t *hdd_sta_ctx;
9381 hdd_adapter_t *adapter;
9382 uint16_t len = 0;
9383 char *buf = *buf_ptr;
9384
9385 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9386 if (!hdd_ctx) {
9387 hdd_err("Failed to get hdd context ");
9388 return;
9389 }
9390
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009391 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309392
9393 len += scnprintf(buf + len, *size - len,
9394 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9395 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009396 "\n is_scheduler_suspended %d",
9397 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309398
9399 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9400
9401 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9402 adapter = adapter_node->pAdapter;
9403 if (adapter->dev)
9404 len += scnprintf(buf + len, *size - len,
9405 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009406 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309407 "\n device_mode: %d", adapter->device_mode);
9408 switch (adapter->device_mode) {
9409 case QDF_STA_MODE:
9410 case QDF_P2P_CLIENT_MODE:
9411 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9412 len += scnprintf(buf + len, *size - len,
9413 "\n connState: %d",
9414 hdd_sta_ctx->conn_info.connState);
9415 break;
9416
9417 default:
9418 break;
9419 }
9420 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9421 adapter_node = next;
9422 }
9423
9424 *size -= len;
9425 *buf_ptr += len;
9426}
9427
9428/**
9429 * hdd_register_debug_callback() - registration function for hdd layer
9430 * to print hdd state information
9431 *
9432 * Return: None
9433 */
9434static void hdd_register_debug_callback(void)
9435{
9436 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9437}
9438
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309439/*
9440 * wlan_init_bug_report_lock() - Initialize bug report lock
9441 *
9442 * This function is used to create bug report lock
9443 *
9444 * Return: None
9445 */
9446static void wlan_init_bug_report_lock(void)
9447{
9448 p_cds_contextType p_cds_context;
9449
9450 p_cds_context = cds_get_global_context();
9451 if (!p_cds_context) {
9452 hdd_err("cds context is NULL");
9453 return;
9454 }
9455
9456 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9457}
9458
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309459/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009460 * hdd_wlan_startup() - HDD init function
9461 * @dev: Pointer to the underlying device
9462 *
9463 * This is the driver startup code executed once a WLAN device has been detected
9464 *
9465 * Return: 0 for success, < 0 for failure
9466 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309467int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009468{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309469 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08009470 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009471 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009472 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309473 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009474 uint32_t num_abg_tx_chains = 0;
9475 uint32_t num_11b_tx_chains = 0;
9476 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009477
9478 ENTER();
9479
Arun Khandavallifae92942016-08-01 13:31:08 +05309480 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009481
9482 if (IS_ERR(hdd_ctx))
9483 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009484
Abhishek Singhe9068f12017-03-31 14:14:52 +05309485 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9486 DEFAULT_PSOC_ID);
9487 if (ret) {
9488 hdd_err("Psoc creation fails!");
9489 QDF_BUG(0);
9490 goto err_hdd_free_context;
9491 }
9492
Arun Khandavallifae92942016-08-01 13:31:08 +05309493 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9494 hdd_iface_change_callback, (void *)hdd_ctx);
9495
9496 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309497#ifdef FEATURE_WLAN_CH_AVOID
9498 mutex_init(&hdd_ctx->avoid_freq_lock);
9499#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309500
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009501 ret = hdd_init_netlink_services(hdd_ctx);
9502 if (ret)
Dustin Brown20912462017-06-07 13:48:25 -07009503 goto err_hdd_free_psoc;
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009504
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009505 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009506 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309507
Jeff Johnson957bc272017-02-02 08:54:48 -08009508 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309509 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009510 hdd_err("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009511 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009512 }
9513
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309514 wlan_init_bug_report_lock();
9515
Yingying Tang80e15f32016-09-27 18:23:01 +08009516 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009517
Anurag Chouhan6d760662016-02-20 16:05:43 +05309518 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009519
9520 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009521 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309522 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009523 }
9524
Prashanth Bhatta07998752016-04-28 12:35:33 -07009525 ret = hdd_wiphy_init(hdd_ctx);
9526 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009527 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309528 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009529 }
9530
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309531 if (hdd_ctx->config->enable_dp_trace)
9532 qdf_dp_trace_init();
9533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309534 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009535 goto err_wiphy_unregister;
9536
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309537 wlan_hdd_init_chan_info(hdd_ctx);
9538
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009539 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009540
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009541 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009542
Jeff Johnson957bc272017-02-02 08:54:48 -08009543 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9544 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009545 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009546 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009547 }
9548
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009549 hdd_release_rtnl_lock();
9550 rtnl_held = false;
9551
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009552 wlan_hdd_update_11n_mode(hdd_ctx->config);
9553
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009554#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309555 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309556 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009557 hdd_skip_acs_scan_timer_handler,
9558 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309559 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009560 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009561 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009562#endif
9563
Nitesh Shah61c10d92016-10-19 19:29:15 +05309564 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9565 QDF_TIMER_TYPE_SW,
9566 wlan_hdd_change_tdls_mode,
9567 hdd_ctx);
9568
Prashanth Bhattaab004382016-10-11 16:08:11 -07009569 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009570
Jeff Johnson9afc5012016-09-23 13:56:27 -07009571 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009572
Nirav Shahbd36b062016-07-18 11:12:59 +05309573 if (hdd_ctx->rps)
9574 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009575
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009576 ret = hdd_register_notifiers(hdd_ctx);
9577 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009578 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309579
9580 status = wlansap_global_init();
9581 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009582 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009583
Komal Seelam8634b772016-09-29 12:12:24 +05309584 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009585 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309586 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009587
Arun Khandavallifae92942016-08-01 13:31:08 +05309588 if (hdd_ctx->config->fIsImpsEnabled)
9589 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309590
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309591 if (hdd_ctx->config->sifs_burst_duration) {
9592 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9593 hdd_ctx->config->sifs_burst_duration;
9594
9595 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009596 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309597 set_value, PDEV_CMD);
9598 }
9599
Paul Zhang42dade02017-05-12 19:20:37 +08009600 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009601 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009602 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309603 /* set chip power save failure detected callback */
9604 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9605 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009606
lifeng959a04c2017-05-10 14:21:28 +08009607 if (hdd_ctx->config->max_mpdus_inampdu) {
9608 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009609 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009610 set_value, PDEV_CMD);
9611 }
9612
9613 if (hdd_ctx->config->enable_rts_sifsbursting) {
9614 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009615 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009616 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9617 set_value, PDEV_CMD);
9618 }
9619
Naveen Rawat247a8682017-06-05 15:00:31 -07009620 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9621 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9622 if (!hdd_ctx->config->enable2x2) {
9623 if (num_11b_tx_chains > 1)
9624 num_11b_tx_chains = 1;
9625 if (num_11ag_tx_chains > 1)
9626 num_11ag_tx_chains = 1;
9627 }
9628 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9629 num_11b_tx_chains);
9630 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9631 num_11ag_tx_chains);
9632 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9633 num_abg_tx_chains, PDEV_CMD);
9634
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309635 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9636 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309637 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309638
Sachin Ahujadddd2632017-03-07 19:07:24 +05309639 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009640 goto success;
9641
Jeff Johnson957bc272017-02-02 08:54:48 -08009642err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009643 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009644
Jeff Johnson46bde382017-02-01 15:31:16 -08009645err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309646 if (rtnl_held)
9647 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009648
Anurag Chouhance6a4052016-09-14 18:20:42 +05309649 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009651err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009652 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009653
Arun Khandavallifae92942016-08-01 13:31:08 +05309654err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009655 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309656
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05309657err_exit_nl_srv:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309658 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
9659 status = cds_sched_close(hdd_ctx->pcds_context);
9660 if (!QDF_IS_STATUS_SUCCESS(status)) {
9661 hdd_err("Failed to close CDS Scheduler");
9662 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9663 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009664 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009665
Houston Hoffman47a4a052016-11-14 23:22:44 -08009666 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009667 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009668 hdd_exit_netlink_services(hdd_ctx);
9669
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309670 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009671
9672err_hdd_free_psoc:
9673 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9674
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009675err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309676 if (cds_is_fw_down())
9677 hdd_err("Not setting the complete event as fw is down");
9678 else
9679 hdd_start_complete(ret);
9680
Arun Khandavallifae92942016-08-01 13:31:08 +05309681 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9682 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009683 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009684 return -EIO;
9685
9686success:
9687 EXIT();
9688 return 0;
9689}
9690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009691/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309692 * hdd_wlan_update_target_info() - update target type info
9693 * @hdd_ctx: HDD context
9694 * @context: hif context
9695 *
9696 * Update target info received from firmware in hdd context
9697 * Return:None
9698 */
9699
9700void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
9701{
9702 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9703
9704 if (!tgt_info) {
9705 hdd_err("Target info is Null");
9706 return;
9707 }
9708
9709 hdd_ctx->target_type = tgt_info->target_type;
9710}
9711
9712/**
9713 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309714 * @hdd_ctx: HDD context
9715 *
9716 * Register the HDD callbacks to CDS/SME.
9717 *
9718 * Return: 0 for success or Error code for failure
9719 */
9720int hdd_register_cb(hdd_context_t *hdd_ctx)
9721{
9722 QDF_STATUS status;
9723 int ret = 0;
9724
9725 ENTER();
9726
9727 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9728
9729 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9730 hdd_send_oem_data_rsp_msg);
9731
9732 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9733 wlan_hdd_cfg80211_fw_mem_dump_cb);
9734 if (!QDF_IS_STATUS_SUCCESS(status)) {
9735 hdd_err("Failed to register memdump callback");
9736 ret = -EINVAL;
9737 return ret;
9738 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309739 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9740 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309741 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9742 sme_nan_register_callback(hdd_ctx->hHal,
9743 wlan_hdd_cfg80211_nan_callback);
9744 sme_stats_ext_register_callback(hdd_ctx->hHal,
9745 wlan_hdd_cfg80211_stats_ext_callback);
9746
9747 sme_ext_scan_register_callback(hdd_ctx->hHal,
9748 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009749 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9750 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309751
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309752 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9753 hdd_rssi_threshold_breached);
9754
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309755 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9756 wlan_hdd_cfg80211_link_layer_stats_callback);
9757
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309758 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9759
Zhang Qianca38fb12016-12-23 11:10:48 +08009760 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9761 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9762
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309763 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9764 hdd_lost_link_info_cb);
9765 /* print error and not block the startup process */
9766 if (!QDF_IS_STATUS_SUCCESS(status))
9767 hdd_err("set lost link info callback failed");
9768
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309769 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9770
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009771 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009772 hdd_set_connection_in_progress,
9773 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309774
9775 status = sme_congestion_register_callback(hdd_ctx->hHal,
9776 hdd_update_cca_info_cb);
9777 if (!QDF_IS_STATUS_SUCCESS(status))
9778 hdd_err("set congestion callback failed");
9779
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +05309780 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
9781 hdd_bt_activity_cb);
9782 if (!QDF_IS_STATUS_SUCCESS(status))
9783 hdd_err("set bt activity info callback failed");
9784
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309785 EXIT();
9786
9787 return ret;
9788}
9789
9790/**
9791 * hdd_deregister_cb() - De-Register HDD callbacks.
9792 * @hdd_ctx: HDD context
9793 *
9794 * De-Register the HDD callbacks to CDS/SME.
9795 *
9796 * Return: void
9797 */
9798void hdd_deregister_cb(hdd_context_t *hdd_ctx)
9799{
9800 QDF_STATUS status;
9801
9802 ENTER();
9803
9804 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9805 if (!QDF_IS_STATUS_SUCCESS(status))
9806 hdd_err("De-register of dcc stats callback failed: %d",
9807 status);
9808
9809 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309810 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9811
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309812 sme_stats_ext_register_callback(hdd_ctx->hHal,
9813 wlan_hdd_cfg80211_stats_ext_callback);
9814
9815 sme_nan_deregister_callback(hdd_ctx->hHal);
9816 status = sme_reset_tsfcb(hdd_ctx->hHal);
9817 if (!QDF_IS_STATUS_SUCCESS(status))
9818 hdd_err("Failed to de-register tsfcb the callback:%d",
9819 status);
9820 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9821 if (!QDF_IS_STATUS_SUCCESS(status))
9822 hdd_err("Failed to de-register the fw mem dump callback: %d",
9823 status);
9824
9825 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9826 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9827
9828 EXIT();
9829}
9830
9831/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009832 * hdd_softap_sta_deauth() - handle deauth req from HDD
9833 * @adapter: Pointer to the HDD
9834 * @enable: bool value
9835 *
9836 * This to take counter measure to handle deauth req from HDD
9837 *
9838 * Return: None
9839 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309840QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009841 struct tagCsrDelStaParams *pDelStaParams)
9842{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309843 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009844
9845 ENTER();
9846
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009847 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009848 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9849
9850 /* Ignore request to deauth bcmc station */
9851 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309852 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009853
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309854 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9856 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009857
9858 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309859 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009860}
9861
9862/**
9863 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
9864 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309865 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009866 *
9867 * This to take counter measure to handle deauth req from HDD
9868 *
9869 * Return: None
9870 */
9871void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309872 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009873{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009874 ENTER();
9875
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009876 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009877 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9878
9879 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309880 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009881 return;
9882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009883 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309884 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009885}
9886
9887void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9888 bool enable)
9889{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009890 ENTER();
9891
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009892 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009893 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009895 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9896 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009897}
9898
9899/**
9900 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9901 * @hdd_ctx: HDD Context
9902 *
9903 * API to find if there is any STA or P2P-Client is connected
9904 *
9905 * Return: true if connected; false otherwise
9906 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309907QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009908{
9909 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9910}
9911
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009912/**
9913 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9914 * @adapter: HDD adapter pointer
9915 *
9916 * This function loop through each adapter and disable roaming on each STA
9917 * device mode except the input adapter.
9918 *
9919 * Note: On the input adapter roaming is not enabled yet hence no need to
9920 * disable.
9921 *
9922 * Return: None
9923 */
9924void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9925{
9926 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9927 hdd_adapter_t *adapterIdx = NULL;
9928 hdd_adapter_list_node_t *adapterNode = NULL;
9929 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309930 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009931
9932 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009933 hdd_ctx->config->isRoamOffloadScanEnabled &&
9934 QDF_STA_MODE == adapter->device_mode &&
9935 policy_mgr_is_sta_active_connection_exists(
9936 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009937 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009938 adapter->sessionId);
9939 /*
9940 * Loop through adapter and disable roaming for each STA device
9941 * mode except the input adapter.
9942 */
9943 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9944
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309945 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009946 adapterIdx = adapterNode->pAdapter;
9947
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009948 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009949 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009950 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009951 adapterIdx->sessionId);
9952 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9953 (adapterIdx),
9954 adapterIdx->sessionId, 0);
9955 }
9956
9957 status = hdd_get_next_adapter(hdd_ctx,
9958 adapterNode,
9959 &pNext);
9960 adapterNode = pNext;
9961 }
9962 }
9963}
9964
9965/**
9966 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9967 * @adapter: HDD adapter pointer
9968 *
9969 * This function loop through each adapter and enable roaming on each STA
9970 * device mode except the input adapter.
9971 * Note: On the input adapter no need to enable roaming because link got
9972 * disconnected on this.
9973 *
9974 * Return: None
9975 */
9976void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
9977{
9978 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9979 hdd_adapter_t *adapterIdx = NULL;
9980 hdd_adapter_list_node_t *adapterNode = NULL;
9981 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309982 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009983
9984 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009985 hdd_ctx->config->isRoamOffloadScanEnabled &&
9986 QDF_STA_MODE == adapter->device_mode &&
9987 policy_mgr_is_sta_active_connection_exists(
9988 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009989 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009990 adapter->sessionId);
9991 /*
9992 * Loop through adapter and enable roaming for each STA device
9993 * mode except the input adapter.
9994 */
9995 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9996
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309997 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009998 adapterIdx = adapterNode->pAdapter;
9999
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010000 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010001 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010002 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010003 adapterIdx->sessionId);
10004 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10005 (adapterIdx),
10006 adapterIdx->sessionId,
10007 REASON_CONNECT);
10008 }
10009
10010 status = hdd_get_next_adapter(hdd_ctx,
10011 adapterNode,
10012 &pNext);
10013 adapterNode = pNext;
10014 }
10015 }
10016}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010017
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010018/**
10019 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10020 * @skb: sk buffer pointer
10021 *
10022 * Sends the bcast message to SVC multicast group with generic nl socket
10023 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10024 *
10025 * Return: None
10026 */
10027static void nl_srv_bcast_svc(struct sk_buff *skb)
10028{
10029#ifdef CNSS_GENL
10030 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10031#else
10032 nl_srv_bcast(skb);
10033#endif
10034}
10035
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010036void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010037{
10038 struct sk_buff *skb;
10039 struct nlmsghdr *nlh;
10040 tAniMsgHdr *ani_hdr;
10041 void *nl_data = NULL;
10042 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010043 struct radio_index_tlv *radio_info;
10044 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010045
10046 if (in_interrupt() || irqs_disabled() || in_atomic())
10047 flags = GFP_ATOMIC;
10048
10049 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10050
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010051 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010052 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010053
10054 nlh = (struct nlmsghdr *)skb->data;
10055 nlh->nlmsg_pid = 0; /* from kernel */
10056 nlh->nlmsg_flags = 0;
10057 nlh->nlmsg_seq = 0;
10058 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10059
10060 ani_hdr = NLMSG_DATA(nlh);
10061 ani_hdr->type = type;
10062
10063 switch (type) {
10064 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010065 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010066 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010067 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010068 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010069 ani_hdr->length = 0;
10070 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010071 break;
10072 case WLAN_SVC_WLAN_STATUS_IND:
10073 case WLAN_SVC_WLAN_VERSION_IND:
10074 case WLAN_SVC_DFS_CAC_START_IND:
10075 case WLAN_SVC_DFS_CAC_END_IND:
10076 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10077 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10078 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010079 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010080 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010081 ani_hdr->length = len;
10082 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10083 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10084 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010085 break;
10086
10087 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010088 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010089 type);
10090 kfree_skb(skb);
10091 return;
10092 }
10093
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010094 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010095 * Add radio index at the end of the svc event in TLV format
10096 * to maintain the backward compatibility with userspace
10097 * applications.
10098 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010099
10100 tlv_len = 0;
10101
10102 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10103 < WLAN_NL_MAX_PAYLOAD) {
10104 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10105 sizeof(*ani_hdr) + len);
10106 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10107 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10108 radio_info->radio = radio;
10109 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010110 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010111 "Added radio index tlv - radio index %d",
10112 radio_info->radio);
10113 }
10114
10115 nlh->nlmsg_len += tlv_len;
10116 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10117
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010118 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010119}
10120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10122void wlan_hdd_auto_shutdown_cb(void)
10123{
hque52fdd62017-06-05 11:27:44 +080010124 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010125
10126 if (!hdd_ctx)
10127 return;
10128
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010129 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010130 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10131 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010132}
10133
10134void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
10135{
10136 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010137 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010138 hdd_adapter_t *adapter;
10139 bool ap_connected = false, sta_connected = false;
10140 tHalHandle hal_handle;
10141
10142 hal_handle = hdd_ctx->hHal;
10143 if (hal_handle == NULL)
10144 return;
10145
10146 if (hdd_ctx->config->WlanAutoShutdown == 0)
10147 return;
10148
10149 if (enable == false) {
10150 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010151 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010152 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010153 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010154 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010155 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010156 return;
10157 }
10158
10159 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010160 if (policy_mgr_concurrent_open_sessions_running(
10161 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010162 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10163
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010164 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010165 adapter = adapterNode->pAdapter;
10166 if (adapter
10167 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010168 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010169 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10170 conn_info.connState ==
10171 eConnectionState_Associated) {
10172 sta_connected = true;
10173 break;
10174 }
10175 }
10176 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010177 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010178 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10179 bApActive == true) {
10180 ap_connected = true;
10181 break;
10182 }
10183 }
10184 status = hdd_get_next_adapter(hdd_ctx,
10185 adapterNode,
10186 &pNext);
10187 adapterNode = pNext;
10188 }
10189 }
10190
10191 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010192 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010193 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010194 }
Jeff Johnson68755312017-02-10 11:46:55 -080010195
10196 if (sme_set_auto_shutdown_timer(hal_handle,
10197 hdd_ctx->config->WlanAutoShutdown)
10198 != QDF_STATUS_SUCCESS)
10199 hdd_err("Failed to start wlan auto shutdown timer");
10200 else
10201 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10202 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010203}
10204#endif
10205
10206hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
10207 bool check_start_bss)
10208{
10209 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
10210 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010211 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010212 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10213
10214 con_sap_adapter = NULL;
10215
10216 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010217 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010218 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010219 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10220 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010221 adapter != this_sap_adapter) {
10222 if (check_start_bss) {
10223 if (test_bit(SOFTAP_BSS_STARTED,
10224 &adapter->event_flags)) {
10225 con_sap_adapter = adapter;
10226 break;
10227 }
10228 } else {
10229 con_sap_adapter = adapter;
10230 break;
10231 }
10232 }
10233 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10234 adapterNode = pNext;
10235 }
10236
10237 return con_sap_adapter;
10238}
10239
10240#ifdef MSM_PLATFORM
Dustin Brown5ec6b552017-03-31 12:11:40 -070010241static inline bool hdd_adapter_is_sta(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010242{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010243 return adapter->device_mode == QDF_STA_MODE ||
10244 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010245}
10246
Dustin Brown5ec6b552017-03-31 12:11:40 -070010247static inline bool hdd_adapter_is_ap(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010248{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010249 return adapter->device_mode == QDF_SAP_MODE ||
10250 adapter->device_mode == QDF_P2P_GO_MODE;
10251}
10252
10253static bool hdd_any_adapter_is_assoc(hdd_context_t *hdd_ctx)
10254{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010255 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010256 hdd_adapter_list_node_t *node;
10257
10258 status = hdd_get_front_adapter(hdd_ctx, &node);
10259 while (QDF_IS_STATUS_SUCCESS(status) && node) {
10260 hdd_adapter_t *adapter = node->pAdapter;
10261
10262 if (adapter &&
10263 hdd_adapter_is_sta(adapter) &&
10264 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10265 conn_info.connState == eConnectionState_Associated) {
10266 return true;
10267 }
10268
10269 if (adapter &&
10270 hdd_adapter_is_ap(adapter) &&
10271 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10272 return true;
10273 }
10274
10275 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10276 }
10277
10278 return false;
10279}
10280
10281static bool hdd_bus_bw_compute_timer_is_running(hdd_context_t *hdd_ctx)
10282{
10283 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010284
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010285 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010286 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010287 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010288
Dustin Brown5ec6b552017-03-31 12:11:40 -070010289 return is_running;
10290}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010291
Dustin Brown5ec6b552017-03-31 12:11:40 -070010292static void __hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10293{
10294 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10295 hdd_ctx->bus_bw_timer_running = true;
10296 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10297 hdd_ctx->config->busBandwidthComputeInterval);
10298 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10299}
10300
10301void hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10302{
10303 ENTER();
10304
10305 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10306 hdd_debug("Bandwidth compute timer already started");
10307 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010308 }
10309
Dustin Brown5ec6b552017-03-31 12:11:40 -070010310 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10311
10312 EXIT();
10313}
10314
10315void hdd_bus_bw_compute_timer_try_start(hdd_context_t *hdd_ctx)
10316{
10317 ENTER();
10318
10319 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10320 hdd_debug("Bandwidth compute timer already started");
10321 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010322 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010323
10324 if (hdd_any_adapter_is_assoc(hdd_ctx))
10325 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10326
10327 EXIT();
10328}
10329
10330static void __hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10331{
10332 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10333
10334 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10335 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10336 hdd_ctx->bus_bw_timer_running = false;
10337 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10338
10339 hdd_reset_tcp_delack(hdd_ctx);
10340}
10341
10342void hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10343{
10344 ENTER();
10345
10346 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10347 hdd_debug("Bandwidth compute timer already stopped");
10348 return;
10349 }
10350
10351 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10352
10353 EXIT();
10354}
10355
10356void hdd_bus_bw_compute_timer_try_stop(hdd_context_t *hdd_ctx)
10357{
10358 ENTER();
10359
10360 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10361 hdd_debug("Bandwidth compute timer already stopped");
10362 return;
10363 }
10364
10365 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10366 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10367
10368 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010369}
10370#endif
10371
10372/**
10373 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10374 * and sta's operating channel.
10375 * @sta_adapter: Describe the first argument to foobar.
10376 * @ap_adapter: Describe the second argument to foobar.
10377 * @roam_profile: Roam profile of AP to which STA wants to connect.
10378 * @concurrent_chnl_same: If both SAP and STA channels are same then
10379 * set this flag to true else false.
10380 *
10381 * This function checks the sap's operating channel and sta's operating channel.
10382 * if both are same then it will return false else it will restart the sap in
10383 * sta's channel and return true.
10384 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010385 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010386 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010387QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010388 hdd_adapter_t *ap_adapter,
10389 tCsrRoamProfile *roam_profile,
10390 tScanResultHandle *scan_cache,
10391 bool *concurrent_chnl_same)
10392{
10393 hdd_ap_ctx_t *hdd_ap_ctx;
10394 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010395 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010396 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010397 *concurrent_chnl_same = true;
10398
10399 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10400 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010401 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010402 scan_cache,
10403 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010404 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010405 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010406 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10407 if (hdd_ap_ctx->operatingChannel != channel_id) {
10408 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010409 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010410 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010411 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010412 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10413 if (hdd_ap_ctx->operatingChannel != channel_id) {
10414 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010415 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 }
10417 }
10418 } else {
10419 /*
10420 * Lets handle worst case scenario here, Scan cache lookup is
10421 * failed so we have to stop the SAP to avoid any channel
10422 * discrepancy between SAP's channel and STA's channel.
10423 * Return the status as failure so caller function could know
10424 * that scan look up is failed.
10425 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010426 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010427 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010428 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010429 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430}
10431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010432/**
10433 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10434 * @ap_adapter: SAP adapter
10435 *
10436 * This function will process the stopping of sap adapter.
10437 *
10438 * Return: None
10439 */
10440void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
10441{
10442 hdd_ap_ctx_t *hdd_ap_ctx;
10443 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010444 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010445 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010446
10447 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010448 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010449 return;
10450 }
10451
10452 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10453 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010454 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010455 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010456
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010457 mutex_lock(&hdd_ctx->sap_lock);
10458 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010459 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10461 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010462 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010463 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010464 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010466 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010467 qdf_stop_bss_event,
10468 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010469 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010470 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010471 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010472 return;
10473 }
10474 }
10475 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010476 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10477 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010478 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010479 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010480 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010481 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010482 }
10483 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010484}
10485
10486/**
10487 * wlan_hdd_start_sap() - this function starts bss of SAP.
10488 * @ap_adapter: SAP adapter
10489 *
10490 * This function will process the starting of sap adapter.
10491 *
10492 * Return: None
10493 */
Arun Khandavallicc544b32017-01-30 19:52:16 +053010494void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495{
10496 hdd_ap_ctx_t *hdd_ap_ctx;
10497 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010498 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010499 hdd_context_t *hdd_ctx;
10500 tsap_Config_t *sap_config;
10501
10502 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010503 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010504 return;
10505 }
10506
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010507 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010508 hdd_err("SoftAp role has not been enabled");
10509 return;
10510 }
10511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010512 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10513 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10514 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10515 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010517 mutex_lock(&hdd_ctx->sap_lock);
10518 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10519 goto end;
10520
10521 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010522 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010523 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10524 goto end;
10525 }
10526
Wei Song2f76f642016-11-18 16:32:53 +080010527 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10529 &hdd_ap_ctx->sapConfig,
10530 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010531 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010532 goto end;
10533
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010534 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010535 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010536 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010537 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010538 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010539 goto end;
10540 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010541 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010542 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010543 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010544 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10545 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010546 ap_adapter->sessionId);
10547 hostapd_state->bCommit = true;
10548
10549end:
10550 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010551 /* SAP context and beacon cleanup will happen during driver unload
10552 * in hdd_stop_adapter
10553 */
10554 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10555
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010556}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010557
10558/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010559 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10560 * mac scan config
10561 * @status: Status of set antenna mode
10562 *
10563 * Callback on setting the dual mac configuration
10564 *
10565 * Return: None
10566 */
10567void wlan_hdd_soc_set_antenna_mode_cb(
10568 enum set_antenna_mode_status status)
10569{
10570 hdd_context_t *hdd_ctx;
10571
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010572 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010573
10574 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10575 if (0 != wlan_hdd_validate_context(hdd_ctx))
10576 return;
10577
10578 /* Signal the completion of set dual mac config */
10579 complete(&hdd_ctx->set_antenna_mode_cmpl);
10580}
10581
10582/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583 * hdd_get_fw_version() - Get FW version
10584 * @hdd_ctx: pointer to HDD context.
10585 * @major_spid: FW version - major spid.
10586 * @minor_spid: FW version - minor spid
10587 * @ssid: FW version - ssid
10588 * @crmid: FW version - crmid
10589 *
10590 * This function is called to get the firmware build version stored
10591 * as part of the HDD context
10592 *
10593 * Return: None
10594 */
10595void hdd_get_fw_version(hdd_context_t *hdd_ctx,
10596 uint32_t *major_spid, uint32_t *minor_spid,
10597 uint32_t *siid, uint32_t *crmid)
10598{
10599 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10600 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10601 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10602 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10603}
10604
10605#ifdef QCA_CONFIG_SMP
10606/**
10607 * wlan_hdd_get_cpu() - get cpu_index
10608 *
10609 * Return: cpu_index
10610 */
10611int wlan_hdd_get_cpu(void)
10612{
10613 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010614
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615 put_cpu();
10616 return cpu_index;
10617}
10618#endif
10619
10620/**
10621 * hdd_get_fwpath() - get framework path
10622 *
10623 * This function is used to get the string written by
10624 * userspace to start the wlan driver
10625 *
10626 * Return: string
10627 */
10628const char *hdd_get_fwpath(void)
10629{
10630 return fwpath.string;
10631}
10632
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010633static int hdd_qdf_print_init(void)
10634{
10635 int qdf_print_idx;
10636 QDF_STATUS status;
10637
10638 status = qdf_print_setup();
10639 if (status != QDF_STATUS_SUCCESS) {
10640 pr_err("qdf_print_setup failed\n");
10641 return -EINVAL;
10642 }
10643
10644 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10645
10646 if (qdf_print_idx < 0) {
10647 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10648 qdf_print_idx);
10649 return -EINVAL;
10650 }
10651
10652 qdf_set_pidx(qdf_print_idx);
10653
10654 return 0;
10655}
10656
10657static void hdd_qdf_print_deinit(void)
10658{
10659 int qdf_print_idx;
10660
10661 qdf_print_idx = qdf_get_pidx();
10662 qdf_print_ctrl_cleanup(qdf_print_idx);
10663}
10664
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010665/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010666 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010667 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010668 * This function initilizes CDS global context with the help of cds_init. This
10669 * has to be the first function called after probe to get a valid global
10670 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010671 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010672 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010673 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010674int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010675{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010676 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010677 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010678
Houston Hoffman9e06e542016-12-12 12:06:26 -080010679 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010680#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10681 wlan_logging_sock_init_svc();
10682#endif
10683
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010684 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010685 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010686 ret = -ENOMEM;
10687 goto err_out;
10688 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010689
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010690 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010691 hdd_qdf_print_init();
10692
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010693 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010694
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010695err_out:
10696 return ret;
10697}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010698
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010699/**
10700 * hdd_deinit() - Deinitialize Driver
10701 *
10702 * This function frees CDS global context with the help of cds_deinit. This
10703 * has to be the last function call in remove callback to free the global
10704 * context.
10705 */
10706void hdd_deinit(void)
10707{
Dustin Brownedce4a52017-05-10 11:59:15 -070010708 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010709 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010710
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010711 hdd_qdf_print_deinit();
10712
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010713#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10714 wlan_logging_sock_deinit_svc();
10715#endif
10716}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010717
Yue Ma6e7b1a02017-04-03 14:17:46 -070010718#ifdef QCA_WIFI_NAPIER_EMULATION
10719#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10720#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010721#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010722#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010723
Sachin Ahujadddd2632017-03-07 19:07:24 +053010724static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10725 struct file *file)
10726{
10727 return 0;
10728}
10729
10730static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10731 const char __user *user_buf,
10732 size_t count,
10733 loff_t *f_pos)
10734{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010735 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010736 static const char wlan_off_str[] = "OFF";
10737 static const char wlan_on_str[] = "ON";
10738 int ret;
10739 unsigned long rc;
10740
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010741 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010742 pr_err("Failed to read buffer\n");
10743 return -EINVAL;
10744 }
10745
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010746 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010747 pr_debug("Wifi turning off from UI\n");
10748 goto exit;
10749 }
10750
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010751 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010752 pr_err("Invalid value received from framework");
10753 goto exit;
10754 }
10755
10756 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010757 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010758 rc = wait_for_completion_timeout(&wlan_start_comp,
10759 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10760 if (!rc) {
10761 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10762 ret = -EINVAL;
10763 hdd_start_complete(ret);
10764 return ret;
10765 }
10766
10767 hdd_start_complete(0);
10768 }
10769
10770exit:
10771 return count;
10772}
10773
10774
10775const struct file_operations wlan_hdd_state_fops = {
10776 .owner = THIS_MODULE,
10777 .open = wlan_hdd_state_ctrl_param_open,
10778 .write = wlan_hdd_state_ctrl_param_write,
10779};
10780
10781static int wlan_hdd_state_ctrl_param_create(void)
10782{
10783 unsigned int wlan_hdd_state_major = 0;
10784 int ret;
10785 struct device *dev;
10786
10787 device = MKDEV(wlan_hdd_state_major, 0);
10788
10789 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10790 if (ret) {
10791 pr_err("Failed to register qcwlanstate");
10792 goto dev_alloc_err;
10793 }
10794 wlan_hdd_state_major = MAJOR(device);
10795
10796 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10797 if (IS_ERR(class)) {
10798 pr_err("wlan_hdd_state class_create error");
10799 goto class_err;
10800 }
10801
10802 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10803 if (IS_ERR(dev)) {
10804 pr_err("wlan_hdd_statedevice_create error");
10805 goto err_class_destroy;
10806 }
10807
10808 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10809 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10810 if (ret) {
10811 pr_err("Failed to add cdev error");
10812 goto cdev_add_err;
10813 }
10814
10815 pr_info("wlan_hdd_state %s major(%d) initialized",
10816 WLAN_MODULE_NAME, wlan_hdd_state_major);
10817
10818 return 0;
10819
10820cdev_add_err:
10821 device_destroy(class, device);
10822err_class_destroy:
10823 class_destroy(class);
10824class_err:
10825 unregister_chrdev_region(device, dev_num);
10826dev_alloc_err:
10827 return -ENODEV;
10828}
10829
10830static void wlan_hdd_state_ctrl_param_destroy(void)
10831{
10832 cdev_del(&wlan_hdd_state_cdev);
10833 device_destroy(class, device);
10834 class_destroy(class);
10835 unregister_chrdev_region(device, dev_num);
10836
10837 pr_info("Device node unregistered");
10838}
10839
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010840/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053010841 * component_init - API to init cld component's
10842 *
10843 * Return: None
10844 */
10845static void component_init(void)
10846{
10847 pmo_init();
10848}
10849
10850/**
10851 * component_deinit - API to deinit cld component's
10852 *
10853 * Return: None
10854 */
10855static void component_deinit(void)
10856{
10857 pmo_deinit();
10858}
10859
10860/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010861 * __hdd_module_init - Module init helper
10862 *
10863 * Module init helper function used by both module and static driver.
10864 *
10865 * Return: 0 for success, errno on failure
10866 */
10867static int __hdd_module_init(void)
10868{
10869 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010870
Dustin Brownab482ac2017-06-09 17:00:44 -070010871 pr_err("%s: Loading driver v%s (%s)%s\n",
10872 WLAN_MODULE_NAME,
10873 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070010874 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070010875 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010876
Sachin Ahujadddd2632017-03-07 19:07:24 +053010877 ret = wlan_hdd_state_ctrl_param_create();
10878 if (ret) {
10879 pr_err("wlan_hdd_state_create:%x\n", ret);
10880 goto err_dev_state;
10881 }
10882
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010883 pld_init();
10884
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010885 ret = hdd_init();
10886 if (ret) {
10887 pr_err("hdd_init failed %x\n", ret);
10888 goto err_hdd_init;
10889 }
10890
Rajeev Kumar97767a02016-11-30 11:20:40 -080010891 dispatcher_init();
10892
Mukul Sharmad75a6672017-06-22 15:40:53 +053010893 /* Ensure to call post objmgr init */
10894 component_init();
10895
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010896 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010897
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010898 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010899
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010900 ret = wlan_hdd_register_driver();
10901 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070010902 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
10903 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010904 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010905 }
10906
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010907 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010908
10909 return 0;
10910out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010911 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080010912 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010913 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080010914
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010915err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010916 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053010917 wlan_hdd_state_ctrl_param_destroy();
10918err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010919 return ret;
10920}
10921
10922/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010923 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
10924 *
10925 * Block the unloading of the driver until the cds recovery is completed
10926 *
10927 * Return: None
10928 */
10929static void hdd_wait_for_recovery_completion(void)
10930{
10931 int retry = 0;
10932
10933 /* Wait for recovery to complete */
10934 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010935 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010936 msleep(1000);
10937 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010938 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010939 QDF_BUG(0);
10940 }
10941 }
10942}
10943
10944/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010945 * __hdd_module_exit - Module exit helper
10946 *
10947 * Module exit helper function used by both module and static driver.
10948 */
10949static void __hdd_module_exit(void)
10950{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010951
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010952 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
10953 QWLAN_VERSIONSTR);
10954
bings6028ee82017-03-29 07:51:40 +080010955 cds_set_unload_in_progress(true);
10956
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010957 hdd_wait_for_recovery_completion();
10958
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010959 wlan_hdd_unregister_driver();
10960
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010961 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010962
Mukul Sharmad75a6672017-06-22 15:40:53 +053010963 /* Ensure to call prior to objmgr deinit */
10964 component_deinit();
10965
Rajeev Kumar97767a02016-11-30 11:20:40 -080010966 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010967 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010968 pld_deinit();
10969
Sachin Ahujadddd2632017-03-07 19:07:24 +053010970 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010971}
10972
Arun Khandavallifae92942016-08-01 13:31:08 +053010973#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010974/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010975 * wlan_boot_cb() - Wlan boot callback
10976 * @kobj: object whose directory we're creating the link in.
10977 * @attr: attribute the user is interacting with
10978 * @buff: the buffer containing the user data
10979 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010980 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010981 * This callback is invoked when the fs is ready to start the
10982 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010983 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010984 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010985 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010986static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010987 struct kobj_attribute *attr,
10988 const char *buf,
10989 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010990{
Arun Khandavallifae92942016-08-01 13:31:08 +053010991
Arun Khandavallifae92942016-08-01 13:31:08 +053010992 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010993 pr_err("%s: wlan driver already initialized\n", __func__);
10994 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053010995 }
10996
Arun Khandavallifae92942016-08-01 13:31:08 +053010997 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010998 pr_err("%s: wlan driver initialization failed\n", __func__);
10999 return -EIO;
11000 }
11001
11002 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011003
11004 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011005}
Arun Khandavallifae92942016-08-01 13:31:08 +053011006
11007/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011008 * hdd_sysfs_cleanup() - cleanup sysfs
11009 *
11010 * Return: None
11011 *
11012 */
11013static void hdd_sysfs_cleanup(void)
11014{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011015 /* remove from group */
11016 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11017 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11018 wlan_loader->attr_group);
11019
11020 /* unlink the object from parent */
11021 kobject_del(wlan_loader->boot_wlan_obj);
11022
11023 /* free the object */
11024 kobject_put(wlan_loader->boot_wlan_obj);
11025
11026 kfree(wlan_loader->attr_group);
11027 kfree(wlan_loader);
11028
11029 wlan_loader = NULL;
11030}
11031
11032/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011033 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11034 * ready
11035 *
11036 * This is creates the syfs entry boot_wlan. Which shall be invoked
11037 * when the filesystem is ready.
11038 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011039 * QDF API cannot be used here since this function is called even before
11040 * initializing WLAN driver.
11041 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011042 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011043 */
11044static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011045{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011046 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011047
11048 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011049 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011050 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011051
11052 wlan_loader->boot_wlan_obj = NULL;
11053 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11054 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011055 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011056 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011057
11058 wlan_loader->loaded_state = 0;
11059 wlan_loader->attr_group->attrs = attrs;
11060
11061 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11062 kernel_kobj);
11063 if (!wlan_loader->boot_wlan_obj) {
11064 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011065 goto error_return;
11066 }
11067
11068 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11069 wlan_loader->attr_group);
11070 if (ret) {
11071 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11072 goto error_return;
11073 }
11074
11075 return 0;
11076
11077error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011078 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011079
11080 return ret;
11081}
11082
11083/**
11084 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11085 *
11086 * Return: 0 on success or errno on failure
11087 */
11088static int wlan_deinit_sysfs(void)
11089{
Arun Khandavallifae92942016-08-01 13:31:08 +053011090 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011091 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011092 return -EINVAL;
11093 }
11094
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011095 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011096 return 0;
11097}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011098
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011099#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011100
11101#ifdef MODULE
11102/**
11103 * __hdd_module_init - Module init helper
11104 *
11105 * Module init helper function used by both module and static driver.
11106 *
11107 * Return: 0 for success, errno on failure
11108 */
11109static int hdd_module_init(void)
11110{
Arun Khandavallifae92942016-08-01 13:31:08 +053011111 if (__hdd_module_init()) {
11112 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011113 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011114 }
11115
Dustin Brownab482ac2017-06-09 17:00:44 -070011116 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011117}
11118#else
11119static int __init hdd_module_init(void)
11120{
11121 int ret = -EINVAL;
11122
11123 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011124 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011125 pr_err("Failed to create sysfs entry for loading wlan");
11126
11127 return ret;
11128}
11129#endif
11130
11131
11132#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011133/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011134 * hdd_module_exit() - Exit function
11135 *
11136 * This is the driver exit point (invoked when module is unloaded using rmmod)
11137 *
11138 * Return: None
11139 */
11140static void __exit hdd_module_exit(void)
11141{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011142 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011143}
Arun Khandavallifae92942016-08-01 13:31:08 +053011144#else
11145static void __exit hdd_module_exit(void)
11146{
11147 __hdd_module_exit();
11148 wlan_deinit_sysfs();
11149}
11150#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011151
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011152static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11153{
11154 return param_set_copystring(kmessage, kp);
11155}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011156
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011157/**
11158 * is_con_mode_valid() check con mode is valid or not
11159 * @mode: global con mode
11160 *
11161 * Return: TRUE on success FALSE on failure
11162 */
11163static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11164{
11165 switch (mode) {
11166 case QDF_GLOBAL_MONITOR_MODE:
11167 case QDF_GLOBAL_FTM_MODE:
11168 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011169 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011170 return true;
11171 default:
11172 return false;
11173 }
11174}
11175
11176/**
11177 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11178 * @mode: global con mode
11179 *
11180 * Return: adapter mode
11181 */
11182static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11183 enum tQDF_GLOBAL_CON_MODE mode)
11184{
11185
11186 switch (mode) {
11187 case QDF_GLOBAL_MISSION_MODE:
11188 return QDF_STA_MODE;
11189 case QDF_GLOBAL_MONITOR_MODE:
11190 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011191 case QDF_GLOBAL_EPPING_MODE:
11192 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011193 case QDF_GLOBAL_FTM_MODE:
11194 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011195 case QDF_GLOBAL_QVIT_MODE:
11196 return QDF_QVIT_MODE;
11197 default:
11198 return QDF_MAX_NO_OF_MODE;
11199 }
11200}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011201
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011202static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
11203 enum tQDF_GLOBAL_CON_MODE curr_mode)
11204{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011205 int driver_status;
11206
11207 driver_status = hdd_ctx->driver_status;
11208
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011209 switch (curr_mode) {
11210 case QDF_GLOBAL_MISSION_MODE:
11211 case QDF_GLOBAL_MONITOR_MODE:
11212 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011213 if (driver_status != DRIVER_MODULES_CLOSED) {
11214 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11215 hdd_stop_all_adapters(hdd_ctx);
11216 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011217 hdd_deinit_all_adapters(hdd_ctx, false);
11218 hdd_close_all_adapters(hdd_ctx, false);
11219 break;
11220 case QDF_GLOBAL_EPPING_MODE:
11221 epping_disable();
11222 epping_close();
11223 break;
11224 default:
11225 return;
11226 }
11227}
11228
11229static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
11230 enum tQDF_GLOBAL_CON_MODE mode)
11231{
11232 hdd_adapter_t *adapter;
11233 int ret = 0;
11234 bool rtnl_held;
11235 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11236 QDF_STATUS status;
11237
11238 if (!qdf_dev) {
11239 hdd_err("qdf device context is Null return!");
11240 return -EINVAL;
11241 }
11242
11243 rtnl_held = hdd_hold_rtnl_lock();
11244 switch (mode) {
11245 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011246 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11247 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011248 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011249 break;
11250 case QDF_GLOBAL_FTM_MODE:
11251 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11252 wlan_hdd_get_intf_addr(hdd_ctx),
11253 NET_NAME_UNKNOWN, rtnl_held);
11254 if (adapter == NULL)
11255 ret = -EINVAL;
11256 break;
11257 case QDF_GLOBAL_MONITOR_MODE:
11258 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11259 wlan_hdd_get_intf_addr(hdd_ctx),
11260 NET_NAME_UNKNOWN, rtnl_held);
11261 if (adapter == NULL)
11262 ret = -EINVAL;
11263 break;
11264 case QDF_GLOBAL_EPPING_MODE:
11265 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011266 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011267 hdd_err("Failed to open in eeping mode: %d", status);
11268 ret = -EINVAL;
11269 break;
11270 }
11271 ret = epping_enable(qdf_dev->dev);
11272 if (ret) {
11273 hdd_err("Failed to enable in epping mode : %d", ret);
11274 epping_close();
11275 }
11276 break;
11277 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011278 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011279 ret = -ENOTSUPP;
11280 break;
11281 }
11282 hdd_release_rtnl_lock();
11283 rtnl_held = false;
11284 return ret;
11285}
11286
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011287/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011288 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011289 * @kmessage: con mode name on which driver to be bring up
11290 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011291 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011292 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011293 * This function is invoked when user updates con mode using sys entry,
11294 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011295 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011296 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011297 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011298static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
11299 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011300{
11301 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011302 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011303 enum tQDF_GLOBAL_CON_MODE curr_mode;
11304 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011305
Dustin Brownab6029b2017-05-24 13:04:19 -070011306 hdd_info("con_mode handler: %s", kmessage);
11307
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011308 ret = wlan_hdd_validate_context(hdd_ctx);
11309 if (ret)
11310 return ret;
11311
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011312 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011313
11314 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011315
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011316 if (!(is_con_mode_valid(con_mode))) {
11317 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011318 ret = -EINVAL;
11319 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011320 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011321
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011322 curr_mode = hdd_get_conparam();
11323 if (curr_mode == con_mode) {
11324 hdd_err("curr mode: %d is same as user triggered mode %d",
11325 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011326 ret = 0;
11327 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011328 }
11329
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011330 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 if (ret) {
11332 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011333 goto reset_flags;
11334 }
11335
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011336 /* Cleanup present mode before switching to new mode */
11337 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11338
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011339 hdd_set_conparam(con_mode);
11340
11341 /* Register for new con_mode & then kick_start modules again */
11342 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11343 if (ret) {
11344 hdd_err("Failed to register for new mode");
11345 goto reset_flags;
11346 }
11347
11348 adapter_mode = hdd_get_adpter_mode(con_mode);
11349 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11350 hdd_err("invalid adapter");
11351 ret = -EINVAL;
11352 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011353 }
11354
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011355 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011356 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011357 hdd_err("Failed to get adapter:%d", adapter_mode);
11358 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011359 }
11360
11361 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11362 if (ret) {
11363 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011364 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011365 }
11366
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011367 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11368 con_mode == QDF_GLOBAL_FTM_MODE) {
11369 if (hdd_start_adapter(adapter)) {
11370 hdd_err("Failed to start %s adapter", kmessage);
11371 ret = -EINVAL;
11372 goto reset_flags;
11373 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011374 }
11375
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011376 hdd_info("Mode successfully changed to %s", kmessage);
11377 ret = 0;
11378
11379reset_flags:
11380 cds_set_load_in_progress(false);
11381 return ret;
11382}
11383
11384
11385static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11386{
11387 int ret;
11388 hdd_context_t *hdd_ctx;
11389
11390 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11391 ret = wlan_hdd_validate_context(hdd_ctx);
11392 if (ret)
11393 return ret;
11394
11395 cds_ssr_protect(__func__);
11396 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11397 cds_ssr_unprotect(__func__);
11398
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011399 return ret;
11400}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011401
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011402static int con_mode_handler_ftm(const char *kmessage,
11403 struct kernel_param *kp)
11404{
11405 int ret;
11406
11407 ret = param_set_int(kmessage, kp);
11408
11409 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11410 pr_err("Only FTM mode supported!");
11411 return -ENOTSUPP;
11412 }
11413
11414 hdd_set_conparam(con_mode_ftm);
11415 con_mode = con_mode_ftm;
11416
11417 return ret;
11418}
11419
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011420/**
11421 * hdd_get_conparam() - driver exit point
11422 *
11423 * This is the driver exit point (invoked when module is unloaded using rmmod)
11424 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011425 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011426 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011427enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011428{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011429 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011430}
11431
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011432void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011433{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011434 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011435}
11436
Komal Seelamc11bb222016-01-27 18:57:10 +053011437/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011438 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11439 * @hdd_ctx: HDD context
11440 *
11441 * Cleans up the pre cac interface, if it exists
11442 *
11443 * Return: None
11444 */
11445void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
11446{
11447 uint8_t session_id;
11448 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011449 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011450
11451 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11452 if (QDF_IS_STATUS_ERROR(status)) {
11453 hdd_err("failed to get pre cac vdev id");
11454 return;
11455 }
11456
11457 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11458 if (!precac_adapter) {
11459 hdd_err("invalid pre cac adapater");
11460 return;
11461 }
11462
11463 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11464 wlan_hdd_sap_pre_cac_failure,
11465 (void *)precac_adapter);
11466 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11467
11468}
11469
11470/**
Komal Seelamec702b02016-02-24 18:42:16 +053011471 * hdd_update_ol_config - API to update ol configuration parameters
11472 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011473 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011474 * Return: void
11475 */
Komal Seelamec702b02016-02-24 18:42:16 +053011476static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011477{
Komal Seelamec702b02016-02-24 18:42:16 +053011478 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011479 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011480
Komal Seelamec702b02016-02-24 18:42:16 +053011481 if (!ol_ctx)
11482 return;
11483
11484 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11485 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11486 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11487 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011488 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011489
11490 ol_init_ini_config(ol_ctx, &cfg);
11491}
11492
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011493#ifdef FEATURE_RUNTIME_PM
11494/**
11495 * hdd_populate_runtime_cfg() - populate runtime configuration
11496 * @hdd_ctx: hdd context
11497 * @cfg: pointer to the configuration memory being populated
11498 *
11499 * Return: void
11500 */
11501static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11502 struct hif_config_info *cfg)
11503{
11504 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11505 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11506}
11507#else
11508static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11509 struct hif_config_info *cfg)
11510{
11511}
11512#endif
11513
Komal Seelamec702b02016-02-24 18:42:16 +053011514/**
11515 * hdd_update_hif_config - API to update HIF configuration parameters
11516 * @hdd_ctx: HDD Context
11517 *
11518 * Return: void
11519 */
11520static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
11521{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011522 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011523 struct hif_config_info cfg;
11524
11525 if (!scn)
11526 return;
11527
11528 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011529 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011530 hif_init_ini_config(scn, &cfg);
11531}
11532
11533/**
11534 * hdd_update_config() - Initialize driver per module ini parameters
11535 * @hdd_ctx: HDD Context
11536 *
11537 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011538 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011539 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011540int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011541{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011542 int ret;
11543
Komal Seelamec702b02016-02-24 18:42:16 +053011544 hdd_update_ol_config(hdd_ctx);
11545 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011546 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11547 ret = hdd_update_cds_config_ftm(hdd_ctx);
11548 else
11549 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011550 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011551
11552 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011553}
11554
Mukul Sharma9d797a02017-01-05 20:26:03 +053011555#ifdef FEATURE_WLAN_RA_FILTERING
11556/**
11557 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11558 * @psoc_cfg: pmo psoc Configuration
11559 * @hdd_ctx: Pointer to hdd context
11560 *
11561 * Return: none
11562 */
11563static inline void hdd_ra_populate_pmo_config(
11564 struct pmo_psoc_cfg *psoc_cfg,
11565 hdd_context_t *hdd_ctx)
11566{
11567 psoc_cfg->ra_ratelimit_interval =
11568 hdd_ctx->config->RArateLimitInterval;
11569 psoc_cfg->ra_ratelimit_enable =
11570 hdd_ctx->config->IsRArateLimitEnabled;
11571}
11572#else
11573static inline void hdd_ra_populate_pmo_config(
11574 struct cds_config_info *cds_cfg,
11575 hdd_context_t *hdd_ctx)
11576{
11577}
11578#endif
11579/**
11580 * hdd_update_pmo_config - API to update pmo configuration parameters
11581 * @hdd_ctx: HDD context
11582 *
11583 * Return: void
11584 */
11585static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
11586{
11587 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11588 struct pmo_psoc_cfg psoc_cfg;
11589 QDF_STATUS status;
11590
11591 /*
11592 * Value of hdd_ctx->wowEnable can be,
11593 * 0 - Disable both magic pattern match and pattern byte match.
11594 * 1 - Enable magic pattern match on all interfaces.
11595 * 2 - Enable pattern byte match on all interfaces.
11596 * 3 - Enable both magic patter and pattern byte match on
11597 * all interfaces.
11598 */
11599 psoc_cfg.magic_ptrn_enable =
11600 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11601 psoc_cfg.ptrn_match_enable_all_vdev =
11602 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11603 psoc_cfg.bpf_enable =
11604 hdd_ctx->config->bpf_packet_filter_enable;
11605 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011606 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011607 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11608 if (hdd_ctx->config->fhostNSOffload)
11609 psoc_cfg.ns_offload_enable_dynamic = true;
11610 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11611 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11612 psoc_cfg.active_mode_offload =
11613 hdd_ctx->config->active_mode_offload;
11614 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11615 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011616 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11617 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11618 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11619 psoc_cfg.power_save_mode =
11620 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011621 psoc_cfg.auto_power_save_fail_mode =
11622 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011623
11624 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011625 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11626 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011627 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11628 if (status != QDF_STATUS_SUCCESS) {
11629 hdd_err("failed pmo psoc configuration");
11630 return -EINVAL;
11631 }
11632
11633 return 0;
11634}
11635
Abhishek Singh257a9482017-03-06 16:52:39 +053011636#ifdef NAPIER_SCAN
Abhishek Singhb20db962017-03-03 21:28:46 +053011637
11638#ifdef FEATURE_WLAN_SCAN_PNO
11639static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11640 struct hdd_config *cfg)
11641{
11642 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11643 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11644 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11645 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11646 pno_cfg->channel_prediction_full_scan =
11647 cfg->channel_prediction_full_scan;
11648}
11649#else
11650static inline void
11651hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11652 struct hdd_config *cfg)
11653{
11654 return;
11655}
11656#endif
11657
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011658void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11659 struct hdd_config *cfg)
11660{
11661 uint8_t i = 0;
11662
11663 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11664 if (!ie_whitelist->white_list)
11665 return;
11666
11667 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11668 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11669 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11670 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11671 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11672 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11673 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11674 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11675
11676 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11677 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11678 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11679}
11680
Abhishek Singh257a9482017-03-06 16:52:39 +053011681/**
11682 * hdd_update_scan_config - API to update scan configuration parameters
11683 * @hdd_ctx: HDD context
11684 *
11685 * Return: 0 if success else err
11686 */
11687static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11688{
11689 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11690 struct scan_user_cfg scan_cfg;
11691 struct hdd_config *cfg = hdd_ctx->config;
11692 QDF_STATUS status;
11693
11694 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11695 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11696 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11697 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11698 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11699 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11700 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011701 /* convert to ms */
11702 scan_cfg.scan_cache_aging_time =
11703 cfg->scanAgingTimeout * 1000;
11704 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11705 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11706 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11707 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011708 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011709 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011710
Abhishek Singhb20db962017-03-03 21:28:46 +053011711 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011712 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011713
Abhishek Singh257a9482017-03-06 16:52:39 +053011714 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11715 if (status != QDF_STATUS_SUCCESS) {
11716 hdd_err("failed pmo psoc configuration");
11717 return -EINVAL;
11718 }
11719
11720 return 0;
11721}
11722#else
11723static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11724{
11725 return 0;
11726}
11727#endif
11728
Frank Liud4b2fa02017-03-29 11:46:48 +080011729#ifdef CONVERGED_TDLS_ENABLE
11730static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11731{
11732 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11733 struct tdls_start_params tdls_cfg;
11734 struct tdls_user_config *config = &tdls_cfg.config;
11735 struct hdd_config *cfg = hdd_ctx->config;
11736 QDF_STATUS status;
11737
11738 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11739 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11740 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11741 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11742 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11743 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11744 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11745 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11746 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11747 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11748 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11749 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11750 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11751 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11752 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11753 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11754 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11755 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11756 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11757 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11758 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11759 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11760 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11761 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11762 (cfg->fEnableTDLSImplicitTrigger ?
11763 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11764 (cfg->fTDLSExternalControl ?
11765 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11766
11767 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11768 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11769 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11770 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011771 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011772 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011773 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11774 tdls_cfg.tdls_evt_cb_data = psoc;
11775 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11776 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11777 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011778 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11779 tdls_cfg.tdls_wmm_cb_data = psoc;
11780 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11781 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011782 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011783
11784 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11785 if (status != QDF_STATUS_SUCCESS) {
11786 hdd_err("failed pmo psoc configuration");
11787 return -EINVAL;
11788 }
11789
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011790 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011791 /* disable napier specific tdls data path */
11792 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011793
Frank Liud4b2fa02017-03-29 11:46:48 +080011794 return 0;
11795}
11796#else
11797static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11798{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011799 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011800 /* disable napier specific tdls data path */
11801 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080011802 return 0;
11803}
11804#endif
11805
Mukul Sharma9d797a02017-01-05 20:26:03 +053011806int hdd_update_components_config(hdd_context_t *hdd_ctx)
11807{
11808 int ret;
11809
11810 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053011811 if (ret)
11812 return ret;
11813 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080011814 if (ret)
11815 return ret;
11816 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011817
11818 return ret;
11819}
11820
Agrawal Ashish65634612016-08-18 13:24:32 +053011821/**
11822 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
11823 * @mode : cfg80211 DFS mode
11824 *
11825 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
11826 */
11827enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
11828{
11829 switch (mode) {
11830 case DFS_MODE_ENABLE:
11831 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011832 case DFS_MODE_DISABLE:
11833 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011834 case DFS_MODE_DEPRIORITIZE:
11835 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011836 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011837 hdd_debug("ACS dfs mode is NONE");
11838 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011839 }
11840}
11841
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011842/**
11843 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
11844 * @hddctx: pointer to hdd context
11845 * @set_value: enable/disable
11846 *
11847 * When Host sends vendor command enable, FW will send *ONE* CA ind to
11848 * Host(even though it is duplicate). When Host send vendor command
11849 * disable,FW doesn't perform any action. Whenever any change in
11850 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
11851 *
11852 * return - 0 on success, appropriate error values on failure.
11853 */
11854int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
11855{
11856 QDF_STATUS status;
11857
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011858 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011859 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011860
11861 if (!hddctx->config->goptimize_chan_avoid_event) {
11862 hdd_warn("goptimize_chan_avoid_event ini param disabled");
11863 return -EINVAL;
11864 }
11865
11866 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
11867 if (!QDF_IS_STATUS_SUCCESS(status)) {
11868 hdd_err("Failed to send chan avoid command to SME");
11869 return -EINVAL;
11870 }
11871 return 0;
11872}
Agrawal Ashish65634612016-08-18 13:24:32 +053011873
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011874/**
11875 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
11876 * @value: value to set
11877 *
11878 * This function will set the passed value to roaming in progress flag.
11879 *
11880 * Return: None
11881 */
11882void hdd_set_roaming_in_progress(bool value)
11883{
11884 hdd_context_t *hdd_ctx;
11885
11886 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11887 if (!hdd_ctx) {
11888 hdd_err("HDD context is NULL");
11889 return;
11890 }
11891
11892 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011893 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011894}
11895
11896/**
11897 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011898 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011899 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011900 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011901 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011902bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011903{
11904 hdd_context_t *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011905 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011906
11907 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11908 if (!hdd_ctx) {
11909 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011910 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011911 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011912 hdd_debug("dev mode = %d, roaming_in_progress = %d",
11913 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011914 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
11915 hdd_ctx->roaming_in_progress);
11916
11917 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011918}
11919
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011920/**
11921 * hdd_is_connection_in_progress() - check if connection is in
11922 * progress
11923 * @session_id: session id
11924 * @reason: scan reject reason
11925 *
11926 * Go through each adapter and check if Connection is in progress
11927 *
11928 * Return: true if connection is in progress else false
11929 */
11930bool hdd_is_connection_in_progress(uint8_t *session_id,
11931 enum scan_reject_states *reason)
11932{
11933 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
11934 hdd_station_ctx_t *hdd_sta_ctx = NULL;
11935 hdd_adapter_t *adapter = NULL;
11936 QDF_STATUS status = 0;
11937 uint8_t sta_id = 0;
11938 uint8_t *sta_mac = NULL;
11939 hdd_context_t *hdd_ctx;
11940
11941 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11942 if (!hdd_ctx) {
11943 hdd_err("HDD context is NULL");
11944 return false;
11945 }
11946
11947 if (true == hdd_ctx->btCoexModeSet) {
11948 hdd_info("BTCoex Mode operation in progress");
11949 return true;
11950 }
11951 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
11952 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
11953 adapter = adapter_node->pAdapter;
11954 if (!adapter)
11955 goto end;
11956
11957 hdd_info("Adapter with device mode %s(%d) exists",
11958 hdd_device_mode_to_string(adapter->device_mode),
11959 adapter->device_mode);
11960 if (((QDF_STA_MODE == adapter->device_mode)
11961 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
11962 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
11963 && (eConnectionState_Connecting ==
11964 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
11965 conn_info.connState)) {
11966 hdd_err("%p(%d) Connection is in progress",
11967 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11968 adapter->sessionId);
11969 if (session_id && reason) {
11970 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011971 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011972 }
11973 return true;
11974 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070011975 /*
11976 * sme_neighbor_middle_of_roaming is for LFR2
11977 * hdd_is_roaming_in_progress is for LFR3
11978 */
11979 if (((QDF_STA_MODE == adapter->device_mode) &&
11980 sme_neighbor_middle_of_roaming(
11981 WLAN_HDD_GET_HAL_CTX(adapter),
11982 adapter->sessionId)) ||
11983 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011984 hdd_err("%p(%d) Reassociation in progress",
11985 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11986 adapter->sessionId);
11987 if (session_id && reason) {
11988 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011989 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011990 }
11991 return true;
11992 }
11993 if ((QDF_STA_MODE == adapter->device_mode) ||
11994 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
11995 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
11996 hdd_sta_ctx =
11997 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11998 if ((eConnectionState_Associated ==
11999 hdd_sta_ctx->conn_info.connState)
12000 && (false ==
12001 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12002 sta_mac = (uint8_t *)
12003 &(adapter->macAddressCurrent.bytes[0]);
12004 hdd_err("client " MAC_ADDRESS_STR
12005 " is in middle of WPS/EAPOL exchange.",
12006 MAC_ADDR_ARRAY(sta_mac));
12007 if (session_id && reason) {
12008 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012009 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012010 }
12011 return true;
12012 }
12013 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12014 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12015 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12016 sta_id++) {
12017 if (!((adapter->aStaInfo[sta_id].isUsed)
12018 && (OL_TXRX_PEER_STATE_CONN ==
12019 adapter->aStaInfo[sta_id].tlSTAState)))
12020 continue;
12021
12022 sta_mac = (uint8_t *)
12023 &(adapter->aStaInfo[sta_id].
12024 macAddrSTA.bytes[0]);
12025 hdd_err("client " MAC_ADDRESS_STR
12026 " of SAP/GO is in middle of WPS/EAPOL exchange",
12027 MAC_ADDR_ARRAY(sta_mac));
12028 if (session_id && reason) {
12029 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012030 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012031 }
12032 return true;
12033 }
12034 if (hdd_ctx->connection_in_progress) {
12035 hdd_err("AP/GO: connection is in progress");
12036 return true;
12037 }
12038 }
12039end:
12040 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12041 adapter_node = next;
12042 }
12043 return false;
12044}
12045
12046/**
12047 * hdd_restart_sap() - to restart SAP in driver internally
12048 * @ap_adapter: Pointer to SAP hdd_adapter_t structure
12049 *
12050 * Return: None
12051 */
12052void hdd_restart_sap(hdd_adapter_t *ap_adapter)
12053{
12054 hdd_ap_ctx_t *hdd_ap_ctx;
12055 hdd_hostapd_state_t *hostapd_state;
12056 QDF_STATUS qdf_status;
12057 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12058 tsap_Config_t *sap_config;
12059 void *sap_ctx;
12060
12061 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12062 sap_config = &hdd_ap_ctx->sapConfig;
12063 sap_ctx = hdd_ap_ctx->sapContext;
12064
12065 mutex_lock(&hdd_ctx->sap_lock);
12066 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12067 wlan_hdd_del_station(ap_adapter);
12068 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12069 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12070 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12071 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12072 qdf_status =
12073 qdf_wait_single_event(&hostapd_state->
12074 qdf_stop_bss_event,
12075 SME_CMD_TIMEOUT_VALUE);
12076
12077 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12078 cds_err("SAP Stop Failed");
12079 goto end;
12080 }
12081 }
12082 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012083 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012084 ap_adapter->device_mode, ap_adapter->sessionId);
12085 cds_err("SAP Stop Success");
12086
12087 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12088 cds_err("SAP Not able to set AP IEs");
12089 wlansap_reset_sap_config_add_ie(sap_config,
12090 eUPDATE_IE_ALL);
12091 goto end;
12092 }
12093
12094 qdf_event_reset(&hostapd_state->qdf_event);
12095 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12096 sap_config,
12097 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12098 cds_err("SAP Start Bss fail");
12099 wlansap_reset_sap_config_add_ie(sap_config,
12100 eUPDATE_IE_ALL);
12101 goto end;
12102 }
12103
12104 cds_info("Waiting for SAP to start");
12105 qdf_status =
12106 qdf_wait_single_event(&hostapd_state->qdf_event,
12107 SME_CMD_TIMEOUT_VALUE);
12108 wlansap_reset_sap_config_add_ie(sap_config,
12109 eUPDATE_IE_ALL);
12110 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12111 cds_err("SAP Start failed");
12112 goto end;
12113 }
12114 cds_err("SAP Start Success");
12115 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12116 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012117 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12118 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012119 ap_adapter->sessionId);
12120 hostapd_state->bCommit = true;
12121 }
12122end:
12123 mutex_unlock(&hdd_ctx->sap_lock);
12124 return;
12125}
12126
12127/**
12128 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12129 * with non dfs acs
12130 *
12131 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12132 *
12133 * Return: None
12134 */
12135void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12136{
12137 hdd_adapter_t *ap_adapter;
12138 hdd_context_t *hdd_ctx;
12139 cds_context_type *cds_ctx;
12140
12141 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12142 if (!hdd_ctx) {
12143 cds_err("HDD context is NULL");
12144 return;
12145 }
12146
12147 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12148 if (!cds_ctx) {
12149 cds_err("Invalid CDS Context");
12150 return;
12151 }
12152
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012153 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12154 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012155 cds_info("Concurrency mode is not SAP");
12156 return;
12157 }
12158
12159 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012160 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12161 &ap_adapter->event_flags) &&
12162 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12163 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012164
12165 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12166 ap_adapter->sessionCtx.ap.sapConfig.channel =
12167 AUTO_CHANNEL_SELECT;
12168 ap_adapter->sessionCtx.ap.sapConfig.
12169 acs_cfg.acs_mode = true;
12170
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012171 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012172 }
12173}
12174
12175/**
12176 * hdd_set_connection_in_progress() - to set the connection in
12177 * progress flag
12178 * @value: value to set
12179 *
12180 * This function will set the passed value to connection in progress flag.
12181 * If value is previously being set to true then no need to set it again.
12182 *
12183 * Return: true if value is being set correctly and false otherwise.
12184 */
12185bool hdd_set_connection_in_progress(bool value)
12186{
12187 bool status = true;
12188 hdd_context_t *hdd_ctx;
12189
12190 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12191 if (!hdd_ctx) {
12192 cds_err("HDD context is NULL");
12193 return false;
12194 }
12195
12196 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12197 /*
12198 * if the value is set to true previously and if someone is
12199 * trying to make it true again then it could be some race
12200 * condition being triggered. Avoid this situation by returning
12201 * false
12202 */
12203 if (hdd_ctx->connection_in_progress && value)
12204 status = false;
12205 else
12206 hdd_ctx->connection_in_progress = value;
12207 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12208 return status;
12209}
12210
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012211int wlan_hdd_send_p2p_quota(hdd_adapter_t *adapter, int set_value)
12212{
12213 if (!adapter) {
12214 hdd_err("Invalid adapter");
12215 return -EINVAL;
12216 }
12217 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012218 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012219 WMA_VDEV_MCC_SET_TIME_QUOTA,
12220 set_value, VDEV_CMD);
12221 return 0;
12222
12223}
12224
12225int wlan_hdd_send_mcc_latency(hdd_adapter_t *adapter, int set_value)
12226{
12227 if (!adapter) {
12228 hdd_err("Invalid adapter");
12229 return -EINVAL;
12230 }
12231
12232 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012233 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012234 WMA_VDEV_MCC_SET_TIME_LATENCY,
12235 set_value, VDEV_CMD);
12236 return 0;
12237}
12238
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012239hdd_adapter_t *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
12240 *psoc, uint8_t vdev_id)
12241{
12242 hdd_adapter_t *adapter = NULL;
12243 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12244
12245 /*
12246 * Currently PSOC is not being used. But this logic will
12247 * change once we have the converged implementation of
12248 * HDD context per PSOC in place. This would break if
12249 * multiple vdev objects reuse the vdev id.
12250 */
12251 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12252 if (!adapter)
12253 hdd_err("Get adapter by vdev id failed");
12254
12255 return adapter;
12256}
12257
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012258int hdd_get_rssi_snr_by_bssid(hdd_adapter_t *adapter, const uint8_t *bssid,
12259 int8_t *rssi, int8_t *snr)
12260{
12261 QDF_STATUS status;
12262 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12263 tCsrRoamProfile *profile = &wext_state->roamProfile;
12264
12265 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12266 profile, bssid, rssi, snr);
12267 if (QDF_STATUS_SUCCESS != status) {
12268 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12269 return -EINVAL;
12270 }
12271
12272 return 0;
12273}
12274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012275/* Register the module init/exit functions */
12276module_init(hdd_module_init);
12277module_exit(hdd_module_exit);
12278
12279MODULE_LICENSE("Dual BSD/GPL");
12280MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12281MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012283module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12284 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012285
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012286module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12287 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012289module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12290 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12291
12292module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12293
12294module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12295
12296module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);