blob: a35d1db76db86d56a683a1e63fb66674c409e750 [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
Rajeev Kumarfec3dbe2016-01-19 15:23:52 -0800694 if (cds_is_load_or_unload_in_progress()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695 return -EAGAIN;
696 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530697
698 if (hdd_ctx->start_modules_in_progress ||
699 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800700 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530701 (void *)_RET_IP_);
702 return -EAGAIN;
703 }
704
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530705 if (cds_is_driver_in_bad_state()) {
706 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
707 (void *)_RET_IP_, cds_get_driver_state());
708 return -ENODEV;
709 }
710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800711 return 0;
712}
713
Dustin Brownf13b8c32017-05-19 17:23:08 -0700714int hdd_validate_adapter(hdd_adapter_t *adapter)
715{
716 if (!adapter) {
717 hdd_err("adapter is null");
718 return -EINVAL;
719 }
720
721 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
722 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
723 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
724 return -EINVAL;
725 }
726
727 if (!adapter->dev) {
728 hdd_err("adapter net_device is null");
729 return -EINVAL;
730 }
731
732 if (!(adapter->dev->flags & IFF_UP)) {
733 hdd_info("adapter net_device is not up");
734 return -EAGAIN;
735 }
736
737 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
738 hdd_info("adapter session is not open");
739 return -EAGAIN;
740 }
741
742 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
743 hdd_err("bad adapter session Id: %u", adapter->sessionId);
744 return -EINVAL;
745 }
746
747 return 0;
748}
749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530751 * wlan_hdd_validate_modules_state() - Check modules status
752 * @hdd_ctx: HDD context pointer
753 *
754 * Check's the driver module's state and returns true if the
755 * modules are enabled returns false if modules are closed.
756 *
757 * Return: True if modules are enabled or false.
758 */
759bool wlan_hdd_validate_modules_state(hdd_context_t *hdd_ctx)
760{
761 mutex_lock(&hdd_ctx->iface_change_lock);
762 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
763 mutex_unlock(&hdd_ctx->iface_change_lock);
764 hdd_notice("Modules not enabled, Present status: %d",
765 hdd_ctx->driver_status);
766 return false;
767 }
768 mutex_unlock(&hdd_ctx->iface_change_lock);
769 return true;
770}
771
772/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
774 * @hdd_adapter_t Hdd adapter.
775 *
776 * This function sets the IBSS power save config parameters to WMA
777 * which will send it to firmware if FW supports IBSS power save
778 * before vdev start.
779 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530780 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781 * on failure.
782 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530783QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784{
785 int ret;
786 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
787
788 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700789 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530790 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 }
792
Naveen Rawat247a8682017-06-05 15:00:31 -0700793 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
795 hdd_ctx->config->ibssATIMWinSize,
796 VDEV_CMD);
797 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700798 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530799 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 }
801
Naveen Rawat247a8682017-06-05 15:00:31 -0700802 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
804 hdd_ctx->config->isIbssPowerSaveAllowed,
805 VDEV_CMD);
806 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700807 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
808 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530809 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 }
811
Naveen Rawat247a8682017-06-05 15:00:31 -0700812 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
814 hdd_ctx->config->
815 isIbssPowerCollapseAllowed, VDEV_CMD);
816 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700817 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
818 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530819 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 }
821
Naveen Rawat247a8682017-06-05 15:00:31 -0700822 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
824 hdd_ctx->config->isIbssAwakeOnTxRx,
825 VDEV_CMD);
826 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700827 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530828 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 }
830
Naveen Rawat247a8682017-06-05 15:00:31 -0700831 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800832 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
833 hdd_ctx->config->ibssInactivityCount,
834 VDEV_CMD);
835 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700836 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530837 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 }
839
Naveen Rawat247a8682017-06-05 15:00:31 -0700840 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
842 hdd_ctx->config->ibssTxSpEndInactivityTime,
843 VDEV_CMD);
844 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700845 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
846 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530847 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848 }
849
Naveen Rawat247a8682017-06-05 15:00:31 -0700850 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
852 hdd_ctx->config->ibssPsWarmupTime,
853 VDEV_CMD);
854 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700855 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
856 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530857 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 }
859
Naveen Rawat247a8682017-06-05 15:00:31 -0700860 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
862 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
863 VDEV_CMD);
864 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700865 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
866 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530867 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868 }
869
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530870 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800871}
872
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873#define INTF_MACADDR_MASK 0x7
874
875/**
876 * hdd_update_macaddr() - update mac address
877 * @config: hdd configuration
878 * @hw_macaddr: mac address
879 *
880 * Mac address for multiple virtual interface is found as following
881 * i) The mac address of the first interface is just the actual hw mac address.
882 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
883 * define the mac address for the remaining interfaces and locally
884 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
885 * supported virtual interfaces, right now this is 0x07 (meaning 8
886 * interface).
887 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
888 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
889 *
890 * Return: None
891 */
892void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530893 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894{
895 int8_t i;
896 uint8_t macaddr_b3, tmp_br3;
897
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530898 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530899 QDF_MAC_ADDR_SIZE);
900 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530901 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530902 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 macaddr_b3 = config->intfMacAddr[i].bytes[3];
904 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
905 INTF_MACADDR_MASK;
906 macaddr_b3 += tmp_br3;
907
908 /* XOR-ing bit-24 of the mac address. This will give enough
909 * mac address range before collision
910 */
911 macaddr_b3 ^= (1 << 7);
912
913 /* Set locally administered bit */
914 config->intfMacAddr[i].bytes[0] |= 0x02;
915 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800916 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 MAC_ADDRESS_STR, i,
918 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
919 }
920}
921
922static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
923 struct wma_tgt_services *cfg)
924{
925 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926
927 /* Set up UAPSD */
928 config->apUapsdEnabled &= cfg->uapsd;
929
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800930 /* 11AX mode support */
931 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
932 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
933 config->dot11Mode = eHDD_DOT11_MODE_11ac;
934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935 /* 11AC mode support */
936 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
937 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
938 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939
940 /* ARP offload: override user setting if invalid */
941 config->fhostArpOffload &= cfg->arp_offload;
942
943#ifdef FEATURE_WLAN_SCAN_PNO
944 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800945 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 if (cfg->pno_offload)
947 config->PnoOffload = true;
948#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949#ifdef FEATURE_WLAN_TDLS
950 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530951 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
952 cfg->en_tdls_offchan;
953 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
954 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700955 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700957 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960#ifdef WLAN_FEATURE_ROAM_OFFLOAD
961 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
962#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700963 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964
965}
966
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700967/**
968 * hdd_update_vdev_nss() - sets the vdev nss
969 * @hdd_ctx: HDD context
970 *
971 * Sets the Nss per vdev type based on INI
972 *
973 * Return: None
974 */
975static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
976{
977 struct hdd_config *cfg_ini = hdd_ctx->config;
978 uint8_t max_supp_nss = 1;
979
Naveen Rawat10b1c152017-01-18 11:16:06 -0800980 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700981 max_supp_nss = 2;
982
983 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
984 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
985
986 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
987 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
988}
989
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530990/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +0530991 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
992 * @hdd_ctx: HDD context
993 *
994 * Updates wiphy vhtcap fields
995 *
996 * Return: None
997 */
998static void hdd_update_wiphy_vhtcap(hdd_context_t *hdd_ctx)
999{
1000 struct ieee80211_supported_band *band_5g =
1001 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1002 uint32_t val;
1003
1004 if (!band_5g) {
1005 hdd_debug("5GHz band disabled, skipping capability population");
1006 return;
1007 }
1008
1009 val = hdd_ctx->config->txBFCsnValue;
1010 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1011
1012 val = NUM_OF_SOUNDING_DIMENSIONS;
1013 band_5g->vht_cap.cap |=
1014 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1015
1016 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1017 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1018}
1019
1020/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301021 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1022 * @hdd_ctx: HDD context
1023 *
1024 * Sets the DBS capability as per INI and firmware capability
1025 *
1026 * Return: None
1027 */
1028static void hdd_update_hw_dbs_capable(hdd_context_t *hdd_ctx)
1029{
1030 struct hdd_config *cfg_ini = hdd_ctx->config;
1031 uint8_t hw_dbs_capable = 0;
1032
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001033 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1034 ((cfg_ini->dual_mac_feature_disable ==
1035 ENABLE_DBS_CXN_AND_SCAN) ||
1036 (cfg_ini->dual_mac_feature_disable ==
1037 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301038 hw_dbs_capable = 1;
1039
1040 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1041}
1042
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
1044 struct wma_tgt_ht_cap *cfg)
1045{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301046 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 uint32_t value, val32;
1048 uint16_t val16;
1049 struct hdd_config *pconfig = hdd_ctx->config;
1050 tSirMacHTCapabilityInfo *phtCapInfo;
1051 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1052 uint8_t enable_tx_stbc;
1053
1054 /* check and update RX STBC */
1055 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1056 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1057
1058 /* get the MPDU density */
1059 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1060
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301061 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001062 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 value = 0;
1064 }
1065
1066 /*
1067 * MPDU density:
1068 * override user's setting if value is larger
1069 * than the one supported by target
1070 */
1071 if (value > cfg->mpdu_density) {
1072 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1073 cfg->mpdu_density);
1074
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301075 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001076 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 }
1078
1079 /* get the HT capability info */
1080 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301081 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001082 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 return;
1084 }
1085 val16 = (uint16_t) val32;
1086 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1087
1088 /* Set the LDPC capability */
1089 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1090
1091 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1092 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1093
1094 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1095 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1096
1097 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1098 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1099
1100 enable_tx_stbc = pconfig->enableTxSTBC;
1101
1102 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1103 pconfig->enable2x2 = 1;
1104 } else {
1105 pconfig->enable2x2 = 0;
1106 enable_tx_stbc = 0;
1107
1108 /* 1x1 */
1109 /* Update Rx Highest Long GI data Rate */
1110 if (sme_cfg_set_int(hdd_ctx->hHal,
1111 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001112 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301113 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001114 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 }
1116
1117 /* Update Tx Highest Long GI data Rate */
1118 if (sme_cfg_set_int
1119 (hdd_ctx->hHal,
1120 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001121 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301122 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001123 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 }
1125 }
1126 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1127 enable_tx_stbc = 0;
1128 phtCapInfo->txSTBC = enable_tx_stbc;
1129
1130 val32 = val16;
1131 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301132 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001133 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1135 value = SIZE_OF_SUPPORTED_MCS_SET;
1136 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301137 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001138 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139
1140 if (pconfig->enable2x2) {
1141 for (value = 0; value < cfg->num_rf_chains; value++)
1142 mcs_set[value] =
1143 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1144
1145 status =
1146 sme_cfg_set_str(hdd_ctx->hHal,
1147 WNI_CFG_SUPPORTED_MCS_SET,
1148 mcs_set,
1149 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301150 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001151 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 }
1153 }
1154#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1155}
1156
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
1158 struct wma_tgt_vht_cap *cfg)
1159{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301160 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 uint32_t value = 0;
1162 struct hdd_config *pconfig = hdd_ctx->config;
1163 struct wiphy *wiphy = hdd_ctx->wiphy;
1164 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001165 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001166 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001167 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001168 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169
Dustin Brown5e06bd32016-10-04 12:49:10 -07001170 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001171 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001172 return;
1173 }
1174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001175 /* Get the current MPDU length */
1176 status =
1177 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1178 &value);
1179
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301180 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001181 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182 value = 0;
1183 }
1184
1185 /*
1186 * VHT max MPDU length:
1187 * override if user configured value is too high
1188 * that the target cannot support
1189 */
1190 if (value > cfg->vht_max_mpdu) {
1191 status = sme_cfg_set_int(hdd_ctx->hHal,
1192 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1193 cfg->vht_max_mpdu);
1194
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001195 if (status == QDF_STATUS_E_FAILURE)
1196 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197 }
1198
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001199 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1200 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1201
1202 if (pconfig->enable2x2)
1203 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1204
1205 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1206 QDF_STATUS_E_FAILURE) {
1207 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1208 }
1209
1210 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1211 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1212 if (pconfig->enable2x2)
1213 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1214
1215 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1216 QDF_STATUS_E_FAILURE) {
1217 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1218 }
1219
1220 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1221 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1222 if (pconfig->enable2x2)
1223 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1224
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001225 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001226 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1227
1228 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1229 QDF_STATUS_E_FAILURE) {
1230 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1231 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001233 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 &value);
1235
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301236 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001237 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238 value = 0;
1239 }
1240
jiad4a7a33c2017-08-08 15:32:24 +08001241 /* Set HW RX LDPC capability */
1242 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1243 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244 status = sme_cfg_set_int(hdd_ctx->hHal,
1245 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001246 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001247
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001248 if (status == QDF_STATUS_E_FAILURE)
1249 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250 }
1251
1252 /* Get current GI 80 value */
1253 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1254 &value);
1255
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301256 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001257 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 value = 0;
1259 }
1260
1261 /* set the Guard interval 80MHz */
1262 if (value && !cfg->vht_short_gi_80) {
1263 status = sme_cfg_set_int(hdd_ctx->hHal,
1264 WNI_CFG_VHT_SHORT_GI_80MHZ,
1265 cfg->vht_short_gi_80);
1266
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001267 if (status == QDF_STATUS_E_FAILURE)
1268 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 }
1270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 /* Get VHT TX STBC cap */
1272 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1273
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301274 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001275 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001276 value = 0;
1277 }
1278
1279 /* VHT TX STBC cap */
1280 if (value && !cfg->vht_tx_stbc) {
1281 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1282 cfg->vht_tx_stbc);
1283
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001284 if (status == QDF_STATUS_E_FAILURE)
1285 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001286 }
1287
1288 /* Get VHT RX STBC cap */
1289 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1290
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301291 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001292 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 value = 0;
1294 }
1295
1296 /* VHT RX STBC cap */
1297 if (value && !cfg->vht_rx_stbc) {
1298 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1299 cfg->vht_rx_stbc);
1300
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001301 if (status == QDF_STATUS_E_FAILURE)
1302 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001303 }
1304
1305 /* Get VHT SU Beamformer cap */
1306 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1307 &value);
1308
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301309 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001310 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001311 value = 0;
1312 }
1313
1314 /* set VHT SU Beamformer cap */
1315 if (value && !cfg->vht_su_bformer) {
1316 status = sme_cfg_set_int(hdd_ctx->hHal,
1317 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1318 cfg->vht_su_bformer);
1319
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001320 if (status == QDF_STATUS_E_FAILURE)
1321 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 }
1323
1324 /* check and update SU BEAMFORMEE capabality */
1325 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1326 pconfig->enableTxBF = cfg->vht_su_bformee;
1327
1328 status = sme_cfg_set_int(hdd_ctx->hHal,
1329 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1330 pconfig->enableTxBF);
1331
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001332 if (status == QDF_STATUS_E_FAILURE)
1333 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334
1335 /* Get VHT MU Beamformer cap */
1336 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1337 &value);
1338
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301339 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001340 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341 value = 0;
1342 }
1343
1344 /* set VHT MU Beamformer cap */
1345 if (value && !cfg->vht_mu_bformer) {
1346 status = sme_cfg_set_int(hdd_ctx->hHal,
1347 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1348 cfg->vht_mu_bformer);
1349
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001350 if (status == QDF_STATUS_E_FAILURE)
1351 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001352 }
1353
1354 /* Get VHT MU Beamformee cap */
1355 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1356 &value);
1357
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301358 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001359 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 value = 0;
1361 }
1362
1363 /* set VHT MU Beamformee cap */
1364 if (value && !cfg->vht_mu_bformee) {
1365 status = sme_cfg_set_int(hdd_ctx->hHal,
1366 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1367 cfg->vht_mu_bformee);
1368
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001369 if (status == QDF_STATUS_E_FAILURE)
1370 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371 }
1372
1373 /* Get VHT MAX AMPDU Len exp */
1374 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1375 &value);
1376
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301377 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001378 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 value = 0;
1380 }
1381
1382 /*
1383 * VHT max AMPDU len exp:
1384 * override if user configured value is too high
1385 * that the target cannot support.
1386 * Even though Rome publish ampdu_len=7, it can
1387 * only support 4 because of some h/w bug.
1388 */
1389
1390 if (value > cfg->vht_max_ampdu_len_exp) {
1391 status = sme_cfg_set_int(hdd_ctx->hHal,
1392 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1393 cfg->vht_max_ampdu_len_exp);
1394
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001395 if (status == QDF_STATUS_E_FAILURE)
1396 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001397 }
1398
1399 /* Get VHT TXOP PS CAP */
1400 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1401
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301402 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001403 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 value = 0;
1405 }
1406
1407 /* set VHT TXOP PS cap */
1408 if (value && !cfg->vht_txop_ps) {
1409 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1410 cfg->vht_txop_ps);
1411
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001412 if (status == QDF_STATUS_E_FAILURE)
1413 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 }
1415
1416 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1417 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1418 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1419 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1420 else
1421 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1422
1423
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001424 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1425 status = sme_cfg_set_int(hdd_ctx->hHal,
1426 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1427 VHT_CAP_160_AND_80P80_SUPP);
1428 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001429 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430 band_5g->vht_cap.cap |=
1431 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001432 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1433 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1434 status = sme_cfg_set_int(hdd_ctx->hHal,
1435 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1436 VHT_CAP_160_SUPP);
1437 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001438 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 band_5g->vht_cap.cap |=
1440 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001441 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1442 }
1443 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1444 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301445 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001446 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301447 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001448 &value);
1449 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301450 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001451 value = 0;
1452 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301453 /* set the Guard interval 160MHz */
1454 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001455 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301456 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1457 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001458
1459 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301460 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001461 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001462
1463 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1464 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1465
1466 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1467 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1468 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1469 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1470
1471 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1472 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1473
1474 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1475 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1476 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1477 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1478 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1479 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1480
1481 band_5g->vht_cap.cap |=
1482 (cfg->vht_max_ampdu_len_exp <<
1483 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1484
1485 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1486 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1487 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1488 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1489 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1490 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1491 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1492 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1493
1494 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1495 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1496
1497}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001499/**
1500 * hdd_generate_macaddr_auto() - Auto-generate mac address
1501 * @hdd_ctx: Pointer to the HDD context
1502 *
1503 * Auto-generate mac address using device serial number.
1504 * Keep the first 3 bytes of OUI as before and replace
1505 * the last 3 bytes with the lower 3 bytes of serial number.
1506 *
1507 * Return: 0 for success
1508 * Non zero failure code for errors
1509 */
1510static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1511{
1512 unsigned int serialno = 0;
1513 struct qdf_mac_addr mac_addr = {
1514 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1515 };
1516
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001517 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001518 if (serialno == 0)
1519 return -EINVAL;
1520
1521 serialno &= 0x00ffffff;
1522
1523 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1524 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1525 mac_addr.bytes[5] = serialno & 0xff;
1526
1527 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1528 return 0;
1529}
1530
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301531/**
1532 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1533 * configuration to cfg_ini in HDD
1534 * @hdd_ctx: Pointer to hdd_ctx
1535 * @cfg: target configuration
1536 *
1537 * Return: None
1538 */
1539#ifdef FEATURE_WLAN_RA_FILTERING
1540static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1541 struct wma_tgt_cfg *cfg)
1542{
1543 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1544}
1545#else
1546static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1547 struct wma_tgt_cfg *cfg)
1548{
1549}
1550#endif
1551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552void hdd_update_tgt_cfg(void *context, void *param)
1553{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001554 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1556 struct wma_tgt_cfg *cfg = param;
1557 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001558 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301559 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301560
Yue Mae3e86ab2017-05-08 10:48:24 -07001561 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301562 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1563 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1564 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1565 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1566 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001567 /* Restore pdev to MAC/WMA contexts */
1568 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001569 } else {
1570 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1571 if (ret) {
1572 hdd_err("pdev creation fails!");
1573 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301574 } else
1575 hdd_debug("New pdev has been created with pdev_id = %u",
1576 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301577 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001578
Naveen Rawat64e477e2016-05-20 10:34:56 -07001579 if (cds_cfg) {
1580 if (hdd_ctx->config->enable_sub_20_channel_width !=
1581 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1582 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1583 cds_cfg->sub_20_channel_width =
1584 WLAN_SUB_20_CH_WIDTH_NONE;
1585 } else {
1586 cds_cfg->sub_20_channel_width =
1587 hdd_ctx->config->enable_sub_20_channel_width;
1588 }
1589 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590
1591 /* first store the INI band capability */
1592 temp_band_cap = hdd_ctx->config->nBandCapability;
1593
1594 hdd_ctx->config->nBandCapability = cfg->band_cap;
1595
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001596 /*
1597 * now overwrite the target band capability with INI
1598 * setting if INI setting is a subset
1599 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600
1601 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1602 (temp_band_cap != eCSR_BAND_ALL))
1603 hdd_ctx->config->nBandCapability = temp_band_cap;
1604 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1605 (temp_band_cap != eCSR_BAND_ALL) &&
1606 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001607 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 }
1609
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301610 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1612 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1613 }
1614
1615 /* This can be extended to other configurations like ht, vht cap... */
1616
Anurag Chouhanc5548422016-02-24 18:33:27 +05301617 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001619 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001621 static struct qdf_mac_addr default_mac_addr = {
1622 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1623 };
1624 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1625 &default_mac_addr)) {
1626 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1627 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1628 MAC_ADDRESS_STR,
1629 MAC_ADDR_ARRAY(hdd_ctx->config->
1630 intfMacAddr[0].bytes));
1631 } else {
1632 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1633 MAC_ADDRESS_STR,
1634 MAC_ADDR_ARRAY(hdd_ctx->config->
1635 intfMacAddr[0].bytes));
1636 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001637 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 }
1639
1640 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001641 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642
1643 hdd_ctx->max_intf_count = cfg->max_intf_count;
1644
Jeff Johnsonc875e242016-09-23 18:12:34 -07001645 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001646 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1649 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1650
1651 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001654 if (cfg->services.en_11ax) {
1655 hdd_info("11AX: 11ax is enabled - update HDD config");
1656 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1657 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001658
1659 hdd_update_vdev_nss(hdd_ctx);
1660
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301661 hdd_update_hw_dbs_capable(hdd_ctx);
1662
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001663 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001664 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001665 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001666 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001667
Nitesh Shahe50711f2017-04-26 16:30:45 +05301668 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1669 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1670 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001671 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001672 hdd_ctx->current_antenna_mode);
1673
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001674 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1675 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301676 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301677
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301678 if ((hdd_ctx->config->txBFCsnValue >
1679 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1680 !cfg->tx_bfee_8ss_enabled)
1681 hdd_ctx->config->txBFCsnValue =
1682 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1683
1684 if (sme_cfg_set_int(hdd_ctx->hHal,
1685 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1686 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1687 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1688
1689
1690 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1691 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1692 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301693
1694 /*
1695 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1696 */
1697 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301698 /*
1699 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1700 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1701 * configure the STA mode wow pattern.
1702 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301703 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301704 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301705
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301706 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1707
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001708 /* Configure NAN datapath features */
1709 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001710 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711}
1712
Arif Hussaincd151632017-02-11 16:57:19 -08001713bool hdd_dfs_indicate_radar(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1716 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301717 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301718 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719
Arif Hussaincd151632017-02-11 16:57:19 -08001720 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
1721 hdd_info("skip tx block hdd_ctx=%p, disableDFSChSwitch=%d",
1722 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301723 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001724 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725
Arif Hussaincd151632017-02-11 16:57:19 -08001726 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1727 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1728 adapter = adapterNode->pAdapter;
1729 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1730
1731 if ((QDF_SAP_MODE == adapter->device_mode ||
1732 QDF_P2P_GO_MODE == adapter->device_mode) &&
1733 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1734 ap_ctx->operatingChannel))) {
1735 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1736 true;
1737 hdd_info("tx blocked for session: %d",
1738 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301739 }
Arif Hussaincd151632017-02-11 16:57:19 -08001740 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1741 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001742 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301743
1744 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001745}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746
1747/**
1748 * hdd_is_valid_mac_address() - validate MAC address
1749 * @pMacAddr: Pointer to the input MAC address
1750 *
1751 * This function validates whether the given MAC address is valid or not
1752 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1753 * where X is the hexa decimal digit character and separated by ':'
1754 * This algorithm works even if MAC address is not separated by ':'
1755 *
1756 * This code checks given input string mac contains exactly 12 hexadecimal
1757 * digits and a separator colon : appears in the input string only after
1758 * an even number of hex digits.
1759 *
1760 * Return: 1 for valid and 0 for invalid
1761 */
1762bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1763{
1764 int xdigit = 0;
1765 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767 while (*pMacAddr) {
1768 if (isxdigit(*pMacAddr)) {
1769 xdigit++;
1770 } else if (':' == *pMacAddr) {
1771 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1772 break;
1773
1774 ++separator;
1775 } else {
1776 /* Invalid MAC found */
1777 return 0;
1778 }
1779 ++pMacAddr;
1780 }
1781 return xdigit == 12 && (separator == 5 || separator == 0);
1782}
1783
1784/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301785 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1786 * @dev: Handle to struct net_device to be updated.
1787 *
1788 * Return: None
1789 */
1790static void hdd_mon_mode_ether_setup(struct net_device *dev)
1791{
1792 dev->header_ops = NULL;
1793 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1794 dev->hard_header_len = ETH_HLEN;
1795 dev->mtu = ETH_DATA_LEN;
1796 dev->addr_len = ETH_ALEN;
1797 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1798 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1799 dev->priv_flags |= IFF_TX_SKB_SHARING;
1800
1801 memset(dev->broadcast, 0xFF, ETH_ALEN);
1802}
1803
1804/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001805 * __hdd__mon_open() - HDD Open function
1806 * @dev: Pointer to net_device structure
1807 *
1808 * This is called in response to ifconfig up
1809 *
1810 * Return: 0 for success; non-zero for failure
1811 */
1812static int __hdd_mon_open(struct net_device *dev)
1813{
1814 int ret;
1815
1816 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301817 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001818 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001819
1820 if (!ret)
1821 ret = hdd_enable_monitor_mode(dev);
1822
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001823 return ret;
1824}
1825
1826/**
1827 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1828 * @dev: Pointer to net_device structure
1829 *
1830 * This is called in response to ifconfig up
1831 *
1832 * Return: 0 for success; non-zero for failure
1833 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001834static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001835{
1836 int ret;
1837
1838 cds_ssr_protect(__func__);
1839 ret = __hdd_mon_open(dev);
1840 cds_ssr_unprotect(__func__);
1841
1842 return ret;
1843}
1844
1845/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301846 * hdd_start_adapter() - Wrapper function for device specific adapter
1847 * @adapter: pointer to HDD adapter
1848 *
1849 * This function is called to start the device specific adapter for
1850 * the mode passed in the adapter's device_mode.
1851 *
1852 * Return: 0 for success; non-zero for failure
1853 */
1854int hdd_start_adapter(hdd_adapter_t *adapter)
1855{
1856
1857 int ret;
1858 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1859
1860 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001861 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301862
1863 switch (device_mode) {
1864 case QDF_P2P_CLIENT_MODE:
1865 case QDF_P2P_DEVICE_MODE:
1866 case QDF_OCB_MODE:
1867 case QDF_STA_MODE:
1868 case QDF_MONITOR_MODE:
1869 ret = hdd_start_station_adapter(adapter);
1870 if (ret)
1871 goto err_start_adapter;
1872 break;
1873 case QDF_P2P_GO_MODE:
1874 case QDF_SAP_MODE:
1875 ret = hdd_start_ap_adapter(adapter);
1876 if (ret)
1877 goto err_start_adapter;
1878 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301879 case QDF_IBSS_MODE:
1880 /*
1881 * For IBSS interface is initialized as part of
1882 * hdd_init_station_mode()
1883 */
1884 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301885 case QDF_FTM_MODE:
1886 ret = hdd_start_ftm_adapter(adapter);
1887 if (ret)
1888 goto err_start_adapter;
1889 break;
1890 default:
1891 hdd_err("Invalid session type %d", device_mode);
1892 QDF_ASSERT(0);
1893 goto err_start_adapter;
1894 }
1895 if (hdd_set_fw_params(adapter))
1896 hdd_err("Failed to set the FW params for the adapter!");
1897
1898 /*
1899 * Action frame registered in one adapter which will
1900 * applicable to all interfaces
1901 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301902 ret = wlan_hdd_cfg80211_register_frames(adapter);
1903 if (ret < 0) {
1904 hdd_err("Failed to register frames - ret %d", ret);
1905 goto err_start_adapter;
1906 }
1907
Arun Khandavallifae92942016-08-01 13:31:08 +05301908 EXIT();
1909 return 0;
1910err_start_adapter:
1911 return -EINVAL;
1912}
1913
1914/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301915 * hdd_enable_power_management() - API to Enable Power Management
1916 *
1917 * API invokes Bus Interface Layer power management functionality
1918 *
1919 * Return: None
1920 */
1921static void hdd_enable_power_management(void)
1922{
1923 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1924
1925 if (!hif_ctx) {
1926 hdd_err("Bus Interface Context is Invalid");
1927 return;
1928 }
1929
1930 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1931}
1932
1933/**
1934 * hdd_disable_power_management() - API to disable Power Management
1935 *
1936 * API disable Bus Interface Layer Power management functionality
1937 *
1938 * Return: None
1939 */
1940static void hdd_disable_power_management(void)
1941{
1942 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1943
1944 if (!hif_ctx) {
1945 hdd_err("Bus Interface Context is Invalid");
1946 return;
1947 }
1948
1949 hif_disable_power_management(hif_ctx);
1950}
1951
1952/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301953 * hdd_update_hw_sw_info() - API to update the HW/SW information
1954 *
1955 * API to update the HW and SW information in the driver
1956 *
1957 * Return: None
1958 */
1959static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1960{
1961 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07001962 size_t target_hw_name_len;
1963 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301964
1965 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1966 if (!hif_sc) {
1967 hdd_err("HIF context is NULL");
1968 return;
1969 }
1970
1971 /*
1972 * target hw version/revision would only be retrieved after firmware
1973 * download
1974 */
Dustin Brown6f17a022017-07-19 13:40:55 -07001975 hif_get_hw_info(hif_sc,
1976 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301977 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07001978 &target_hw_name);
1979
1980 if (hdd_ctx->target_hw_name)
1981 qdf_mem_free(hdd_ctx->target_hw_name);
1982
1983 target_hw_name_len = strlen(target_hw_name) + 1;
1984 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
1985 if (hdd_ctx->target_hw_name)
1986 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
1987 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301988
1989 /* Get the wlan hw/fw version */
1990 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
1991
1992 return;
1993}
1994
1995/**
gbian62edd7e2017-03-07 13:12:13 +08001996 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1997 * @hdd_ctx: Pointer to hdd context
1998 *
1999 * Return: none
2000 */
2001static void
2002hdd_update_cds_ac_specs_params(hdd_context_t *hdd_ctx)
2003{
2004 uint8_t num_entries = 0;
2005 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2006 uint8_t *tx_sched_wrr_ac;
2007 int i;
2008 cds_context_type *cds_ctx;
2009
2010 if (NULL == hdd_ctx)
2011 return;
2012
2013 if (NULL == hdd_ctx->config) {
2014 /* Do nothing if hdd_ctx is invalid */
2015 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2016 return;
2017 }
2018
2019 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2020
2021 if (!cds_ctx) {
2022 hdd_err("Invalid CDS Context");
2023 return;
2024 }
2025
2026 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2027 switch (i) {
2028 case OL_TX_WMM_AC_BE:
2029 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2030 break;
2031 case OL_TX_WMM_AC_BK:
2032 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2033 break;
2034 case OL_TX_WMM_AC_VI:
2035 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2036 break;
2037 case OL_TX_WMM_AC_VO:
2038 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2039 break;
2040 default:
2041 tx_sched_wrr_ac = NULL;
2042 break;
2043 }
2044
2045 hdd_string_to_u8_array(tx_sched_wrr_ac,
2046 tx_sched_wrr_param,
2047 &num_entries,
2048 sizeof(tx_sched_wrr_param));
2049
2050 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2051 cds_ctx->ac_specs[i].wrr_skip_weight =
2052 tx_sched_wrr_param[0];
2053 cds_ctx->ac_specs[i].credit_threshold =
2054 tx_sched_wrr_param[1];
2055 cds_ctx->ac_specs[i].send_limit =
2056 tx_sched_wrr_param[2];
2057 cds_ctx->ac_specs[i].credit_reserve =
2058 tx_sched_wrr_param[3];
2059 cds_ctx->ac_specs[i].discard_weight =
2060 tx_sched_wrr_param[4];
2061 }
2062
2063 num_entries = 0;
2064 }
2065}
2066
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002067#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002068static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2069 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2070{
2071 hdd_adapter_t *adapter = NULL;
2072 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2073
2074 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2075 if (!adapter) {
2076 hdd_err("Adapter is NULL");
2077 return PM_MAX_NUM_OF_MODE;
2078 }
2079
2080 return policy_mgr_convert_device_mode_to_qdf_type(
2081 adapter->device_mode);
2082}
2083
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002084static void hdd_register_policy_manager_callback(
2085 struct wlan_objmgr_psoc *psoc)
2086{
2087 struct policy_mgr_hdd_cbacks hdd_cbacks;
2088 hdd_cbacks.sap_restart_chan_switch_cb =
2089 sap_restart_chan_switch_cb;
2090 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2091 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002092 hdd_cbacks.get_mode_for_non_connected_vdev =
2093 wlan_hdd_get_mode_for_non_connected_vdev;
2094
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002095 if (QDF_STATUS_SUCCESS !=
2096 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2097 hdd_err("HDD callback registration with policy manager failed");
2098 }
2099}
2100#else
2101static void hdd_register_policy_manager_callback(
2102 struct wlan_objmgr_psoc *psoc)
2103{
2104}
2105#endif
2106
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002107#ifdef WLAN_FEATURE_NAN_CONVERGENCE
2108static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2109{
2110 struct nan_callbacks cb_obj = {0};
2111
2112 cb_obj.ndi_open = hdd_ndi_open;
2113 cb_obj.ndi_close = hdd_ndi_close;
2114 cb_obj.ndi_start = hdd_ndi_start;
2115 cb_obj.ndi_delete = hdd_ndi_delete;
2116 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2117 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2118
Naveen Rawat37f62c82017-03-26 22:24:43 -07002119 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2120 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002121 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002122
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002123 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2124}
2125#else
2126static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2127{
2128}
2129#endif
2130
gbian62edd7e2017-03-07 13:12:13 +08002131/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302132 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2133 * @hdd_ctx: HDD context
2134 * @adapter: HDD adapter
2135 * @reinit: flag to indicate from SSR or normal path
2136 *
2137 * This function maintains the driver state machine it will be invoked from
2138 * startup, reinit and change interface. Depending on the driver state shall
2139 * perform the opening of the modules.
2140 *
2141 * Return: 0 for success; non-zero for failure
2142 */
2143int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
2144 bool reinit)
2145{
2146 int ret;
2147 qdf_device_t qdf_dev;
2148 QDF_STATUS status;
2149 p_cds_contextType p_cds_context;
2150 bool unint = false;
2151 void *hif_ctx;
2152
2153 ENTER();
2154
2155 p_cds_context = cds_get_global_context();
2156 if (!p_cds_context) {
2157 hdd_err("Global Context is NULL");
2158 QDF_ASSERT(0);
2159 return -EINVAL;
2160 }
2161
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002162 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302163 hdd_ctx->driver_status, reinit);
2164
2165 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2166 if (!qdf_dev) {
2167 hdd_err("QDF Device Context is Invalid return");
2168 return -EINVAL;
2169 }
2170
2171 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302172 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302173
2174 if (QDF_TIMER_STATE_RUNNING ==
2175 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2176
2177 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002178 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302179 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2180 }
2181
2182 switch (hdd_ctx->driver_status) {
2183 case DRIVER_MODULES_UNINITIALIZED:
2184 unint = true;
2185 /* Fall through dont add break here */
2186 case DRIVER_MODULES_CLOSED:
2187 if (!reinit && !unint) {
2188 ret = pld_power_on(qdf_dev->dev);
2189 if (ret) {
2190 hdd_err("Failed to Powerup the device: %d", ret);
2191 goto release_lock;
2192 }
2193 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002194
2195 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2196 hdd_ctx->config->enable_fw_log);
2197
Arun Khandavallifae92942016-08-01 13:31:08 +05302198 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2199 qdf_dev->bus_type,
2200 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2201 HIF_ENABLE_TYPE_PROBE);
2202 if (ret) {
2203 hdd_err("Failed to open hif: %d", ret);
2204 goto power_down;
2205 }
2206
2207 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302208 if (!hif_ctx) {
2209 hdd_err("hif context is null!!");
2210 goto power_down;
2211 }
2212
Arun Khandavallifae92942016-08-01 13:31:08 +05302213 status = ol_cds_init(qdf_dev, hif_ctx);
2214 if (status != QDF_STATUS_SUCCESS) {
2215 hdd_err("No Memory to Create BMI Context :%d", status);
2216 goto hif_close;
2217 }
2218
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002219 ret = hdd_update_config(hdd_ctx);
2220 if (ret) {
2221 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302222 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002223 }
2224
gbian62edd7e2017-03-07 13:12:13 +08002225 hdd_update_cds_ac_specs_params(hdd_ctx);
2226
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302227 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302228 if (!QDF_IS_STATUS_SUCCESS(status)) {
2229 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302230 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302231 }
2232
Mukul Sharma9d797a02017-01-05 20:26:03 +05302233 /* initalize components configurations after psoc open */
2234 ret = hdd_update_components_config(hdd_ctx);
2235 if (ret) {
2236 hdd_err("Failed to update components configs :%d",
2237 ret);
2238 goto close;
2239 }
2240
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002241 /*
2242 * NAN compoenet requires certian operations like, open adapter,
2243 * close adapter, etc. to be initiated by HDD, for those
2244 * register HDD callbacks with UMAC's NAN componenet.
2245 */
2246 hdd_nan_register_callbacks(hdd_ctx);
2247
Arun Khandavallifae92942016-08-01 13:31:08 +05302248 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2249
2250 status = cds_pre_enable(hdd_ctx->pcds_context);
2251 if (!QDF_IS_STATUS_SUCCESS(status)) {
2252 hdd_err("Failed to pre-enable CDS: %d", status);
2253 goto close;
2254 }
2255
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002256 hdd_register_policy_manager_callback(
2257 hdd_ctx->hdd_psoc);
2258
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302259 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302260 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302261
Arun Khandavallifae92942016-08-01 13:31:08 +05302262 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2263 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2264 hdd_ftm_mc_process_msg);
2265 break;
2266 }
2267 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002268 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302269 break;
2270 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302271
2272 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002273 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2274 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002275 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002276 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302277 }
2278
Arun Khandavallifae92942016-08-01 13:31:08 +05302279 /* Fall through dont add break here */
2280 case DRIVER_MODULES_OPENED:
2281 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002282 hdd_alert("adapter is Null");
2283 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302284 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302285 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2286 hdd_err("in ftm mode, no need to configure cds modules");
2287 break;
2288 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302289 if (hdd_configure_cds(hdd_ctx, adapter)) {
2290 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002291 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302292 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302293 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302294 hdd_info("Driver Modules Successfully Enabled");
2295 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2296 break;
2297 case DRIVER_MODULES_ENABLED:
2298 hdd_info("Driver modules already Enabled");
2299 break;
2300 default:
2301 hdd_err("WLAN start invoked in wrong state! :%d\n",
2302 hdd_ctx->driver_status);
2303 goto release_lock;
2304 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302305 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302306 mutex_unlock(&hdd_ctx->iface_change_lock);
2307 EXIT();
2308 return 0;
2309
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002310post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002311 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002312
Arun Khandavallifae92942016-08-01 13:31:08 +05302313close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002314 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302315 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302316
2317ol_cds_free:
2318 ol_cds_free();
2319
2320hif_close:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302321 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302322power_down:
2323 if (!reinit && !unint)
2324 pld_power_off(qdf_dev->dev);
2325release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302326 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302328 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002329
Arun Khandavallifae92942016-08-01 13:31:08 +05302330 return -EINVAL;
2331}
2332
Naveen Rawat910726a2017-03-06 11:42:51 -08002333#ifdef WIFI_POS_CONVERGED
2334static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2335{
2336 int ret = os_if_wifi_pos_register_nl();
2337
2338 if (ret)
2339 hdd_err("os_if_wifi_pos_register_nl failed");
2340
2341 return ret;
2342}
2343
2344static int hdd_deactivate_wifi_pos(void)
2345{
2346 int ret = os_if_wifi_pos_deregister_nl();
2347
2348 if (ret)
2349 hdd_err("os_if_wifi_pos_deregister_nl failed");
2350
2351 return ret;
2352}
2353
2354/**
2355 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2356 * @hdd_ctx: hdd context
2357 *
2358 * Return: status of operation
2359 */
2360static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2361{
2362 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2363 struct hdd_config *cfg = hdd_ctx->config;
2364
2365 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2366 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2367 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2368 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2369 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2370 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2371 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2372 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2373}
2374#else
2375static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2376{
2377 return oem_activate_service(hdd_ctx);
2378}
2379
2380static int hdd_deactivate_wifi_pos(void)
2381{
2382 return 0;
2383}
2384
2385static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2386{
2387}
2388#endif
2389
Arun Khandavallifae92942016-08-01 13:31:08 +05302390/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002391 * __hdd_open() - HDD Open function
2392 * @dev: Pointer to net_device structure
2393 *
2394 * This is called in response to ifconfig up
2395 *
2396 * Return: 0 for success; non-zero for failure
2397 */
2398static int __hdd_open(struct net_device *dev)
2399{
2400 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2401 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2402 int ret;
2403
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002404 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302405 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302406 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002407
2408 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302409 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412
Arun Khandavallifae92942016-08-01 13:31:08 +05302413 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2414 if (ret) {
2415 hdd_err("Failed to start WLAN modules return");
2416 return -ret;
2417 }
2418
2419
2420 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2421 ret = hdd_start_adapter(adapter);
2422 if (ret) {
2423 hdd_err("Failed to start adapter :%d",
2424 adapter->device_mode);
2425 return ret;
2426 }
2427 }
2428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2430 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002431 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002432 /* Enable TX queues only when we are connected */
2433 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302434 WLAN_START_ALL_NETIF_QUEUE,
2435 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436 }
2437
Naveen Rawat286def52016-09-23 15:38:02 -07002438 /* Enable carrier and transmit queues for NDI */
2439 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002440 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002441 wlan_hdd_netif_queue_control(adapter,
2442 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2443 WLAN_CONTROL_PATH);
2444 }
2445
Naveen Rawat910726a2017-03-06 11:42:51 -08002446 hdd_populate_wifi_pos_cfg(hdd_ctx);
2447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002448 return ret;
2449}
2450
Arun Khandavallifae92942016-08-01 13:31:08 +05302451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002452/**
2453 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2454 * @dev: Pointer to net_device structure
2455 *
2456 * This is called in response to ifconfig up
2457 *
2458 * Return: 0 for success; non-zero for failure
2459 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002460static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002461{
2462 int ret;
2463
2464 cds_ssr_protect(__func__);
2465 ret = __hdd_open(dev);
2466 cds_ssr_unprotect(__func__);
2467
2468 return ret;
2469}
2470
2471/**
2472 * __hdd_stop() - HDD stop function
2473 * @dev: Pointer to net_device structure
2474 *
2475 * This is called in response to ifconfig down
2476 *
2477 * Return: 0 for success; non-zero for failure
2478 */
2479static int __hdd_stop(struct net_device *dev)
2480{
2481 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2482 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2483 int ret;
2484
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002485 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002486
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302487 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 adapter->sessionId, adapter->device_mode));
2489
2490 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302491 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493
2494 /* Nothing to be done if the interface is not opened */
2495 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002496 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002497 return -ENODEV;
2498 }
2499
2500 /* Make sure the interface is marked as closed */
2501 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002502 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302503 wlan_hdd_netif_queue_control(adapter,
2504 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2505 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002506
2507 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002508 * NAN data interface is different in some sense. The traffic on NDI is
2509 * bursty in nature and depends on the need to transfer. The service
2510 * layer may down the interface after the usage and up again when
2511 * required. In some sense, the NDI is expected to be available
2512 * (like SAP) iface until NDI delete request is issued by the service
2513 * layer. Skip BSS termination and adapter deletion for NAN Data
2514 * interface (NDI).
2515 */
2516 if (WLAN_HDD_IS_NDI(adapter))
2517 return 0;
2518
2519 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002520 * The interface is marked as down for outside world (aka kernel)
2521 * But the driver is pretty much alive inside. The driver needs to
2522 * tear down the existing connection on the netdev (session)
2523 * cleanup the data pipes and wait until the control plane is stabilized
2524 * for this interface. The call also needs to wait until the above
2525 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002526 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 * That is intentional to be able to scan if it is a STA/P2P interface
2528 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302529 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530
2531 /* DeInit the adapter. This ensures datapath cleanup as well */
2532 hdd_deinit_adapter(hdd_ctx, adapter, true);
2533
Arun Khandavallifae92942016-08-01 13:31:08 +05302534
2535 /*
2536 * Find if any iface is up. If any iface is up then can't put device to
2537 * sleep/power save mode
2538 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302539 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002540 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302541 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302542 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302543 }
2544
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002545 EXIT();
2546 return 0;
2547}
2548
2549/**
2550 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2551 * @dev: pointer to net_device structure
2552 *
2553 * This is called in response to ifconfig down
2554 *
2555 * Return: 0 for success and error number for failure
2556 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002557static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002558{
2559 int ret;
2560
2561 cds_ssr_protect(__func__);
2562 ret = __hdd_stop(dev);
2563 cds_ssr_unprotect(__func__);
2564
2565 return ret;
2566}
2567
2568/**
2569 * __hdd_uninit() - HDD uninit function
2570 * @dev: Pointer to net_device structure
2571 *
2572 * This is called during the netdev unregister to uninitialize all data
2573 * associated with the device
2574 *
2575 * Return: None
2576 */
2577static void __hdd_uninit(struct net_device *dev)
2578{
2579 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2580
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002581 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002582
2583 do {
2584 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002585 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586 break;
2587 }
2588
2589 if (NULL == adapter->pHddCtx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002590 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002591 break;
2592 }
2593
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002594 if (dev != adapter->dev)
2595 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002596
2597 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2598
2599 /* after uninit our adapter structure will no longer be valid */
2600 adapter->dev = NULL;
2601 adapter->magic = 0;
2602 } while (0);
2603
2604 EXIT();
2605}
2606
2607/**
2608 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2609 * @dev: pointer to net_device structure
2610 *
2611 * This is called during the netdev unregister to uninitialize all data
2612 * associated with the device
2613 *
2614 * Return: none
2615 */
2616static void hdd_uninit(struct net_device *dev)
2617{
2618 cds_ssr_protect(__func__);
2619 __hdd_uninit(dev);
2620 cds_ssr_unprotect(__func__);
2621}
2622
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002623static int hdd_open_cesium_nl_sock(void)
2624{
2625#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2626 struct netlink_kernel_cfg cfg = {
2627 .groups = WLAN_NLINK_MCAST_GRP_ID,
2628 .input = NULL
2629 };
2630#endif
2631 int ret = 0;
2632
2633#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2634 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2635#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2636 THIS_MODULE,
2637#endif
2638 &cfg);
2639#else
2640 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2641 WLAN_NLINK_MCAST_GRP_ID,
2642 NULL, NULL, THIS_MODULE);
2643#endif
2644
2645 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002646 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002647 ret = -ECONNREFUSED;
2648 }
2649
2650 return ret;
2651}
2652
2653static void hdd_close_cesium_nl_sock(void)
2654{
2655 if (NULL != cesium_nl_srv_sock) {
2656 netlink_kernel_release(cesium_nl_srv_sock);
2657 cesium_nl_srv_sock = NULL;
2658 }
2659}
2660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661/**
2662 * __hdd_set_mac_address() - set the user specified mac address
2663 * @dev: Pointer to the net device.
2664 * @addr: Pointer to the sockaddr.
2665 *
2666 * This function sets the user specified mac address using
2667 * the command ifconfig wlanX hw ether <mac adress>.
2668 *
2669 * Return: 0 for success, non zero for failure
2670 */
2671static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2672{
2673 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2674 hdd_context_t *hdd_ctx;
2675 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302676 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002677 int ret;
2678
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002679 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680
2681 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2682 ret = wlan_hdd_validate_context(hdd_ctx);
2683 if (0 != ret)
2684 return ret;
2685
2686 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2687 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2688
2689 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302690 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002691}
2692
2693/**
2694 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2695 * function from SSR
2696 * @dev: pointer to net_device structure
2697 * @addr: Pointer to the sockaddr
2698 *
2699 * This function sets the user specified mac address using
2700 * the command ifconfig wlanX hw ether <mac adress>.
2701 *
2702 * Return: 0 for success.
2703 */
2704static int hdd_set_mac_address(struct net_device *dev, void *addr)
2705{
2706 int ret;
2707
2708 cds_ssr_protect(__func__);
2709 ret = __hdd_set_mac_address(dev, addr);
2710 cds_ssr_unprotect(__func__);
2711
2712 return ret;
2713}
2714
2715uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2716{
2717 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002718
Anurag Chouhan6d760662016-02-20 16:05:43 +05302719 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002720 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2721 break;
2722 }
2723
Anurag Chouhan6d760662016-02-20 16:05:43 +05302724 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725 return NULL;
2726
2727 hdd_ctx->config->intfAddrMask |= (1 << i);
2728 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2729}
2730
2731void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2732{
2733 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002734
Anurag Chouhan6d760662016-02-20 16:05:43 +05302735 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002736 if (!memcmp(releaseAddr,
2737 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2738 6)) {
2739 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2740 break;
2741 }
2742 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743}
2744
2745#ifdef WLAN_FEATURE_PACKET_FILTERING
2746/**
2747 * __hdd_set_multicast_list() - set the multicast address list
2748 * @dev: Pointer to the WLAN device.
2749 * @skb: Pointer to OS packet (sk_buff).
2750 *
2751 * This funciton sets the multicast address list.
2752 *
2753 * Return: None
2754 */
2755static void __hdd_set_multicast_list(struct net_device *dev)
2756{
2757 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002758 int i = 0, status;
2759 struct netdev_hw_addr *ha;
2760 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302761 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2762 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2763 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002764
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002765 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302766 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302767 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002769 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302770 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302771 goto out;
2772
2773 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2774 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002775 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302776 goto out;
2777 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302779 /* Delete already configured multicast address list */
2780 if (adapter->mc_addr_list.mc_cnt > 0) {
2781 hdd_info("clear previously configured MC address list");
2782 hdd_disable_and_flush_mc_addr_list(adapter,
2783 pmo_mc_list_change_notify);
2784 }
2785
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002787 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302788 hdd_disable_and_flush_mc_addr_list(adapter,
2789 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002790 } else {
2791 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302792 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002793 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302794 pmo_ucfg_max_mc_addr_supported(psoc));
2795 hdd_disable_and_flush_mc_addr_list(adapter,
2796 pmo_mc_list_change_notify);
2797 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002798 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002800 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302801 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802 if (i == mc_count)
2803 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302804 memset(&(mc_list_request->mc_addr[i].bytes),
2805 0, ETH_ALEN);
2806 memcpy(&(mc_list_request->mc_addr[i].bytes),
2807 ha->addr, ETH_ALEN);
2808 hdd_info("mlist[%d] = %pM", i,
2809 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002810 i++;
2811 }
2812 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302813
2814 mc_list_request->psoc = psoc;
2815 mc_list_request->vdev_id = adapter->sessionId;
2816 mc_list_request->count = mc_count;
2817 status = hdd_cache_mc_addr_list(mc_list_request);
2818 if (status == 0) {
2819 hdd_enable_mc_addr_filtering(adapter,
2820 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302822 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002823 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302824out:
2825 if (mc_list_request)
2826 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302827 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828}
2829
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831/**
2832 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2833 * @dev: pointer to net_device
2834 *
2835 * Return: none
2836 */
2837static void hdd_set_multicast_list(struct net_device *dev)
2838{
2839 cds_ssr_protect(__func__);
2840 __hdd_set_multicast_list(dev);
2841 cds_ssr_unprotect(__func__);
2842}
2843#endif
2844
2845/**
2846 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2847 * @dev: Pointer to the WLAN device.
2848 * @skb: Pointer to OS packet (sk_buff).
2849 *
2850 * This function is registered with the Linux OS for network
2851 * core to decide which queue to use first.
2852 *
2853 * Return: ac, Queue Index/access category corresponding to UP in IP header
2854 */
2855static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2856#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2857 , void *accel_priv
2858#endif
2859#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2860 , select_queue_fallback_t fallback
2861#endif
2862)
2863{
2864 return hdd_wmm_select_queue(dev, skb);
2865}
2866
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002867static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002868 .ndo_open = hdd_open,
2869 .ndo_stop = hdd_stop,
2870 .ndo_uninit = hdd_uninit,
2871 .ndo_start_xmit = hdd_hard_start_xmit,
2872 .ndo_tx_timeout = hdd_tx_timeout,
2873 .ndo_get_stats = hdd_get_stats,
2874 .ndo_do_ioctl = hdd_ioctl,
2875 .ndo_set_mac_address = hdd_set_mac_address,
2876 .ndo_select_queue = hdd_select_queue,
2877#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879#endif
2880};
2881
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002882/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002883static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002884 .ndo_open = hdd_mon_open,
2885 .ndo_stop = hdd_stop,
2886 .ndo_get_stats = hdd_get_stats,
2887};
2888
2889/**
2890 * hdd_set_station_ops() - update net_device ops for monitor mode
2891 * @pWlanDev: Handle to struct net_device to be updated.
2892 * Return: None
2893 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894void hdd_set_station_ops(struct net_device *pWlanDev)
2895{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002896 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2897 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2898 else
2899 pWlanDev->netdev_ops = &wlan_drv_ops;
2900}
2901
Komal Seelama89be8d2016-09-29 11:09:26 +05302902#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302903/**
2904 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2905 * @hdd_ctx: HDD context
2906 *
2907 * Return: None
2908 */
2909static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2910{
2911 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2912
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002913 qdf_runtime_lock_init(&ctx->roc);
2914 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05302915}
2916
2917/**
2918 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2919 * @hdd_ctx: HDD Context
2920 *
2921 * Return: None
2922 */
2923static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2924{
2925 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2926
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002927 qdf_runtime_lock_deinit(&ctx->roc);
2928 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302929
2930 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302931}
2932
Komal Seelama89be8d2016-09-29 11:09:26 +05302933static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2934{
2935 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2936
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002937 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302938}
2939
2940static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2941{
2942 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2943
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002944 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302945}
2946#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302947static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2948static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302949static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2950static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2951#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002952/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002953 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2954 * @hdd_ctx: global hdd context
2955 * @macAddr: mac address to assign to the interface
2956 * @name: User-visible name of the interface
2957 *
2958 * hdd adapter pointer would point to the netdev->priv space, this function
2959 * would retrive the pointer, and setup the hdd adapter configuration.
2960 *
2961 * Return: the pointer to hdd adapter, otherwise NULL
2962 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002963static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2964 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002965 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002966 const char *name)
2967{
2968 struct net_device *pWlanDev = NULL;
2969 hdd_adapter_t *adapter = NULL;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05302970 hdd_station_ctx_t *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002971 /*
2972 * cfg80211 initialization and registration....
2973 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002974 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2975#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2976 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002978 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2979 hdd_mon_mode_ether_setup : ether_setup),
2980 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981
2982 if (pWlanDev != NULL) {
2983
2984 /* Save the pointer to the net_device in the HDD adapter */
2985 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2986
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302987 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05302988 sta_ctx = &adapter->sessionCtx.station;
2989 qdf_mem_set(sta_ctx->conn_info.staId,
2990 sizeof(sta_ctx->conn_info.staId),
2991 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 adapter->dev = pWlanDev;
2993 adapter->pHddCtx = hdd_ctx;
2994 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302995 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996
2997 init_completion(&adapter->session_open_comp_var);
2998 init_completion(&adapter->session_close_comp_var);
2999 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303000 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001 init_completion(&adapter->linkup_event_var);
3002 init_completion(&adapter->cancel_rem_on_chan_var);
3003 init_completion(&adapter->rem_on_chan_ready_event);
3004 init_completion(&adapter->sta_authorized_event);
3005 init_completion(&adapter->offchannel_tx_event);
3006 init_completion(&adapter->tx_action_cnf_event);
3007#ifdef FEATURE_WLAN_TDLS
3008 init_completion(&adapter->tdls_add_station_comp);
3009 init_completion(&adapter->tdls_del_station_comp);
3010 init_completion(&adapter->tdls_mgmt_comp);
3011 init_completion(&adapter->tdls_link_establish_req_comp);
3012#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003013 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 init_completion(&adapter->change_country_code);
3015
3016
3017 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303018 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003019
3020 adapter->offloads_configured = false;
3021 adapter->isLinkUpSvcNeeded = false;
3022 adapter->higherDtimTransition = true;
3023 /* Init the net_device structure */
3024 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3025
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303026 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303028 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 sizeof(tSirMacAddr));
3030 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031
3032 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3033 pWlanDev->features |=
3034 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3035 pWlanDev->features |= NETIF_F_RXCSUM;
3036
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003037 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003039 hdd_set_station_ops(adapter->dev);
3040
3041 pWlanDev->destructor = free_netdev;
3042 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003043 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003044 adapter->wdev.wiphy = hdd_ctx->wiphy;
3045 adapter->wdev.netdev = pWlanDev;
3046 /* set pWlanDev's parent to underlying device */
3047 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3048 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303049 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003050 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303051 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 }
3053
3054 return adapter;
3055}
3056
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003057static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003058{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003059 struct net_device *dev = adapter->dev;
3060 int ret;
3061
3062 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003064 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003065 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3066
3067 ret = dev_alloc_name(dev, dev->name);
3068 if (ret < 0) {
3069 hdd_err(
3070 "unable to get dev name: %s, err = 0x%x",
3071 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303072 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 }
3074 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003075
3076 ret = register_netdevice(dev);
3077 if (ret) {
3078 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3079 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303080 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081 }
3082 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003083 ret = register_netdev(dev);
3084 if (ret) {
3085 hdd_err("register_netdev(%s) failed, err = 0x%x",
3086 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303087 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003088 }
3089 }
3090 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3091
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003092 EXIT();
3093
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303094 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095}
3096
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003097QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098{
3099 hdd_adapter_t *adapter = pContext;
3100
3101 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003102 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303103 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104 }
3105
3106 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003107 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303108 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109 }
3110
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003111 /*
3112 * For NAN Data interface, the close session results in the final
3113 * indication to the userspace
3114 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003115 if (adapter->device_mode == QDF_NDI_MODE)
3116 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3119
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 /*
3121 * We can be blocked while waiting for scheduled work to be
3122 * flushed, and the adapter structure can potentially be freed, in
3123 * which case the magic will have been reset. So make sure the
3124 * magic is still good, and hence the adapter structure is still
3125 * valid, before signaling completion
3126 */
3127 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3128 complete(&adapter->session_close_comp_var);
3129
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303130 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131}
3132
Krunal Soni8c37e322016-02-03 16:08:37 -08003133/**
3134 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3135 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003136 *
3137 * This routine will check the mode of adapter and if it is required then it
3138 * will initialize the TDLS operations
3139 *
3140 * Return: QDF_STATUS
3141 */
3142#ifdef FEATURE_WLAN_TDLS
Dustin Brownd28772b2017-03-17 14:16:07 -07003143static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003144{
Dustin Brownd28772b2017-03-17 14:16:07 -07003145 if (adapter->device_mode == QDF_IBSS_MODE)
3146 return QDF_STATUS_SUCCESS;
3147
3148 if (wlan_hdd_tdls_init(adapter)) {
3149 hdd_err("wlan_hdd_tdls_init failed");
3150 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003151 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003152 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3153
Krunal Soni8c37e322016-02-03 16:08:37 -08003154 return QDF_STATUS_SUCCESS;
3155}
3156#else
Dustin Brownd28772b2017-03-17 14:16:07 -07003157static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003158{
3159 return QDF_STATUS_SUCCESS;
3160}
3161#endif
3162
Dustin Brownd28772b2017-03-17 14:16:07 -07003163int hdd_vdev_ready(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164{
Dustin Brownd28772b2017-03-17 14:16:07 -07003165 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166
Dustin Brownd28772b2017-03-17 14:16:07 -07003167 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003168 if (QDF_IS_STATUS_ERROR(status))
3169 return qdf_status_to_os_return(status);
3170
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003171 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003172 if (QDF_IS_STATUS_ERROR(status))
3173 return qdf_status_to_os_return(status);
3174
3175 if (wma_capability_enhanced_mcast_filter())
3176 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3177 else
3178 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003179
3180 return qdf_status_to_os_return(status);
3181}
3182
3183int hdd_vdev_destroy(hdd_adapter_t *adapter)
3184{
3185 QDF_STATUS status;
3186 int errno;
3187 hdd_context_t *hdd_ctx;
3188 unsigned long rc;
3189
3190 hdd_info("destroying vdev %d", adapter->sessionId);
3191
3192 /* vdev created sanity check */
3193 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3194 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3195 return -EINVAL;
3196 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003197 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003198 /* do vdev logical destroy via objmgr */
3199 errno = hdd_objmgr_destroy_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003200 if (errno) {
3201 hdd_err("failed to destroy objmgr vdev: %d", errno);
3202 return errno;
3203 }
3204
Yue Maf9782842017-05-08 12:49:49 -07003205 /*
3206 * In SSR case, there is no need to destroy vdev in firmware since
3207 * it has already asserted. vdev can be released directly.
3208 */
3209 if (cds_is_driver_recovering())
3210 goto release_vdev;
3211
Dustin Brownd28772b2017-03-17 14:16:07 -07003212 /* close sme session (destroy vdev in firmware via legacy API) */
3213 INIT_COMPLETION(adapter->session_close_comp_var);
3214 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3215 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3216 hdd_sme_close_session_callback, adapter);
3217 if (QDF_IS_STATUS_ERROR(status)) {
3218 hdd_err("failed to close sme session: %d", status);
3219 return qdf_status_to_os_return(status);
3220 }
3221
3222 /* block on a completion variable until sme session is closed */
3223 rc = wait_for_completion_timeout(
3224 &adapter->session_close_comp_var,
3225 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3226 if (!rc) {
3227 hdd_err("timed out waiting for close sme session: %ld", rc);
3228 if (adapter->device_mode == QDF_NDI_MODE)
3229 hdd_ndp_session_end_handler(adapter);
3230 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3231 return -ETIMEDOUT;
3232 }
3233
Yue Maf9782842017-05-08 12:49:49 -07003234release_vdev:
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003235 /* now that sme session is closed, allow physical vdev destroy */
3236 errno = hdd_objmgr_release_vdev(adapter);
3237 if (errno) {
3238 hdd_err("failed to release objmgr vdev: %d", errno);
3239 return errno;
3240 }
3241
Dustin Brownd28772b2017-03-17 14:16:07 -07003242 hdd_info("vdev destroyed successfully");
3243
3244 return 0;
3245}
3246
3247int hdd_vdev_create(hdd_adapter_t *adapter)
3248{
3249 QDF_STATUS status;
3250 int errno;
3251 hdd_context_t *hdd_ctx;
3252 uint32_t type;
3253 uint32_t sub_type;
3254 unsigned long rc;
3255
3256 hdd_info("creating new vdev");
3257
3258 /* determine vdev (sub)type */
3259 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303260 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003261 hdd_err("failed to get vdev type: %d", status);
3262 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003264
3265 /* do vdev create via objmgr */
3266 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003267 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003268 if (errno) {
3269 hdd_err("failed to create objmgr vdev: %d", errno);
3270 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003272
3273 /* Open a SME session (prepare vdev in firmware via legacy API) */
3274 INIT_COMPLETION(adapter->session_open_comp_var);
3275 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3276 (uint8_t *)&adapter->macAddressCurrent,
3277 adapter->sessionId, type, sub_type);
3278 if (QDF_IS_STATUS_ERROR(status)) {
3279 hdd_err("failed to open sme session: %d", status);
3280 errno = qdf_status_to_os_return(status);
3281 goto objmgr_vdev_destroy;
3282 }
3283
3284 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285 rc = wait_for_completion_timeout(
3286 &adapter->session_open_comp_var,
3287 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3288 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003289 hdd_err("timed out waiting for open sme session: %ld", rc);
3290 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303291 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3292 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003293 }
3294
3295 /* firmware ready for component communication, raise vdev_ready event */
3296 errno = hdd_vdev_ready(adapter);
3297 if (errno) {
3298 hdd_err("failed to dispatch vdev ready event: %d", errno);
3299 goto hdd_vdev_destroy;
3300 }
3301
3302 hdd_info("vdev %d created successfully", adapter->sessionId);
3303
3304 return 0;
3305
3306 /*
3307 * Due to legacy constraints, we need to destroy in the same order as
3308 * create. So, split error handling into 2 cases to accommodate.
3309 */
3310
3311objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003312 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003313
3314 return errno;
3315
3316hdd_vdev_destroy:
3317 QDF_BUG(!hdd_vdev_destroy(adapter));
3318
3319 return errno;
3320}
3321
3322QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
3323{
3324 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
3325 hdd_context_t *hdd_ctx;
3326 QDF_STATUS status;
3327 int ret_val;
3328
3329 ret_val = hdd_vdev_create(adapter);
3330 if (ret_val) {
3331 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303332 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 }
3334
Dustin Brownd28772b2017-03-17 14:16:07 -07003335 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3336 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3337 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003338 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003341 status = hdd_register_wext(adapter->dev);
3342 if (QDF_IS_STATUS_ERROR(status)) {
3343 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 goto error_register_wext;
3345 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003346 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003347
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303348 qdf_mem_set(pHddStaCtx->conn_info.staId,
3349 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3350
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003351 /* set fast roaming capability in sme session */
3352 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3353 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354 /* Set the default operation channel */
3355 pHddStaCtx->conn_info.operationChannel =
3356 hdd_ctx->config->OperatingChannel;
3357
3358 /* Make the default Auth Type as OPEN */
3359 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3360
3361 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303362 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003363 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 status, status);
3365 goto error_init_txrx;
3366 }
3367
3368 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3369
3370 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303371 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003372 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 status, status);
3374 goto error_wmm_init;
3375 }
3376
3377 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3378
Naveen Rawat247a8682017-06-05 15:00:31 -07003379 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380 WMI_PDEV_PARAM_BURST_ENABLE,
3381 hdd_ctx->config->enableSifsBurst,
3382 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003383 if (ret_val)
3384 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385
Dustin Brownd28772b2017-03-17 14:16:07 -07003386 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003387 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003390 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303391 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003393error_tdls_init:
3394 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3395 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396error_wmm_init:
3397 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3398 hdd_deinit_tx_rx(adapter);
3399error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003400 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003402 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 return status;
3405}
3406
3407void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
3408{
3409 hdd_cfg80211_state_t *cfgState;
3410
3411 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3412
3413 if (NULL != cfgState->buf) {
3414 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 rc = wait_for_completion_timeout(
3417 &adapter->tx_action_cnf_event,
3418 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3419 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003420 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303421 /*
3422 * Inform tx status as FAILURE to upper layer and free
3423 * cfgState->buf
3424 */
3425 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426 }
3427 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428}
3429
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303430/**
3431 * hdd_station_adapter_deinit() - De-initialize the station adapter
3432 * @hdd_ctx: global hdd context
3433 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003434 * @rtnl_held: Used to indicate whether or not the caller is holding
3435 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303436 *
3437 * This function De-initializes the STA/P2P/OCB adapter.
3438 *
3439 * Return: None.
3440 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003441static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
3442 hdd_adapter_t *adapter,
3443 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303444{
3445 ENTER_DEV(adapter->dev);
3446
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303447 if (adapter->dev) {
3448 if (rtnl_held)
3449 adapter->dev->wireless_handlers = NULL;
3450 else {
3451 rtnl_lock();
3452 adapter->dev->wireless_handlers = NULL;
3453 rtnl_unlock();
3454 }
3455 }
3456
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303457 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3458 hdd_deinit_tx_rx(adapter);
3459 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3460 }
3461
3462 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3463 hdd_wmm_adapter_close(adapter);
3464 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3465 }
3466
3467 hdd_cleanup_actionframe(hdd_ctx, adapter);
3468 wlan_hdd_tdls_exit(adapter);
3469
3470 EXIT();
3471}
3472
3473/**
3474 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3475 * @hdd_ctx: global hdd context
3476 * @adapter: HDD adapter
3477 * @rtnl_held: the rtnl lock hold flag
3478 * This function De-initializes the AP/P2PGo adapter.
3479 *
3480 * Return: None.
3481 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003482static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
3483 hdd_adapter_t *adapter,
3484 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303485{
3486 ENTER_DEV(adapter->dev);
3487
3488 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3489 hdd_wmm_adapter_close(adapter);
3490 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3491 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003492 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303493
3494 hdd_cleanup_actionframe(hdd_ctx, adapter);
3495
3496 hdd_unregister_hostapd(adapter, rtnl_held);
3497
3498 EXIT();
3499}
3500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3502 bool rtnl_held)
3503{
3504 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003507 case QDF_STA_MODE:
3508 case QDF_P2P_CLIENT_MODE:
3509 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303511 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 break;
3513 }
3514
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003515 case QDF_SAP_MODE:
3516 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517 {
3518
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303519 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520 break;
3521 }
3522
3523 default:
3524 break;
3525 }
3526
3527 EXIT();
3528}
3529
Jeff Johnson590e2012016-10-05 16:16:24 -07003530static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3531 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532{
3533 struct net_device *pWlanDev = NULL;
3534
3535 if (adapter)
3536 pWlanDev = adapter->dev;
3537 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003538 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003539 return;
3540 }
3541
Rajeev Kumardca5f812016-02-04 17:28:06 -08003542 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303543
3544 if (adapter->scan_info.default_scan_ies) {
3545 qdf_mem_free(adapter->scan_info.default_scan_ies);
3546 adapter->scan_info.default_scan_ies = NULL;
3547 }
3548
Komal Seelama89be8d2016-09-29 11:09:26 +05303549 hdd_adapter_runtime_suspend_denit(adapter);
3550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 /*
3552 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3553 * the driver is almost closed and cannot handle either control
3554 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003555 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3556 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 * is not right. Setting this flag helps hdd_stop() to recognize that
3558 * the interface is closed and restricts any operations on that
3559 */
3560 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3561
3562 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003563 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003565 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567 /*
3568 * Note that the adapter is no longer valid at this point
3569 * since the memory has been reclaimed
3570 */
3571 }
3572}
3573
Jeff Johnson590e2012016-10-05 16:16:24 -07003574static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3575 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576{
3577 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3578 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303579 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303582 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583 adapter = adapterNode->pAdapter;
3584 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303585 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303587 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 }
3589 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3590 adapterNode = pNext;
3591 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303592 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003593}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003594
Arun Khandavalli2358d522016-05-16 18:05:37 +05303595#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3596/**
3597 * hdd_set_fw_log_params() - Set log parameters to FW
3598 * @hdd_ctx: HDD Context
3599 * @adapter: HDD Adapter
3600 *
3601 * This function set the FW Debug log level based on the INI.
3602 *
3603 * Return: None
3604 */
3605static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3606 hdd_adapter_t *adapter)
3607{
3608 uint8_t count = 0, numentries = 0,
3609 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3610 uint32_t value = 0;
3611 int ret;
3612
Arun Khandavallifae92942016-08-01 13:31:08 +05303613 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3614 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003615 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303616 return;
3617 }
3618
Arun Khandavallifae92942016-08-01 13:31:08 +05303619 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303620 hdd_ctx->fw_log_settings.dl_type =
3621 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003622 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303623 WMI_DBGLOG_TYPE,
3624 hdd_ctx->config->enableFwLogType,
3625 DBG_CMD);
3626 if (ret != 0)
3627 hdd_err("Failed to enable FW log type ret %d",
3628 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303629
3630 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303631 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003632 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303633 WMI_DBGLOG_LOG_LEVEL,
3634 hdd_ctx->config->enableFwLogLevel,
3635 DBG_CMD);
3636 if (ret != 0)
3637 hdd_err("Failed to enable FW log level ret %d",
3638 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303639
3640 hdd_string_to_u8_array(
3641 hdd_ctx->config->enableFwModuleLogLevel,
3642 moduleloglevel,
3643 &numentries,
3644 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3645
3646 while (count < numentries) {
3647 /*
3648 * FW module log level input string looks like
3649 * below:
3650 * gFwDebugModuleLoglevel=<FW Module ID>,
3651 * <Log Level>,...
3652 * For example:
3653 * gFwDebugModuleLoglevel=
3654 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3655 * Above input string means :
3656 * For FW module ID 1 enable log level 0
3657 * For FW module ID 2 enable log level 1
3658 * For FW module ID 3 enable log level 2
3659 * For FW module ID 4 enable log level 3
3660 * For FW module ID 5 enable log level 4
3661 * For FW module ID 6 enable log level 5
3662 * For FW module ID 7 enable log level 6
3663 */
3664
Nishank Aggarwale239d962017-03-03 12:26:02 +05303665 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3666 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3667 hdd_err("Module id %d and dbglog level %d input length is more than max",
3668 moduleloglevel[count],
3669 moduleloglevel[count + 1]);
3670 return;
3671 }
3672
3673 value = moduleloglevel[count] << 16;
3674 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003675 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303676 WMI_DBGLOG_MOD_LOG_LEVEL,
3677 value, DBG_CMD);
3678 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303679 hdd_err("Failed to enable FW module log level %d ret %d",
3680 value, ret);
3681
3682 count += 2;
3683 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303684
Arun Khandavalli2358d522016-05-16 18:05:37 +05303685}
3686#else
3687static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3688 hdd_adapter_t *adapter)
3689{
3690}
3691
3692#endif
3693
3694/**
3695 * hdd_set_fw_params() - Set parameters to firmware
3696 * @adapter: HDD adapter
3697 *
3698 * This function Sets various parameters to fw once the
3699 * adapter is started.
3700 *
3701 * Return: 0 on success or errno on failure
3702 */
3703int hdd_set_fw_params(hdd_adapter_t *adapter)
3704{
3705 int ret;
3706 hdd_context_t *hdd_ctx;
3707
3708 ENTER_DEV(adapter->dev);
3709
3710 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3711 if (!hdd_ctx)
3712 return -EINVAL;
3713
Dustin Brown732ab9c2017-06-15 13:24:09 -07003714 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3715 hdd_debug("FTM Mode is active; nothing to do");
3716 return 0;
3717 }
3718
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303719 ret = sme_cli_set_command(adapter->sessionId,
3720 WMI_PDEV_PARAM_DTIM_SYNTH,
3721 hdd_ctx->config->enable_lprx, PDEV_CMD);
3722 if (ret) {
3723 hdd_err("Failed to set LPRx");
3724 goto error;
3725 }
3726
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303727 if (adapter->device_mode == QDF_STA_MODE) {
3728 sme_set_smps_cfg(adapter->sessionId,
3729 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3730 hdd_ctx->config->upper_brssi_thresh);
3731
3732 sme_set_smps_cfg(adapter->sessionId,
3733 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3734 hdd_ctx->config->lower_brssi_thresh);
3735
3736 sme_set_smps_cfg(adapter->sessionId,
3737 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3738 hdd_ctx->config->enable_dtim_1chrx);
3739 }
3740
Dustin Brown732ab9c2017-06-15 13:24:09 -07003741 if (hdd_ctx->config->enable2x2) {
3742 hdd_debug("configuring 2x2 mode fw params");
3743
Naveen Rawat247a8682017-06-05 15:00:31 -07003744 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003745 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3746 hdd_ctx->config->enable_cck_tx_fir_override,
3747 PDEV_CMD);
3748 if (ret) {
3749 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3750 ret);
3751 goto error;
3752 }
3753 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303754#define HDD_DTIM_1CHAIN_RX_ID 0x5
3755#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003756 hdd_debug("configuring 1x1 mode fw params");
3757
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003758 /*
3759 * Disable DTIM 1 chain Rx when in 1x1,
3760 * we are passing two value
3761 * as param_id << 29 | param_value.
3762 * Below param_value = 0(disable)
3763 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003764 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003765 WMI_STA_SMPS_PARAM_CMDID,
3766 HDD_DTIM_1CHAIN_RX_ID <<
3767 HDD_SMPS_PARAM_VALUE_S,
3768 VDEV_CMD);
3769 if (ret) {
3770 hdd_err("DTIM 1 chain set failed %d", ret);
3771 goto error;
3772 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303773
Naveen Rawat247a8682017-06-05 15:00:31 -07003774 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003775 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3776 hdd_ctx->config->txchainmask1x1,
3777 PDEV_CMD);
3778 if (ret) {
3779 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3780 ret);
3781 goto error;
3782 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303783
Naveen Rawat247a8682017-06-05 15:00:31 -07003784 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003785 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3786 hdd_ctx->config->rxchainmask1x1,
3787 PDEV_CMD);
3788 if (ret) {
3789 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3790 ret);
3791 goto error;
3792 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303793#undef HDD_DTIM_1CHAIN_RX_ID
3794#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003795 }
3796
Naveen Rawat247a8682017-06-05 15:00:31 -07003797 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003798 WMI_PDEV_PARAM_HYST_EN,
3799 hdd_ctx->config->enableMemDeepSleep,
3800 PDEV_CMD);
3801 if (ret) {
3802 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3803 goto error;
3804 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303805
Naveen Rawat247a8682017-06-05 15:00:31 -07003806 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003807 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3808 hdd_ctx->config->rts_profile,
3809 VDEV_CMD);
3810 if (ret) {
3811 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3812 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303813 }
3814
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003815 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3816
3817 ret = wma_cli_set_command(adapter->sessionId,
3818 GEN_VDEV_PARAM_AMSDU,
3819 hdd_ctx->config->max_amsdu_num,
3820 GEN_CMD);
3821 if (ret != 0) {
3822 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3823 goto error;
3824 }
3825
Arun Khandavalli2358d522016-05-16 18:05:37 +05303826 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303827 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003828
Arun Khandavalli2358d522016-05-16 18:05:37 +05303829 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303830
Arun Khandavalli2358d522016-05-16 18:05:37 +05303831error:
3832 return -EINVAL;
3833}
3834
Ryan Hsu07495ea2016-01-21 15:25:39 -08003835/**
3836 * hdd_open_adapter() - open and setup the hdd adatper
3837 * @hdd_ctx: global hdd context
3838 * @session_type: type of the interface to be created
3839 * @iface_name: User-visible name of the interface
3840 * @macAddr: MAC address to assign to the interface
3841 * @name_assign_type: the name of assign type of the netdev
3842 * @rtnl_held: the rtnl lock hold flag
3843 *
3844 * This function open and setup the hdd adpater according to the device
3845 * type request, assign the name, the mac address assigned, and then prepared
3846 * the hdd related parameters, queue, lock and ready to start.
3847 *
3848 * Return: the pointer of hdd adapter, otherwise NULL.
3849 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3851 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003852 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003853 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854{
3855 hdd_adapter_t *adapter = NULL;
3856 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303857 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860
3861 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3862 /*
3863 * Max limit reached on the number of vdevs configured by the
3864 * host. Return error
3865 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303866 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3867 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003868 return NULL;
3869 }
3870
3871 if (macAddr == NULL) {
3872 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303873 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874 return NULL;
3875 }
3876 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303877 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303878 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3879 " already exists",
3880 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 return NULL;
3882 }
3883
3884 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003885 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 /* Reset locally administered bit if the device mode is STA */
3887 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3888 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003889 case QDF_P2P_CLIENT_MODE:
3890 case QDF_P2P_DEVICE_MODE:
3891 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003892 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303893 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003894 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3895 name_assign_type,
3896 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897
3898 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303899 hdd_err("failed to allocate adapter for session %d",
3900 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 return NULL;
3902 }
3903
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003904 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003905 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003906 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303908 else if (QDF_MONITOR_MODE == session_type)
3909 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 else
3911 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3912
3913 adapter->device_mode = session_type;
3914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 /*
3917 * Workqueue which gets scheduled in IPv4 notification
3918 * callback
3919 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3921 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922
3923#ifdef WLAN_NS_OFFLOAD
3924 /*
3925 * Workqueue which gets scheduled in IPv6
3926 * notification callback.
3927 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3929 hdd_ipv6_notifier_work_queue);
3930#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303932 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303934 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 }
3936
3937 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003938 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303940 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3941 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303942
Ravi Joshi1a292562017-05-18 16:28:54 -07003943 /* Initialize NAN Data Interface */
3944 if (QDF_NDI_MODE == session_type) {
3945 status = hdd_init_nan_data_mode(adapter);
3946 if (QDF_STATUS_SUCCESS != status)
3947 goto err_free_netdev;
3948 }
3949
3950 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003952 case QDF_P2P_GO_MODE:
3953 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003954 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3955 name_assign_type,
3956 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003958 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303959 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 return NULL;
3961 }
3962
3963 adapter->wdev.iftype =
3964 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003965 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 NL80211_IFTYPE_P2P_GO;
3967 adapter->device_mode = session_type;
3968
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003969 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303970 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3972 goto err_free_netdev;
3973 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003974 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303976 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3977 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303979 case QDF_FTM_MODE:
3980 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3981 name_assign_type,
3982 "wlan0");
3983 if (NULL == adapter) {
3984 hdd_err("Failed to allocate adapter for FTM mode");
3985 return NULL;
3986 }
3987 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3988 adapter->device_mode = session_type;
3989 status = hdd_register_interface(adapter, rtnl_held);
3990 if (QDF_STATUS_SUCCESS != status) {
3991 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3992 goto err_free_netdev;
3993 }
3994 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003995 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303996 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303997 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3998 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303999 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004001 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304002 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 return NULL;
4004 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005
hqueaa33ee2017-05-04 17:56:35 +08004006 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4009 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4010
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304011 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 /* Add it to the hdd's session list. */
4013 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304014 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304016 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 } else {
4018 pHddAdapterNode->pAdapter = adapter;
4019 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4020 }
4021 }
4022
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304023 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 if (NULL != adapter) {
4025 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4026 adapter = NULL;
4027 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004028 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304029 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 return NULL;
4032 }
4033
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304034 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004035 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4036 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 /* Adapter successfully added. Increment the vdev count */
4039 hdd_ctx->current_intf_count++;
4040
Jeff Johnson5880d792016-08-15 13:32:30 -07004041 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 hdd_ctx->current_intf_count);
4043
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004044 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 }
4046
Rajeev Kumardca5f812016-02-04 17:28:06 -08004047 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004048 hdd_err("Interface %s wow debug_fs init failed",
4049 netdev_name(adapter->dev));
4050
4051 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4052 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053
4054 return adapter;
4055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304058 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059
4060 return NULL;
4061}
4062
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304063QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004064 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065{
4066 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304067 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068
4069 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304070 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004071 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 status);
4073 return status;
4074 }
4075
4076 while (pCurrent->pAdapter != adapter) {
4077 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304078 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 break;
4080
4081 pCurrent = pNext;
4082 }
4083 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304084 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004085 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004086 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304087 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004088
4089 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004090 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4091 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304094 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 adapterNode = NULL;
4096
Dustin Brown5ec6b552017-03-31 12:11:40 -07004097 /* conditionally restart the bw timer */
4098 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4099
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 /* Adapter removed. Decrement vdev count */
4101 if (hdd_ctx->current_intf_count != 0)
4102 hdd_ctx->current_intf_count--;
4103
4104 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304105 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004106 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304107
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304108 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109}
4110
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004111/**
4112 * hdd_close_all_adapters - Close all open adapters
4113 * @hdd_ctx: Hdd context
4114 * rtnl_held: True if RTNL lock held
4115 *
4116 * Close all open adapters.
4117 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304118 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004119 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304120QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121{
4122 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304123 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124
4125 ENTER();
4126
4127 do {
4128 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304129 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304130 wlan_hdd_release_intf_addr(hdd_ctx,
4131 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004133 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304134 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304135 /* Adapter removed. Decrement vdev count */
4136 if (hdd_ctx->current_intf_count != 0)
4137 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304139 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004140
4141 EXIT();
4142
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304143 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144}
4145
4146void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
4147{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304148 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004150
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004152 case QDF_STA_MODE:
4153 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154 {
4155 hdd_station_ctx_t *pHddStaCtx =
4156 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004157 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158 break;
4159 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004160 case QDF_SAP_MODE:
4161 case QDF_P2P_GO_MODE:
4162 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004164 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165 break;
4166 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004167 case QDF_FTM_MODE:
4168 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 default:
4170 /*
4171 * wlan_hdd_reset_prob_rspies should not have been called
4172 * for these kind of devices
4173 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004174 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 pHostapdAdapter->device_mode);
4176 return;
4177 }
4178
Anurag Chouhanc5548422016-02-24 18:33:27 +05304179 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4181 updateIE.ieBufferlength = 0;
4182 updateIE.pAdditionIEBuffer = NULL;
4183 updateIE.append = true;
4184 updateIE.notify = false;
4185 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4186 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004188 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189 }
4190}
4191
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304192QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 const bool bCloseSession)
4194{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304195 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4197 union iwreq_data wrqu;
4198 tSirUpdateIE updateIE;
4199 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004200 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201
4202 ENTER();
4203
Sachin Ahuja988fd102016-09-15 17:16:25 +05304204 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004205 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304206 wlan_hdd_netif_queue_control(adapter,
4207 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4208 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004210 case QDF_STA_MODE:
4211 case QDF_P2P_CLIENT_MODE:
4212 case QDF_IBSS_MODE:
4213 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004214 case QDF_NDI_MODE:
4215 if ((QDF_NDI_MODE == adapter->device_mode) ||
4216 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4218 hdd_is_connecting(
4219 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004220 INIT_COMPLETION(adapter->disconnect_comp_var);
4221 /*
4222 * For NDI do not use pWextState from sta_ctx, if needed
4223 * extract from ndi_ctx.
4224 */
4225 if (QDF_NDI_MODE == adapter->device_mode)
4226 qdf_ret_status = sme_roam_disconnect(
4227 hdd_ctx->hHal,
4228 adapter->sessionId,
4229 eCSR_DISCONNECT_REASON_NDI_DELETE);
4230 else if (pWextState->roamProfile.BSSType ==
4231 eCSR_BSS_TYPE_START_IBSS)
4232 qdf_ret_status = sme_roam_disconnect(
4233 hdd_ctx->hHal,
4234 adapter->sessionId,
4235 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004236 else if (QDF_STA_MODE == adapter->device_mode)
4237 qdf_ret_status =
4238 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004240 qdf_ret_status = sme_roam_disconnect(
4241 hdd_ctx->hHal,
4242 adapter->sessionId,
4243 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004244 /* success implies disconnect command got
4245 * queued up successfully
4246 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004247 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4248 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249 rc = wait_for_completion_timeout(
4250 &adapter->disconnect_comp_var,
4251 msecs_to_jiffies
4252 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004253 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004254 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004256 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4257 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258 memset(&wrqu, '\0', sizeof(wrqu));
4259 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4260 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4261 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4262 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304263 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004264 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304265 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004266
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304267 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268
4269#ifdef WLAN_OPEN_SOURCE
4270 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4271#endif
4272
4273 hdd_deregister_tx_flow_control(adapter);
4274
4275#ifdef WLAN_NS_OFFLOAD
4276#ifdef WLAN_OPEN_SOURCE
4277 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4278#endif
4279#endif
4280
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304281 if (adapter->device_mode == QDF_STA_MODE)
4282 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4283 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 /*
4285 * It is possible that the caller of this function does not
4286 * wish to close the session
4287 */
Krunal Soni985b8132017-02-10 18:49:08 -08004288 if (true == bCloseSession) {
4289 if (0 != wlan_hdd_try_disconnect(adapter)) {
4290 hdd_err("Error: Can't disconnect adapter");
4291 return QDF_STATUS_E_FAILURE;
4292 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004293 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004294 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 break;
4296
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004297 case QDF_SAP_MODE:
4298 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004300 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4302
4303 hdd_deregister_tx_flow_control(adapter);
4304
Kapil Guptac1224bf2017-06-22 21:22:40 +05304305 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004306 mutex_lock(&hdd_ctx->sap_lock);
4307 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304308 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304309 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310
4311 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312 status = wlansap_stop_bss(
4313 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304315 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 hdd_hostapd_state_t *hostapd_state =
4317 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304318 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304319 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304320 qdf_status =
4321 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004322 qdf_stop_bss_event,
4323 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324
Anurag Chouhance0dc992016-02-16 18:18:03 +05304325 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004326 hdd_err("failure waiting for wlansap_stop_bss %d",
4327 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 }
4329 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004330 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 }
4332 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004333 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4334 adapter->device_mode,
4335 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004336
Anurag Chouhanc5548422016-02-24 18:33:27 +05304337 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004338 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 updateIE.smeSessionId = adapter->sessionId;
4340 updateIE.ieBufferlength = 0;
4341 updateIE.pAdditionIEBuffer = NULL;
4342 updateIE.append = false;
4343 updateIE.notify = false;
4344 /* Probe bcn reset */
4345 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4346 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304347 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004348 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 }
4350 /* Assoc resp reset */
4351 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4352 &updateIE,
4353 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304354 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004355 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356 }
4357 /* Reset WNI_CFG_PROBE_RSP Flags */
4358 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004360 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4361 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304362 /*
4363 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4364 */
4365 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4366 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4367
Peng Xu66162de2016-02-11 17:01:20 -08004368 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004369 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004370 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004372 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004373 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004374 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004375 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376 break;
4377 default:
4378 break;
4379 }
4380
4381 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304382 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383}
4384
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304385/**
4386 * hdd_deinit_all_adapters - deinit all adapters
4387 * @hdd_ctx: HDD context
4388 * @rtnl_held: True if RTNL lock held
4389 *
4390 */
4391void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
4392{
4393 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4394 QDF_STATUS status;
4395 hdd_adapter_t *adapter;
4396
4397 ENTER();
4398
4399 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4400
4401 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4402 adapter = adapter_node->pAdapter;
4403 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4404 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4405 adapter_node = next;
4406 }
4407
4408 EXIT();
4409}
4410
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304411QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412{
4413 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304414 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 hdd_adapter_t *adapter;
4416
4417 ENTER();
4418
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304419 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4422
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304423 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 adapter = adapterNode->pAdapter;
4425 hdd_stop_adapter(hdd_ctx, adapter, true);
4426 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4427 adapterNode = pNext;
4428 }
4429
4430 EXIT();
4431
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304432 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433}
4434
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436{
4437 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304438 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 hdd_adapter_t *adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004440 hdd_station_ctx_t *pHddStaCtx;
4441 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442
4443 ENTER();
4444
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304445 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4446
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004447 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4448
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304449 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004451 hdd_notice("Disabling queues for adapter type: %d",
4452 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304453
4454 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004455 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304456 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004457 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304458
Arun Khandavallicc544b32017-01-30 19:52:16 +05304459 if (hdd_ctx->config->sap_internal_restart &&
4460 adapter->device_mode == QDF_SAP_MODE) {
4461 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304462 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304463 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004464 if (test_bit(SOFTAP_BSS_STARTED,
4465 &adapter->event_flags)) {
4466 hdd_sap_indicate_disconnect_for_sta(adapter);
4467 hdd_cleanup_actionframe(hdd_ctx, adapter);
4468 hdd_sap_destroy_events(adapter);
4469 }
4470 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4471 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304472 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304473 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476
4477 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4478
4479 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004480 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4481 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004482 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4483 hdd_wmm_adapter_close(adapter);
4484 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4485 }
4486
Wu Gao3545e642017-07-14 19:24:41 +08004487 if (adapter->device_mode == QDF_SAP_MODE) {
4488 /*
4489 * If adapter is SAP, set session ID to invalid
4490 * since SAP session will be cleanup during SSR.
4491 */
Wu Gao36717432016-11-21 15:09:48 +08004492 wlansap_set_invalid_session(
4493 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4494
Wu Gao3545e642017-07-14 19:24:41 +08004495 wlansap_cleanup_cac_timer(
4496 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4497 }
4498
Yue Mad5b4b9f2017-05-26 16:23:40 -07004499 /* Delete peers if any for STA and P2P client modes */
4500 if (adapter->device_mode == QDF_STA_MODE ||
4501 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4502 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4503 qdf_copy_macaddr(&peerMacAddr,
4504 &pHddStaCtx->conn_info.bssId);
4505
4506 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4507 peerMacAddr.bytes);
4508 }
4509
Yue Maf9782842017-05-08 12:49:49 -07004510 /* Destroy vdev which will be recreated during reinit. */
4511 hdd_vdev_destroy(adapter);
4512
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4514 adapterNode = pNext;
4515 }
4516
4517 EXIT();
4518
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304519 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520}
4521
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304522bool hdd_check_for_opened_interfaces(hdd_context_t *hdd_ctx)
4523{
4524 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4525 QDF_STATUS status;
4526 bool close_modules = true;
4527
Arun Khandavalliba479c42017-07-26 21:29:40 +05304528 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4529 hdd_info("FTM mode, don't close the module");
4530 return false;
4531 }
4532
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304533 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4534 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4535 if (test_bit(DEVICE_IFACE_OPENED,
4536 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004537 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304538 close_modules = false;
4539 break;
4540 }
4541 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4542 adapter_node = next;
4543 }
4544
4545 return close_modules;
4546}
4547
Arun Khandavallifae92942016-08-01 13:31:08 +05304548/**
4549 * hdd_is_interface_up()- Checkfor interface up before ssr
4550 * @hdd_ctx: HDD context
4551 *
4552 * check if there are any wlan interfaces before SSR accordingly start
4553 * the interface.
4554 *
4555 * Return: 0 if interface was opened else false
4556 */
4557static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4558{
4559 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4560 return true;
4561 else
4562 return false;
4563}
4564
Anurag Chouhanc4092922016-09-08 15:56:11 +05304565#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004566 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304567struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4568 struct ieee80211_channel *channel,
4569 const u8 *bssid, const u8 *ssid,
4570 size_t ssid_len)
4571{
4572 return cfg80211_get_bss(wiphy, channel, bssid,
4573 ssid, ssid_len,
4574 WLAN_CAPABILITY_ESS,
4575 WLAN_CAPABILITY_ESS);
4576}
4577#else
4578struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4579 struct ieee80211_channel *channel,
4580 const u8 *bssid, const u8 *ssid,
4581 size_t ssid_len)
4582{
4583 return cfg80211_get_bss(wiphy, channel, bssid,
4584 ssid, ssid_len,
4585 IEEE80211_BSS_TYPE_ESS,
4586 IEEE80211_PRIVACY_ANY);
4587}
4588#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304589
Abhishek Singha84d3952016-09-13 13:45:05 +05304590#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304591#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4592 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4593/**
4594 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4595 * @timeout_reason: reason for connect timeout
4596 *
4597 * This function is used to convert host timeout
4598 * reason enum to kernel specific enum.
4599 *
4600 * Return: nl timeout enum
4601 */
4602static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4603 tSirResultCodes timeout_reason)
4604{
4605 switch (timeout_reason) {
4606 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4607 return NL80211_TIMEOUT_SCAN;
4608 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4609 return NL80211_TIMEOUT_AUTH;
4610 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4611 return NL80211_TIMEOUT_ASSOC;
4612 default:
4613 return NL80211_TIMEOUT_UNSPECIFIED;
4614 }
4615}
4616
4617/**
4618 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4619 * @dev: network device
4620 * @bssid: bssid to which we want to associate
4621 * @timeout_reason: reason for connect timeout
4622 *
4623 * This API is used to send connection timeout reason to supplicant
4624 *
4625 * Return: void
4626 */
4627static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4628 const u8 *bssid,
4629 tSirResultCodes timeout_reason)
4630{
4631 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004632
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304633 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4634
4635 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4636 nl_timeout_reason);
4637}
4638
4639/**
4640 * __hdd_connect_bss() - API to send connection status to supplicant
4641 * @dev: network device
4642 * @bssid: bssid to which we want to associate
4643 * @req_ie: Request Information Element
4644 * @req_ie_len: len of the req IE
4645 * @resp_ie: Response IE
4646 * @resp_ie_len: len of ht response IE
4647 * @status: status
4648 * @gfp: Kernel Flag
4649 * @timeout_reason: reason for connect timeout
4650 *
4651 * Return: void
4652 */
4653static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4654 struct cfg80211_bss *bss, const u8 *req_ie,
4655 size_t req_ie_len, const u8 *resp_ie,
4656 size_t resp_ie_len, int status, gfp_t gfp,
4657 tSirResultCodes timeout_reason)
4658{
4659 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004660
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304661 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4662
4663 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4664 resp_ie, resp_ie_len, status, gfp,
4665 nl_timeout_reason);
4666}
4667#else
4668#if defined CFG80211_CONNECT_TIMEOUT
4669static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4670 const u8 *bssid,
4671 tSirResultCodes timeout_reason)
4672{
4673 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4674}
4675#endif
4676
4677static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4678 struct cfg80211_bss *bss, const u8 *req_ie,
4679 size_t req_ie_len, const u8 *resp_ie,
4680 size_t resp_ie_len, int status, gfp_t gfp,
4681 tSirResultCodes timeout_reason)
4682{
4683 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4684 resp_ie, resp_ie_len, status, gfp);
4685}
4686#endif
4687
Abhishek Singha84d3952016-09-13 13:45:05 +05304688/**
4689 * hdd_connect_bss() - API to send connection status to supplicant
4690 * @dev: network device
4691 * @bssid: bssid to which we want to associate
4692 * @req_ie: Request Information Element
4693 * @req_ie_len: len of the req IE
4694 * @resp_ie: Response IE
4695 * @resp_ie_len: len of ht response IE
4696 * @status: status
4697 * @gfp: Kernel Flag
4698 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304699 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304700 *
4701 * The API is a wrapper to send connection status to supplicant
4702 *
4703 * Return: Void
4704 */
4705#if defined CFG80211_CONNECT_TIMEOUT
4706static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4707 struct cfg80211_bss *bss, const u8 *req_ie,
4708 size_t req_ie_len, const u8 *resp_ie,
4709 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304710 bool connect_timeout,
4711 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304712{
4713 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304714 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304715 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304716 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4717 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304718}
4719#else
4720static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4721 struct cfg80211_bss *bss, const u8 *req_ie,
4722 size_t req_ie_len, const u8 *resp_ie,
4723 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304724 bool connect_timeout,
4725 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304726{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304727 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4728 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304729}
4730#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304731
4732/**
4733 * hdd_connect_result() - API to send connection status to supplicant
4734 * @dev: network device
4735 * @bssid: bssid to which we want to associate
4736 * @roam_info: information about connected bss
4737 * @req_ie: Request Information Element
4738 * @req_ie_len: len of the req IE
4739 * @resp_ie: Response IE
4740 * @resp_ie_len: len of ht response IE
4741 * @status: status
4742 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304743 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304744 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304745 *
4746 * The API is a wrapper to send connection status to supplicant
4747 * and allow runtime suspend
4748 *
4749 * Return: Void
4750 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304751void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4752 tCsrRoamInfo *roam_info, const u8 *req_ie,
4753 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304754 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304755 bool connect_timeout,
4756 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304757{
4758 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4759 struct cfg80211_bss *bss = NULL;
4760
4761 if (WLAN_STATUS_SUCCESS == status) {
4762 struct ieee80211_channel *chan;
4763 int freq;
4764 int chan_no = roam_info->pBssDesc->channelId;
4765
4766 if (chan_no <= 14)
4767 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004768 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304769 else
4770 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004771 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304772
4773 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4774 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4775 roam_info->u.pConnectedProfile->SSID.ssId,
4776 roam_info->u.pConnectedProfile->SSID.length);
4777 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304778
Abhishek Singha84d3952016-09-13 13:45:05 +05304779 hdd_connect_bss(dev, bssid, bss, req_ie,
4780 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304781 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304782
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004783 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004784 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304785}
4786#else
4787void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4788 tCsrRoamInfo *roam_info, const u8 *req_ie,
4789 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304790 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304791 bool connect_timeout,
4792 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304793{
Komal Seelama89be8d2016-09-29 11:09:26 +05304794 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4795
Anurag Chouhanc4092922016-09-08 15:56:11 +05304796 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4797 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004798
4799 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004800 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304801}
4802#endif
4803
4804
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304805QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806{
4807 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304808 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809 hdd_adapter_t *adapter;
4810#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304811 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004812#endif
4813 eConnectionState connState;
4814
4815 ENTER();
4816
4817 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304818 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819 adapter = adapterNode->pAdapter;
4820
Arun Khandavallifae92942016-08-01 13:31:08 +05304821 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304822 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004824 hdd_wmm_init(adapter);
4825
Dustin Browna7e6a5c2017-07-07 12:52:24 -07004826 adapter->scan_info.mScanPending = false;
4827
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004828 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004829 case QDF_STA_MODE:
4830 case QDF_P2P_CLIENT_MODE:
4831 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004832
4833 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4834 ->conn_info.connState;
4835
4836 hdd_init_station_mode(adapter);
4837 /* Open the gates for HDD to receive Wext commands */
4838 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004840 /* Indicate disconnect event to supplicant
4841 * if associated previously
4842 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004844 eConnectionState_IbssConnected == connState ||
4845 eConnectionState_NotConnected == connState ||
4846 eConnectionState_IbssDisconnected == connState ||
4847 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004849
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 memset(&wrqu, '\0', sizeof(wrqu));
4851 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4852 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4853 wireless_send_event(adapter->dev, SIOCGIWAP,
4854 &wrqu, NULL);
4855 adapter->sessionCtx.station.
4856 hdd_ReassocScenario = false;
4857
4858 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304859 wlan_hdd_cfg80211_indicate_disconnect(
4860 adapter->dev, false,
4861 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 } else if (eConnectionState_Connecting == connState) {
4863 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004864 * Indicate connect failure to supplicant if we
4865 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304867 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304868 NULL, 0, NULL, 0,
4869 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004870 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 }
4872
4873 hdd_register_tx_flow_control(adapter,
4874 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08004875 hdd_tx_resume_cb,
4876 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004877
4878 break;
4879
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004880 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004881 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05304882 hdd_init_ap_mode(adapter, true);
4883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 break;
4885
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004886 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004888 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4890#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004891 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 /* event supplicant to restart */
4893 cfg80211_del_sta(adapter->dev,
4894 (const u8 *)&bcastMac.bytes[0],
4895 GFP_KERNEL);
4896#endif
4897 break;
4898
4899 default:
4900 break;
4901 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304902get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004903 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4904 adapterNode = pNext;
4905 }
4906
4907 EXIT();
4908
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304909 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910}
4911
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304912QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004913 hdd_adapter_list_node_t **padapterNode)
4914{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304915 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004916
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004917 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304918 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4919 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004920 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 return status;
4922}
4923
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304924QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925 hdd_adapter_list_node_t *adapterNode,
4926 hdd_adapter_list_node_t **pNextAdapterNode)
4927{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304928 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004929
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004930 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304931 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4932 (qdf_list_node_t *) adapterNode,
4933 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004934
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004935 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004936 return status;
4937}
4938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304939QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 hdd_adapter_list_node_t *adapterNode)
4941{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304942 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004943
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004944 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304945 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004946 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004947 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004948 return status;
4949}
4950
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304951QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004952 hdd_adapter_list_node_t **padapterNode)
4953{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304954 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004955
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004956 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304957 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4958 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004959 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004960 return status;
4961}
4962
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304963QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964 hdd_adapter_list_node_t *adapterNode)
4965{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304966 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004967
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004968 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304969 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4970 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004971 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972 return status;
4973}
4974
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304975QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976 hdd_adapter_list_node_t *adapterNode)
4977{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304978 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004979
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004980 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304981 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4982 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004983 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004984 return status;
4985}
4986
4987hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4988 tSirMacAddr macAddr)
4989{
4990 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4991 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304992 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993
4994 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4995
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304996 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004997 adapter = adapterNode->pAdapter;
4998
4999 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305000 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005001 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005003
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5005 adapterNode = pNext;
5006 }
5007
5008 return NULL;
5009
5010}
5011
5012hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
5013 uint32_t vdev_id)
5014{
5015 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5016 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305017 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005018
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305019 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305021 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 adapter = adapterNode->pAdapter;
5023
5024 if (adapter->sessionId == vdev_id)
5025 return adapter;
5026
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305027 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5029 adapterNode = pNext;
5030 }
5031
Jeff Johnson5880d792016-08-15 13:32:30 -07005032 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033
5034 return NULL;
5035}
5036
Abhishek Singh7996eb72015-12-30 17:24:02 +05305037/**
5038 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5039 * the sessionid
5040 * @hdd_ctx: hdd context.
5041 * @sme_session_id: sme session is for the adapter to get.
5042 *
5043 * This function is used to get the adapter with provided session id
5044 *
5045 * Return: adapter pointer if found
5046 *
5047 */
5048hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
5049 uint32_t sme_session_id)
5050{
5051 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5052 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305053 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305054
5055
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305056 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305057
5058 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305059 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305060 adapter = adapter_node->pAdapter;
5061
5062 if (adapter &&
5063 adapter->sessionId == sme_session_id)
5064 return adapter;
5065
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305066 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305067 hdd_get_next_adapter(hdd_ctx,
5068 adapter_node, &next);
5069 adapter_node = next;
5070 }
5071 return NULL;
5072}
5073
Naveen Rawat4edb6822017-04-12 10:09:17 -07005074hdd_adapter_t *hdd_get_adapter_by_iface_name(hdd_context_t *hdd_ctx,
5075 const char *iface_name)
5076{
5077 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5078 hdd_adapter_t *adapter;
5079 QDF_STATUS qdf_status;
5080
5081 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5082
5083 while ((NULL != adapter_node) &&
5084 (QDF_STATUS_SUCCESS == qdf_status)) {
5085 adapter = adapter_node->pAdapter;
5086
5087 if (adapter &&
5088 !qdf_str_cmp(adapter->dev->name, iface_name))
5089 return adapter;
5090
5091 qdf_status =
5092 hdd_get_next_adapter(hdd_ctx,
5093 adapter_node, &next);
5094 adapter_node = next;
5095 }
5096 return NULL;
5097}
5098
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005099/**
5100 * hdd_get_adapter() - to get adapter matching the mode
5101 * @hdd_ctx: hdd context
5102 * @mode: adapter mode
5103 *
5104 * This routine will return the pointer to adapter matching
5105 * with the passed mode.
5106 *
5107 * Return: pointer to adapter or null
5108 */
5109hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
5110 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111{
5112 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5113 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305114 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115
5116 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5117
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305118 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 adapter = adapterNode->pAdapter;
5120
5121 if (adapter && (mode == adapter->device_mode))
5122 return adapter;
5123
5124 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5125 adapterNode = pNext;
5126 }
5127
5128 return NULL;
5129
5130}
5131
5132/**
5133 * hdd_get_operating_channel() - return operating channel of the device mode
5134 * @hdd_ctx: Pointer to the HDD context.
5135 * @mode: Device mode for which operating channel is required.
5136 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005137 * QDF_STA_MODE,
5138 * QDF_P2P_CLIENT_MODE,
5139 * QDF_SAP_MODE,
5140 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005141 *
5142 * This API returns the operating channel of the requested device mode
5143 *
5144 * Return: channel number. "0" id the requested device is not found OR it is
5145 * not connected.
5146 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005147uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
5148 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149{
5150 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305151 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 hdd_adapter_t *adapter;
5153 uint8_t operatingChannel = 0;
5154
5155 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5156
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305157 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158 adapter = adapterNode->pAdapter;
5159
5160 if (mode == adapter->device_mode) {
5161 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005162 case QDF_STA_MODE:
5163 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164 if (hdd_conn_is_connected
5165 (WLAN_HDD_GET_STATION_CTX_PTR
5166 (adapter))) {
5167 operatingChannel =
5168 (WLAN_HDD_GET_STATION_CTX_PTR
5169 (adapter))->conn_info.
5170 operationChannel;
5171 }
5172 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005173 case QDF_SAP_MODE:
5174 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175 /* softap connection info */
5176 if (test_bit
5177 (SOFTAP_BSS_STARTED,
5178 &adapter->event_flags))
5179 operatingChannel =
5180 (WLAN_HDD_GET_AP_CTX_PTR
5181 (adapter))->operatingChannel;
5182 break;
5183 default:
5184 break;
5185 }
5186
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005187 /* Found the device of interest. break the loop */
5188 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 }
5190
5191 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5192 adapterNode = pNext;
5193 }
5194 return operatingChannel;
5195}
5196
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305197static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 hdd_ctx)
5199{
5200 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305201 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 hdd_adapter_t *adapter;
5203
5204 ENTER();
5205
5206 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305208 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005210 if ((adapter->device_mode == QDF_STA_MODE) ||
5211 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5212 (adapter->device_mode == QDF_IBSS_MODE) ||
5213 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5214 (adapter->device_mode == QDF_SAP_MODE) ||
5215 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 wlan_hdd_cfg80211_deregister_frames(adapter);
5217 hdd_unregister_wext(adapter->dev);
5218 }
5219 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5220 adapterNode = pNext;
5221 }
5222
5223 EXIT();
5224
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305225 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226}
5227
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305228QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005229{
5230 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305231 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 hdd_adapter_t *adapter;
5233
5234 ENTER();
5235
5236 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5237
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305238 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005240 if ((adapter->device_mode == QDF_STA_MODE) ||
5241 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5242 (adapter->device_mode == QDF_IBSS_MODE) ||
5243 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5244 (adapter->device_mode == QDF_SAP_MODE) ||
5245 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305246 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5247 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248 }
5249 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5250 adapterNode = pNext;
5251 }
5252
5253 EXIT();
5254
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305255 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256}
5257
Dustin Brownf27bce82016-11-03 12:52:27 -07005258/**
5259 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5260 * adapters
5261 * @hdd_ctx: The HDD context containing the adapters to operate on
5262 *
5263 * return: QDF_STATUS_SUCCESS
5264 */
5265static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
5266{
5267 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5268 QDF_STATUS status;
5269 hdd_adapter_t *adapter;
5270 int err;
5271
5272 ENTER();
5273
5274 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5275
5276 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5277 adapter = adapter_node->pAdapter;
5278 if ((adapter->device_mode == QDF_STA_MODE) ||
5279 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5280 (adapter->device_mode == QDF_IBSS_MODE) ||
5281 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5282 (adapter->device_mode == QDF_SAP_MODE) ||
5283 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5284 err = wlan_hdd_sched_scan_stop(adapter->dev);
5285 if (err)
5286 hdd_err("Unable to stop scheduled scan");
5287 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005288 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5289 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005290 adapter_node = next_node;
5291 }
5292
5293 EXIT();
5294
5295 return QDF_STATUS_SUCCESS;
5296}
5297
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298#ifdef WLAN_NS_OFFLOAD
5299/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005300 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301 * @hdd_ctx: Pointer to hdd context
5302 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005303 * Unregister for IPv6 address change notifications.
5304 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 * Return: None
5306 */
5307static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5308{
5309 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310}
5311
5312/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005313 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 * @hdd_ctx: Pointer to hdd context
5315 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005316 * Register for IPv6 address change notifications.
5317 *
5318 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005320static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321{
5322 int ret;
5323
5324 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5325 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005326 if (ret) {
5327 hdd_err("Failed to register IPv6 notifier: %d", ret);
5328 goto out;
5329 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005330
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005331 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005332out:
5333 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005334}
5335#else
5336/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005337 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005338 * @hdd_ctx: Pointer to hdd context
5339 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005340 * Unregister for IPv6 address change notifications.
5341 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 * Return: None
5343 */
5344static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5345{
5346}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005347
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005349 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350 * @hdd_ctx: Pointer to hdd context
5351 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005352 * Register for IPv6 address change notifications.
5353 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 * Return: None
5355 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005356static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005358 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359}
5360#endif
5361
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305362#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
5363/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005364 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305365 * @hdd_ctx: HDD context
5366 *
5367 * Activates the logging service
5368 *
5369 * Return: Zero in case of success, negative value otherwise
5370 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005371static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305372{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005373 int ret;
5374 struct hdd_config *config = hdd_ctx->config;
5375
5376 if (!config->wlanLoggingEnable)
5377 return 0;
5378
Srinivas Girigowda8187e792017-03-03 11:50:59 -08005379 ret = wlan_logging_sock_activate_svc(config->wlanLoggingToConsole,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005380 config->wlanLoggingNumBuf);
5381 if (ret)
5382 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
5383 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305384}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005385
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305386/**
5387 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
5388 * @hdd_ctx: HDD context
5389 *
5390 * Deactivates the logging service
5391 *
5392 * Return: 0 on deactivating the logging service
5393 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005394static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305395{
5396 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
5397 return wlan_logging_sock_deactivate_svc();
5398
5399 return 0;
5400}
5401#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005402static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305403{
5404 return 0;
5405}
5406
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005407static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305408{
5409 return 0;
5410}
5411#endif
5412
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005414 * hdd_register_notifiers - Register netdev notifiers.
5415 * @hdd_ctx: HDD context
5416 *
5417 * Register netdev notifiers like IPv4 and IPv6.
5418 *
5419 * Return: 0 on success and errno on failure
5420 */
5421static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
5422{
5423 int ret;
5424
5425 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5426 if (ret) {
5427 hdd_err("register_netdevice_notifier failed: %d", ret);
5428 goto out;
5429 }
5430
5431 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5432 if (ret)
5433 goto unregister_notifier;
5434
5435 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5436 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5437 if (ret) {
5438 hdd_err("Failed to register IPv4 notifier: %d", ret);
5439 goto unregister_ip6_notifier;
5440 }
5441
5442 return 0;
5443
5444unregister_ip6_notifier:
5445 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5446unregister_notifier:
5447 unregister_netdevice_notifier(&hdd_netdev_notifier);
5448out:
5449 return ret;
5450
5451}
5452
5453/**
5454 * hdd_unregister_notifiers - Unregister netdev notifiers.
5455 * @hdd_ctx: HDD context
5456 *
5457 * Unregister netdev notifiers like IPv4 and IPv6.
5458 *
5459 * Return: None.
5460 */
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305461void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005462{
5463 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5464
5465 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5466
5467 unregister_netdevice_notifier(&hdd_netdev_notifier);
5468}
5469
5470/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005471 * hdd_exit_netlink_services - Exit netlink services
5472 * @hdd_ctx: HDD context
5473 *
5474 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5475 * nl service.
5476 *
5477 * Return: None.
5478 */
5479static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
5480{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005481 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005482 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005483 ptt_sock_deactivate_svc();
5484
5485 nl_srv_exit();
5486}
5487
5488/**
5489 * hdd_init_netlink_services- Init netlink services
5490 * @hdd_ctx: HDD context
5491 *
5492 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5493 * nl service.
5494 *
5495 * Return: 0 on success and errno on failure.
5496 */
5497static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
5498{
5499 int ret;
5500
Ryan Hsuceddceb2016-04-28 10:20:14 -07005501 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005502 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005503 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005504 goto out;
5505 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005506 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005507
Naveen Rawat910726a2017-03-06 11:42:51 -08005508 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005509 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005510 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005511 goto err_nl_srv;
5512 }
5513
5514 ret = ptt_sock_activate_svc();
5515 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005516 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005517 goto err_nl_srv;
5518 }
5519
5520 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005521 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005522 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005523
5524 ret = cnss_diag_activate_service();
5525 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005526 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005527 goto err_close_cesium;
5528 }
5529
5530 return 0;
5531
5532err_close_cesium:
5533 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005534 ptt_sock_deactivate_svc();
5535err_nl_srv:
5536 nl_srv_exit();
5537out:
5538 return ret;
5539}
5540
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005541/**
5542 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5543 * @hdd_ctx: HDD context.
5544 *
5545 * Destroy RX wakelock.
5546 *
5547 * Return: None.
5548 */
5549static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
5550{
5551 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5552}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005553
5554/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005555 * hdd_rx_wake_lock_create() - Create RX wakelock
5556 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005557 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005558 * Create RX wakelock.
5559 *
5560 * Return: None.
5561 */
5562static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
5563{
5564 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5565}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005566
5567/**
5568 * hdd_roc_context_init() - Init ROC context
5569 * @hdd_ctx: HDD context.
5570 *
5571 * Initialize ROC context.
5572 *
5573 * Return: 0 on success and errno on failure.
5574 */
5575static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
5576{
5577 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5578 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5579
5580 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5581
5582 return 0;
5583}
5584
5585/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305586 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5587 * @hdd_ctx: HDD context.
5588 *
5589 * Free memory allocations made in ROC Req Queue nodes.
5590 *
5591 * Return: None.
5592 */
5593static void hdd_destroy_roc_req_q(hdd_context_t *hdd_ctx)
5594{
5595 hdd_roc_req_t *hdd_roc_req;
5596 QDF_STATUS status;
5597
5598 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5599
5600 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5601 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5602 (qdf_list_node_t **) &hdd_roc_req);
5603
5604 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305605 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5606 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305607 QDF_ASSERT(0);
5608 return;
5609 }
5610
5611 if (hdd_roc_req->pRemainChanCtx)
5612 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5613
5614 qdf_mem_free(hdd_roc_req);
5615 }
5616
5617 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5618}
5619
5620/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005621 * hdd_roc_context_destroy() - Destroy ROC context
5622 * @hdd_ctx: HDD context.
5623 *
5624 * Destroy roc list and flush the pending roc work.
5625 *
5626 * Return: None.
5627 */
5628static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
5629{
5630 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305631 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005632 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005633}
5634
5635/**
Houston Hoffman160db392016-10-10 17:37:51 -07005636 * hdd_context_deinit() - Deinitialize HDD context
5637 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005638 *
Houston Hoffman160db392016-10-10 17:37:51 -07005639 * Deinitialize HDD context along with all the feature specific contexts but
5640 * do not free hdd context itself. Caller of this API is supposed to free
5641 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005642 *
Houston Hoffman160db392016-10-10 17:37:51 -07005643 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005644 */
Houston Hoffman160db392016-10-10 17:37:51 -07005645static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005646{
Houston Hoffman160db392016-10-10 17:37:51 -07005647 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005648
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005649 hdd_roc_context_destroy(hdd_ctx);
5650
5651 hdd_sap_context_destroy(hdd_ctx);
5652
5653 hdd_rx_wake_lock_destroy(hdd_ctx);
5654
5655 hdd_tdls_context_destroy(hdd_ctx);
5656
5657 hdd_scan_context_destroy(hdd_ctx);
5658
5659 qdf_list_destroy(&hdd_ctx->hddAdapters);
5660
Houston Hoffman160db392016-10-10 17:37:51 -07005661 return 0;
5662}
5663
5664/**
5665 * hdd_context_destroy() - Destroy HDD context
5666 * @hdd_ctx: HDD context to be destroyed.
5667 *
5668 * Free config and HDD context as well as destroy all the resources.
5669 *
5670 * Return: None
5671 */
5672static void hdd_context_destroy(hdd_context_t *hdd_ctx)
5673{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305674
5675 hdd_logging_sock_deactivate_svc(hdd_ctx);
Houston Hoffman160db392016-10-10 17:37:51 -07005676
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305677 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5678
Houston Hoffman160db392016-10-10 17:37:51 -07005679 hdd_context_deinit(hdd_ctx);
5680
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305681 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005682 hdd_ctx->config = NULL;
5683
5684 wiphy_free(hdd_ctx->wiphy);
5685}
5686
5687/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305688 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5689 *
5690 * This function is used to destroy bug report lock
5691 *
5692 * Return: None
5693 */
5694static void wlan_destroy_bug_report_lock(void)
5695{
5696 p_cds_contextType p_cds_context;
5697
5698 p_cds_context = cds_get_global_context();
5699 if (!p_cds_context) {
5700 hdd_err("cds context is NULL");
5701 return;
5702 }
5703
5704 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5705}
5706
5707/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 * hdd_wlan_exit() - HDD WLAN exit function
5709 * @hdd_ctx: Pointer to the HDD Context
5710 *
5711 * This is the driver exit point (invoked during rmmod)
5712 *
5713 * Return: None
5714 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005715static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716{
5717 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305718 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005719 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305720 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721
5722 ENTER();
5723
Arun Khandavallifae92942016-08-01 13:31:08 +05305724 if (QDF_TIMER_STATE_RUNNING ==
5725 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005726 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305727 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 }
5729
Arun Khandavallifae92942016-08-01 13:31:08 +05305730 if (!QDF_IS_STATUS_SUCCESS
5731 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5732 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005733
Arun Khandavallifae92942016-08-01 13:31:08 +05305734
5735 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736
Nitesh Shah61c10d92016-10-19 19:29:15 +05305737 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5738
Prashanth Bhattaab004382016-10-11 16:08:11 -07005739 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005740
5741#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305742 if (QDF_TIMER_STATE_RUNNING ==
5743 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5744 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005745 }
5746
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305747 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305748 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005749 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005751 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5752 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5753 hdd_ctx->last_acs_channel_list = NULL;
5754 hdd_ctx->num_of_channels = 0;
5755 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005757
Arun Khandavallifae92942016-08-01 13:31:08 +05305758 mutex_lock(&hdd_ctx->iface_change_lock);
5759 driver_status = hdd_ctx->driver_status;
5760 mutex_unlock(&hdd_ctx->iface_change_lock);
5761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005762 /*
5763 * Powersave Offload Case
5764 * Disable Idle Power Save Mode
5765 */
5766 hdd_set_idle_ps_config(hdd_ctx, false);
5767
Arun Khandavallifae92942016-08-01 13:31:08 +05305768 if (driver_status != DRIVER_MODULES_CLOSED) {
5769 hdd_unregister_wext_all_adapters(hdd_ctx);
5770 /*
5771 * Cancel any outstanding scan requests. We are about to close
5772 * all of our adapters, but an adapter structure is what SME
5773 * passes back to our callback function. Hence if there
5774 * are any outstanding scan requests then there is a
5775 * race condition between when the adapter is closed and
5776 * when the callback is invoked. We try to resolve that
5777 * race condition here by canceling any outstanding scans
5778 * before we close the adapters.
5779 * Note that the scans may be cancelled in an asynchronous
5780 * manner, so ideally there needs to be some kind of
5781 * synchronization. Rather than introduce a new
5782 * synchronization here, we will utilize the fact that we are
5783 * about to Request Full Power, and since that is synchronized,
5784 * the expectation is that by the time Request Full Power has
5785 * completed, all scans will be cancelled
5786 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005787 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305788 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005789 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305790 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791 }
5792
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305793 wlan_destroy_bug_report_lock();
5794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305796 * Close the scheduler before calling cds_close to make sure
5797 * no thread is scheduled after the each module close is
5798 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005799 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305800 qdf_status = cds_sched_close(p_cds_context);
5801 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305802 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305803 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005806 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305807
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305808 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5809 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5810 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5811
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812 /*
5813 * Close CDS
5814 * This frees pMac(HAL) context. There should not be any call
5815 * that requires pMac access after this.
5816 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005817
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005818 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005819 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005820
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005821 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005822
5823 hdd_ipa_cleanup(hdd_ctx);
5824
5825 /* Free up RoC request queue and flush workqueue */
5826 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005827
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305828 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305829 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305830 /*
5831 * If there is re_init failure wiphy would have already de-registered
5832 * check the wiphy status before un-registering again
5833 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305834 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305835 wiphy_unregister(wiphy);
5836 wlan_hdd_cfg80211_deinit(wiphy);
5837 hdd_lpass_notify_stop(hdd_ctx);
5838 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005839
Arun Khandavallifae92942016-08-01 13:31:08 +05305840 hdd_exit_netlink_services(hdd_ctx);
5841 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05305842#ifdef FEATURE_WLAN_CH_AVOID
5843 mutex_destroy(&hdd_ctx->avoid_freq_lock);
5844#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05305845
5846 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5847 if (driver_status)
5848 hdd_err("Pdev delete failed");
5849
5850 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
5851 if (driver_status)
5852 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07005853
5854 qdf_mem_free(hdd_ctx->target_hw_name);
5855
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005856 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857}
5858
5859void __hdd_wlan_exit(void)
5860{
5861 hdd_context_t *hdd_ctx;
5862
5863 ENTER();
5864
Anurag Chouhan6d760662016-02-20 16:05:43 +05305865 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005867 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005868 EXIT();
5869 return;
5870 }
5871
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005872 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305873 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875 /* Do all the cleanup before deregistering the driver */
5876 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878 EXIT();
5879}
5880
5881#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005882/**
5883 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5884 * @data: pointer to hdd_context_t
5885 *
5886 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5887 * Then new ACS request will do a fresh scan without reusing the cached
5888 * scan information.
5889 *
5890 * Return: void
5891 */
Tang Yingying523322d2017-01-17 23:28:43 +08005892static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005893{
5894 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5895
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005896 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005897 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005898 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5899 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5900 hdd_ctx->last_acs_channel_list = NULL;
5901 hdd_ctx->num_of_channels = 0;
5902 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903
5904 if (!hdd_ctx->hHal)
5905 return;
5906 sme_scan_flush_result(hdd_ctx->hHal);
5907}
5908#endif
5909
5910#ifdef QCA_HT_2040_COEX
5911/**
5912 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5913 * @adapter: pointer to adapter
5914 * @staId: station id
5915 * @macAddrSTA: station MAC address
5916 * @channel_type: channel type
5917 *
5918 * This function notifies FW with HT20/HT40 mode
5919 *
5920 * Return: 0 if successful, error number otherwise
5921 */
5922int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305923 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005924{
5925 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305926 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927 hdd_context_t *hdd_ctx = NULL;
5928
5929 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5930
5931 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305932 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005933 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005935 if (!hdd_ctx->hHal)
5936 return -EINVAL;
5937
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305938 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005939 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305940 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005941 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 return -EINVAL;
5943 }
5944
5945 return 0;
5946}
5947#endif
5948
5949/**
5950 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5951 * @state: state
5952 *
5953 * This function notifies FW with modem power status
5954 *
5955 * Return: 0 if successful, error number otherwise
5956 */
5957int hdd_wlan_notify_modem_power_state(int state)
5958{
5959 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305960 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961 hdd_context_t *hdd_ctx;
5962
Anurag Chouhan6d760662016-02-20 16:05:43 +05305963 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005964 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305965 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968 if (!hdd_ctx->hHal)
5969 return -EINVAL;
5970
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305971 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5972 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005973 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005974 state);
5975 return -EINVAL;
5976 }
5977 return 0;
5978}
5979
5980/**
5981 *
5982 * hdd_post_cds_enable_config() - HDD post cds start config helper
5983 * @adapter - Pointer to the HDD
5984 *
5985 * Return: None
5986 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305987QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005988{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305989 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005990
5991 /*
5992 * Send ready indication to the HDD. This will kick off the MAC
5993 * into a 'running' state and should kick off an initial scan.
5994 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305995 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5996 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005997 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5998 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305999 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006000 }
6001
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306002 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006003}
6004
6005/* wake lock APIs for HDD */
6006void hdd_prevent_suspend(uint32_t reason)
6007{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306008 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009}
6010
6011void hdd_allow_suspend(uint32_t reason)
6012{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306013 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006014}
6015
6016void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6017{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306018 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6019 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006020}
6021
6022/**
6023 * hdd_exchange_version_and_caps() - exchange version and capability with target
6024 * @hdd_ctx: Pointer to HDD context
6025 *
6026 * This is the HDD function to exchange version and capability information
6027 * between Host and Target
6028 *
6029 * This function gets reported version of FW.
6030 * It also finds the version of target headers used to compile the host;
6031 * It compares the above two and prints a warning if they are different;
6032 * It gets the SW and HW version string;
6033 * Finally, it exchanges capabilities between host and target i.e. host
6034 * and target exchange a msg indicating the features they support through a
6035 * bitmap
6036 *
6037 * Return: None
6038 */
6039void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
6040{
6041
6042 tSirVersionType versionCompiled;
6043 tSirVersionType versionReported;
6044 tSirVersionString versionString;
6045 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306046 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047
6048 memset(&versionCompiled, 0, sizeof(versionCompiled));
6049 memset(&versionReported, 0, sizeof(versionReported));
6050
6051 /* retrieve and display WCNSS version information */
6052 do {
6053
6054 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
6055 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306056 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006057 hdd_err("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058 break;
6059 }
6060
6061 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
6062 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306063 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006064 hdd_err("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065 break;
6066 }
6067
6068 if ((versionCompiled.major != versionReported.major) ||
6069 (versionCompiled.minor != versionReported.minor) ||
6070 (versionCompiled.version != versionReported.version) ||
6071 (versionCompiled.revision != versionReported.revision)) {
6072 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
6073 "Host expected %u.%u.%u.%u\n",
6074 WLAN_MODULE_NAME,
6075 (int)versionReported.major,
6076 (int)versionReported.minor,
6077 (int)versionReported.version,
6078 (int)versionReported.revision,
6079 (int)versionCompiled.major,
6080 (int)versionCompiled.minor,
6081 (int)versionCompiled.version,
6082 (int)versionCompiled.revision);
6083 } else {
6084 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
6085 WLAN_MODULE_NAME,
6086 (int)versionReported.major,
6087 (int)versionReported.minor,
6088 (int)versionReported.version,
6089 (int)versionReported.revision);
6090 }
6091
6092 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
6093 versionString,
6094 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306095 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006096 hdd_err("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097 break;
6098 }
6099
6100 pr_info("%s: WCNSS software version %s\n",
6101 WLAN_MODULE_NAME, versionString);
6102
6103 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
6104 versionString,
6105 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306106 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006107 hdd_err("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108 break;
6109 }
6110
6111 pr_info("%s: WCNSS hardware version %s\n",
6112 WLAN_MODULE_NAME, versionString);
6113
6114 /*
6115 * 1.Check if FW version is greater than 0.1.1.0. Only then
6116 * send host-FW capability exchange message
6117 * 2.Host-FW capability exchange message is only present on
6118 * target 1.1 so send the message only if it the target is 1.1
6119 * minor numbers for different target branches:
6120 * 0 -> (1.0)Mainline Build
6121 * 1 -> (1.1)Mainline Build
6122 * 2->(1.04) Stability Build
6123 */
6124 if (((versionReported.major > 0) || (versionReported.minor > 1)
6125 || ((versionReported.minor >= 1)
6126 && (versionReported.version >= 1)))
6127 && ((versionReported.major == 1)
6128 && (versionReported.minor >= 1)))
6129 fwFeatCapsMsgSupported = 1;
6130
6131 if (fwFeatCapsMsgSupported) {
6132 /*
6133 * Indicate if IBSS heartbeat monitoring needs to be
6134 * offloaded
6135 */
6136 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
6137 sme_disable_feature_capablity
6138 (IBSS_HEARTBEAT_OFFLOAD);
6139 }
6140
6141 sme_feature_caps_exchange(hdd_ctx->hHal);
6142 }
6143
6144 } while (0);
6145
6146}
6147
6148/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306149QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006151
Amar Singhal6f8592b2017-04-26 14:31:58 -07006152 return sme_init_chan_list(hdd_ctx->hHal,
6153 hdd_ctx->reg.alpha2,
6154 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155}
6156
6157/**
6158 * hdd_is_5g_supported() - check if hardware supports 5GHz
6159 * @hdd_ctx: Pointer to the hdd context
6160 *
6161 * HDD function to know if hardware supports 5GHz
6162 *
6163 * Return: true if hardware supports 5GHz
6164 */
6165bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
6166{
zdingf54169a2016-10-12 17:08:45 +08006167 if (!hdd_ctx || !hdd_ctx->config)
6168 return true;
6169
6170 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
6171 return true;
6172 else
6173 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006174}
6175
Amar Singhale4f28ee2015-10-21 14:36:56 -07006176static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177{
6178 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006179 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180
6181 wiphy = hdd_ctx->wiphy;
6182
6183 /*
6184 * The channel information in
6185 * wiphy needs to be initialized before wiphy registration
6186 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006187 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6188 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006189 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006190 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006191 }
6192
6193#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6194 wiphy->wowlan = &wowlan_support_reg_init;
6195#else
6196 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6197 WIPHY_WOWLAN_MAGIC_PKT |
6198 WIPHY_WOWLAN_DISCONNECT |
6199 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6200 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6201 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6202 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6203 WIPHY_WOWLAN_RFKILL_RELEASE;
6204
6205 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6206 WOW_MAX_FILTERS_PER_LIST);
6207 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6208 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6209#endif
6210
6211 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006212 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306213 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006214 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306215 return ret_val;
6216 }
6217
Amar Singhal5cccafe2017-02-15 12:42:58 -08006218 if (!hdd_ctx->reg_offload)
6219 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220
Amar Singhale4f28ee2015-10-21 14:36:56 -07006221 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006222}
6223
Ravi Joshie2331e82015-07-01 18:18:54 -07006224/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006225 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006226 * @hdd_ctx - handle to hdd context
6227 * @tx_packets - transmit packet count
6228 * @rx_packets - receive packet count
6229 *
6230 * The function controls the bus bandwidth and dynamic control of
6231 * tcp delayed ack configuration
6232 *
6233 * Returns: None
6234 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07006236static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
6237 const uint64_t tx_packets,
6238 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006241 uint64_t temp_rx = 0;
6242 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006243 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006244 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006245 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006246 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006247 uint16_t index = 0;
6248 bool vote_level_change = false;
6249 bool rx_level_change = false;
6250 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006253 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006255 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006256 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006257 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006258 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006259 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006262 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6263 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006264 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006265 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006266 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306267 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306268 if (hdd_ctx->hbw_requested) {
6269 pld_remove_pm_qos(hdd_ctx->parent_dev);
6270 hdd_ctx->hbw_requested = false;
6271 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306272 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006273 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306274 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306275 if (!hdd_ctx->hbw_requested) {
6276 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6277 hdd_ctx->hbw_requested = true;
6278 }
6279
Nirav Shah3bbfa512016-05-12 16:43:49 +05306280 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006281 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306282 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006283 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006285
6286 /* fine-tuning parameters for RX Flows */
6287 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006290
Ravi Joshifed83572016-10-07 16:20:37 -07006291 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6292 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6293 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6294 next_rx_level = WLAN_SVC_TP_HIGH;
6295 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006296 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006297 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006298 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006299 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006302 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006303 next_rx_level, temp_rx);
6304 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006305 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006306 /* Send throughput indication only if it is enabled.
6307 * Disabling tcp_del_ack will revert the tcp stack behavior
6308 * to default delayed ack. Note that this will disable the
6309 * dynamic delayed ack mechanism across the system
6310 */
6311 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306312 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6313 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314 &next_rx_level,
6315 sizeof(next_rx_level));
6316 }
6317
Mohit Khannae71e2262015-11-10 09:37:24 -08006318 /* fine-tuning parameters for TX Flows */
6319 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6320 hdd_ctx->prev_tx = tx_packets;
6321 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6322 next_tx_level = WLAN_SVC_TP_HIGH;
6323 else
6324 next_tx_level = WLAN_SVC_TP_LOW;
6325
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006326 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006327 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6328 next_tx_level, temp_tx);
6329 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006330 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306331 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6332 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006333 &next_tx_level,
6334 sizeof(next_tx_level));
6335 }
6336
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006337 index = hdd_ctx->hdd_txrx_hist_idx;
6338
6339 if (vote_level_change || tx_level_change || rx_level_change) {
6340 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6341 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6342 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6343 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6344 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6345 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6346 hdd_ctx->hdd_txrx_hist_idx++;
6347 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6348 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349}
6350
6351#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306352static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306354 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
6355 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006356 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306357 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306358 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6359 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360 uint64_t total_tx = 0, total_rx = 0;
6361 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306362 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306363 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364 bool connected = false;
6365 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6366
Prashanth Bhattaab004382016-10-11 16:08:11 -07006367 if (wlan_hdd_validate_context(hdd_ctx))
6368 return;
6369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306371 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372 status =
6373 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6374
6375 if (adapterNode->pAdapter == NULL)
6376 continue;
6377 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306378 /*
6379 * Validate magic so we don't end up accessing
6380 * an invalid adapter.
6381 */
6382 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6383 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006384
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006385 if ((adapter->device_mode == QDF_STA_MODE ||
6386 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006387 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6388 != eConnectionState_Associated) {
6389
6390 continue;
6391 }
6392
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006393 if ((adapter->device_mode == QDF_SAP_MODE ||
6394 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6396
6397 continue;
6398 }
6399
6400 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6401 adapter->prev_tx_packets);
6402 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6403 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306404
6405 if (adapter->device_mode == QDF_SAP_MODE ||
6406 adapter->device_mode == QDF_P2P_GO_MODE ||
6407 adapter->device_mode == QDF_IBSS_MODE) {
6408
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006409 ret = cdp_get_intra_bss_fwd_pkts_count(
6410 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306411 adapter->sessionId,
6412 &fwd_tx_packets, &fwd_rx_packets);
6413 if (ret == A_OK) {
6414 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6415 fwd_tx_packets,
6416 adapter->prev_fwd_tx_packets);
6417 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6418 fwd_tx_packets,
6419 adapter->prev_fwd_rx_packets);
6420 }
6421 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422
6423 total_rx += adapter->stats.rx_packets;
6424 total_tx += adapter->stats.tx_packets;
6425
6426 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6427 adapter->prev_tx_packets = adapter->stats.tx_packets;
6428 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306429 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6430 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6432 connected = true;
6433 }
6434
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306435 /* add intra bss forwarded tx and rx packets */
6436 tx_packets += fwd_tx_packets_diff;
6437 rx_packets += fwd_rx_packets_diff;
6438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006439 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6440 tx_packets += (uint64_t)ipa_tx_packets;
6441 rx_packets += (uint64_t)ipa_rx_packets;
6442
6443 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006444 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006445 return;
6446 }
6447
Yuanyuan Liu13738502016-04-06 17:41:37 -07006448 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449
6450 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6451 hdd_ipa_uc_stat_request(adapter, 2);
6452
Dustin Brown2ed60362017-01-18 12:25:50 -08006453 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006454 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006455 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306456 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006457 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006458 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006460
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306461/**
6462 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6463 * @arg: Argument of timer function
6464 *
6465 * Schedule a workqueue in this function where all the processing is done.
6466 *
6467 * Return: None.
6468 */
6469static void __hdd_bus_bw_cbk(void *arg)
6470{
6471 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
6472
6473 if (wlan_hdd_validate_context(hdd_ctx))
6474 return;
6475
6476 schedule_work(&hdd_ctx->bus_bw_work);
6477}
6478
6479/**
6480 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6481 * @arg: Argument of timer function
6482 *
6483 * Return: None.
6484 */
6485static void hdd_bus_bw_cbk(void *arg)
6486{
6487 cds_ssr_protect(__func__);
6488 __hdd_bus_bw_cbk(arg);
6489 cds_ssr_unprotect(__func__);
6490}
6491
Prashanth Bhattaab004382016-10-11 16:08:11 -07006492int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
6493{
6494 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306495 INIT_WORK(&hdd_ctx->bus_bw_work,
6496 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006497 hdd_ctx->bus_bw_timer_running = false;
6498 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306499 qdf_timer_init(NULL,
6500 &hdd_ctx->bus_bw_timer,
6501 hdd_bus_bw_cbk, (void *)hdd_ctx,
6502 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006503
6504 return 0;
6505}
6506
6507void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
6508{
Dustin Brownfce08d12017-01-17 16:29:38 -08006509 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006510 hdd_reset_tcp_delack(hdd_ctx);
6511
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006512 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306513 cancel_work_sync(&hdd_ctx->bus_bw_work);
6514 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006515 hdd_ctx->bus_bw_timer_running = false;
6516 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006517}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518#endif
6519
6520/**
Nirav Shahed34b212016-04-25 10:59:16 +05306521 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6522 * @hdd_ctx: hdd context
6523 *
6524 * Return: 0 for success or error code
6525 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07006526static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306527{
6528 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6529 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6530 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006531 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306532 return -ENOMEM;
6533 }
6534 return 0;
6535}
6536
6537/**
6538 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6539 * @hdd_ctx: hdd context
6540 *
6541 * Return: none
6542 */
6543void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
6544{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306545 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6546 return;
6547
6548 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6549 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306550}
6551
Nirav Shahda008342016-05-17 18:50:40 +05306552static uint8_t *convert_level_to_string(uint32_t level)
6553{
6554 switch (level) {
6555 /* initialize the wlan sub system */
6556 case WLAN_SVC_TP_NONE:
6557 return "NONE";
6558 case WLAN_SVC_TP_LOW:
6559 return "LOW";
6560 case WLAN_SVC_TP_MEDIUM:
6561 return "MED";
6562 case WLAN_SVC_TP_HIGH:
6563 return "HIGH";
6564 default:
6565 return "INVAL";
6566 }
6567}
6568
Nirav Shahed34b212016-04-25 10:59:16 +05306569
6570/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006571 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6572 * @hdd_ctx: hdd context
6573 *
6574 * Return: none
6575 */
6576void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
6577{
6578 int i;
6579
6580#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006581 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306582 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006583 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 hdd_ctx->config->busBandwidthHighThreshold,
6585 hdd_ctx->config->busBandwidthMediumThreshold,
6586 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006587 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306588 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006589 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590 hdd_ctx->config->tcpDelackThresholdHigh,
6591 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006592 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306593 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594#endif
6595
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006596 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306597 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6598
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006599 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006600
6601 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006602 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006603 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006604 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006605 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6606 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006607 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006608 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6609 convert_level_to_string(
6610 hdd_ctx->hdd_txrx_hist[i].
6611 next_vote_level),
6612 convert_level_to_string(
6613 hdd_ctx->hdd_txrx_hist[i].
6614 next_rx_level),
6615 convert_level_to_string(
6616 hdd_ctx->hdd_txrx_hist[i].
6617 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006618 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006619
6620 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621}
6622
6623/**
6624 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6625 * @hdd_ctx: hdd context
6626 *
6627 * Return: none
6628 */
6629void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
6630{
6631 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306632 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6633 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006634}
6635
6636/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006637 * wlan_hdd_display_netif_queue_history() - display netif queue history
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638 * @pHddCtx: hdd context
6639 *
6640 * Return: none
6641 */
6642void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
6643{
6644
6645 hdd_adapter_t *adapter = NULL;
6646 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306647 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306649 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
6651 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306652 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653 adapter = adapter_node->pAdapter;
6654
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006655 hdd_debug("Netif queue operation statistics:");
6656 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306657 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006658 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306659 curr_time = qdf_system_ticks();
6660 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306661 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306662 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306663 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306664 unpause = adapter->total_unpause_time;
6665 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306666 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306667 pause = adapter->total_pause_time;
6668 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006669 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306670 qdf_system_ticks_to_msecs(total),
6671 qdf_system_ticks_to_msecs(pause),
6672 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006673 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006674
Nirav Shahda008342016-05-17 18:50:40 +05306675 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6676 qdf_time_t pause_delta = 0;
6677
6678 if (adapter->pause_map & (1 << i))
6679 pause_delta = delta;
6680
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006681 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006682 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006683 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684 hdd_reason_type_to_string(i),
6685 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306686 adapter->queue_oper_stats[i].unpause_count,
6687 qdf_system_ticks_to_msecs(
6688 adapter->queue_oper_stats[i].total_pause_time +
6689 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006690 }
6691
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006692 hdd_debug("Netif queue operation history:");
6693 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306694 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6695
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006696 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697
6698 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006699 /* using hdd_log to avoid printing function name */
6700 if (adapter->queue_oper_history[i].time == 0)
6701 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006702 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006703 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306704 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006705 adapter->queue_oper_history[i].time),
6706 hdd_action_type_to_string(
6707 adapter->queue_oper_history[i].netif_action),
6708 hdd_reason_type_to_string(
6709 adapter->queue_oper_history[i].netif_reason),
6710 adapter->queue_oper_history[i].pause_map);
6711 }
6712
6713 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6714 adapter_node = next;
6715 }
6716
6717
6718}
6719
6720/**
6721 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6722 * @hdd_ctx: hdd context
6723 *
6724 * Return: none
6725 */
6726void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
6727{
6728 hdd_adapter_t *adapter = NULL;
6729 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306730 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731
6732 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306733 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734 adapter = adapter_node->pAdapter;
6735
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306736 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006737 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306738 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306740 adapter->history_index = 0;
6741 adapter->start_time = adapter->last_time = qdf_system_ticks();
6742 adapter->total_pause_time = 0;
6743 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6745 adapter_node = next;
6746 }
6747}
6748
6749/**
6750 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6751 * @halHandle: Hal handle
6752 * @pContext: Pointer to the context
6753 * @sessionId: Session ID
6754 * @scanId: Scan ID
6755 * @status: Status
6756 *
6757 * This is the callback to be executed when 11d scan is completed to flush out
6758 * the scan results
6759 *
6760 * 11d scan is done during driver load and is a passive scan on all
6761 * channels supported by the device, 11d scans may find some APs on
6762 * frequencies which are forbidden to be used in the regulatory domain
6763 * the device is operating in. If these APs are notified to the supplicant
6764 * it may try to connect to these APs, thus flush out all the scan results
6765 * which are present in SME after 11d scan is done.
6766 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306767 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306769static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 uint8_t sessionId, uint32_t scanId,
6771 eCsrScanStatus status)
6772{
6773 ENTER();
6774
6775 sme_scan_flush_result(halHandle);
6776
6777 EXIT();
6778
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306779 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780}
6781
6782#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6783/**
6784 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6785 * @hdd_ctx: hdd global context
6786 *
6787 * Return: none
6788 */
6789static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6790{
6791 uint8_t i;
6792
6793 mutex_init(&hdd_ctx->op_ctx.op_lock);
6794 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6795 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6796 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6797 }
6798}
6799#else
6800static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6801{
6802}
6803#endif
6804
Yingying Tang95409972016-10-20 15:16:15 +08006805#ifdef WLAN_FEATURE_WOW_PULSE
6806/**
6807 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6808 * @phddctx: hdd_context_t structure pointer
6809 * @enable: enable or disable this behaviour
6810 *
6811 * Return: int
6812 */
6813static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6814{
6815 struct hdd_config *pcfg_ini = phddctx->config;
6816 struct wow_pulse_mode wow_pulse_set_info;
6817 QDF_STATUS status;
6818
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006819 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006820
6821 if (false == phddctx->config->wow_pulse_support)
6822 return 0;
6823
6824 /* prepare the request to send to SME */
6825 if (enable == true) {
6826 wow_pulse_set_info.wow_pulse_enable = true;
6827 wow_pulse_set_info.wow_pulse_pin =
6828 pcfg_ini->wow_pulse_pin;
6829 wow_pulse_set_info.wow_pulse_interval_low =
6830 pcfg_ini->wow_pulse_interval_low;
6831 wow_pulse_set_info.wow_pulse_interval_high =
6832 pcfg_ini->wow_pulse_interval_high;
6833 } else {
6834 wow_pulse_set_info.wow_pulse_enable = false;
6835 wow_pulse_set_info.wow_pulse_pin = 0;
6836 wow_pulse_set_info.wow_pulse_interval_low = 0;
6837 wow_pulse_set_info.wow_pulse_interval_high = 0;
6838 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006839 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006840 wow_pulse_set_info.wow_pulse_enable,
6841 wow_pulse_set_info.wow_pulse_pin,
6842 wow_pulse_set_info.wow_pulse_interval_low,
6843 wow_pulse_set_info.wow_pulse_interval_high);
6844
6845 status = sme_set_wow_pulse(&wow_pulse_set_info);
6846 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006847 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006848 return -EIO;
6849 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006850 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006851 return 0;
6852}
6853#else
6854static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6855{
6856 return 0;
6857}
6858#endif
6859
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860#ifdef WLAN_FEATURE_FASTPATH
6861/**
6862 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6863 * @hdd_cfg: hdd config
6864 * @context: lower layer context
6865 *
6866 * Return: none
6867 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306868void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869 void *context)
6870{
6871 if (hdd_cfg->fastpath_enable)
6872 hif_enable_fastpath(context);
6873}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874#endif
6875
Yuanyuan Liu13738502016-04-06 17:41:37 -07006876#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006877/**
6878 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006879 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006880 * @level: thermal level
6881 *
6882 * Change IPA data path to SW path when the thermal throttle level greater
6883 * than 0, and restore the original data path when throttle level is 0
6884 *
6885 * Return: none
6886 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006887static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006889 hdd_context_t *hdd_ctx = context;
6890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006891 /* Change IPA to SW path when throttle level greater than 0 */
6892 if (level > THROTTLE_LEVEL_0)
6893 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6894 else
6895 /* restore original concurrency mode */
6896 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6897}
6898
6899/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306900 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6901 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306902 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306904 * Get a safe channel to restart SAP. PCL already takes into account the
6905 * unsafe channels. So, the PCL is validated with the ACS range to provide
6906 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306908 * Return: Channel number to restart SAP in case of success. In case of any
6909 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306911static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6912 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006913{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306914 struct sir_pcl_list pcl;
6915 QDF_STATUS status;
6916 uint32_t i, j;
6917 tHalHandle *hal_handle;
6918 hdd_context_t *hdd_ctx;
6919 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306921 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6922 if (!hdd_ctx) {
6923 hdd_err("invalid HDD context");
6924 return INVALID_CHANNEL_ID;
6925 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006926
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306927 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6928 if (!hal_handle) {
6929 hdd_err("invalid HAL handle");
6930 return INVALID_CHANNEL_ID;
6931 }
6932
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006933 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6934 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08006935 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
6936 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306937 if (QDF_IS_STATUS_ERROR(status)) {
6938 hdd_err("Get PCL failed");
6939 return INVALID_CHANNEL_ID;
6940 }
6941
Frank Liudc2cefb2017-06-21 15:38:18 +08006942 /*
6943 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
6944 * channel is unsafe channel, the pcl may be empty, instead of return,
6945 * try to choose a safe channel from acs range.
6946 */
6947 if (!pcl.pcl_len)
6948 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306949
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006950 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306951 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6952 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6953
6954 /* PCL already takes unsafe channel into account */
6955 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006956 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306957 if ((pcl.pcl_list[i] >=
6958 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6959 (pcl.pcl_list[i] <=
6960 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006961 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306962 return pcl.pcl_list[i];
6963 }
6964 }
6965
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006966 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306967
6968 /* Try for safe channel from all valid channel */
6969 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006970 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306971 &pcl.pcl_len);
6972 if (QDF_IS_STATUS_ERROR(status)) {
6973 hdd_err("error in getting valid channel list");
6974 return INVALID_CHANNEL_ID;
6975 }
6976
6977 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006978 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306979 found = false;
6980 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006981 if (pcl.pcl_list[i] ==
6982 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006983 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306984 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 break;
6986 }
6987 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306988
6989 if (found)
6990 continue;
6991
6992 if ((pcl.pcl_list[i] >=
6993 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6994 (pcl.pcl_list[i] <=
6995 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006996 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306997 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998 }
6999 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307000
7001 return INVALID_CHANNEL_ID;
7002}
7003
7004/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007005 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307006 * @adapter: AP adapter
7007 * @channel: Channel
7008 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007009 * Moves the SAP interface by invoking the function which
7010 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307011 *
7012 * Return: None
7013 */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007014void hdd_switch_sap_channel(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307015{
7016 hdd_ap_ctx_t *hdd_ap_ctx;
7017 tHalHandle *hal_handle;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007018 hdd_context_t *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307019
7020 if (!adapter) {
7021 hdd_err("invalid adapter");
7022 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007023 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307024
7025 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7026
7027 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7028 if (!hal_handle) {
7029 hdd_err("invalid HAL handle");
7030 return;
7031 }
7032
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007033 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7034
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307035 hdd_ap_ctx->sapConfig.channel = channel;
7036 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7037 hdd_ap_ctx->sapConfig.ch_width_orig;
7038
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007039 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307040 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7041
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007042 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7043 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307044 hdd_ap_ctx->sapConfig.sec_ch,
7045 &hdd_ap_ctx->sapConfig.ch_params);
7046
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007047 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7048 adapter->sessionId, channel,
7049 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307051
7052int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
7053{
7054 struct hdd_external_acs_timer_context *timer_context;
7055
7056 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7057
7058 if (QDF_TIMER_STATE_RUNNING ==
7059 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7060 ap.vendor_acs_timer)) {
7061 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7062 }
7063 timer_context = (struct hdd_external_acs_timer_context *)
7064 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7065 timer_context->reason = reason;
7066 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7067 WLAN_VENDOR_ACS_WAIT_TIME);
7068 /* Update config to application */
7069 hdd_cfg80211_update_acs_config(adapter, reason);
7070 hdd_notice("Updated ACS config to nl with reason %d", reason);
7071
7072 return 0;
7073}
7074
Agrawal Ashish467dde42016-09-08 18:44:22 +05307075/**
7076 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7077 * @hdd_ctx: hdd context pointer
7078 *
7079 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7080 * and if ACS is enabled, driver will ask userspace to restart the
7081 * sap. User space on LTE coex indication restart driver.
7082 *
7083 * Return - none
7084 */
7085void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
7086{
7087 QDF_STATUS status;
7088 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
7089 hdd_adapter_t *adapter_temp;
7090 uint32_t i;
7091 bool found = false;
7092 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007093
Agrawal Ashish467dde42016-09-08 18:44:22 +05307094 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7095 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7096 adapter_temp = adapter_node->pAdapter;
7097
7098 if (!adapter_temp) {
7099 hdd_err("adapter is NULL, moving to next one");
7100 goto next_adapater;
7101 }
7102
7103 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7104 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007105 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307106 adapter_temp->device_mode,
7107 adapter_temp->sessionCtx.ap.sapConfig.
7108 acs_cfg.acs_mode);
7109 goto next_adapater;
7110 }
7111
7112 found = false;
7113 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007114 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307115 hdd_ctxt->unsafe_channel_list[i]) {
7116 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007117 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307118 adapter_temp->sessionCtx.ap.operatingChannel);
7119 break;
7120 }
7121 }
7122
7123 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007124 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307125 adapter_temp->sessionCtx.ap.operatingChannel);
7126 goto next_adapater;
7127 }
7128
Kapil Gupta8878ad92017-02-13 11:56:04 +05307129 if (hdd_ctxt->config->vendor_acs_support &&
7130 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7131 hdd_update_acs_timer_reason(adapter_temp,
7132 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7133 goto next_adapater;
7134 } else
7135 restart_chan =
7136 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307137 adapter_temp);
7138 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007139 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307140 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007141 /*
7142 * SAP restart due to unsafe channel. While
7143 * restarting the SAP, make sure to clear
7144 * acs_channel, channel to reset to
7145 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307146 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007147 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307148 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7149 adapter_temp->sessionCtx.ap.sapConfig.channel =
7150 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007151 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307152 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7153 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007154 hdd_switch_sap_channel(adapter_temp, restart_chan);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307155 }
7156
7157next_adapater:
7158 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7159 adapter_node = next;
7160 }
7161}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007163/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007164 * hdd_init_channel_avoidance() - Initialize channel avoidance
7165 * @hdd_ctx: HDD global context
7166 *
7167 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007168 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169 * down to the lower layers. Then subscribe to subsequent channel
7170 * avoidance events.
7171 *
7172 * Return: None
7173 */
7174static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7175{
7176 uint16_t unsafe_channel_count;
7177 int index;
7178
Yuanyuan Liu13738502016-04-06 17:41:37 -07007179 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7180 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007181 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007182 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007184 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007185 hdd_ctx->unsafe_channel_count);
7186
Anurag Chouhan6d760662016-02-20 16:05:43 +05307187 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007188 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007189
7190 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007191 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007192 hdd_ctx->unsafe_channel_list[index]);
7193
7194 }
7195
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007196}
7197#else
7198static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7199{
7200}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007201static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007202{
7203}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007204#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007205
7206/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007207 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7208 * user space
7209 * @frame_ind: Management frame data to be informed.
7210 *
7211 * This function is used to indicate management frame to
7212 * user space
7213 *
7214 * Return: None
7215 *
7216 */
7217void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7218{
7219 hdd_context_t *hdd_ctx = NULL;
7220 hdd_adapter_t *adapter = NULL;
7221 void *cds_context = NULL;
7222 int i;
7223
7224 /* Get the global VOSS context.*/
7225 cds_context = cds_get_global_context();
7226 if (!cds_context) {
7227 hdd_err("Global CDS context is Null");
7228 return;
7229 }
7230 /* Get the HDD context.*/
7231 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
7232
7233 if (0 != wlan_hdd_validate_context(hdd_ctx))
7234 return;
7235
7236 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7237 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7238 adapter =
7239 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7240 if (adapter)
7241 break;
7242 }
7243 } else {
7244 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7245 frame_ind->sessionId);
7246 }
7247
7248 if ((NULL != adapter) &&
7249 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7250 __hdd_indicate_mgmt_frame(adapter,
7251 frame_ind->frame_len,
7252 frame_ind->frameBuf,
7253 frame_ind->frameType,
7254 frame_ind->rxChan,
7255 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007256}
7257
Kapil Gupta8878ad92017-02-13 11:56:04 +05307258static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
7259 hdd_context_t *hdd_ctx)
7260{
7261 uint8_t restart_chan = 0;
7262
7263 restart_chan =
7264 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7265 if (!restart_chan) {
7266 hdd_alert("fail to restart SAP");
7267 } else {
7268 /* SAP restart due to unsafe channel. While restarting
7269 * the SAP, make sure to clear acs_channel, channel to
7270 * reset to 0. Otherwise these settings will override
7271 * the ACS while restart.
7272 */
7273 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7274 adapter->sessionCtx.ap.sapConfig.channel =
7275 AUTO_CHANNEL_SELECT;
7276 hdd_info("sending coex indication");
7277 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7278 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007279 hdd_switch_sap_channel(adapter, restart_chan);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307280 }
7281}
7282
7283void hdd_acs_response_timeout_handler(void *context)
7284{
7285 struct hdd_external_acs_timer_context *timer_context =
7286 (struct hdd_external_acs_timer_context *)context;
7287 hdd_adapter_t *adapter;
7288 hdd_context_t *hdd_ctx;
7289 uint8_t reason;
7290
7291 ENTER();
7292 if (!timer_context) {
7293 hdd_err("invlaid timer context");
7294 return;
7295 }
7296 adapter = timer_context->adapter;
7297 reason = timer_context->reason;
7298
7299
7300 if ((!adapter) ||
7301 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7302 hdd_err("invalid adapter or adapter has invalid magic");
7303 return;
7304 }
7305 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7306 if (wlan_hdd_validate_context(hdd_ctx))
7307 return;
7308
7309 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7310 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7311 else
7312 return;
7313
7314 hdd_err("ACS timeout happened for %s reason %d",
7315 adapter->dev->name, reason);
7316 switch (reason) {
7317 /* SAP init case */
7318 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7319 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7320 false);
7321 wlan_hdd_cfg80211_start_acs(adapter);
7322 break;
7323 /* DFS detected on current channel */
7324 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7325 wlan_sap_update_next_channel(
7326 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7327 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7328 adapter->sessionId);
7329 break;
7330 /* LTE coex event on current channel */
7331 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7332 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7333 break;
7334 default:
7335 hdd_info("invalid reason for timer invoke");
7336
7337 }
7338}
7339
Rajeev Kumard004abc2016-02-17 12:09:56 -08007340/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007341 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7342 * @hdd_ctx: HDD context
7343 *
7344 * Disables all the dual mac features like DBS, Agile DFS etc.
7345 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307346 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007347 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307348static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007349{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007350 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307351 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007352
7353 if (!hdd_ctx) {
7354 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307355 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007356 }
7357
7358 cfg.scan_config = 0;
7359 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007360 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007361
7362 hdd_debug("Disabling all dual mac features...");
7363
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007364 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307365 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007366 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7367 return status;
7368 }
7369
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307370 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007371}
7372
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007373static QDF_STATUS
7374wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_context_t *hdd_ctx)
7375{
7376 struct policy_mgr_dual_mac_config cfg = {0};
7377 QDF_STATUS status;
7378
7379 if (!hdd_ctx) {
7380 hdd_err("HDD context is NULL");
7381 return QDF_STATUS_E_FAILURE;
7382 }
7383
7384 cfg.scan_config = 0;
7385 cfg.fw_mode_config = 0;
7386 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7387 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7388 hdd_ctx->hdd_psoc, &cfg.scan_config,
7389 &cfg.fw_mode_config,
7390 hdd_ctx->config->dual_mac_feature_disable);
7391
7392 if (status != QDF_STATUS_SUCCESS) {
7393 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7394 status);
7395 return status;
7396 }
7397
7398 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7399 cfg.scan_config, cfg.fw_mode_config);
7400
7401 status = sme_soc_set_dual_mac_config(cfg);
7402 if (status != QDF_STATUS_SUCCESS) {
7403 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7404 return status;
7405 }
7406
7407 return QDF_STATUS_SUCCESS;
7408}
7409
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007410/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007411 * hdd_override_ini_config - Override INI config
7412 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007414 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007416 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007417 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007418static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007419{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007421 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7422 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007423 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007424 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007425 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007426 if (0 == enable_11d || 1 == enable_11d) {
7427 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007428 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429 }
Leo Chang11545d62016-10-17 14:53:50 -07007430
7431 if (!hdd_ipa_is_present(hdd_ctx))
7432 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007433}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007434
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007435/**
7436 * hdd_set_trace_level_for_each - Set trace level for each INI config
7437 * @hdd_ctx - HDD context
7438 *
7439 * Set trace level for each module based on INI config.
7440 *
7441 * Return: None
7442 */
7443static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
7444{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307445 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7446 hdd_ctx->config->qdf_trace_enable_wdi);
7447 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7448 hdd_ctx->config->qdf_trace_enable_hdd);
7449 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7450 hdd_ctx->config->qdf_trace_enable_sme);
7451 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7452 hdd_ctx->config->qdf_trace_enable_pe);
7453 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7454 hdd_ctx->config->qdf_trace_enable_wma);
7455 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7456 hdd_ctx->config->qdf_trace_enable_sys);
7457 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7458 hdd_ctx->config->qdf_trace_enable_qdf);
7459 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7460 hdd_ctx->config->qdf_trace_enable_sap);
7461 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7462 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7463 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7464 hdd_ctx->config->qdf_trace_enable_bmi);
7465 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7466 hdd_ctx->config->qdf_trace_enable_cfg);
7467 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7468 hdd_ctx->config->qdf_trace_enable_epping);
7469 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7470 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7471 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05307472 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307473 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7474 hdd_ctx->config->qdf_trace_enable_htc);
7475 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7476 hdd_ctx->config->qdf_trace_enable_hif);
7477 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7478 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7479 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7480 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007481 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7482 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007483 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7484 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007485 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7486 hdd_ctx->config->qdf_trace_enable_regulatory);
7487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007488 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007489}
7490
7491/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007492 * hdd_context_init() - Initialize HDD context
7493 * @hdd_ctx: HDD context.
7494 *
7495 * Initialize HDD context along with all the feature specific contexts.
7496 *
7497 * return: 0 on success and errno on failure.
7498 */
7499static int hdd_context_init(hdd_context_t *hdd_ctx)
7500{
7501 int ret;
7502
7503 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7504 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7505
7506 hdd_init_ll_stats_ctx();
7507
7508 init_completion(&hdd_ctx->mc_sus_event_var);
7509 init_completion(&hdd_ctx->ready_to_suspend);
7510
7511 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307512 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007513 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307514
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007515 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7516
7517 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7518
7519 ret = hdd_scan_context_init(hdd_ctx);
7520 if (ret)
7521 goto list_destroy;
7522
Nitesh Shahd1266d72017-01-25 22:07:07 +05307523 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007524
7525 hdd_rx_wake_lock_create(hdd_ctx);
7526
7527 ret = hdd_sap_context_init(hdd_ctx);
7528 if (ret)
7529 goto scan_destroy;
7530
7531 ret = hdd_roc_context_init(hdd_ctx);
7532 if (ret)
7533 goto sap_destroy;
7534
7535 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7536
7537 hdd_init_offloaded_packets_ctx(hdd_ctx);
7538
7539 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7540 hdd_ctx->config);
7541 if (ret)
7542 goto roc_destroy;
7543
7544 return 0;
7545
7546roc_destroy:
7547 hdd_roc_context_destroy(hdd_ctx);
7548
7549sap_destroy:
7550 hdd_sap_context_destroy(hdd_ctx);
7551
7552scan_destroy:
7553 hdd_scan_context_destroy(hdd_ctx);
7554 hdd_rx_wake_lock_destroy(hdd_ctx);
7555 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007556list_destroy:
7557 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007558
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007559 return ret;
7560}
7561
7562/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307563 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7564 * @hdd_ctx: pointer to hdd context
7565 *
7566 * Return: status of initialization
7567 * 0 - success
7568 * negative value - failure
7569 */
7570static int ie_whitelist_attrs_init(hdd_context_t *hdd_ctx)
7571{
7572 int ret;
7573
7574 if (!hdd_ctx->config->probe_req_ie_whitelist)
7575 return 0;
7576
7577 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7578 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7579 hdd_ctx->config->probe_req_ie_whitelist = false;
7580 return -EINVAL;
7581 }
7582
7583 /* parse ini string probe req oui */
7584 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7585 if (ret) {
7586 hdd_err("parsing error: disable ie whitelisting");
7587 hdd_ctx->config->probe_req_ie_whitelist = false;
7588 }
7589
7590 return ret;
7591}
7592
7593/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007594 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307595 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007596 *
7597 * Allocate and initialize HDD context. HDD context is allocated as part of
7598 * wiphy allocation and then context is initialized.
7599 *
7600 * Return: HDD context on success and ERR_PTR on failure
7601 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007602static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007603{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307604 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007605 int ret = 0;
7606 hdd_context_t *hdd_ctx;
7607 v_CONTEXT_t p_cds_context;
7608
7609 ENTER();
7610
7611 p_cds_context = cds_get_global_context();
7612 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007613 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007614 ret = -EINVAL;
7615 goto err_out;
7616 }
7617
7618 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
7619
7620 if (hdd_ctx == NULL) {
7621 ret = -ENOMEM;
7622 goto err_out;
7623 }
7624
7625 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007626 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307627 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007628
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307629 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007630 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007631 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007632 ret = -ENOMEM;
7633 goto err_free_hdd_context;
7634 }
7635
7636 /* Read and parse the qcom_cfg.ini file */
7637 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307638 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307639 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007640 WLAN_INI_FILE);
7641 ret = -EINVAL;
7642 goto err_free_config;
7643 }
7644
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307645 ie_whitelist_attrs_init(hdd_ctx);
7646
Dustin Brown7f939932017-05-18 15:02:17 -07007647 hdd_debug("setting timer multiplier: %u",
7648 hdd_ctx->config->timer_multiplier);
7649 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7650
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007651
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307652 if (hdd_ctx->config->fhostNSOffload)
7653 hdd_ctx->ns_offload_enable = true;
7654
Abhishek Singh5ea86532016-04-27 14:10:53 +05307655 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7656
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007657 hdd_override_ini_config(hdd_ctx);
7658
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007659 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007660
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007661 ret = hdd_context_init(hdd_ctx);
7662
7663 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007664 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007665
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007666 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307667 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007668
Anurag Chouhan6d760662016-02-20 16:05:43 +05307669 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007670 goto skip_multicast_logging;
7671
7672 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7673
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007674 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7675 if (ret)
7676 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307677
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007678 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7679 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307680 goto err_free_histogram;
7681
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007682skip_multicast_logging:
7683 hdd_set_trace_level_for_each(hdd_ctx);
7684
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007685 EXIT();
7686
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007687 return hdd_ctx;
7688
Nirav Shahed34b212016-04-25 10:59:16 +05307689err_free_histogram:
7690 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7691
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007692err_deinit_hdd_context:
7693 hdd_context_deinit(hdd_ctx);
7694
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007695err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307696 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007697
7698err_free_hdd_context:
7699 wiphy_free(hdd_ctx->wiphy);
7700
7701err_out:
7702 return ERR_PTR(ret);
7703}
7704
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007705#ifdef WLAN_OPEN_P2P_INTERFACE
7706/**
7707 * hdd_open_p2p_interface - Open P2P interface
7708 * @hdd_ctx: HDD context
7709 * @rtnl_held: True if RTNL lock held
7710 *
7711 * Open P2P interface during probe. This function called to open the P2P
7712 * interface at probe along with STA interface.
7713 *
7714 * Return: 0 on success and errno on failure
7715 */
7716static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7717{
7718 hdd_adapter_t *adapter;
7719 uint8_t *p2p_dev_addr;
7720
7721 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7722 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307723 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007724 hdd_ctx->config->intfMacAddr[0].bytes,
7725 sizeof(tSirMacAddr));
7726
7727 /*
7728 * Generate the P2P Device Address. This consists of
7729 * the device's primary MAC address with the locally
7730 * administered bit set.
7731 */
7732 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7733 } else {
7734 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7735 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007736 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007737 return -ENOSPC;
7738 }
7739
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307740 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307741 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007742 }
7743
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007744 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007745 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007746 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007747
7748 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007749 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007750 return -ENOSPC;
7751 }
7752
7753 return 0;
7754}
7755#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307756static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007757 bool rtnl_held)
7758{
7759 return 0;
7760}
7761#endif
7762
Jeff Johnson957bc272017-02-02 08:54:48 -08007763static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7764{
7765 hdd_adapter_t *adapter;
7766 int ret = 0;
7767
7768 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7769 wlan_hdd_get_intf_addr(hdd_ctx),
7770 NET_NAME_UNKNOWN, rtnl_held);
7771 if (adapter == NULL) {
7772 hdd_err("Failed to open 802.11p interface");
7773 ret = -ENOSPC;
7774 }
7775
7776 return ret;
7777}
7778
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007779/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307780 * hdd_start_station_adapter()- Start the Station Adapter
7781 * @adapter: HDD adapter
7782 *
7783 * This function initializes the adapter for the station mode.
7784 *
7785 * Return: 0 on success or errno on failure.
7786 */
7787int hdd_start_station_adapter(hdd_adapter_t *adapter)
7788{
7789 QDF_STATUS status;
7790
7791 ENTER_DEV(adapter->dev);
7792
7793 status = hdd_init_station_mode(adapter);
7794
7795 if (QDF_STATUS_SUCCESS != status) {
7796 hdd_err("Error Initializing station mode: %d", status);
7797 return qdf_status_to_os_return(status);
7798 }
7799
Arun Khandavallifae92942016-08-01 13:31:08 +05307800 hdd_register_tx_flow_control(adapter,
7801 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007802 hdd_tx_resume_cb,
7803 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307804
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307805 EXIT();
7806 return 0;
7807}
7808
7809/**
7810 * hdd_start_ap_adapter()- Start AP Adapter
7811 * @adapter: HDD adapter
7812 *
7813 * This function initializes the adapter for the AP mode.
7814 *
7815 * Return: 0 on success errno on failure.
7816 */
7817int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7818{
7819 QDF_STATUS status;
7820
7821 ENTER();
7822
Arun Khandavallicc544b32017-01-30 19:52:16 +05307823 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307824
7825 if (QDF_STATUS_SUCCESS != status) {
7826 hdd_err("Error Initializing the AP mode: %d", status);
7827 return qdf_status_to_os_return(status);
7828 }
7829
Arun Khandavallifae92942016-08-01 13:31:08 +05307830 hdd_register_tx_flow_control(adapter,
7831 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007832 hdd_softap_tx_resume_cb,
7833 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307834
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307835 EXIT();
7836 return 0;
7837}
7838
7839/**
7840 * hdd_start_ftm_adapter()- Start FTM adapter
7841 * @adapter: HDD adapter
7842 *
7843 * This function initializes the adapter for the FTM mode.
7844 *
7845 * Return: 0 on success or errno on failure.
7846 */
7847int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7848{
7849 QDF_STATUS qdf_status;
7850
7851 ENTER_DEV(adapter->dev);
7852
7853 qdf_status = hdd_init_tx_rx(adapter);
7854
7855 if (QDF_STATUS_SUCCESS != qdf_status) {
7856 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7857 return qdf_status_to_os_return(qdf_status);
7858 }
7859
7860 return 0;
7861 EXIT();
7862}
7863
7864/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007865 * hdd_open_interfaces - Open all required interfaces
7866 * hdd_ctx: HDD context
7867 * rtnl_held: True if RTNL lock is held
7868 *
7869 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7870 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007871 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007872 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007873static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007874{
Jeff Johnson957bc272017-02-02 08:54:48 -08007875 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007876 int ret;
7877
Jeff Johnson957bc272017-02-02 08:54:48 -08007878 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307879 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007880 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007881
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007882 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007883 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007884 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007885
7886 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007887 return -ENOSPC;
7888
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007889 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7890 adapter->fast_roaming_allowed = true;
7891
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007892 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7893 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007894 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007895
7896 /* Open 802.11p Interface */
7897 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007898 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7899 if (ret)
7900 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007901 }
7902
Jeff Johnson957bc272017-02-02 08:54:48 -08007903 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007904
Jeff Johnson957bc272017-02-02 08:54:48 -08007905err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007906 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007907 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007908}
7909
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007910/**
7911 * hdd_update_country_code - Update country code
7912 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007913 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007914 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007915 *
7916 * Return: 0 on success and errno on failure
7917 */
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007918static int hdd_update_country_code(hdd_context_t *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007919{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007920 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007921 return 0;
7922
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007923 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007924}
7925
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307926#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7927/**
7928 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7929 * @cds_cfg: CDS Configuration
7930 * @hdd_ctx: Pointer to hdd context
7931 *
7932 * Return: none
7933 */
7934static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7935 *cds_cfg,
7936 hdd_context_t *hdd_ctx)
7937{
7938 cds_cfg->tx_flow_stop_queue_th =
7939 hdd_ctx->config->TxFlowStopQueueThreshold;
7940 cds_cfg->tx_flow_start_queue_offset =
7941 hdd_ctx->config->TxFlowStartQueueOffset;
7942}
7943#else
7944static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7945 *cds_cfg,
7946 hdd_context_t *hdd_ctx)
7947{
7948}
7949#endif
7950
7951#ifdef FEATURE_WLAN_RA_FILTERING
7952/**
7953 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
7954 * @cds_cfg: CDS Configuration
7955 * @hdd_ctx: Pointer to hdd context
7956 *
7957 * Return: none
7958 */
Anand Kumar3b92a912016-12-05 12:01:26 +05307959static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307960 hdd_context_t *hdd_ctx)
7961{
7962 cds_cfg->ra_ratelimit_interval =
7963 hdd_ctx->config->RArateLimitInterval;
7964 cds_cfg->is_ra_ratelimit_enabled =
7965 hdd_ctx->config->IsRArateLimitEnabled;
7966}
7967#else
Anand Kumar3b92a912016-12-05 12:01:26 +05307968static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307969 hdd_context_t *hdd_ctx)
7970{
7971}
7972#endif
7973
7974/**
7975 * hdd_update_cds_config() - API to update cds configuration parameters
7976 * @hdd_ctx: HDD Context
7977 *
7978 * Return: 0 for Success, errno on failure
7979 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007980static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307981{
7982 struct cds_config_info *cds_cfg;
7983
7984 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
7985 if (!cds_cfg) {
7986 hdd_err("failed to allocate cds config");
7987 return -ENOMEM;
7988 }
7989
Srinivas Girigowda35b00312017-06-27 21:52:03 -07007990 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08007991 if (!hdd_ctx->config->nMaxPsPoll ||
7992 !hdd_ctx->config->enablePowersaveOffload) {
7993 cds_cfg->powersave_offload_enabled =
7994 hdd_ctx->config->enablePowersaveOffload;
7995 } else {
7996 if ((hdd_ctx->config->enablePowersaveOffload ==
7997 PS_QPOWER_NODEEPSLEEP) ||
7998 (hdd_ctx->config->enablePowersaveOffload ==
7999 PS_LEGACY_NODEEPSLEEP))
8000 cds_cfg->powersave_offload_enabled =
8001 PS_LEGACY_NODEEPSLEEP;
8002 else
8003 cds_cfg->powersave_offload_enabled =
8004 PS_LEGACY_DEEPSLEEP;
8005 hdd_info("Qpower disabled in cds config, %d",
8006 cds_cfg->powersave_offload_enabled);
8007 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308008 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8009 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8010 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8011 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8012 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8013
8014 /* Here ol_ini_info is used to store ini status of arp offload
8015 * ns offload and others. Currently 1st bit is used for arp
8016 * off load and 2nd bit for ns offload currently, rest bits are unused
8017 */
8018 if (hdd_ctx->config->fhostArpOffload)
8019 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8020 if (hdd_ctx->config->fhostNSOffload)
8021 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8022
8023 /*
8024 * Copy the DFS Phyerr Filtering Offload status.
8025 * This parameter reflects the value of the
8026 * dfs_phyerr_filter_offload flag as set in the ini.
8027 */
8028 cds_cfg->dfs_phyerr_filter_offload =
8029 hdd_ctx->config->fDfsPhyerrFilterOffload;
8030 if (hdd_ctx->config->ssdp)
8031 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8032
8033 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8034 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8035
8036 cds_cfg->ap_maxoffload_reorderbuffs =
8037 hdd_ctx->config->apMaxOffloadReorderBuffs;
8038
8039 cds_cfg->ap_disable_intrabss_fwd =
8040 hdd_ctx->config->apDisableIntraBssFwd;
8041
8042 cds_cfg->dfs_pri_multiplier =
8043 hdd_ctx->config->dfsRadarPriMultiplier;
8044 cds_cfg->reorder_offload =
8045 hdd_ctx->config->reorderOffloadSupport;
8046
8047 /* IPA micro controller data path offload resource config item */
8048 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008049 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8050 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008051 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008052 hdd_ctx->config->IpaUcTxBufCount);
8053 hdd_ctx->config->IpaUcTxBufCount =
8054 rounddown_pow_of_two(
8055 hdd_ctx->config->IpaUcTxBufCount);
8056 if (!hdd_ctx->config->IpaUcTxBufCount) {
8057 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308058 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008059 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008060 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008061 hdd_ctx->config->IpaUcTxBufCount);
8062 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308063 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8064 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008065 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8066 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008067 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008068 hdd_ctx->config->IpaUcRxIndRingCount);
8069 hdd_ctx->config->IpaUcRxIndRingCount =
8070 rounddown_pow_of_two(
8071 hdd_ctx->config->IpaUcRxIndRingCount);
8072 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8073 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308074 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008075 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008076 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008077 hdd_ctx->config->IpaUcRxIndRingCount);
8078 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308079 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008080 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308081 cds_cfg->uc_tx_partition_base =
8082 hdd_ctx->config->IpaUcTxPartitionBase;
8083 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8084
8085 cds_cfg->ip_tcp_udp_checksum_offload =
8086 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308087 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308088 cds_cfg->ce_classify_enabled =
8089 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008090 cds_cfg->bpf_packet_filter_enable =
8091 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308092 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8093 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8094 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008095 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008096 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008097 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008098 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308099 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8100 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308101 cds_cfg->auto_power_save_fail_mode =
8102 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308103
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308104 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8105
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308106 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8107 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8108 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008109 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308110 cds_init_ini_config(cds_cfg);
8111 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308112
8113exit:
8114 qdf_mem_free(cds_cfg);
8115 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308116}
8117
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008118/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008119 * hdd_update_user_config() - API to update user configuration
8120 * parameters to obj mgr which are used by multiple components
8121 * @hdd_ctx: HDD Context
8122 *
8123 * Return: 0 for Success, errno on failure
8124 */
8125static int hdd_update_user_config(hdd_context_t *hdd_ctx)
8126{
8127 struct wlan_objmgr_psoc_user_config *user_config;
8128
8129 user_config = qdf_mem_malloc(sizeof(*user_config));
8130 if (user_config == NULL) {
8131 hdd_alert("Failed to alloc memory for user_config!");
8132 return -ENOMEM;
8133 }
8134
8135 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8136 user_config->dual_mac_feature_disable =
8137 hdd_ctx->config->dual_mac_feature_disable;
8138 user_config->indoor_channel_support =
8139 hdd_ctx->config->indoor_channel_support;
8140 user_config->is_11d_support_enabled =
8141 hdd_ctx->config->Is11dSupportEnabled;
8142 user_config->is_11h_support_enabled =
8143 hdd_ctx->config->Is11hSupportEnabled;
8144 user_config->optimize_chan_avoid_event =
8145 hdd_ctx->config->goptimize_chan_avoid_event;
8146 user_config->skip_dfs_chnl_in_p2p_search =
8147 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008148 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008149 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8150
8151 qdf_mem_free(user_config);
8152 return 0;
8153}
8154
8155/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008156 * hdd_init_thermal_info - Initialize thermal level
8157 * @hdd_ctx: HDD context
8158 *
8159 * Initialize thermal level at SME layer and set the thermal level callback
8160 * which would be called when a configured thermal threshold is hit.
8161 *
8162 * Return: 0 on success and errno on failure
8163 */
8164static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
8165{
8166 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308167 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008168
8169 thermal_param.smeThermalMgmtEnabled =
8170 hdd_ctx->config->thermalMitigationEnable;
8171 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8172
Poddar, Siddarth83905022016-04-16 17:56:08 -07008173 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8174 hdd_ctx->config->throttle_dutycycle_level0;
8175 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8176 hdd_ctx->config->throttle_dutycycle_level1;
8177 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8178 hdd_ctx->config->throttle_dutycycle_level2;
8179 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8180 hdd_ctx->config->throttle_dutycycle_level3;
8181
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008182 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8183 hdd_ctx->config->thermalTempMinLevel0;
8184 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8185 hdd_ctx->config->thermalTempMaxLevel0;
8186 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8187 hdd_ctx->config->thermalTempMinLevel1;
8188 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8189 hdd_ctx->config->thermalTempMaxLevel1;
8190 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8191 hdd_ctx->config->thermalTempMinLevel2;
8192 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8193 hdd_ctx->config->thermalTempMaxLevel2;
8194 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8195 hdd_ctx->config->thermalTempMinLevel3;
8196 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8197 hdd_ctx->config->thermalTempMaxLevel3;
8198
8199 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8200
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308201 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308202 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008203
8204 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8205 hdd_set_thermal_level_cb);
8206
8207 return 0;
8208
8209}
8210
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008211#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8212/**
8213 * hdd_hold_rtnl_lock - Hold RTNL lock
8214 *
8215 * Hold RTNL lock
8216 *
8217 * Return: True if held and false otherwise
8218 */
8219static inline bool hdd_hold_rtnl_lock(void)
8220{
8221 rtnl_lock();
8222 return true;
8223}
8224
8225/**
8226 * hdd_release_rtnl_lock - Release RTNL lock
8227 *
8228 * Release RTNL lock
8229 *
8230 * Return: None
8231 */
8232static inline void hdd_release_rtnl_lock(void)
8233{
8234 rtnl_unlock();
8235}
8236#else
8237static inline bool hdd_hold_rtnl_lock(void) { return false; }
8238static inline void hdd_release_rtnl_lock(void) { }
8239#endif
8240
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008241#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008242
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308243/* MAX iwpriv command support */
8244#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308245#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308246#define MAX_PKTLOG_SIZE 16
8247
8248/**
8249 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8250 * @hdd_ctx: hdd context
8251 * @set_value2: pktlog buffer size value
8252 *
8253 *
8254 * Return: 0 for success or error.
8255 */
8256static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
8257{
8258 struct sir_wifi_start_log start_log = { 0 };
8259 QDF_STATUS status;
8260
8261 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8262 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8263 start_log.ini_triggered = cds_is_packet_log_enabled();
8264 start_log.user_triggered = 1;
8265 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308266 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308267
8268 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8269 if (!QDF_IS_STATUS_SUCCESS(status)) {
8270 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8271 EXIT();
8272 return -EINVAL;
8273 }
8274
8275 return 0;
8276}
8277
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008278/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308279 * hdd_pktlog_clear_buff() - clear pktlog buffer
8280 * @hdd_ctx: hdd context
8281 *
8282 * Return: 0 for success or error.
8283 */
8284static int hdd_pktlog_clear_buff(hdd_context_t *hdd_ctx)
8285{
8286 struct sir_wifi_start_log start_log;
8287 QDF_STATUS status;
8288
8289 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8290 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8291 start_log.ini_triggered = cds_is_packet_log_enabled();
8292 start_log.user_triggered = 1;
8293 start_log.size = 0;
8294 start_log.is_pktlog_buff_clear = true;
8295
8296 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8297 if (!QDF_IS_STATUS_SUCCESS(status)) {
8298 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8299 EXIT();
8300 return -EINVAL;
8301 }
8302
8303 return 0;
8304}
8305
8306
8307/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008308 * hdd_process_pktlog_command() - process pktlog command
8309 * @hdd_ctx: hdd context
8310 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308311 * @set_value2: pktlog buffer size value
8312 *
8313 * This function process pktlog command.
8314 * set_value2 only matters when set_value is 3 (set buff size)
8315 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008316 *
8317 * Return: 0 for success or error.
8318 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308319int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
8320 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008321{
8322 int ret;
8323 bool enable;
8324 uint8_t user_triggered = 0;
8325
8326 ret = wlan_hdd_validate_context(hdd_ctx);
8327 if (0 != ret)
8328 return ret;
8329
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008330 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008331
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308332 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008333 hdd_err("invalid pktlog value %d", set_value);
8334 return -EINVAL;
8335 }
8336
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308337 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8338 if (set_value2 <= 0) {
8339 hdd_err("invalid pktlog size %d", set_value2);
8340 return -EINVAL;
8341 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8342 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8343 return -EINVAL;
8344 }
8345 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308346 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8347 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308348 }
8349
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008350 /*
8351 * set_value = 0 then disable packetlog
8352 * set_value = 1 enable packetlog forcefully
8353 * set_vlaue = 2 then disable packetlog if disabled through ini or
8354 * enable packetlog with AUTO type.
8355 */
8356 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8357 true : false;
8358
8359 if (1 == set_value) {
8360 enable = true;
8361 user_triggered = 1;
8362 }
8363
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308364 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008365}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008366/**
8367 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8368 * @hdd_ctx: HDD context
8369 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308370 * @user_triggered: triggered through iwpriv
8371 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008372 *
8373 * Return: 0 on success; error number otherwise
8374 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008375int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308376 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008377{
8378 struct sir_wifi_start_log start_log;
8379 QDF_STATUS status;
8380
8381 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8382 start_log.verbose_level =
8383 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008384 start_log.ini_triggered = cds_is_packet_log_enabled();
8385 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308386 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308387 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308388 /*
8389 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8390 * commands. Host uses this flag to decide whether to send pktlog
8391 * disable command to fw without sending pktlog enable command
8392 * previously. For eg, If vendor sends pktlog disable command without
8393 * sending pktlog enable command, then host discards the packet
8394 * but for iwpriv command, host will send it to fw.
8395 */
8396 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008397 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8398 if (!QDF_IS_STATUS_SUCCESS(status)) {
8399 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8400 EXIT();
8401 return -EINVAL;
8402 }
8403
8404 return 0;
8405}
8406#endif /* REMOVE_PKT_LOG */
8407
Komal Seelam92fff912016-03-24 11:51:41 +05308408/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008409 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8410 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308411 * @dev: Device Pointer
8412 * @num: Number of Valid Mac address
8413 *
8414 * Return: Pointer to MAC address buffer
8415 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008416static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8417 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308418{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008419 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308420}
Komal Seelam92fff912016-03-24 11:51:41 +05308421
8422/**
8423 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8424 * @hdd_ctx: HDD Context
8425 * @num: Number of random mac addresses needed
8426 *
8427 * Generate random addresses using bit manipulation on the base mac address
8428 *
8429 * Return: None
8430 */
Nachiket Kukadee4d86442017-06-23 16:57:00 +05308431void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308432{
8433 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8434 uint32_t iter;
8435 struct hdd_config *ini = hdd_ctx->config;
8436 uint8_t *buf = NULL;
8437 uint8_t macaddr_b3, tmp_br3;
8438 uint8_t *src = ini->intfMacAddr[0].bytes;
8439
8440 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8441 buf = ini->intfMacAddr[iter].bytes;
8442 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8443 macaddr_b3 = buf[3];
8444 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8445 INTF_MACADDR_MASK;
8446 macaddr_b3 += tmp_br3;
8447 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8448 buf[0] |= 0x02;
8449 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008450 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308451 }
8452}
8453
8454/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008455 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308456 * @hdd_ctx: HDD Context
8457 *
8458 * API to get mac addresses from platform driver and update the driver
8459 * structures and configure FW with the base mac address.
8460 * Return: int
8461 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008462static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308463{
8464 uint32_t no_of_mac_addr, iter;
8465 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8466 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8467 uint8_t *addr, *buf;
8468 struct device *dev = hdd_ctx->parent_dev;
8469 struct hdd_config *ini = hdd_ctx->config;
8470 tSirMacAddr mac_addr;
8471 QDF_STATUS status;
8472
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008473 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308474
8475 if (no_of_mac_addr == 0 || !addr) {
8476 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8477 return -EINVAL;
8478 }
8479
8480 if (no_of_mac_addr > max_mac_addr)
8481 no_of_mac_addr = max_mac_addr;
8482
8483 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8484
8485 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8486 buf = ini->intfMacAddr[iter].bytes;
8487 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008488 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308489 }
8490
8491 status = sme_set_custom_mac_addr(mac_addr);
8492
8493 if (!QDF_IS_STATUS_SUCCESS(status))
8494 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008495
Komal Seelam92fff912016-03-24 11:51:41 +05308496 if (no_of_mac_addr < max_mac_addr)
8497 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8498 no_of_mac_addr);
8499 return 0;
8500}
8501
8502/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008503 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8504 * @hdd_ctx: HDD Context
8505 *
8506 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8507 * will generate its own MAC and update it to FW.
8508 *
8509 * Return: 0 for success
8510 * Non-zero error code for failure
8511 */
8512static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
8513{
8514 tSirMacAddr customMacAddr;
8515 QDF_STATUS status;
8516
8517 qdf_mem_copy(&customMacAddr,
8518 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8519 sizeof(tSirMacAddr));
8520 status = sme_set_custom_mac_addr(customMacAddr);
8521 if (!QDF_IS_STATUS_SUCCESS(status))
8522 return -EAGAIN;
8523 return 0;
8524}
8525
8526/**
Komal Seelam92fff912016-03-24 11:51:41 +05308527 * hdd_initialize_mac_address() - API to get wlan mac addresses
8528 * @hdd_ctx: HDD Context
8529 *
8530 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8531 * is provisioned with mac addresses, driver uses it, else it will use
8532 * wlan_mac.bin to update HW MAC addresses.
8533 *
8534 * Return: None
8535 */
8536static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
8537{
8538 QDF_STATUS status;
8539 int ret;
8540
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008541 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308542 if (ret == 0)
8543 return;
8544
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008545 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8546 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308547
8548 status = hdd_update_mac_config(hdd_ctx);
8549
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008550 if (QDF_IS_STATUS_SUCCESS(status))
8551 return;
8552
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008553 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8554 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008555
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008556 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008557 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008558 if (ret != 0) {
8559 hdd_err("MAC address out-of-sync, ret:%d", ret);
8560 QDF_ASSERT(ret);
8561 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008562 }
Komal Seelam92fff912016-03-24 11:51:41 +05308563}
8564
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008565static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
8566{
8567 int vdev_id = 0;
8568 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8569 int value = hdd_ctx->config->smart_chainmask_enabled;
8570 int vpdev = PDEV_CMD;
8571 int ret;
8572
Naveen Rawat247a8682017-06-05 15:00:31 -07008573 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008574 if (ret)
8575 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8576
8577 return ret;
8578}
8579
8580static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
8581{
8582 int vdev_id = 0;
8583 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8584 int value = hdd_ctx->config->alternative_chainmask_enabled;
8585 int vpdev = PDEV_CMD;
8586 int ret;
8587
Naveen Rawat247a8682017-06-05 15:00:31 -07008588 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008589 if (ret)
8590 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8591 ret);
8592
8593 return ret;
8594}
8595
Jeff Johnson12a744b2017-04-04 08:19:37 -07008596static int hdd_set_ani_enabled(hdd_context_t *hdd_ctx)
8597{
8598 int vdev_id = 0;
8599 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8600 int value = hdd_ctx->config->ani_enabled;
8601 int vpdev = PDEV_CMD;
8602 int ret;
8603
Naveen Rawat247a8682017-06-05 15:00:31 -07008604 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008605 if (ret)
8606 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8607
8608 return ret;
8609}
8610
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008611/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008612 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8613 * @hdd_ctx: HDD context
8614 *
8615 * Pre configurations to be done at lower layer before calling cds enable.
8616 *
8617 * Return: 0 on success and errno on failure.
8618 */
8619static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
8620{
8621 int ret;
8622 QDF_STATUS status;
8623 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008624 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008625
Leo Changfdb45c32016-10-28 11:09:23 -07008626 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008627 /*
8628 * Set 802.11p config
8629 * TODO-OCB: This has been temporarily added here to ensure this
8630 * parameter is set in CSR when we init the channel list. This should
8631 * be removed once the 5.9 GHz channels are added to the regulatory
8632 * domain.
8633 */
8634 hdd_set_dot11p_config(hdd_ctx);
8635
8636 /*
8637 * Note that the cds_pre_enable() sequence triggers the cfg download.
8638 * The cfg download must occur before we update the SME config
8639 * since the SME config operation must access the cfg database
8640 */
8641 status = hdd_set_sme_config(hdd_ctx);
8642
8643 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008644 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008645 ret = qdf_status_to_os_return(status);
8646 goto out;
8647 }
8648
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008649 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8650 if (QDF_STATUS_SUCCESS != status) {
8651 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8652 ret = qdf_status_to_os_return(status);
8653 goto out;
8654 }
8655
Naveen Rawat247a8682017-06-05 15:00:31 -07008656 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008657 hdd_ctx->config->tx_chain_mask_1ss,
8658 PDEV_CMD);
8659 if (0 != ret) {
8660 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8661 goto out;
8662 }
8663
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008664 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8665 if (ret)
8666 goto out;
8667
8668 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8669 if (ret)
8670 goto out;
8671
Jeff Johnson12a744b2017-04-04 08:19:37 -07008672 ret = hdd_set_ani_enabled(hdd_ctx);
8673 if (ret)
8674 goto out;
8675
Naveen Rawat247a8682017-06-05 15:00:31 -07008676 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008677 hdd_ctx->config->arp_ac_category,
8678 PDEV_CMD);
8679 if (0 != ret) {
8680 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8681 hdd_ctx->config->arp_ac_category, ret);
8682 goto out;
8683 }
8684
8685
Prashanth Bhatta07998752016-04-28 12:35:33 -07008686 status = hdd_set_sme_chan_list(hdd_ctx);
8687 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008688 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008689 ret = qdf_status_to_os_return(status);
8690 goto out;
8691 }
8692
8693 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008694 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008695 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008696 ret = -EINVAL;
8697 goto out;
8698 }
8699
Prashanth Bhatta07998752016-04-28 12:35:33 -07008700 /*
8701 * Set the MAC Address Currently this is used by HAL to add self sta.
8702 * Remove this once self sta is added as part of session open.
8703 */
8704 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8705 hdd_ctx->config->intfMacAddr[0].bytes,
8706 sizeof(hdd_ctx->config->intfMacAddr[0]));
8707
8708 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8709 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8710 hal_status, hal_status);
8711 ret = -EINVAL;
8712 goto out;
8713 }
8714
8715 hdd_init_channel_avoidance(hdd_ctx);
8716
8717out:
8718 return ret;
8719}
8720
8721/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008722 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8723 * @context_ptr - hdd context pointer
8724 * @event_ptr - event structure pointer
8725 *
8726 * This is the p2p listen offload stop event handler, it sends vendor
8727 * event back to supplicant to notify the stop reason.
8728 *
8729 * Return: None
8730 */
8731static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8732 void *event_ptr)
8733{
8734 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8735 struct sir_p2p_lo_event *evt = event_ptr;
8736 struct sk_buff *vendor_event;
Peng Xu5c682812017-08-06 07:39:13 -07008737 hdd_adapter_t *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008738
8739 ENTER();
8740
8741 if (hdd_ctx == NULL) {
8742 hdd_err("Invalid HDD context pointer");
8743 return;
8744 }
8745
Peng Xu5c682812017-08-06 07:39:13 -07008746 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8747 if (!adapter) {
8748 hdd_err("Cannot find adapter by vdev_id = %d",
8749 evt->vdev_id);
8750 return;
8751 }
8752
Peng Xu8fdaa492016-06-22 10:20:47 -07008753 vendor_event =
8754 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008755 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008756 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8757 GFP_KERNEL);
8758
8759 if (!vendor_event) {
8760 hdd_err("cfg80211_vendor_event_alloc failed");
8761 return;
8762 }
8763
8764 if (nla_put_u32(vendor_event,
8765 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8766 evt->reason_code)) {
8767 hdd_err("nla put failed");
8768 kfree_skb(vendor_event);
8769 return;
8770 }
8771
8772 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008773 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8774 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008775}
8776
8777/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308778 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8779 * @hdd_ctx: HDD context
8780 *
8781 * This function sends the adaptive dwell time config configuration to the
8782 * firmware via WMA
8783 *
8784 * Return: 0 - success, < 0 - failure
8785 */
8786static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8787{
8788 QDF_STATUS status;
8789 struct adaptive_dwelltime_params dwelltime_params;
8790
8791 dwelltime_params.is_enabled =
8792 hdd_ctx->config->adaptive_dwell_mode_enabled;
8793 dwelltime_params.dwelltime_mode =
8794 hdd_ctx->config->global_adapt_dwelltime_mode;
8795 dwelltime_params.lpf_weight =
8796 hdd_ctx->config->adapt_dwell_lpf_weight;
8797 dwelltime_params.passive_mon_intval =
8798 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8799 dwelltime_params.wifi_act_threshold =
8800 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8801
8802 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8803 &dwelltime_params);
8804
8805 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8806 if (!QDF_IS_STATUS_SUCCESS(status)) {
8807 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8808 return -EAGAIN;
8809 }
8810 return 0;
8811}
8812
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308813int hdd_dbs_scan_selection_init(hdd_context_t *hdd_ctx)
8814{
8815 QDF_STATUS status;
8816 struct wmi_dbs_scan_sel_params dbs_scan_params;
8817 uint32_t i = 0;
8818 uint8_t count = 0, numentries = 0;
8819 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8820 * CDS_DBS_SCAN_CLIENTS_MAX];
8821
8822 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008823 if (hdd_ctx->config->dual_mac_feature_disable ==
8824 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308825 return -EINVAL;
8826
8827 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8828 dbs_scan_config, &numentries,
8829 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8830 * CDS_DBS_SCAN_CLIENTS_MAX));
8831
8832 hdd_info("numentries %hu", numentries);
8833 if (!numentries) {
8834 hdd_info("Donot send scan_selection_config");
8835 return 0;
8836 }
8837
8838 /* hdd_set_fw_log_params */
8839 dbs_scan_params.num_clients = 0;
8840 while (count < (numentries - 2)) {
8841 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8842 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8843 dbs_scan_params.num_non_dbs_scans[i] =
8844 dbs_scan_config[count + 2];
8845 dbs_scan_params.num_clients++;
8846 hdd_debug("module:%d NDS:%d NNDS:%d",
8847 dbs_scan_params.module_id[i],
8848 dbs_scan_params.num_dbs_scans[i],
8849 dbs_scan_params.num_non_dbs_scans[i]);
8850 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8851 i++;
8852 }
8853
8854 dbs_scan_params.pdev_id = 0;
8855
8856 hdd_debug("clients:%d pdev:%d",
8857 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
8858
8859 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
8860 &dbs_scan_params);
8861 hdd_debug("Sending DBS Scan Selection Configuration to fw");
8862 if (!QDF_IS_STATUS_SUCCESS(status)) {
8863 hdd_err("Failed to send DBS Scan selection configuration!");
8864 return -EAGAIN;
8865 }
8866 return 0;
8867}
8868
Arun Khandavallid4349a92016-07-25 11:10:43 +05308869#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8870/**
8871 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8872 * @hdd_ctx: HDD context
8873 *
8874 * Set auto shutdown callback to get indications from firmware to indicate
8875 * userspace to shutdown WLAN after a configured amount of inactivity.
8876 *
8877 * Return: 0 on success and errno on failure.
8878 */
8879static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8880{
8881 QDF_STATUS status;
8882
8883 if (!hdd_ctx->config->WlanAutoShutdown)
8884 return 0;
8885
8886 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8887 wlan_hdd_auto_shutdown_cb);
8888 if (status != QDF_STATUS_SUCCESS)
8889 hdd_err("Auto shutdown feature could not be enabled: %d",
8890 status);
8891
8892 return qdf_status_to_os_return(status);
8893}
8894#else
8895static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8896{
8897 return 0;
8898}
8899#endif
8900
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008901static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(hdd_context_t *hdd_ctx)
8902{
8903 QDF_STATUS status = QDF_STATUS_SUCCESS;
8904
8905 switch (hdd_ctx->config->dual_mac_feature_disable) {
8906 case DISABLE_DBS_CXN_AND_SCAN:
8907 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
8908 if (status != QDF_STATUS_SUCCESS)
8909 hdd_err("Failed to disable dual mac features");
8910 break;
8911 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
8912 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
8913 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
8914 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
8915 if (status != QDF_STATUS_SUCCESS)
8916 hdd_err("Failed to set dbs scan and fw mode config");
8917 break;
8918 default:
8919 break;
8920 }
8921
8922 return status;
8923}
8924
Arun Khandavallid4349a92016-07-25 11:10:43 +05308925/**
8926 * hdd_features_init() - Init features
8927 * @hdd_ctx: HDD context
8928 * @adapter: Primary adapter context
8929 *
8930 * Initialize features and their feature context after WLAN firmware is up.
8931 *
8932 * Return: 0 on success and errno on failure.
8933 */
8934static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8935{
8936 tSirTxPowerLimit hddtxlimit;
8937 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05308938 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05308939 int ret;
8940
8941 ENTER();
8942
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008943 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308944 if (ret) {
8945 hdd_err("Failed to update country code: %d", ret);
8946 goto out;
8947 }
8948
8949 /* FW capabilities received, Set the Dot11 mode */
8950 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008951 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8952 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308953
Arun Khandavallid4349a92016-07-25 11:10:43 +05308954
8955 if (hdd_ctx->config->fIsImpsEnabled)
8956 hdd_set_idle_ps_config(hdd_ctx, true);
8957 else
8958 hdd_set_idle_ps_config(hdd_ctx, false);
8959
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308960 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008961 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308962
Arun Khandavallid4349a92016-07-25 11:10:43 +05308963 if (hdd_lro_init(hdd_ctx))
8964 hdd_err("Unable to initialize LRO in fw");
8965
8966 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8967 hdd_err("Unable to send adaptive dwelltime setting to FW");
8968
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308969 if (hdd_dbs_scan_selection_init(hdd_ctx))
8970 hdd_err("Unable to send DBS scan selection setting to FW");
8971
Arun Khandavallid4349a92016-07-25 11:10:43 +05308972 ret = hdd_init_thermal_info(hdd_ctx);
8973 if (ret) {
8974 hdd_err("Error while initializing thermal information");
8975 goto deregister_frames;
8976 }
8977
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308978 if (cds_is_packet_log_enabled())
8979 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8980
Arun Khandavallid4349a92016-07-25 11:10:43 +05308981 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
8982 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
8983 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
8984 if (!QDF_IS_STATUS_SUCCESS(status))
8985 hdd_err("Error setting txlimit in sme: %d", status);
8986
Yu Wangf5d5b5f2017-05-25 22:38:32 +08008987 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308988
Arun Khandavallid4349a92016-07-25 11:10:43 +05308989 ret = hdd_register_cb(hdd_ctx);
8990 if (ret) {
8991 hdd_err("Failed to register HDD callbacks!");
8992 goto deregister_frames;
8993 }
8994
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008995 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
8996 if (!QDF_IS_STATUS_SUCCESS(status)) {
8997 hdd_err("Failed to set dbs scan and fw mode cfg");
8998 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05308999 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009000
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309001 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9002 status = sme_enable_disable_chanavoidind_event(
9003 hdd_ctx->hHal, 0);
9004 if (!QDF_IS_STATUS_SUCCESS(status)) {
9005 hdd_err("Failed to disable Chan Avoidance Indication");
9006 goto deregister_cb;
9007 }
9008 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309009
Manjeet Singha9cae432017-02-28 11:58:22 +05309010 if (hdd_ctx->config->enable_5g_band_pref) {
9011 band_pref_params.rssi_boost_threshold_5g =
9012 hdd_ctx->config->rssi_boost_threshold_5g;
9013 band_pref_params.rssi_boost_factor_5g =
9014 hdd_ctx->config->rssi_boost_factor_5g;
9015 band_pref_params.max_rssi_boost_5g =
9016 hdd_ctx->config->max_rssi_boost_5g;
9017 band_pref_params.rssi_penalize_threshold_5g =
9018 hdd_ctx->config->rssi_penalize_threshold_5g;
9019 band_pref_params.rssi_penalize_factor_5g =
9020 hdd_ctx->config->rssi_penalize_factor_5g;
9021 band_pref_params.max_rssi_penalize_5g =
9022 hdd_ctx->config->max_rssi_penalize_5g;
9023 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9024 }
9025
Arun Khandavallid4349a92016-07-25 11:10:43 +05309026 /* register P2P Listen Offload event callback */
9027 if (wma_is_p2p_lo_capable())
9028 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9029 wlan_hdd_p2p_lo_event_callback);
9030
9031 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9032
9033 if (ret)
9034 goto deregister_cb;
9035
9036 EXIT();
9037 return 0;
9038
9039deregister_cb:
9040 hdd_deregister_cb(hdd_ctx);
9041deregister_frames:
9042 wlan_hdd_cfg80211_deregister_frames(adapter);
9043out:
9044 return -EINVAL;
9045
9046}
9047
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009048/**
9049 * hdd_features_deinit() - Deinit features
9050 * @hdd_ctx: HDD context
9051 *
9052 * De-Initialize features and their feature context.
9053 *
9054 * Return: none.
9055 */
9056static void hdd_features_deinit(hdd_context_t *hdd_ctx)
9057{
9058 wlan_hdd_tsf_deinit(hdd_ctx);
9059}
9060
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309061/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009062 * hdd_register_bcn_cb() - register scan beacon callback
9063 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309064 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009065 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309066 */
9067static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
9068{
9069 QDF_STATUS status;
9070
9071 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9072 wlan_cfg80211_inform_bss_frame,
9073 SCAN_CB_TYPE_INFORM_BCN);
9074 if (!QDF_IS_STATUS_SUCCESS(status)) {
9075 hdd_err("failed with status code %08d [x%08x]",
9076 status, status);
9077 return status;
9078 }
9079
9080 return QDF_STATUS_SUCCESS;
9081}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309082
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309083/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309084 * hdd_configure_cds() - Configure cds modules
9085 * @hdd_ctx: HDD context
9086 * @adapter: Primary adapter context
9087 *
9088 * Enable Cds modules after WLAN firmware is up.
9089 *
9090 * Return: 0 on success and errno on failure.
9091 */
9092int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
9093{
9094 int ret;
9095 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309096
9097 ret = hdd_pre_enable_configure(hdd_ctx);
9098 if (ret) {
9099 hdd_err("Failed to pre-configure cds");
9100 goto out;
9101 }
9102
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009103 /* Always get latest IPA resources allocated from cds_open and configure
9104 * IPA module before configuring them to FW. Sequence required as crash
9105 * observed otherwise.
9106 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009107 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9108 hdd_err("Failed to setup pipes");
9109 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009110 }
9111
Arun Khandavallifae92942016-08-01 13:31:08 +05309112 /*
9113 * Start CDS which starts up the SME/MAC/HAL modules and everything
9114 * else
9115 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309116 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309117
9118 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009119 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309120 goto out;
9121 }
9122
9123 status = hdd_post_cds_enable_config(hdd_ctx);
9124 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009125 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009126 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309127 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309128 status = hdd_register_bcn_cb(hdd_ctx);
9129 if (!QDF_IS_STATUS_SUCCESS(status)) {
9130 hdd_alert("hdd_post_cds_enable_config failed");
9131 goto cds_disable;
9132 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309133
9134 ret = hdd_features_init(hdd_ctx, adapter);
9135 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009136 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309137
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309138 if (hdd_enable_egap(hdd_ctx))
9139 hdd_debug("enhance green ap is not enabled");
9140
Nachiket Kukadedd302662017-07-13 17:31:44 +05309141 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9142 hdd_debug("Failed to set wow pulse");
9143
Arun Khandavallifae92942016-08-01 13:31:08 +05309144 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009145
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009146cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309147 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009148
Arun Khandavallifae92942016-08-01 13:31:08 +05309149out:
9150 return -EINVAL;
9151}
9152
9153/**
9154 * hdd_deconfigure_cds() -De-Configure cds
9155 * @hdd_ctx: HDD context
9156 *
9157 * Deconfigure Cds modules before WLAN firmware is down.
9158 *
9159 * Return: 0 on success and errno on failure.
9160 */
Jeff Johnson590e2012016-10-05 16:16:24 -07009161static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309162{
9163 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009164 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309165
9166 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009167
9168 /* De-init features */
9169 hdd_features_deinit(hdd_ctx);
9170
Arun Khandavallifae92942016-08-01 13:31:08 +05309171 /* De-register the SME callbacks */
9172 hdd_deregister_cb(hdd_ctx);
9173
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309174 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309175 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9176 hdd_err("Failed to Disable the CDS Modules! :%d",
9177 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009178 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309179 }
9180
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309181 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9182 hdd_err("Failed to disconnect pipes");
9183 ret = -EINVAL;
9184 }
9185
Arun Khandavallifae92942016-08-01 13:31:08 +05309186 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009187 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309188}
9189
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009190#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9191static void hdd_deregister_policy_manager_callback(
9192 struct wlan_objmgr_psoc *psoc)
9193{
9194 if (QDF_STATUS_SUCCESS !=
9195 policy_mgr_deregister_hdd_cb(psoc)) {
9196 hdd_err("HDD callback deregister with policy manager failed");
9197 }
9198}
9199#else
9200static void hdd_deregister_policy_manager_callback(
9201 struct wlan_objmgr_psoc *psoc)
9202{
9203}
9204#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309205
9206/**
9207 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9208 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009209 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309210 *
9211 * This function maintains the driver state machine it will be invoked from
9212 * exit, shutdown and con_mode change handler. Depending on the driver state
9213 * shall perform the stopping/closing of the modules.
9214 *
9215 * Return: 0 for success; non-zero for failure
9216 */
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009217int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309218{
9219 void *hif_ctx;
9220 qdf_device_t qdf_ctx;
9221 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309222 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009223 bool is_idle_stop = !cds_is_driver_unloading() &&
9224 !cds_is_driver_recovering();
9225 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309226
9227 ENTER();
9228
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009229 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9230
Arun Khandavallifae92942016-08-01 13:31:08 +05309231 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9232 if (!qdf_ctx) {
9233 hdd_err("QDF device context NULL");
9234 return -EINVAL;
9235 }
9236
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309237 mutex_lock(&hdd_ctx->iface_change_lock);
9238 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309239
Dustin Brown70111822017-03-30 15:31:40 -07009240 active_threads = cds_return_external_threads_count();
9241 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009242 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009243 active_threads, hdd_ctx->isWiphySuspended);
9244
9245 cds_print_external_threads();
9246
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009247 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009248 mutex_unlock(&hdd_ctx->iface_change_lock);
9249 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009250 hdd_ctx->config->iface_change_wait_time);
9251 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009252 return 0;
9253 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009254 }
9255
Arun Khandavallifae92942016-08-01 13:31:08 +05309256 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9257
9258 switch (hdd_ctx->driver_status) {
9259 case DRIVER_MODULES_UNINITIALIZED:
9260 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309261 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309262 case DRIVER_MODULES_CLOSED:
9263 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309264 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309265 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309266 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309267 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009268 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309269 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309270 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309271 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009272 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309273 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9274 break;
9275 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009276 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309277 break;
9278 default:
9279 hdd_err("Trying to stop wlan in a wrong state: %d",
9280 hdd_ctx->driver_status);
9281 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309282 ret = -EINVAL;
9283 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309284 }
9285
Rajeev Kumarbe021242017-02-16 16:12:23 -08009286 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309287 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9288 hdd_err("Failed to process post CDS disable Modules! :%d",
9289 qdf_status);
9290 ret = -EINVAL;
9291 QDF_ASSERT(0);
9292 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309293 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309294 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009295 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309296 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309297 QDF_ASSERT(0);
9298 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009299
Arun Khandavallifae92942016-08-01 13:31:08 +05309300 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9301 if (!hif_ctx) {
9302 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309303 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309304 }
9305
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309306 hdd_runtime_suspend_context_deinit(hdd_ctx);
9307
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309308 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309309
9310 ol_cds_free();
9311
Dustin Brown70111822017-03-30 15:31:40 -07009312 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309313 ret = pld_power_off(qdf_ctx->dev);
9314 if (ret)
9315 hdd_err("CNSS power down failed put device into Low power mode:%d",
9316 ret);
9317 }
9318 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009319 /*
9320 * Reset total mac phy during module stop such that during
9321 * next module start same psoc is used to populate new service
9322 * ready data
9323 */
9324 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309325
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309326done:
9327 hdd_ctx->stop_modules_in_progress = false;
9328 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309329 EXIT();
9330
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309331 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309332
9333}
9334
9335/**
9336 * hdd_iface_change_callback() - Function invoked when stop modules expires
9337 * @priv: pointer to hdd context
9338 *
9339 * This function is invoked when the timer waiting for the interface change
9340 * expires, it shall cut-down the power to wlan and stop all the modules.
9341 *
9342 * Return: void
9343 */
9344static void hdd_iface_change_callback(void *priv)
9345{
9346 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
9347 int ret;
9348 int status = wlan_hdd_validate_context(hdd_ctx);
9349
9350 if (status)
9351 return;
9352
9353 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009354 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009355 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309356 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009357 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309358 EXIT();
9359}
9360
9361/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309362 * hdd_state_info_dump() - prints state information of hdd layer
9363 * @buf: buffer pointer
9364 * @size: size of buffer to be filled
9365 *
9366 * This function is used to dump state information of hdd layer
9367 *
9368 * Return: None
9369 */
9370static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9371{
9372 hdd_context_t *hdd_ctx;
9373 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9374 QDF_STATUS status;
9375 hdd_station_ctx_t *hdd_sta_ctx;
9376 hdd_adapter_t *adapter;
9377 uint16_t len = 0;
9378 char *buf = *buf_ptr;
9379
9380 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9381 if (!hdd_ctx) {
9382 hdd_err("Failed to get hdd context ");
9383 return;
9384 }
9385
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009386 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309387
9388 len += scnprintf(buf + len, *size - len,
9389 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9390 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009391 "\n is_scheduler_suspended %d",
9392 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309393
9394 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9395
9396 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9397 adapter = adapter_node->pAdapter;
9398 if (adapter->dev)
9399 len += scnprintf(buf + len, *size - len,
9400 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009401 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309402 "\n device_mode: %d", adapter->device_mode);
9403 switch (adapter->device_mode) {
9404 case QDF_STA_MODE:
9405 case QDF_P2P_CLIENT_MODE:
9406 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9407 len += scnprintf(buf + len, *size - len,
9408 "\n connState: %d",
9409 hdd_sta_ctx->conn_info.connState);
9410 break;
9411
9412 default:
9413 break;
9414 }
9415 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9416 adapter_node = next;
9417 }
9418
9419 *size -= len;
9420 *buf_ptr += len;
9421}
9422
9423/**
9424 * hdd_register_debug_callback() - registration function for hdd layer
9425 * to print hdd state information
9426 *
9427 * Return: None
9428 */
9429static void hdd_register_debug_callback(void)
9430{
9431 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9432}
9433
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309434/*
9435 * wlan_init_bug_report_lock() - Initialize bug report lock
9436 *
9437 * This function is used to create bug report lock
9438 *
9439 * Return: None
9440 */
9441static void wlan_init_bug_report_lock(void)
9442{
9443 p_cds_contextType p_cds_context;
9444
9445 p_cds_context = cds_get_global_context();
9446 if (!p_cds_context) {
9447 hdd_err("cds context is NULL");
9448 return;
9449 }
9450
9451 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9452}
9453
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309454/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009455 * hdd_wlan_startup() - HDD init function
9456 * @dev: Pointer to the underlying device
9457 *
9458 * This is the driver startup code executed once a WLAN device has been detected
9459 *
9460 * Return: 0 for success, < 0 for failure
9461 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309462int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009463{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309464 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08009465 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009466 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009467 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309468 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009469 uint32_t num_abg_tx_chains = 0;
9470 uint32_t num_11b_tx_chains = 0;
9471 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009472
9473 ENTER();
9474
Arun Khandavallifae92942016-08-01 13:31:08 +05309475 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009476
9477 if (IS_ERR(hdd_ctx))
9478 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009479
Abhishek Singhe9068f12017-03-31 14:14:52 +05309480 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9481 DEFAULT_PSOC_ID);
9482 if (ret) {
9483 hdd_err("Psoc creation fails!");
9484 QDF_BUG(0);
9485 goto err_hdd_free_context;
9486 }
9487
Arun Khandavallifae92942016-08-01 13:31:08 +05309488 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9489 hdd_iface_change_callback, (void *)hdd_ctx);
9490
9491 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309492#ifdef FEATURE_WLAN_CH_AVOID
9493 mutex_init(&hdd_ctx->avoid_freq_lock);
9494#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309495
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009496 ret = hdd_init_netlink_services(hdd_ctx);
9497 if (ret)
Dustin Brown20912462017-06-07 13:48:25 -07009498 goto err_hdd_free_psoc;
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009499
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009500 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009501 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309502
Jeff Johnson957bc272017-02-02 08:54:48 -08009503 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309504 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009505 hdd_err("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009506 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009507 }
9508
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309509 wlan_init_bug_report_lock();
9510
Yingying Tang80e15f32016-09-27 18:23:01 +08009511 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009512
Anurag Chouhan6d760662016-02-20 16:05:43 +05309513 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009514
9515 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009516 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309517 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009518 }
9519
Prashanth Bhatta07998752016-04-28 12:35:33 -07009520 ret = hdd_wiphy_init(hdd_ctx);
9521 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009522 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309523 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009524 }
9525
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309526 if (hdd_ctx->config->enable_dp_trace)
9527 qdf_dp_trace_init();
9528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309529 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009530 goto err_wiphy_unregister;
9531
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309532 wlan_hdd_init_chan_info(hdd_ctx);
9533
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009534 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009535
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009536 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009537
Jeff Johnson957bc272017-02-02 08:54:48 -08009538 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9539 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009540 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009541 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009542 }
9543
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009544 hdd_release_rtnl_lock();
9545 rtnl_held = false;
9546
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009547 wlan_hdd_update_11n_mode(hdd_ctx->config);
9548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009549#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309550 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309551 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009552 hdd_skip_acs_scan_timer_handler,
9553 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309554 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009555 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009556 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009557#endif
9558
Nitesh Shah61c10d92016-10-19 19:29:15 +05309559 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9560 QDF_TIMER_TYPE_SW,
9561 wlan_hdd_change_tdls_mode,
9562 hdd_ctx);
9563
Prashanth Bhattaab004382016-10-11 16:08:11 -07009564 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009565
Jeff Johnson9afc5012016-09-23 13:56:27 -07009566 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009567
Nirav Shahbd36b062016-07-18 11:12:59 +05309568 if (hdd_ctx->rps)
9569 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009570
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009571 ret = hdd_register_notifiers(hdd_ctx);
9572 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009573 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309574
9575 status = wlansap_global_init();
9576 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009577 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009578
Komal Seelam8634b772016-09-29 12:12:24 +05309579 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009580 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309581 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009582
Arun Khandavallifae92942016-08-01 13:31:08 +05309583 if (hdd_ctx->config->fIsImpsEnabled)
9584 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309585
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309586 if (hdd_ctx->config->sifs_burst_duration) {
9587 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9588 hdd_ctx->config->sifs_burst_duration;
9589
9590 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009591 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309592 set_value, PDEV_CMD);
9593 }
9594
Paul Zhang42dade02017-05-12 19:20:37 +08009595 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009596 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009597 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309598 /* set chip power save failure detected callback */
9599 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9600 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009601
lifeng959a04c2017-05-10 14:21:28 +08009602 if (hdd_ctx->config->max_mpdus_inampdu) {
9603 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009604 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009605 set_value, PDEV_CMD);
9606 }
9607
9608 if (hdd_ctx->config->enable_rts_sifsbursting) {
9609 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009610 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009611 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9612 set_value, PDEV_CMD);
9613 }
9614
Naveen Rawat247a8682017-06-05 15:00:31 -07009615 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9616 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9617 if (!hdd_ctx->config->enable2x2) {
9618 if (num_11b_tx_chains > 1)
9619 num_11b_tx_chains = 1;
9620 if (num_11ag_tx_chains > 1)
9621 num_11ag_tx_chains = 1;
9622 }
9623 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9624 num_11b_tx_chains);
9625 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9626 num_11ag_tx_chains);
9627 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9628 num_abg_tx_chains, PDEV_CMD);
9629
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309630 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9631 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309632 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309633
Sachin Ahujadddd2632017-03-07 19:07:24 +05309634 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009635 goto success;
9636
Jeff Johnson957bc272017-02-02 08:54:48 -08009637err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009638 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009639
Jeff Johnson46bde382017-02-01 15:31:16 -08009640err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309641 if (rtnl_held)
9642 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009643
Anurag Chouhance6a4052016-09-14 18:20:42 +05309644 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009645
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009646err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009647 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009648
Arun Khandavallifae92942016-08-01 13:31:08 +05309649err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009650 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309651
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05309652err_exit_nl_srv:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309653 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
9654 status = cds_sched_close(hdd_ctx->pcds_context);
9655 if (!QDF_IS_STATUS_SUCCESS(status)) {
9656 hdd_err("Failed to close CDS Scheduler");
9657 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9658 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009659 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009660
Houston Hoffman47a4a052016-11-14 23:22:44 -08009661 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009662 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009663 hdd_exit_netlink_services(hdd_ctx);
9664
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309665 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009666
9667err_hdd_free_psoc:
9668 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9669
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009670err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309671 if (cds_is_fw_down())
9672 hdd_err("Not setting the complete event as fw is down");
9673 else
9674 hdd_start_complete(ret);
9675
Arun Khandavallifae92942016-08-01 13:31:08 +05309676 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9677 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009678 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009679 return -EIO;
9680
9681success:
9682 EXIT();
9683 return 0;
9684}
9685
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009686/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309687 * hdd_wlan_update_target_info() - update target type info
9688 * @hdd_ctx: HDD context
9689 * @context: hif context
9690 *
9691 * Update target info received from firmware in hdd context
9692 * Return:None
9693 */
9694
9695void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
9696{
9697 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9698
9699 if (!tgt_info) {
9700 hdd_err("Target info is Null");
9701 return;
9702 }
9703
9704 hdd_ctx->target_type = tgt_info->target_type;
9705}
9706
9707/**
9708 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309709 * @hdd_ctx: HDD context
9710 *
9711 * Register the HDD callbacks to CDS/SME.
9712 *
9713 * Return: 0 for success or Error code for failure
9714 */
9715int hdd_register_cb(hdd_context_t *hdd_ctx)
9716{
9717 QDF_STATUS status;
9718 int ret = 0;
9719
9720 ENTER();
9721
9722 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9723
9724 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9725 hdd_send_oem_data_rsp_msg);
9726
9727 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9728 wlan_hdd_cfg80211_fw_mem_dump_cb);
9729 if (!QDF_IS_STATUS_SUCCESS(status)) {
9730 hdd_err("Failed to register memdump callback");
9731 ret = -EINVAL;
9732 return ret;
9733 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309734 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9735 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309736 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9737 sme_nan_register_callback(hdd_ctx->hHal,
9738 wlan_hdd_cfg80211_nan_callback);
9739 sme_stats_ext_register_callback(hdd_ctx->hHal,
9740 wlan_hdd_cfg80211_stats_ext_callback);
9741
9742 sme_ext_scan_register_callback(hdd_ctx->hHal,
9743 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009744 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9745 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309746
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309747 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9748 hdd_rssi_threshold_breached);
9749
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309750 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9751 wlan_hdd_cfg80211_link_layer_stats_callback);
9752
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309753 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9754
Zhang Qianca38fb12016-12-23 11:10:48 +08009755 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9756 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9757
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309758 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9759 hdd_lost_link_info_cb);
9760 /* print error and not block the startup process */
9761 if (!QDF_IS_STATUS_SUCCESS(status))
9762 hdd_err("set lost link info callback failed");
9763
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309764 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9765
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009766 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009767 hdd_set_connection_in_progress,
9768 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309769
9770 status = sme_congestion_register_callback(hdd_ctx->hHal,
9771 hdd_update_cca_info_cb);
9772 if (!QDF_IS_STATUS_SUCCESS(status))
9773 hdd_err("set congestion callback failed");
9774
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +05309775 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
9776 hdd_bt_activity_cb);
9777 if (!QDF_IS_STATUS_SUCCESS(status))
9778 hdd_err("set bt activity info callback failed");
9779
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309780 EXIT();
9781
9782 return ret;
9783}
9784
9785/**
9786 * hdd_deregister_cb() - De-Register HDD callbacks.
9787 * @hdd_ctx: HDD context
9788 *
9789 * De-Register the HDD callbacks to CDS/SME.
9790 *
9791 * Return: void
9792 */
9793void hdd_deregister_cb(hdd_context_t *hdd_ctx)
9794{
9795 QDF_STATUS status;
9796
9797 ENTER();
9798
9799 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9800 if (!QDF_IS_STATUS_SUCCESS(status))
9801 hdd_err("De-register of dcc stats callback failed: %d",
9802 status);
9803
9804 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309805 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9806
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309807 sme_stats_ext_register_callback(hdd_ctx->hHal,
9808 wlan_hdd_cfg80211_stats_ext_callback);
9809
9810 sme_nan_deregister_callback(hdd_ctx->hHal);
9811 status = sme_reset_tsfcb(hdd_ctx->hHal);
9812 if (!QDF_IS_STATUS_SUCCESS(status))
9813 hdd_err("Failed to de-register tsfcb the callback:%d",
9814 status);
9815 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9816 if (!QDF_IS_STATUS_SUCCESS(status))
9817 hdd_err("Failed to de-register the fw mem dump callback: %d",
9818 status);
9819
9820 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9821 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9822
9823 EXIT();
9824}
9825
9826/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009827 * hdd_softap_sta_deauth() - handle deauth req from HDD
9828 * @adapter: Pointer to the HDD
9829 * @enable: bool value
9830 *
9831 * This to take counter measure to handle deauth req from HDD
9832 *
9833 * Return: None
9834 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309835QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009836 struct tagCsrDelStaParams *pDelStaParams)
9837{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309838 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009839
9840 ENTER();
9841
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009842 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009843 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9844
9845 /* Ignore request to deauth bcmc station */
9846 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309847 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009848
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309849 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009850 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9851 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009852
9853 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309854 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855}
9856
9857/**
9858 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
9859 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309860 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009861 *
9862 * This to take counter measure to handle deauth req from HDD
9863 *
9864 * Return: None
9865 */
9866void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309867 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009868{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009869 ENTER();
9870
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009871 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009872 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9873
9874 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309875 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009876 return;
9877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009878 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309879 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009880}
9881
9882void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9883 bool enable)
9884{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009885 ENTER();
9886
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009887 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009888 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9889
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009890 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9891 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009892}
9893
9894/**
9895 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9896 * @hdd_ctx: HDD Context
9897 *
9898 * API to find if there is any STA or P2P-Client is connected
9899 *
9900 * Return: true if connected; false otherwise
9901 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309902QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009903{
9904 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9905}
9906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009907/**
9908 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9909 * @adapter: HDD adapter pointer
9910 *
9911 * This function loop through each adapter and disable roaming on each STA
9912 * device mode except the input adapter.
9913 *
9914 * Note: On the input adapter roaming is not enabled yet hence no need to
9915 * disable.
9916 *
9917 * Return: None
9918 */
9919void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9920{
9921 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9922 hdd_adapter_t *adapterIdx = NULL;
9923 hdd_adapter_list_node_t *adapterNode = NULL;
9924 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309925 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009926
9927 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009928 hdd_ctx->config->isRoamOffloadScanEnabled &&
9929 QDF_STA_MODE == adapter->device_mode &&
9930 policy_mgr_is_sta_active_connection_exists(
9931 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009932 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009933 adapter->sessionId);
9934 /*
9935 * Loop through adapter and disable roaming for each STA device
9936 * mode except the input adapter.
9937 */
9938 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9939
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309940 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009941 adapterIdx = adapterNode->pAdapter;
9942
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009943 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009944 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009945 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009946 adapterIdx->sessionId);
9947 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9948 (adapterIdx),
9949 adapterIdx->sessionId, 0);
9950 }
9951
9952 status = hdd_get_next_adapter(hdd_ctx,
9953 adapterNode,
9954 &pNext);
9955 adapterNode = pNext;
9956 }
9957 }
9958}
9959
9960/**
9961 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9962 * @adapter: HDD adapter pointer
9963 *
9964 * This function loop through each adapter and enable roaming on each STA
9965 * device mode except the input adapter.
9966 * Note: On the input adapter no need to enable roaming because link got
9967 * disconnected on this.
9968 *
9969 * Return: None
9970 */
9971void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
9972{
9973 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9974 hdd_adapter_t *adapterIdx = NULL;
9975 hdd_adapter_list_node_t *adapterNode = NULL;
9976 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309977 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009978
9979 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009980 hdd_ctx->config->isRoamOffloadScanEnabled &&
9981 QDF_STA_MODE == adapter->device_mode &&
9982 policy_mgr_is_sta_active_connection_exists(
9983 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009984 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009985 adapter->sessionId);
9986 /*
9987 * Loop through adapter and enable roaming for each STA device
9988 * mode except the input adapter.
9989 */
9990 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9991
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309992 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009993 adapterIdx = adapterNode->pAdapter;
9994
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009995 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009996 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009997 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009998 adapterIdx->sessionId);
9999 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10000 (adapterIdx),
10001 adapterIdx->sessionId,
10002 REASON_CONNECT);
10003 }
10004
10005 status = hdd_get_next_adapter(hdd_ctx,
10006 adapterNode,
10007 &pNext);
10008 adapterNode = pNext;
10009 }
10010 }
10011}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010012
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010013/**
10014 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10015 * @skb: sk buffer pointer
10016 *
10017 * Sends the bcast message to SVC multicast group with generic nl socket
10018 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10019 *
10020 * Return: None
10021 */
10022static void nl_srv_bcast_svc(struct sk_buff *skb)
10023{
10024#ifdef CNSS_GENL
10025 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10026#else
10027 nl_srv_bcast(skb);
10028#endif
10029}
10030
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010031void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010032{
10033 struct sk_buff *skb;
10034 struct nlmsghdr *nlh;
10035 tAniMsgHdr *ani_hdr;
10036 void *nl_data = NULL;
10037 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010038 struct radio_index_tlv *radio_info;
10039 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010040
10041 if (in_interrupt() || irqs_disabled() || in_atomic())
10042 flags = GFP_ATOMIC;
10043
10044 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10045
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010046 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010047 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010048
10049 nlh = (struct nlmsghdr *)skb->data;
10050 nlh->nlmsg_pid = 0; /* from kernel */
10051 nlh->nlmsg_flags = 0;
10052 nlh->nlmsg_seq = 0;
10053 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10054
10055 ani_hdr = NLMSG_DATA(nlh);
10056 ani_hdr->type = type;
10057
10058 switch (type) {
10059 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010060 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010061 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010062 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010063 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010064 ani_hdr->length = 0;
10065 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010066 break;
10067 case WLAN_SVC_WLAN_STATUS_IND:
10068 case WLAN_SVC_WLAN_VERSION_IND:
10069 case WLAN_SVC_DFS_CAC_START_IND:
10070 case WLAN_SVC_DFS_CAC_END_IND:
10071 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10072 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10073 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010074 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010075 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010076 ani_hdr->length = len;
10077 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10078 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10079 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010080 break;
10081
10082 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010083 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010084 type);
10085 kfree_skb(skb);
10086 return;
10087 }
10088
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010089 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010090 * Add radio index at the end of the svc event in TLV format
10091 * to maintain the backward compatibility with userspace
10092 * applications.
10093 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010094
10095 tlv_len = 0;
10096
10097 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10098 < WLAN_NL_MAX_PAYLOAD) {
10099 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10100 sizeof(*ani_hdr) + len);
10101 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10102 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10103 radio_info->radio = radio;
10104 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010105 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010106 "Added radio index tlv - radio index %d",
10107 radio_info->radio);
10108 }
10109
10110 nlh->nlmsg_len += tlv_len;
10111 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10112
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010113 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010114}
10115
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010116#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10117void wlan_hdd_auto_shutdown_cb(void)
10118{
hque52fdd62017-06-05 11:27:44 +080010119 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010120
10121 if (!hdd_ctx)
10122 return;
10123
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010124 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010125 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10126 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010127}
10128
10129void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
10130{
10131 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010132 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010133 hdd_adapter_t *adapter;
10134 bool ap_connected = false, sta_connected = false;
10135 tHalHandle hal_handle;
10136
10137 hal_handle = hdd_ctx->hHal;
10138 if (hal_handle == NULL)
10139 return;
10140
10141 if (hdd_ctx->config->WlanAutoShutdown == 0)
10142 return;
10143
10144 if (enable == false) {
10145 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010146 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010147 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010148 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010149 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010150 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010151 return;
10152 }
10153
10154 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010155 if (policy_mgr_concurrent_open_sessions_running(
10156 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010157 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10158
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010159 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010160 adapter = adapterNode->pAdapter;
10161 if (adapter
10162 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010163 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010164 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10165 conn_info.connState ==
10166 eConnectionState_Associated) {
10167 sta_connected = true;
10168 break;
10169 }
10170 }
10171 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010172 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010173 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10174 bApActive == true) {
10175 ap_connected = true;
10176 break;
10177 }
10178 }
10179 status = hdd_get_next_adapter(hdd_ctx,
10180 adapterNode,
10181 &pNext);
10182 adapterNode = pNext;
10183 }
10184 }
10185
10186 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010187 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010188 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010189 }
Jeff Johnson68755312017-02-10 11:46:55 -080010190
10191 if (sme_set_auto_shutdown_timer(hal_handle,
10192 hdd_ctx->config->WlanAutoShutdown)
10193 != QDF_STATUS_SUCCESS)
10194 hdd_err("Failed to start wlan auto shutdown timer");
10195 else
10196 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10197 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010198}
10199#endif
10200
10201hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
10202 bool check_start_bss)
10203{
10204 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
10205 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010206 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010207 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10208
10209 con_sap_adapter = NULL;
10210
10211 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010212 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010213 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010214 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10215 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010216 adapter != this_sap_adapter) {
10217 if (check_start_bss) {
10218 if (test_bit(SOFTAP_BSS_STARTED,
10219 &adapter->event_flags)) {
10220 con_sap_adapter = adapter;
10221 break;
10222 }
10223 } else {
10224 con_sap_adapter = adapter;
10225 break;
10226 }
10227 }
10228 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10229 adapterNode = pNext;
10230 }
10231
10232 return con_sap_adapter;
10233}
10234
10235#ifdef MSM_PLATFORM
Dustin Brown5ec6b552017-03-31 12:11:40 -070010236static inline bool hdd_adapter_is_sta(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010237{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010238 return adapter->device_mode == QDF_STA_MODE ||
10239 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010240}
10241
Dustin Brown5ec6b552017-03-31 12:11:40 -070010242static inline bool hdd_adapter_is_ap(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010243{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010244 return adapter->device_mode == QDF_SAP_MODE ||
10245 adapter->device_mode == QDF_P2P_GO_MODE;
10246}
10247
10248static bool hdd_any_adapter_is_assoc(hdd_context_t *hdd_ctx)
10249{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010250 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010251 hdd_adapter_list_node_t *node;
10252
10253 status = hdd_get_front_adapter(hdd_ctx, &node);
10254 while (QDF_IS_STATUS_SUCCESS(status) && node) {
10255 hdd_adapter_t *adapter = node->pAdapter;
10256
10257 if (adapter &&
10258 hdd_adapter_is_sta(adapter) &&
10259 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10260 conn_info.connState == eConnectionState_Associated) {
10261 return true;
10262 }
10263
10264 if (adapter &&
10265 hdd_adapter_is_ap(adapter) &&
10266 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10267 return true;
10268 }
10269
10270 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10271 }
10272
10273 return false;
10274}
10275
10276static bool hdd_bus_bw_compute_timer_is_running(hdd_context_t *hdd_ctx)
10277{
10278 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010279
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010280 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010281 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010282 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010283
Dustin Brown5ec6b552017-03-31 12:11:40 -070010284 return is_running;
10285}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010286
Dustin Brown5ec6b552017-03-31 12:11:40 -070010287static void __hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10288{
10289 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10290 hdd_ctx->bus_bw_timer_running = true;
10291 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10292 hdd_ctx->config->busBandwidthComputeInterval);
10293 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10294}
10295
10296void hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10297{
10298 ENTER();
10299
10300 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10301 hdd_debug("Bandwidth compute timer already started");
10302 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010303 }
10304
Dustin Brown5ec6b552017-03-31 12:11:40 -070010305 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10306
10307 EXIT();
10308}
10309
10310void hdd_bus_bw_compute_timer_try_start(hdd_context_t *hdd_ctx)
10311{
10312 ENTER();
10313
10314 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10315 hdd_debug("Bandwidth compute timer already started");
10316 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010317 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010318
10319 if (hdd_any_adapter_is_assoc(hdd_ctx))
10320 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10321
10322 EXIT();
10323}
10324
10325static void __hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10326{
10327 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10328
10329 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10330 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10331 hdd_ctx->bus_bw_timer_running = false;
10332 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10333
10334 hdd_reset_tcp_delack(hdd_ctx);
10335}
10336
10337void hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10338{
10339 ENTER();
10340
10341 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10342 hdd_debug("Bandwidth compute timer already stopped");
10343 return;
10344 }
10345
10346 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10347
10348 EXIT();
10349}
10350
10351void hdd_bus_bw_compute_timer_try_stop(hdd_context_t *hdd_ctx)
10352{
10353 ENTER();
10354
10355 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10356 hdd_debug("Bandwidth compute timer already stopped");
10357 return;
10358 }
10359
10360 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10361 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10362
10363 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010364}
10365#endif
10366
10367/**
10368 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10369 * and sta's operating channel.
10370 * @sta_adapter: Describe the first argument to foobar.
10371 * @ap_adapter: Describe the second argument to foobar.
10372 * @roam_profile: Roam profile of AP to which STA wants to connect.
10373 * @concurrent_chnl_same: If both SAP and STA channels are same then
10374 * set this flag to true else false.
10375 *
10376 * This function checks the sap's operating channel and sta's operating channel.
10377 * if both are same then it will return false else it will restart the sap in
10378 * sta's channel and return true.
10379 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010380 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010381 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010382QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010383 hdd_adapter_t *ap_adapter,
10384 tCsrRoamProfile *roam_profile,
10385 tScanResultHandle *scan_cache,
10386 bool *concurrent_chnl_same)
10387{
10388 hdd_ap_ctx_t *hdd_ap_ctx;
10389 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010390 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010391 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010392 *concurrent_chnl_same = true;
10393
10394 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10395 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010396 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010397 scan_cache,
10398 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010399 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010400 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10402 if (hdd_ap_ctx->operatingChannel != channel_id) {
10403 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010404 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010405 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010406 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010407 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10408 if (hdd_ap_ctx->operatingChannel != channel_id) {
10409 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010410 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010411 }
10412 }
10413 } else {
10414 /*
10415 * Lets handle worst case scenario here, Scan cache lookup is
10416 * failed so we have to stop the SAP to avoid any channel
10417 * discrepancy between SAP's channel and STA's channel.
10418 * Return the status as failure so caller function could know
10419 * that scan look up is failed.
10420 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010421 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010422 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010424 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010425}
10426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427/**
10428 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10429 * @ap_adapter: SAP adapter
10430 *
10431 * This function will process the stopping of sap adapter.
10432 *
10433 * Return: None
10434 */
10435void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
10436{
10437 hdd_ap_ctx_t *hdd_ap_ctx;
10438 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010439 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010440 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010441
10442 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010443 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010444 return;
10445 }
10446
10447 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10448 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010449 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010450 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010452 mutex_lock(&hdd_ctx->sap_lock);
10453 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010454 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010455 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10456 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010457 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010458 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010459 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010460 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010461 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010462 qdf_stop_bss_event,
10463 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010464 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010466 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010467 return;
10468 }
10469 }
10470 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010471 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10472 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010473 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010474 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010475 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010476 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010477 }
10478 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010479}
10480
10481/**
10482 * wlan_hdd_start_sap() - this function starts bss of SAP.
10483 * @ap_adapter: SAP adapter
10484 *
10485 * This function will process the starting of sap adapter.
10486 *
10487 * Return: None
10488 */
Arun Khandavallicc544b32017-01-30 19:52:16 +053010489void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010490{
10491 hdd_ap_ctx_t *hdd_ap_ctx;
10492 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010493 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010494 hdd_context_t *hdd_ctx;
10495 tsap_Config_t *sap_config;
10496
10497 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010498 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010499 return;
10500 }
10501
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010502 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010503 hdd_err("SoftAp role has not been enabled");
10504 return;
10505 }
10506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010507 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10508 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10509 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10510 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010512 mutex_lock(&hdd_ctx->sap_lock);
10513 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10514 goto end;
10515
10516 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010517 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010518 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10519 goto end;
10520 }
10521
Wei Song2f76f642016-11-18 16:32:53 +080010522 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010523 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10524 &hdd_ap_ctx->sapConfig,
10525 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010526 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527 goto end;
10528
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010529 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010530 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010531 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010532 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010533 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010534 goto end;
10535 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010536 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010537 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010538 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010539 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10540 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010541 ap_adapter->sessionId);
10542 hostapd_state->bCommit = true;
10543
10544end:
10545 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010546 /* SAP context and beacon cleanup will happen during driver unload
10547 * in hdd_stop_adapter
10548 */
10549 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010552
10553/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010554 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10555 * mac scan config
10556 * @status: Status of set antenna mode
10557 *
10558 * Callback on setting the dual mac configuration
10559 *
10560 * Return: None
10561 */
10562void wlan_hdd_soc_set_antenna_mode_cb(
10563 enum set_antenna_mode_status status)
10564{
10565 hdd_context_t *hdd_ctx;
10566
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010567 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010568
10569 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10570 if (0 != wlan_hdd_validate_context(hdd_ctx))
10571 return;
10572
10573 /* Signal the completion of set dual mac config */
10574 complete(&hdd_ctx->set_antenna_mode_cmpl);
10575}
10576
10577/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010578 * hdd_get_fw_version() - Get FW version
10579 * @hdd_ctx: pointer to HDD context.
10580 * @major_spid: FW version - major spid.
10581 * @minor_spid: FW version - minor spid
10582 * @ssid: FW version - ssid
10583 * @crmid: FW version - crmid
10584 *
10585 * This function is called to get the firmware build version stored
10586 * as part of the HDD context
10587 *
10588 * Return: None
10589 */
10590void hdd_get_fw_version(hdd_context_t *hdd_ctx,
10591 uint32_t *major_spid, uint32_t *minor_spid,
10592 uint32_t *siid, uint32_t *crmid)
10593{
10594 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10595 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10596 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10597 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10598}
10599
10600#ifdef QCA_CONFIG_SMP
10601/**
10602 * wlan_hdd_get_cpu() - get cpu_index
10603 *
10604 * Return: cpu_index
10605 */
10606int wlan_hdd_get_cpu(void)
10607{
10608 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010610 put_cpu();
10611 return cpu_index;
10612}
10613#endif
10614
10615/**
10616 * hdd_get_fwpath() - get framework path
10617 *
10618 * This function is used to get the string written by
10619 * userspace to start the wlan driver
10620 *
10621 * Return: string
10622 */
10623const char *hdd_get_fwpath(void)
10624{
10625 return fwpath.string;
10626}
10627
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010628static int hdd_qdf_print_init(void)
10629{
10630 int qdf_print_idx;
10631 QDF_STATUS status;
10632
10633 status = qdf_print_setup();
10634 if (status != QDF_STATUS_SUCCESS) {
10635 pr_err("qdf_print_setup failed\n");
10636 return -EINVAL;
10637 }
10638
10639 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10640
10641 if (qdf_print_idx < 0) {
10642 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10643 qdf_print_idx);
10644 return -EINVAL;
10645 }
10646
10647 qdf_set_pidx(qdf_print_idx);
10648
10649 return 0;
10650}
10651
10652static void hdd_qdf_print_deinit(void)
10653{
10654 int qdf_print_idx;
10655
10656 qdf_print_idx = qdf_get_pidx();
10657 qdf_print_ctrl_cleanup(qdf_print_idx);
10658}
10659
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010660/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010661 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010662 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010663 * This function initilizes CDS global context with the help of cds_init. This
10664 * has to be the first function called after probe to get a valid global
10665 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010666 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010667 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010668 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010669int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010670{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010671 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010672 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010673
Houston Hoffman9e06e542016-12-12 12:06:26 -080010674 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010675#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10676 wlan_logging_sock_init_svc();
10677#endif
10678
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010679 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010680 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010681 ret = -ENOMEM;
10682 goto err_out;
10683 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010684
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010685 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010686 hdd_qdf_print_init();
10687
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010688 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010689
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010690err_out:
10691 return ret;
10692}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010693
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010694/**
10695 * hdd_deinit() - Deinitialize Driver
10696 *
10697 * This function frees CDS global context with the help of cds_deinit. This
10698 * has to be the last function call in remove callback to free the global
10699 * context.
10700 */
10701void hdd_deinit(void)
10702{
Dustin Brownedce4a52017-05-10 11:59:15 -070010703 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010704 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010705
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010706 hdd_qdf_print_deinit();
10707
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010708#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10709 wlan_logging_sock_deinit_svc();
10710#endif
10711}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010712
Yue Ma6e7b1a02017-04-03 14:17:46 -070010713#ifdef QCA_WIFI_NAPIER_EMULATION
10714#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10715#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010716#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010717#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010718
Sachin Ahujadddd2632017-03-07 19:07:24 +053010719static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10720 struct file *file)
10721{
10722 return 0;
10723}
10724
10725static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10726 const char __user *user_buf,
10727 size_t count,
10728 loff_t *f_pos)
10729{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010730 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010731 static const char wlan_off_str[] = "OFF";
10732 static const char wlan_on_str[] = "ON";
10733 int ret;
10734 unsigned long rc;
10735
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010736 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010737 pr_err("Failed to read buffer\n");
10738 return -EINVAL;
10739 }
10740
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010741 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010742 pr_debug("Wifi turning off from UI\n");
10743 goto exit;
10744 }
10745
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010746 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010747 pr_err("Invalid value received from framework");
10748 goto exit;
10749 }
10750
10751 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010752 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010753 rc = wait_for_completion_timeout(&wlan_start_comp,
10754 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10755 if (!rc) {
10756 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10757 ret = -EINVAL;
10758 hdd_start_complete(ret);
10759 return ret;
10760 }
10761
10762 hdd_start_complete(0);
10763 }
10764
10765exit:
10766 return count;
10767}
10768
10769
10770const struct file_operations wlan_hdd_state_fops = {
10771 .owner = THIS_MODULE,
10772 .open = wlan_hdd_state_ctrl_param_open,
10773 .write = wlan_hdd_state_ctrl_param_write,
10774};
10775
10776static int wlan_hdd_state_ctrl_param_create(void)
10777{
10778 unsigned int wlan_hdd_state_major = 0;
10779 int ret;
10780 struct device *dev;
10781
10782 device = MKDEV(wlan_hdd_state_major, 0);
10783
10784 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10785 if (ret) {
10786 pr_err("Failed to register qcwlanstate");
10787 goto dev_alloc_err;
10788 }
10789 wlan_hdd_state_major = MAJOR(device);
10790
10791 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10792 if (IS_ERR(class)) {
10793 pr_err("wlan_hdd_state class_create error");
10794 goto class_err;
10795 }
10796
10797 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10798 if (IS_ERR(dev)) {
10799 pr_err("wlan_hdd_statedevice_create error");
10800 goto err_class_destroy;
10801 }
10802
10803 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10804 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10805 if (ret) {
10806 pr_err("Failed to add cdev error");
10807 goto cdev_add_err;
10808 }
10809
10810 pr_info("wlan_hdd_state %s major(%d) initialized",
10811 WLAN_MODULE_NAME, wlan_hdd_state_major);
10812
10813 return 0;
10814
10815cdev_add_err:
10816 device_destroy(class, device);
10817err_class_destroy:
10818 class_destroy(class);
10819class_err:
10820 unregister_chrdev_region(device, dev_num);
10821dev_alloc_err:
10822 return -ENODEV;
10823}
10824
10825static void wlan_hdd_state_ctrl_param_destroy(void)
10826{
10827 cdev_del(&wlan_hdd_state_cdev);
10828 device_destroy(class, device);
10829 class_destroy(class);
10830 unregister_chrdev_region(device, dev_num);
10831
10832 pr_info("Device node unregistered");
10833}
10834
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010835/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053010836 * component_init - API to init cld component's
10837 *
10838 * Return: None
10839 */
10840static void component_init(void)
10841{
10842 pmo_init();
10843}
10844
10845/**
10846 * component_deinit - API to deinit cld component's
10847 *
10848 * Return: None
10849 */
10850static void component_deinit(void)
10851{
10852 pmo_deinit();
10853}
10854
10855/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010856 * __hdd_module_init - Module init helper
10857 *
10858 * Module init helper function used by both module and static driver.
10859 *
10860 * Return: 0 for success, errno on failure
10861 */
10862static int __hdd_module_init(void)
10863{
10864 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010865
Dustin Brownab482ac2017-06-09 17:00:44 -070010866 pr_err("%s: Loading driver v%s (%s)%s\n",
10867 WLAN_MODULE_NAME,
10868 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070010869 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070010870 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010871
Sachin Ahujadddd2632017-03-07 19:07:24 +053010872 ret = wlan_hdd_state_ctrl_param_create();
10873 if (ret) {
10874 pr_err("wlan_hdd_state_create:%x\n", ret);
10875 goto err_dev_state;
10876 }
10877
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010878 pld_init();
10879
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010880 ret = hdd_init();
10881 if (ret) {
10882 pr_err("hdd_init failed %x\n", ret);
10883 goto err_hdd_init;
10884 }
10885
Rajeev Kumar97767a02016-11-30 11:20:40 -080010886 dispatcher_init();
10887
Mukul Sharmad75a6672017-06-22 15:40:53 +053010888 /* Ensure to call post objmgr init */
10889 component_init();
10890
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010891 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010892
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010893 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010894
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010895 ret = wlan_hdd_register_driver();
10896 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070010897 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
10898 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010899 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010900 }
10901
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010902 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010903
10904 return 0;
10905out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010906 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080010907 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010908 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080010909
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010910err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010911 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053010912 wlan_hdd_state_ctrl_param_destroy();
10913err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010914 return ret;
10915}
10916
10917/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010918 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
10919 *
10920 * Block the unloading of the driver until the cds recovery is completed
10921 *
10922 * Return: None
10923 */
10924static void hdd_wait_for_recovery_completion(void)
10925{
10926 int retry = 0;
10927
10928 /* Wait for recovery to complete */
10929 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010930 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010931 msleep(1000);
10932 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010933 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010934 QDF_BUG(0);
10935 }
10936 }
10937}
10938
10939/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010940 * __hdd_module_exit - Module exit helper
10941 *
10942 * Module exit helper function used by both module and static driver.
10943 */
10944static void __hdd_module_exit(void)
10945{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010946
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010947 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
10948 QWLAN_VERSIONSTR);
10949
bings6028ee82017-03-29 07:51:40 +080010950 cds_set_unload_in_progress(true);
10951
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010952 hdd_wait_for_recovery_completion();
10953
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010954 wlan_hdd_unregister_driver();
10955
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010956 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010957
Mukul Sharmad75a6672017-06-22 15:40:53 +053010958 /* Ensure to call prior to objmgr deinit */
10959 component_deinit();
10960
Rajeev Kumar97767a02016-11-30 11:20:40 -080010961 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010962 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010963 pld_deinit();
10964
Sachin Ahujadddd2632017-03-07 19:07:24 +053010965 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010966}
10967
Arun Khandavallifae92942016-08-01 13:31:08 +053010968#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010969/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010970 * wlan_boot_cb() - Wlan boot callback
10971 * @kobj: object whose directory we're creating the link in.
10972 * @attr: attribute the user is interacting with
10973 * @buff: the buffer containing the user data
10974 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010975 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010976 * This callback is invoked when the fs is ready to start the
10977 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010978 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010979 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010980 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010981static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010982 struct kobj_attribute *attr,
10983 const char *buf,
10984 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010985{
Arun Khandavallifae92942016-08-01 13:31:08 +053010986
Arun Khandavallifae92942016-08-01 13:31:08 +053010987 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010988 pr_err("%s: wlan driver already initialized\n", __func__);
10989 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053010990 }
10991
Arun Khandavallifae92942016-08-01 13:31:08 +053010992 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010993 pr_err("%s: wlan driver initialization failed\n", __func__);
10994 return -EIO;
10995 }
10996
10997 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053010998
10999 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011000}
Arun Khandavallifae92942016-08-01 13:31:08 +053011001
11002/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011003 * hdd_sysfs_cleanup() - cleanup sysfs
11004 *
11005 * Return: None
11006 *
11007 */
11008static void hdd_sysfs_cleanup(void)
11009{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011010 /* remove from group */
11011 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11012 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11013 wlan_loader->attr_group);
11014
11015 /* unlink the object from parent */
11016 kobject_del(wlan_loader->boot_wlan_obj);
11017
11018 /* free the object */
11019 kobject_put(wlan_loader->boot_wlan_obj);
11020
11021 kfree(wlan_loader->attr_group);
11022 kfree(wlan_loader);
11023
11024 wlan_loader = NULL;
11025}
11026
11027/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011028 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11029 * ready
11030 *
11031 * This is creates the syfs entry boot_wlan. Which shall be invoked
11032 * when the filesystem is ready.
11033 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011034 * QDF API cannot be used here since this function is called even before
11035 * initializing WLAN driver.
11036 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011037 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011038 */
11039static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011040{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011041 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011042
11043 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011044 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011045 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011046
11047 wlan_loader->boot_wlan_obj = NULL;
11048 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11049 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011050 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011051 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011052
11053 wlan_loader->loaded_state = 0;
11054 wlan_loader->attr_group->attrs = attrs;
11055
11056 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11057 kernel_kobj);
11058 if (!wlan_loader->boot_wlan_obj) {
11059 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011060 goto error_return;
11061 }
11062
11063 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11064 wlan_loader->attr_group);
11065 if (ret) {
11066 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11067 goto error_return;
11068 }
11069
11070 return 0;
11071
11072error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011073 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011074
11075 return ret;
11076}
11077
11078/**
11079 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11080 *
11081 * Return: 0 on success or errno on failure
11082 */
11083static int wlan_deinit_sysfs(void)
11084{
Arun Khandavallifae92942016-08-01 13:31:08 +053011085 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011086 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011087 return -EINVAL;
11088 }
11089
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011090 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011091 return 0;
11092}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011093
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011094#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011095
11096#ifdef MODULE
11097/**
11098 * __hdd_module_init - Module init helper
11099 *
11100 * Module init helper function used by both module and static driver.
11101 *
11102 * Return: 0 for success, errno on failure
11103 */
11104static int hdd_module_init(void)
11105{
Arun Khandavallifae92942016-08-01 13:31:08 +053011106 if (__hdd_module_init()) {
11107 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011108 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011109 }
11110
Dustin Brownab482ac2017-06-09 17:00:44 -070011111 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011112}
11113#else
11114static int __init hdd_module_init(void)
11115{
11116 int ret = -EINVAL;
11117
11118 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011119 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011120 pr_err("Failed to create sysfs entry for loading wlan");
11121
11122 return ret;
11123}
11124#endif
11125
11126
11127#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011128/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011129 * hdd_module_exit() - Exit function
11130 *
11131 * This is the driver exit point (invoked when module is unloaded using rmmod)
11132 *
11133 * Return: None
11134 */
11135static void __exit hdd_module_exit(void)
11136{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011137 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011138}
Arun Khandavallifae92942016-08-01 13:31:08 +053011139#else
11140static void __exit hdd_module_exit(void)
11141{
11142 __hdd_module_exit();
11143 wlan_deinit_sysfs();
11144}
11145#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011146
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011147static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11148{
11149 return param_set_copystring(kmessage, kp);
11150}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011151
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011152/**
11153 * is_con_mode_valid() check con mode is valid or not
11154 * @mode: global con mode
11155 *
11156 * Return: TRUE on success FALSE on failure
11157 */
11158static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11159{
11160 switch (mode) {
11161 case QDF_GLOBAL_MONITOR_MODE:
11162 case QDF_GLOBAL_FTM_MODE:
11163 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011164 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011165 return true;
11166 default:
11167 return false;
11168 }
11169}
11170
11171/**
11172 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11173 * @mode: global con mode
11174 *
11175 * Return: adapter mode
11176 */
11177static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11178 enum tQDF_GLOBAL_CON_MODE mode)
11179{
11180
11181 switch (mode) {
11182 case QDF_GLOBAL_MISSION_MODE:
11183 return QDF_STA_MODE;
11184 case QDF_GLOBAL_MONITOR_MODE:
11185 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011186 case QDF_GLOBAL_EPPING_MODE:
11187 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011188 case QDF_GLOBAL_FTM_MODE:
11189 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011190 case QDF_GLOBAL_QVIT_MODE:
11191 return QDF_QVIT_MODE;
11192 default:
11193 return QDF_MAX_NO_OF_MODE;
11194 }
11195}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011196
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011197static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
11198 enum tQDF_GLOBAL_CON_MODE curr_mode)
11199{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011200 int driver_status;
11201
11202 driver_status = hdd_ctx->driver_status;
11203
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011204 switch (curr_mode) {
11205 case QDF_GLOBAL_MISSION_MODE:
11206 case QDF_GLOBAL_MONITOR_MODE:
11207 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011208 if (driver_status != DRIVER_MODULES_CLOSED) {
11209 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11210 hdd_stop_all_adapters(hdd_ctx);
11211 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011212 hdd_deinit_all_adapters(hdd_ctx, false);
11213 hdd_close_all_adapters(hdd_ctx, false);
11214 break;
11215 case QDF_GLOBAL_EPPING_MODE:
11216 epping_disable();
11217 epping_close();
11218 break;
11219 default:
11220 return;
11221 }
11222}
11223
11224static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
11225 enum tQDF_GLOBAL_CON_MODE mode)
11226{
11227 hdd_adapter_t *adapter;
11228 int ret = 0;
11229 bool rtnl_held;
11230 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11231 QDF_STATUS status;
11232
11233 if (!qdf_dev) {
11234 hdd_err("qdf device context is Null return!");
11235 return -EINVAL;
11236 }
11237
11238 rtnl_held = hdd_hold_rtnl_lock();
11239 switch (mode) {
11240 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011241 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11242 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011243 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011244 break;
11245 case QDF_GLOBAL_FTM_MODE:
11246 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11247 wlan_hdd_get_intf_addr(hdd_ctx),
11248 NET_NAME_UNKNOWN, rtnl_held);
11249 if (adapter == NULL)
11250 ret = -EINVAL;
11251 break;
11252 case QDF_GLOBAL_MONITOR_MODE:
11253 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11254 wlan_hdd_get_intf_addr(hdd_ctx),
11255 NET_NAME_UNKNOWN, rtnl_held);
11256 if (adapter == NULL)
11257 ret = -EINVAL;
11258 break;
11259 case QDF_GLOBAL_EPPING_MODE:
11260 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011261 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011262 hdd_err("Failed to open in eeping mode: %d", status);
11263 ret = -EINVAL;
11264 break;
11265 }
11266 ret = epping_enable(qdf_dev->dev);
11267 if (ret) {
11268 hdd_err("Failed to enable in epping mode : %d", ret);
11269 epping_close();
11270 }
11271 break;
11272 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011273 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011274 ret = -ENOTSUPP;
11275 break;
11276 }
11277 hdd_release_rtnl_lock();
11278 rtnl_held = false;
11279 return ret;
11280}
11281
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011282/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011283 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011284 * @kmessage: con mode name on which driver to be bring up
11285 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011286 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011287 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011288 * This function is invoked when user updates con mode using sys entry,
11289 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011290 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011291 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011292 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011293static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
11294 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011295{
11296 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011297 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011298 enum tQDF_GLOBAL_CON_MODE curr_mode;
11299 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011300
Dustin Brownab6029b2017-05-24 13:04:19 -070011301 hdd_info("con_mode handler: %s", kmessage);
11302
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011303 ret = wlan_hdd_validate_context(hdd_ctx);
11304 if (ret)
11305 return ret;
11306
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011307 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011308
11309 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011310
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011311 if (!(is_con_mode_valid(con_mode))) {
11312 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011313 ret = -EINVAL;
11314 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011315 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011316
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011317 curr_mode = hdd_get_conparam();
11318 if (curr_mode == con_mode) {
11319 hdd_err("curr mode: %d is same as user triggered mode %d",
11320 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011321 ret = 0;
11322 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011323 }
11324
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011325 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011326 if (ret) {
11327 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011328 goto reset_flags;
11329 }
11330
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011331 /* Cleanup present mode before switching to new mode */
11332 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11333
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011334 hdd_set_conparam(con_mode);
11335
11336 /* Register for new con_mode & then kick_start modules again */
11337 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11338 if (ret) {
11339 hdd_err("Failed to register for new mode");
11340 goto reset_flags;
11341 }
11342
11343 adapter_mode = hdd_get_adpter_mode(con_mode);
11344 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11345 hdd_err("invalid adapter");
11346 ret = -EINVAL;
11347 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011348 }
11349
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011350 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011352 hdd_err("Failed to get adapter:%d", adapter_mode);
11353 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011354 }
11355
11356 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11357 if (ret) {
11358 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011359 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011360 }
11361
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011362 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11363 con_mode == QDF_GLOBAL_FTM_MODE) {
11364 if (hdd_start_adapter(adapter)) {
11365 hdd_err("Failed to start %s adapter", kmessage);
11366 ret = -EINVAL;
11367 goto reset_flags;
11368 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011369 }
11370
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011371 hdd_info("Mode successfully changed to %s", kmessage);
11372 ret = 0;
11373
11374reset_flags:
11375 cds_set_load_in_progress(false);
11376 return ret;
11377}
11378
11379
11380static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11381{
11382 int ret;
11383 hdd_context_t *hdd_ctx;
11384
11385 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11386 ret = wlan_hdd_validate_context(hdd_ctx);
11387 if (ret)
11388 return ret;
11389
11390 cds_ssr_protect(__func__);
11391 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11392 cds_ssr_unprotect(__func__);
11393
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011394 return ret;
11395}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011396
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011397static int con_mode_handler_ftm(const char *kmessage,
11398 struct kernel_param *kp)
11399{
11400 int ret;
11401
11402 ret = param_set_int(kmessage, kp);
11403
11404 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11405 pr_err("Only FTM mode supported!");
11406 return -ENOTSUPP;
11407 }
11408
11409 hdd_set_conparam(con_mode_ftm);
11410 con_mode = con_mode_ftm;
11411
11412 return ret;
11413}
11414
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011415/**
11416 * hdd_get_conparam() - driver exit point
11417 *
11418 * This is the driver exit point (invoked when module is unloaded using rmmod)
11419 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011420 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011421 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011422enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011423{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011424 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011425}
11426
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011427void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011428{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011429 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011430}
11431
Komal Seelamc11bb222016-01-27 18:57:10 +053011432/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011433 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11434 * @hdd_ctx: HDD context
11435 *
11436 * Cleans up the pre cac interface, if it exists
11437 *
11438 * Return: None
11439 */
11440void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
11441{
11442 uint8_t session_id;
11443 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011444 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011445
11446 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11447 if (QDF_IS_STATUS_ERROR(status)) {
11448 hdd_err("failed to get pre cac vdev id");
11449 return;
11450 }
11451
11452 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11453 if (!precac_adapter) {
11454 hdd_err("invalid pre cac adapater");
11455 return;
11456 }
11457
11458 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11459 wlan_hdd_sap_pre_cac_failure,
11460 (void *)precac_adapter);
11461 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11462
11463}
11464
11465/**
Komal Seelamec702b02016-02-24 18:42:16 +053011466 * hdd_update_ol_config - API to update ol configuration parameters
11467 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011468 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011469 * Return: void
11470 */
Komal Seelamec702b02016-02-24 18:42:16 +053011471static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011472{
Komal Seelamec702b02016-02-24 18:42:16 +053011473 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011474 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011475
Komal Seelamec702b02016-02-24 18:42:16 +053011476 if (!ol_ctx)
11477 return;
11478
11479 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11480 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11481 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11482 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011483 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011484
11485 ol_init_ini_config(ol_ctx, &cfg);
11486}
11487
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011488#ifdef FEATURE_RUNTIME_PM
11489/**
11490 * hdd_populate_runtime_cfg() - populate runtime configuration
11491 * @hdd_ctx: hdd context
11492 * @cfg: pointer to the configuration memory being populated
11493 *
11494 * Return: void
11495 */
11496static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11497 struct hif_config_info *cfg)
11498{
11499 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11500 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11501}
11502#else
11503static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11504 struct hif_config_info *cfg)
11505{
11506}
11507#endif
11508
Komal Seelamec702b02016-02-24 18:42:16 +053011509/**
11510 * hdd_update_hif_config - API to update HIF configuration parameters
11511 * @hdd_ctx: HDD Context
11512 *
11513 * Return: void
11514 */
11515static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
11516{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011517 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011518 struct hif_config_info cfg;
11519
11520 if (!scn)
11521 return;
11522
11523 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011524 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011525 hif_init_ini_config(scn, &cfg);
11526}
11527
11528/**
11529 * hdd_update_config() - Initialize driver per module ini parameters
11530 * @hdd_ctx: HDD Context
11531 *
11532 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011533 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011534 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011535int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011536{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011537 int ret;
11538
Komal Seelamec702b02016-02-24 18:42:16 +053011539 hdd_update_ol_config(hdd_ctx);
11540 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011541 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11542 ret = hdd_update_cds_config_ftm(hdd_ctx);
11543 else
11544 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011545 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011546
11547 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011548}
11549
Mukul Sharma9d797a02017-01-05 20:26:03 +053011550#ifdef FEATURE_WLAN_RA_FILTERING
11551/**
11552 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11553 * @psoc_cfg: pmo psoc Configuration
11554 * @hdd_ctx: Pointer to hdd context
11555 *
11556 * Return: none
11557 */
11558static inline void hdd_ra_populate_pmo_config(
11559 struct pmo_psoc_cfg *psoc_cfg,
11560 hdd_context_t *hdd_ctx)
11561{
11562 psoc_cfg->ra_ratelimit_interval =
11563 hdd_ctx->config->RArateLimitInterval;
11564 psoc_cfg->ra_ratelimit_enable =
11565 hdd_ctx->config->IsRArateLimitEnabled;
11566}
11567#else
11568static inline void hdd_ra_populate_pmo_config(
11569 struct cds_config_info *cds_cfg,
11570 hdd_context_t *hdd_ctx)
11571{
11572}
11573#endif
11574/**
11575 * hdd_update_pmo_config - API to update pmo configuration parameters
11576 * @hdd_ctx: HDD context
11577 *
11578 * Return: void
11579 */
11580static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
11581{
11582 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11583 struct pmo_psoc_cfg psoc_cfg;
11584 QDF_STATUS status;
11585
11586 /*
11587 * Value of hdd_ctx->wowEnable can be,
11588 * 0 - Disable both magic pattern match and pattern byte match.
11589 * 1 - Enable magic pattern match on all interfaces.
11590 * 2 - Enable pattern byte match on all interfaces.
11591 * 3 - Enable both magic patter and pattern byte match on
11592 * all interfaces.
11593 */
11594 psoc_cfg.magic_ptrn_enable =
11595 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11596 psoc_cfg.ptrn_match_enable_all_vdev =
11597 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11598 psoc_cfg.bpf_enable =
11599 hdd_ctx->config->bpf_packet_filter_enable;
11600 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011601 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011602 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11603 if (hdd_ctx->config->fhostNSOffload)
11604 psoc_cfg.ns_offload_enable_dynamic = true;
11605 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11606 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11607 psoc_cfg.active_mode_offload =
11608 hdd_ctx->config->active_mode_offload;
11609 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11610 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011611 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11612 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11613 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11614 psoc_cfg.power_save_mode =
11615 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011616 psoc_cfg.auto_power_save_fail_mode =
11617 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011618
11619 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011620 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11621 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011622 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11623 if (status != QDF_STATUS_SUCCESS) {
11624 hdd_err("failed pmo psoc configuration");
11625 return -EINVAL;
11626 }
11627
11628 return 0;
11629}
11630
Abhishek Singh257a9482017-03-06 16:52:39 +053011631#ifdef NAPIER_SCAN
Abhishek Singhb20db962017-03-03 21:28:46 +053011632
11633#ifdef FEATURE_WLAN_SCAN_PNO
11634static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11635 struct hdd_config *cfg)
11636{
11637 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11638 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11639 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11640 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11641 pno_cfg->channel_prediction_full_scan =
11642 cfg->channel_prediction_full_scan;
11643}
11644#else
11645static inline void
11646hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11647 struct hdd_config *cfg)
11648{
11649 return;
11650}
11651#endif
11652
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011653void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11654 struct hdd_config *cfg)
11655{
11656 uint8_t i = 0;
11657
11658 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11659 if (!ie_whitelist->white_list)
11660 return;
11661
11662 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11663 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11664 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11665 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11666 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11667 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11668 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11669 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11670
11671 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11672 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11673 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11674}
11675
Abhishek Singh257a9482017-03-06 16:52:39 +053011676/**
11677 * hdd_update_scan_config - API to update scan configuration parameters
11678 * @hdd_ctx: HDD context
11679 *
11680 * Return: 0 if success else err
11681 */
11682static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11683{
11684 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11685 struct scan_user_cfg scan_cfg;
11686 struct hdd_config *cfg = hdd_ctx->config;
11687 QDF_STATUS status;
11688
11689 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11690 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11691 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11692 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11693 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11694 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11695 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011696 /* convert to ms */
11697 scan_cfg.scan_cache_aging_time =
11698 cfg->scanAgingTimeout * 1000;
11699 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11700 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11701 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11702 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011703 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011704 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011705
Abhishek Singhb20db962017-03-03 21:28:46 +053011706 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011707 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011708
Abhishek Singh257a9482017-03-06 16:52:39 +053011709 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11710 if (status != QDF_STATUS_SUCCESS) {
11711 hdd_err("failed pmo psoc configuration");
11712 return -EINVAL;
11713 }
11714
11715 return 0;
11716}
11717#else
11718static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11719{
11720 return 0;
11721}
11722#endif
11723
Frank Liud4b2fa02017-03-29 11:46:48 +080011724#ifdef CONVERGED_TDLS_ENABLE
11725static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11726{
11727 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11728 struct tdls_start_params tdls_cfg;
11729 struct tdls_user_config *config = &tdls_cfg.config;
11730 struct hdd_config *cfg = hdd_ctx->config;
11731 QDF_STATUS status;
11732
11733 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11734 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11735 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11736 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11737 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11738 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11739 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11740 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11741 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11742 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11743 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11744 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11745 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11746 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11747 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11748 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11749 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11750 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11751 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11752 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11753 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11754 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11755 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11756 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11757 (cfg->fEnableTDLSImplicitTrigger ?
11758 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11759 (cfg->fTDLSExternalControl ?
11760 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11761
11762 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11763 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11764 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11765 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011766 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011767 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011768 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11769 tdls_cfg.tdls_evt_cb_data = psoc;
11770 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11771 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11772 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011773 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11774 tdls_cfg.tdls_wmm_cb_data = psoc;
11775 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11776 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011777 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011778
11779 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11780 if (status != QDF_STATUS_SUCCESS) {
11781 hdd_err("failed pmo psoc configuration");
11782 return -EINVAL;
11783 }
11784
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011785 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011786 /* disable napier specific tdls data path */
11787 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011788
Frank Liud4b2fa02017-03-29 11:46:48 +080011789 return 0;
11790}
11791#else
11792static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11793{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011794 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011795 /* disable napier specific tdls data path */
11796 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080011797 return 0;
11798}
11799#endif
11800
Mukul Sharma9d797a02017-01-05 20:26:03 +053011801int hdd_update_components_config(hdd_context_t *hdd_ctx)
11802{
11803 int ret;
11804
11805 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053011806 if (ret)
11807 return ret;
11808 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080011809 if (ret)
11810 return ret;
11811 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011812
11813 return ret;
11814}
11815
Agrawal Ashish65634612016-08-18 13:24:32 +053011816/**
11817 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
11818 * @mode : cfg80211 DFS mode
11819 *
11820 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
11821 */
11822enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
11823{
11824 switch (mode) {
11825 case DFS_MODE_ENABLE:
11826 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011827 case DFS_MODE_DISABLE:
11828 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011829 case DFS_MODE_DEPRIORITIZE:
11830 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011831 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011832 hdd_debug("ACS dfs mode is NONE");
11833 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011834 }
11835}
11836
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011837/**
11838 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
11839 * @hddctx: pointer to hdd context
11840 * @set_value: enable/disable
11841 *
11842 * When Host sends vendor command enable, FW will send *ONE* CA ind to
11843 * Host(even though it is duplicate). When Host send vendor command
11844 * disable,FW doesn't perform any action. Whenever any change in
11845 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
11846 *
11847 * return - 0 on success, appropriate error values on failure.
11848 */
11849int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
11850{
11851 QDF_STATUS status;
11852
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011853 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011854 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011855
11856 if (!hddctx->config->goptimize_chan_avoid_event) {
11857 hdd_warn("goptimize_chan_avoid_event ini param disabled");
11858 return -EINVAL;
11859 }
11860
11861 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
11862 if (!QDF_IS_STATUS_SUCCESS(status)) {
11863 hdd_err("Failed to send chan avoid command to SME");
11864 return -EINVAL;
11865 }
11866 return 0;
11867}
Agrawal Ashish65634612016-08-18 13:24:32 +053011868
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011869/**
11870 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
11871 * @value: value to set
11872 *
11873 * This function will set the passed value to roaming in progress flag.
11874 *
11875 * Return: None
11876 */
11877void hdd_set_roaming_in_progress(bool value)
11878{
11879 hdd_context_t *hdd_ctx;
11880
11881 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11882 if (!hdd_ctx) {
11883 hdd_err("HDD context is NULL");
11884 return;
11885 }
11886
11887 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011888 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011889}
11890
11891/**
11892 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011893 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011894 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011895 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011896 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011897bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011898{
11899 hdd_context_t *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011900 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011901
11902 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11903 if (!hdd_ctx) {
11904 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011905 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011906 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011907 hdd_debug("dev mode = %d, roaming_in_progress = %d",
11908 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011909 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
11910 hdd_ctx->roaming_in_progress);
11911
11912 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011913}
11914
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011915/**
11916 * hdd_is_connection_in_progress() - check if connection is in
11917 * progress
11918 * @session_id: session id
11919 * @reason: scan reject reason
11920 *
11921 * Go through each adapter and check if Connection is in progress
11922 *
11923 * Return: true if connection is in progress else false
11924 */
11925bool hdd_is_connection_in_progress(uint8_t *session_id,
11926 enum scan_reject_states *reason)
11927{
11928 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
11929 hdd_station_ctx_t *hdd_sta_ctx = NULL;
11930 hdd_adapter_t *adapter = NULL;
11931 QDF_STATUS status = 0;
11932 uint8_t sta_id = 0;
11933 uint8_t *sta_mac = NULL;
11934 hdd_context_t *hdd_ctx;
11935
11936 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11937 if (!hdd_ctx) {
11938 hdd_err("HDD context is NULL");
11939 return false;
11940 }
11941
11942 if (true == hdd_ctx->btCoexModeSet) {
11943 hdd_info("BTCoex Mode operation in progress");
11944 return true;
11945 }
11946 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
11947 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
11948 adapter = adapter_node->pAdapter;
11949 if (!adapter)
11950 goto end;
11951
11952 hdd_info("Adapter with device mode %s(%d) exists",
11953 hdd_device_mode_to_string(adapter->device_mode),
11954 adapter->device_mode);
11955 if (((QDF_STA_MODE == adapter->device_mode)
11956 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
11957 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
11958 && (eConnectionState_Connecting ==
11959 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
11960 conn_info.connState)) {
11961 hdd_err("%p(%d) Connection is in progress",
11962 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11963 adapter->sessionId);
11964 if (session_id && reason) {
11965 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011966 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011967 }
11968 return true;
11969 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070011970 /*
11971 * sme_neighbor_middle_of_roaming is for LFR2
11972 * hdd_is_roaming_in_progress is for LFR3
11973 */
11974 if (((QDF_STA_MODE == adapter->device_mode) &&
11975 sme_neighbor_middle_of_roaming(
11976 WLAN_HDD_GET_HAL_CTX(adapter),
11977 adapter->sessionId)) ||
11978 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011979 hdd_err("%p(%d) Reassociation in progress",
11980 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11981 adapter->sessionId);
11982 if (session_id && reason) {
11983 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011984 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011985 }
11986 return true;
11987 }
11988 if ((QDF_STA_MODE == adapter->device_mode) ||
11989 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
11990 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
11991 hdd_sta_ctx =
11992 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11993 if ((eConnectionState_Associated ==
11994 hdd_sta_ctx->conn_info.connState)
11995 && (false ==
11996 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
11997 sta_mac = (uint8_t *)
11998 &(adapter->macAddressCurrent.bytes[0]);
11999 hdd_err("client " MAC_ADDRESS_STR
12000 " is in middle of WPS/EAPOL exchange.",
12001 MAC_ADDR_ARRAY(sta_mac));
12002 if (session_id && reason) {
12003 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012004 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012005 }
12006 return true;
12007 }
12008 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12009 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12010 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12011 sta_id++) {
12012 if (!((adapter->aStaInfo[sta_id].isUsed)
12013 && (OL_TXRX_PEER_STATE_CONN ==
12014 adapter->aStaInfo[sta_id].tlSTAState)))
12015 continue;
12016
12017 sta_mac = (uint8_t *)
12018 &(adapter->aStaInfo[sta_id].
12019 macAddrSTA.bytes[0]);
12020 hdd_err("client " MAC_ADDRESS_STR
12021 " of SAP/GO is in middle of WPS/EAPOL exchange",
12022 MAC_ADDR_ARRAY(sta_mac));
12023 if (session_id && reason) {
12024 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012025 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012026 }
12027 return true;
12028 }
12029 if (hdd_ctx->connection_in_progress) {
12030 hdd_err("AP/GO: connection is in progress");
12031 return true;
12032 }
12033 }
12034end:
12035 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12036 adapter_node = next;
12037 }
12038 return false;
12039}
12040
12041/**
12042 * hdd_restart_sap() - to restart SAP in driver internally
12043 * @ap_adapter: Pointer to SAP hdd_adapter_t structure
12044 *
12045 * Return: None
12046 */
12047void hdd_restart_sap(hdd_adapter_t *ap_adapter)
12048{
12049 hdd_ap_ctx_t *hdd_ap_ctx;
12050 hdd_hostapd_state_t *hostapd_state;
12051 QDF_STATUS qdf_status;
12052 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12053 tsap_Config_t *sap_config;
12054 void *sap_ctx;
12055
12056 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12057 sap_config = &hdd_ap_ctx->sapConfig;
12058 sap_ctx = hdd_ap_ctx->sapContext;
12059
12060 mutex_lock(&hdd_ctx->sap_lock);
12061 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12062 wlan_hdd_del_station(ap_adapter);
12063 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12064 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12065 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12066 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12067 qdf_status =
12068 qdf_wait_single_event(&hostapd_state->
12069 qdf_stop_bss_event,
12070 SME_CMD_TIMEOUT_VALUE);
12071
12072 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12073 cds_err("SAP Stop Failed");
12074 goto end;
12075 }
12076 }
12077 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012078 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012079 ap_adapter->device_mode, ap_adapter->sessionId);
12080 cds_err("SAP Stop Success");
12081
12082 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12083 cds_err("SAP Not able to set AP IEs");
12084 wlansap_reset_sap_config_add_ie(sap_config,
12085 eUPDATE_IE_ALL);
12086 goto end;
12087 }
12088
12089 qdf_event_reset(&hostapd_state->qdf_event);
12090 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12091 sap_config,
12092 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12093 cds_err("SAP Start Bss fail");
12094 wlansap_reset_sap_config_add_ie(sap_config,
12095 eUPDATE_IE_ALL);
12096 goto end;
12097 }
12098
12099 cds_info("Waiting for SAP to start");
12100 qdf_status =
12101 qdf_wait_single_event(&hostapd_state->qdf_event,
12102 SME_CMD_TIMEOUT_VALUE);
12103 wlansap_reset_sap_config_add_ie(sap_config,
12104 eUPDATE_IE_ALL);
12105 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12106 cds_err("SAP Start failed");
12107 goto end;
12108 }
12109 cds_err("SAP Start Success");
12110 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12111 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012112 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12113 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012114 ap_adapter->sessionId);
12115 hostapd_state->bCommit = true;
12116 }
12117end:
12118 mutex_unlock(&hdd_ctx->sap_lock);
12119 return;
12120}
12121
12122/**
12123 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12124 * with non dfs acs
12125 *
12126 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12127 *
12128 * Return: None
12129 */
12130void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12131{
12132 hdd_adapter_t *ap_adapter;
12133 hdd_context_t *hdd_ctx;
12134 cds_context_type *cds_ctx;
12135
12136 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12137 if (!hdd_ctx) {
12138 cds_err("HDD context is NULL");
12139 return;
12140 }
12141
12142 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12143 if (!cds_ctx) {
12144 cds_err("Invalid CDS Context");
12145 return;
12146 }
12147
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012148 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12149 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012150 cds_info("Concurrency mode is not SAP");
12151 return;
12152 }
12153
12154 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012155 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12156 &ap_adapter->event_flags) &&
12157 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12158 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012159
12160 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12161 ap_adapter->sessionCtx.ap.sapConfig.channel =
12162 AUTO_CHANNEL_SELECT;
12163 ap_adapter->sessionCtx.ap.sapConfig.
12164 acs_cfg.acs_mode = true;
12165
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012166 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012167 }
12168}
12169
12170/**
12171 * hdd_set_connection_in_progress() - to set the connection in
12172 * progress flag
12173 * @value: value to set
12174 *
12175 * This function will set the passed value to connection in progress flag.
12176 * If value is previously being set to true then no need to set it again.
12177 *
12178 * Return: true if value is being set correctly and false otherwise.
12179 */
12180bool hdd_set_connection_in_progress(bool value)
12181{
12182 bool status = true;
12183 hdd_context_t *hdd_ctx;
12184
12185 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12186 if (!hdd_ctx) {
12187 cds_err("HDD context is NULL");
12188 return false;
12189 }
12190
12191 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12192 /*
12193 * if the value is set to true previously and if someone is
12194 * trying to make it true again then it could be some race
12195 * condition being triggered. Avoid this situation by returning
12196 * false
12197 */
12198 if (hdd_ctx->connection_in_progress && value)
12199 status = false;
12200 else
12201 hdd_ctx->connection_in_progress = value;
12202 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12203 return status;
12204}
12205
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012206int wlan_hdd_send_p2p_quota(hdd_adapter_t *adapter, int set_value)
12207{
12208 if (!adapter) {
12209 hdd_err("Invalid adapter");
12210 return -EINVAL;
12211 }
12212 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012213 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012214 WMA_VDEV_MCC_SET_TIME_QUOTA,
12215 set_value, VDEV_CMD);
12216 return 0;
12217
12218}
12219
12220int wlan_hdd_send_mcc_latency(hdd_adapter_t *adapter, int set_value)
12221{
12222 if (!adapter) {
12223 hdd_err("Invalid adapter");
12224 return -EINVAL;
12225 }
12226
12227 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012228 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012229 WMA_VDEV_MCC_SET_TIME_LATENCY,
12230 set_value, VDEV_CMD);
12231 return 0;
12232}
12233
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012234hdd_adapter_t *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
12235 *psoc, uint8_t vdev_id)
12236{
12237 hdd_adapter_t *adapter = NULL;
12238 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12239
12240 /*
12241 * Currently PSOC is not being used. But this logic will
12242 * change once we have the converged implementation of
12243 * HDD context per PSOC in place. This would break if
12244 * multiple vdev objects reuse the vdev id.
12245 */
12246 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12247 if (!adapter)
12248 hdd_err("Get adapter by vdev id failed");
12249
12250 return adapter;
12251}
12252
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012253int hdd_get_rssi_snr_by_bssid(hdd_adapter_t *adapter, const uint8_t *bssid,
12254 int8_t *rssi, int8_t *snr)
12255{
12256 QDF_STATUS status;
12257 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12258 tCsrRoamProfile *profile = &wext_state->roamProfile;
12259
12260 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12261 profile, bssid, rssi, snr);
12262 if (QDF_STATUS_SUCCESS != status) {
12263 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12264 return -EINVAL;
12265 }
12266
12267 return 0;
12268}
12269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012270/* Register the module init/exit functions */
12271module_init(hdd_module_init);
12272module_exit(hdd_module_exit);
12273
12274MODULE_LICENSE("Dual BSD/GPL");
12275MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12276MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12277
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012278module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12279 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012280
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012281module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12282 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12283
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012284module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12285 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12286
12287module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12288
12289module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12290
12291module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);