blob: a1b4bc531a4b8ae4e2d1f99915ddce149a0e25ea [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
96
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530103#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700104#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700105#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530106#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700107#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530108#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800109#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530111#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800112#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800113#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530114#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530115#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800116#include "os_if_wifi_pos.h"
117#include "wifi_pos_api.h"
118#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800119#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700120#include "os_if_nan.h"
121#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700122#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530124#include "sme_power_save_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800125
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530126#ifdef CNSS_GENL
127#include <net/cnss_nl.h>
128#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800129#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800131#ifdef MODULE
132#define WLAN_MODULE_NAME module_name(THIS_MODULE)
133#else
134#define WLAN_MODULE_NAME "wlan"
135#endif
136
137#ifdef TIMER_MANAGER
138#define TIMER_MANAGER_STR " +TIMER_MANAGER"
139#else
140#define TIMER_MANAGER_STR ""
141#endif
142
143#ifdef MEMORY_DEBUG
144#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
145#else
146#define MEMORY_DEBUG_STR ""
147#endif
148
Sachin Ahujadddd2632017-03-07 19:07:24 +0530149int wlan_start_ret_val;
150static DECLARE_COMPLETION(wlan_start_comp);
151static unsigned int dev_num = 1;
152static struct cdev wlan_hdd_state_cdev;
153static struct class *class;
154static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530155#ifndef MODULE
156static struct gwlan_loader *wlan_loader;
157static ssize_t wlan_boot_cb(struct kobject *kobj,
158 struct kobj_attribute *attr,
159 const char *buf, size_t count);
160struct gwlan_loader {
161 bool loaded_state;
162 struct kobject *boot_wlan_obj;
163 struct attribute_group *attr_group;
164};
165
166static struct kobj_attribute wlan_boot_attribute =
167 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
168
169static struct attribute *attrs[] = {
170 &wlan_boot_attribute.attr,
171 NULL,
172};
173
174#define MODULE_INITIALIZED 1
175#endif
176
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800177/* the Android framework expects this param even though we don't use it */
178#define BUF_LEN 20
179static char fwpath_buffer[BUF_LEN];
180static struct kparam_string fwpath = {
181 .string = fwpath_buffer,
182 .maxlen = BUF_LEN,
183};
184
185static char *country_code;
186static int enable_11d = -1;
187static int enable_dfs_chan_scan = -1;
188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189/*
190 * spinlock for synchronizing asynchronous request/response
191 * (full description of use in wlan_hdd_main.h)
192 */
193DEFINE_SPINLOCK(hdd_context_lock);
194
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800195#define WLAN_NLINK_CESIUM 30
196
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530197static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198
199#define WOW_MAX_FILTER_LISTS 1
200#define WOW_MAX_FILTERS_PER_LIST 4
201#define WOW_MIN_PATTERN_SIZE 6
202#define WOW_MAX_PATTERN_SIZE 64
203
204#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
205static const struct wiphy_wowlan_support wowlan_support_reg_init = {
206 .flags = WIPHY_WOWLAN_ANY |
207 WIPHY_WOWLAN_MAGIC_PKT |
208 WIPHY_WOWLAN_DISCONNECT |
209 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
210 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
211 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
212 WIPHY_WOWLAN_4WAY_HANDSHAKE |
213 WIPHY_WOWLAN_RFKILL_RELEASE,
214 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
215 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
216 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
217};
218#endif
219
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700220static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
221 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
222 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
223 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
224 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
225 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
226 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
227 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
228 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
229 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
233 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
234 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
235 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
236 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
237 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700255 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700256};
257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530259struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260
261struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700263static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800264#endif
265
Sachin Ahujadddd2632017-03-07 19:07:24 +0530266void hdd_start_complete(int ret)
267{
268 wlan_start_ret_val = ret;
269
270 complete(&wlan_start_comp);
271}
272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530274 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700275 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530276 *
277 * Return: none
278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700279static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530280{
281 hdd_adapter_t *adapter;
282 hdd_adapter_list_node_t *adapter_node, *next;
283 QDF_STATUS status = QDF_STATUS_SUCCESS;
284
285 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
286 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
287 adapter = adapter_node->pAdapter;
288 if (NULL != adapter)
289 hdd_send_rps_ind(adapter);
290 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
291 adapter_node = next;
292 }
293}
294
295/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
297 * @vdev_id: vdev_id
298 * @action: action type
299 * @reason: reason type
300 *
301 * Return: none
302 */
303void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
304 enum netif_action_type action, enum netif_reason_type reason)
305{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700306 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800307 hdd_adapter_t *adapter;
308
309 if (!hdd_ctx) {
310 hdd_err("hdd ctx is NULL");
311 return;
312 }
313 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
314
315 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800316}
317
318/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700319 * Store WLAN driver version and timestamp info in global variables such that
320 * crash debugger can extract them from driver debug symbol and crashdump for
321 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 */
323uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700324
325#ifndef BUILD_TIMESTAMP
326#define BUILD_TIMESTAMP ""
327#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700328uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329
330/**
331 * hdd_device_mode_to_string() - return string conversion of device mode
332 * @device_mode: device mode
333 *
334 * This utility function helps log string conversion of device mode.
335 *
336 * Return: string conversion of device mode, if match found;
337 * "Unknown" otherwise.
338 */
339const char *hdd_device_mode_to_string(uint8_t device_mode)
340{
341 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800342 CASE_RETURN_STRING(QDF_STA_MODE);
343 CASE_RETURN_STRING(QDF_SAP_MODE);
344 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
345 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
346 CASE_RETURN_STRING(QDF_FTM_MODE);
347 CASE_RETURN_STRING(QDF_IBSS_MODE);
348 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
349 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700350 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351 default:
352 return "Unknown";
353 }
354}
355
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530356/**
357 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
358 * @adapter: HDD adapter
359 * @chan_number: Channel number
360 * @chan_bw: Bandwidth
361 *
362 * Checks if the given bandwidth is valid for the given channel number.
363 *
364 * Return: 0 for success, non-zero for failure
365 */
366int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
367 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800368 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530369{
370 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
371 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
372 bool found = false;
373 tHalHandle hal;
374
375 hal = WLAN_HDD_GET_HAL_CTX(adapter);
376 if (!hal) {
377 hdd_err("Invalid HAL context");
378 return -EINVAL;
379 }
380
381 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
382 hdd_err("No valid channel list");
383 return -EOPNOTSUPP;
384 }
385
386 for (i = 0; i < len; i++) {
387 if (chan[i] == chan_number) {
388 found = true;
389 break;
390 }
391 }
392
393 if (found == false) {
394 hdd_err("Channel not in driver's valid channel list");
395 return -EOPNOTSUPP;
396 }
397
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700398 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
399 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530400 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
401 return -EINVAL;
402 }
403
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700404 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530405 if (chan_bw == CH_WIDTH_80MHZ) {
406 hdd_err("BW80 not possible in 2.4GHz band");
407 return -EINVAL;
408 }
409 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
410 (chan_bw != CH_WIDTH_MAX)) {
411 hdd_err("Only BW20 possible on channel 14");
412 return -EINVAL;
413 }
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530417 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
418 (chan_bw != CH_WIDTH_MAX)) {
419 hdd_err("Only BW20 possible on channel 165");
420 return -EINVAL;
421 }
422 }
423
424 return 0;
425}
426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427static int __hdd_netdev_notifier_call(struct notifier_block *nb,
428 unsigned long state, void *data)
429{
430#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
431 struct netdev_notifier_info *dev_notif_info = data;
432 struct net_device *dev = dev_notif_info->dev;
433#else
434 struct net_device *dev = data;
435#endif
436 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700437 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800438
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800439 ENTER_DEV(dev);
440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 /* Make sure that this callback corresponds to our device. */
442 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
443 return NOTIFY_DONE;
444
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530445 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700447 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 return NOTIFY_DONE;
449 }
450
451 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700452 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 return NOTIFY_DONE;
454 }
455
456 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
457 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800458 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530459 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 return NOTIFY_DONE;
461 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530462 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800463 return NOTIFY_DONE;
464
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800465 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 dev->name, state);
467
468 switch (state) {
469 case NETDEV_REGISTER:
470 break;
471
472 case NETDEV_UNREGISTER:
473 break;
474
475 case NETDEV_UP:
476 sme_ch_avoid_update_req(hdd_ctx->hHal);
477 break;
478
479 case NETDEV_DOWN:
480 break;
481
482 case NETDEV_CHANGE:
483 if (true == adapter->isLinkUpSvcNeeded)
484 complete(&adapter->linkup_event_var);
485 break;
486
487 case NETDEV_GOING_DOWN:
488 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530489 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
490 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 } else {
hqueaa33ee2017-05-04 17:56:35 +0800492 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800493 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 }
495 break;
496
497 default:
498 break;
499 }
500
501 return NOTIFY_DONE;
502}
503
504/**
505 * hdd_netdev_notifier_call() - netdev notifier callback function
506 * @nb: pointer to notifier block
507 * @state: state
508 * @ndev: ndev pointer
509 *
510 * Return: 0 on success, error number otherwise.
511 */
512static int hdd_netdev_notifier_call(struct notifier_block *nb,
513 unsigned long state,
514 void *ndev)
515{
516 int ret;
517
518 cds_ssr_protect(__func__);
519 ret = __hdd_netdev_notifier_call(nb, state, ndev);
520 cds_ssr_unprotect(__func__);
521
522 return ret;
523}
524
525struct notifier_block hdd_netdev_notifier = {
526 .notifier_call = hdd_netdev_notifier_call,
527};
528
529/* variable to hold the insmod parameters */
530static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800531
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530532static int con_mode_ftm;
533
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800534/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800535static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800536
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530537/**
538 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
539 * @ch_width: NL channel width
540 *
541 * Converts the NL channel width to the driver's internal representation
542 *
543 * Return: Converted channel width. In case of non matching NL channel width,
544 * CH_WIDTH_MAX will be returned.
545 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800546enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530547{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800548 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700549
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800550 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530551 switch (ch_width) {
552 case NL80211_CHAN_WIDTH_20_NOHT:
553 case NL80211_CHAN_WIDTH_20:
554 return CH_WIDTH_20MHZ;
555 case NL80211_CHAN_WIDTH_40:
556 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530557 case NL80211_CHAN_WIDTH_80:
558 return CH_WIDTH_80MHZ;
559 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800560 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
561 return CH_WIDTH_80P80MHZ;
562 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
563 return CH_WIDTH_160MHZ;
564 else
565 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530566 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800567 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
568 return CH_WIDTH_160MHZ;
569 else
570 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530571 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800572 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530573 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800574 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530575 default:
576 hdd_err("Invalid channel width %d, setting to default",
577 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800578 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530579 }
580}
581
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530582/* wlan_hdd_find_opclass() - Find operating class for a channel
583 * @hal: handler to HAL
584 * @channel: channel id
585 * @bw_offset: bandwidth offset
586 *
587 * Function invokes sme api to find the operating class
588 *
589 * Return: operating class
590 */
591uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
592 uint8_t bw_offset)
593{
594 uint8_t opclass = 0;
595
596 sme_get_opclass(hal, channel, bw_offset, &opclass);
597 return opclass;
598}
599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530601 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530602 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 * @bitmask: Bitmask of log levels to be enabled
604 *
605 * Called immediately after the cfg.ini is read in order to configure
606 * the desired trace levels.
607 *
608 * Return: None
609 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530610int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800611{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530612 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530613 int qdf_print_idx = -1;
614 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800615 /*
616 * if the bitmask is the default value, then a bitmask was not
617 * specified in cfg.ini, so leave the logging level alone (it
618 * will remain at the "compiled in" default value)
619 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700620 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530621 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530623 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800624
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530625 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530626 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530627 QDF_TRACE_LEVEL_NONE, 0);
628
629 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530630 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800631 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530632 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800633 while (0 != bitmask) {
634 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530635 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530636 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530637 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530638 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700640
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800641 level++;
642 bitmask >>= 1;
643 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530644 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800645}
646
647/**
Chris Guo1751acf2017-07-03 14:09:01 +0800648 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
649 * @hdd_ctx: HDD context pointer
650 *
651 * Return: 0 if the context is valid. Error code otherwise
652 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700653int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800654{
655 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
656 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
657 return -ENODEV;
658 }
659
660 if (cds_is_driver_recovering()) {
661 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
662 (void *)_RET_IP_, cds_get_driver_state());
663 return -EAGAIN;
664 }
665
666 if (hdd_ctx->start_modules_in_progress ||
667 hdd_ctx->stop_modules_in_progress) {
668 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
669 (void *)_RET_IP_);
670 return -EAGAIN;
671 }
672
673 return 0;
674}
675
676
677/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678 * wlan_hdd_validate_context() - check the HDD context
679 * @hdd_ctx: HDD context pointer
680 *
681 * Return: 0 if the context is valid. Error code otherwise
682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700683int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530686 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687 return -ENODEV;
688 }
689
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800690 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800691 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530692 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 return -EAGAIN;
694 }
695
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700696 if (cds_is_load_or_unload_in_progress())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697 return -EAGAIN;
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530698
699 if (hdd_ctx->start_modules_in_progress ||
700 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800701 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530702 (void *)_RET_IP_);
703 return -EAGAIN;
704 }
705
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530706 if (cds_is_driver_in_bad_state()) {
707 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
708 (void *)_RET_IP_, cds_get_driver_state());
709 return -ENODEV;
710 }
711
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800712 return 0;
713}
714
Dustin Brownf13b8c32017-05-19 17:23:08 -0700715int hdd_validate_adapter(hdd_adapter_t *adapter)
716{
717 if (!adapter) {
718 hdd_err("adapter is null");
719 return -EINVAL;
720 }
721
722 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
723 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
724 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
725 return -EINVAL;
726 }
727
728 if (!adapter->dev) {
729 hdd_err("adapter net_device is null");
730 return -EINVAL;
731 }
732
733 if (!(adapter->dev->flags & IFF_UP)) {
734 hdd_info("adapter net_device is not up");
735 return -EAGAIN;
736 }
737
738 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
739 hdd_info("adapter session is not open");
740 return -EAGAIN;
741 }
742
743 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
744 hdd_err("bad adapter session Id: %u", adapter->sessionId);
745 return -EINVAL;
746 }
747
748 return 0;
749}
750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530752 * wlan_hdd_validate_modules_state() - Check modules status
753 * @hdd_ctx: HDD context pointer
754 *
755 * Check's the driver module's state and returns true if the
756 * modules are enabled returns false if modules are closed.
757 *
758 * Return: True if modules are enabled or false.
759 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700760bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530761{
762 mutex_lock(&hdd_ctx->iface_change_lock);
763 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
764 mutex_unlock(&hdd_ctx->iface_change_lock);
765 hdd_notice("Modules not enabled, Present status: %d",
766 hdd_ctx->driver_status);
767 return false;
768 }
769 mutex_unlock(&hdd_ctx->iface_change_lock);
770 return true;
771}
772
773/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
775 * @hdd_adapter_t Hdd adapter.
776 *
777 * This function sets the IBSS power save config parameters to WMA
778 * which will send it to firmware if FW supports IBSS power save
779 * before vdev start.
780 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530781 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 * on failure.
783 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530784QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785{
786 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700787 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788
789 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700790 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530791 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 }
793
Naveen Rawat247a8682017-06-05 15:00:31 -0700794 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
796 hdd_ctx->config->ibssATIMWinSize,
797 VDEV_CMD);
798 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700799 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530800 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801 }
802
Naveen Rawat247a8682017-06-05 15:00:31 -0700803 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
805 hdd_ctx->config->isIbssPowerSaveAllowed,
806 VDEV_CMD);
807 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700808 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
809 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530810 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800811 }
812
Naveen Rawat247a8682017-06-05 15:00:31 -0700813 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
815 hdd_ctx->config->
816 isIbssPowerCollapseAllowed, VDEV_CMD);
817 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700818 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
819 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530820 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 }
822
Naveen Rawat247a8682017-06-05 15:00:31 -0700823 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
825 hdd_ctx->config->isIbssAwakeOnTxRx,
826 VDEV_CMD);
827 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700828 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530829 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 }
831
Naveen Rawat247a8682017-06-05 15:00:31 -0700832 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
834 hdd_ctx->config->ibssInactivityCount,
835 VDEV_CMD);
836 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700837 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530838 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 }
840
Naveen Rawat247a8682017-06-05 15:00:31 -0700841 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
843 hdd_ctx->config->ibssTxSpEndInactivityTime,
844 VDEV_CMD);
845 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700846 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
847 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530848 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800849 }
850
Naveen Rawat247a8682017-06-05 15:00:31 -0700851 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
853 hdd_ctx->config->ibssPsWarmupTime,
854 VDEV_CMD);
855 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700856 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
857 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530858 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 }
860
Naveen Rawat247a8682017-06-05 15:00:31 -0700861 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
863 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
864 VDEV_CMD);
865 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700866 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
867 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530868 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 }
870
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530871 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872}
873
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874#define INTF_MACADDR_MASK 0x7
875
876/**
877 * hdd_update_macaddr() - update mac address
878 * @config: hdd configuration
879 * @hw_macaddr: mac address
880 *
881 * Mac address for multiple virtual interface is found as following
882 * i) The mac address of the first interface is just the actual hw mac address.
883 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
884 * define the mac address for the remaining interfaces and locally
885 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
886 * supported virtual interfaces, right now this is 0x07 (meaning 8
887 * interface).
888 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
889 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
890 *
891 * Return: None
892 */
893void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530894 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895{
896 int8_t i;
897 uint8_t macaddr_b3, tmp_br3;
898
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530899 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530900 QDF_MAC_ADDR_SIZE);
901 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530902 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530903 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 macaddr_b3 = config->intfMacAddr[i].bytes[3];
905 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
906 INTF_MACADDR_MASK;
907 macaddr_b3 += tmp_br3;
908
909 /* XOR-ing bit-24 of the mac address. This will give enough
910 * mac address range before collision
911 */
912 macaddr_b3 ^= (1 << 7);
913
914 /* Set locally administered bit */
915 config->intfMacAddr[i].bytes[0] |= 0x02;
916 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800917 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 MAC_ADDRESS_STR, i,
919 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
920 }
921}
922
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700923static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 struct wma_tgt_services *cfg)
925{
926 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927
928 /* Set up UAPSD */
929 config->apUapsdEnabled &= cfg->uapsd;
930
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800931 /* 11AX mode support */
932 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
933 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
934 config->dot11Mode = eHDD_DOT11_MODE_11ac;
935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 /* 11AC mode support */
937 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
938 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
939 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940
941 /* ARP offload: override user setting if invalid */
942 config->fhostArpOffload &= cfg->arp_offload;
943
944#ifdef FEATURE_WLAN_SCAN_PNO
945 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800946 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947 if (cfg->pno_offload)
948 config->PnoOffload = true;
949#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950#ifdef FEATURE_WLAN_TDLS
951 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530952 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
953 cfg->en_tdls_offchan;
954 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
955 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700956 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700958 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961#ifdef WLAN_FEATURE_ROAM_OFFLOAD
962 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
963#endif
Will Huang496b36c2017-07-11 16:38:50 +0800964 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700965 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966
967}
968
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700969/**
970 * hdd_update_vdev_nss() - sets the vdev nss
971 * @hdd_ctx: HDD context
972 *
973 * Sets the Nss per vdev type based on INI
974 *
975 * Return: None
976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700977static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700978{
979 struct hdd_config *cfg_ini = hdd_ctx->config;
980 uint8_t max_supp_nss = 1;
981
Naveen Rawat10b1c152017-01-18 11:16:06 -0800982 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700983 max_supp_nss = 2;
984
985 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
986 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
987
988 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
989 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
990}
991
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530992/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +0530993 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
994 * @hdd_ctx: HDD context
995 *
996 * Updates wiphy vhtcap fields
997 *
998 * Return: None
999 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001000static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301001{
1002 struct ieee80211_supported_band *band_5g =
1003 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1004 uint32_t val;
1005
1006 if (!band_5g) {
1007 hdd_debug("5GHz band disabled, skipping capability population");
1008 return;
1009 }
1010
1011 val = hdd_ctx->config->txBFCsnValue;
1012 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1013
1014 val = NUM_OF_SOUNDING_DIMENSIONS;
1015 band_5g->vht_cap.cap |=
1016 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1017
1018 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1019 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1020}
1021
1022/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301023 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1024 * @hdd_ctx: HDD context
1025 *
1026 * Sets the DBS capability as per INI and firmware capability
1027 *
1028 * Return: None
1029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001030static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301031{
1032 struct hdd_config *cfg_ini = hdd_ctx->config;
1033 uint8_t hw_dbs_capable = 0;
1034
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001035 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1036 ((cfg_ini->dual_mac_feature_disable ==
1037 ENABLE_DBS_CXN_AND_SCAN) ||
1038 (cfg_ini->dual_mac_feature_disable ==
1039 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301040 hw_dbs_capable = 1;
1041
1042 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1043}
1044
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001045static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 struct wma_tgt_ht_cap *cfg)
1047{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301048 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049 uint32_t value, val32;
1050 uint16_t val16;
1051 struct hdd_config *pconfig = hdd_ctx->config;
1052 tSirMacHTCapabilityInfo *phtCapInfo;
1053 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1054 uint8_t enable_tx_stbc;
1055
1056 /* check and update RX STBC */
1057 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1058 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1059
1060 /* get the MPDU density */
1061 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1062
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301063 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001064 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 value = 0;
1066 }
1067
1068 /*
1069 * MPDU density:
1070 * override user's setting if value is larger
1071 * than the one supported by target
1072 */
1073 if (value > cfg->mpdu_density) {
1074 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1075 cfg->mpdu_density);
1076
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301077 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001078 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 }
1080
1081 /* get the HT capability info */
1082 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301083 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001084 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 return;
1086 }
1087 val16 = (uint16_t) val32;
1088 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1089
1090 /* Set the LDPC capability */
1091 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1092
1093 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1094 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1095
1096 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1097 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1098
1099 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1100 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1101
1102 enable_tx_stbc = pconfig->enableTxSTBC;
1103
1104 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1105 pconfig->enable2x2 = 1;
1106 } else {
1107 pconfig->enable2x2 = 0;
1108 enable_tx_stbc = 0;
1109
1110 /* 1x1 */
1111 /* Update Rx Highest Long GI data Rate */
1112 if (sme_cfg_set_int(hdd_ctx->hHal,
1113 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001114 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301115 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001116 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 }
1118
1119 /* Update Tx Highest Long GI data Rate */
1120 if (sme_cfg_set_int
1121 (hdd_ctx->hHal,
1122 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001123 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301124 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001125 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126 }
1127 }
1128 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1129 enable_tx_stbc = 0;
1130 phtCapInfo->txSTBC = enable_tx_stbc;
1131
1132 val32 = val16;
1133 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301134 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001135 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1137 value = SIZE_OF_SUPPORTED_MCS_SET;
1138 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301139 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001140 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141
1142 if (pconfig->enable2x2) {
1143 for (value = 0; value < cfg->num_rf_chains; value++)
1144 mcs_set[value] =
1145 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1146
1147 status =
1148 sme_cfg_set_str(hdd_ctx->hHal,
1149 WNI_CFG_SUPPORTED_MCS_SET,
1150 mcs_set,
1151 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301152 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001153 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 }
1155 }
1156#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1157}
1158
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001159static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 struct wma_tgt_vht_cap *cfg)
1161{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301162 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 uint32_t value = 0;
1164 struct hdd_config *pconfig = hdd_ctx->config;
1165 struct wiphy *wiphy = hdd_ctx->wiphy;
1166 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001167 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001168 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001169 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001170 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001171
Dustin Brown5e06bd32016-10-04 12:49:10 -07001172 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001173 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001174 return;
1175 }
1176
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001177 /* Get the current MPDU length */
1178 status =
1179 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1180 &value);
1181
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301182 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001183 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001184 value = 0;
1185 }
1186
1187 /*
1188 * VHT max MPDU length:
1189 * override if user configured value is too high
1190 * that the target cannot support
1191 */
1192 if (value > cfg->vht_max_mpdu) {
1193 status = sme_cfg_set_int(hdd_ctx->hHal,
1194 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1195 cfg->vht_max_mpdu);
1196
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001197 if (status == QDF_STATUS_E_FAILURE)
1198 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 }
1200
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001201 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1202 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1203
1204 if (pconfig->enable2x2)
1205 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1206
1207 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1208 QDF_STATUS_E_FAILURE) {
1209 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1210 }
1211
1212 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1213 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1214 if (pconfig->enable2x2)
1215 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1216
1217 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1218 QDF_STATUS_E_FAILURE) {
1219 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1220 }
1221
1222 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1223 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1224 if (pconfig->enable2x2)
1225 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1226
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001227 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001228 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1229
1230 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1231 QDF_STATUS_E_FAILURE) {
1232 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1233 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001235 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 &value);
1237
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301238 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001239 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240 value = 0;
1241 }
1242
jiad4a7a33c2017-08-08 15:32:24 +08001243 /* Set HW RX LDPC capability */
1244 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1245 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001246 status = sme_cfg_set_int(hdd_ctx->hHal,
1247 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001248 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001250 if (status == QDF_STATUS_E_FAILURE)
1251 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 }
1253
1254 /* Get current GI 80 value */
1255 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1256 &value);
1257
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301258 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001259 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 value = 0;
1261 }
1262
1263 /* set the Guard interval 80MHz */
1264 if (value && !cfg->vht_short_gi_80) {
1265 status = sme_cfg_set_int(hdd_ctx->hHal,
1266 WNI_CFG_VHT_SHORT_GI_80MHZ,
1267 cfg->vht_short_gi_80);
1268
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001269 if (status == QDF_STATUS_E_FAILURE)
1270 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 }
1272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273 /* Get VHT TX STBC cap */
1274 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001277 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 value = 0;
1279 }
1280
1281 /* VHT TX STBC cap */
1282 if (value && !cfg->vht_tx_stbc) {
1283 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1284 cfg->vht_tx_stbc);
1285
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001286 if (status == QDF_STATUS_E_FAILURE)
1287 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 }
1289
1290 /* Get VHT RX STBC cap */
1291 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1292
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301293 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001294 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001295 value = 0;
1296 }
1297
1298 /* VHT RX STBC cap */
1299 if (value && !cfg->vht_rx_stbc) {
1300 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1301 cfg->vht_rx_stbc);
1302
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001303 if (status == QDF_STATUS_E_FAILURE)
1304 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 }
1306
1307 /* Get VHT SU Beamformer cap */
1308 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1309 &value);
1310
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301311 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001312 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 value = 0;
1314 }
1315
1316 /* set VHT SU Beamformer cap */
1317 if (value && !cfg->vht_su_bformer) {
1318 status = sme_cfg_set_int(hdd_ctx->hHal,
1319 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1320 cfg->vht_su_bformer);
1321
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001322 if (status == QDF_STATUS_E_FAILURE)
1323 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324 }
1325
1326 /* check and update SU BEAMFORMEE capabality */
1327 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1328 pconfig->enableTxBF = cfg->vht_su_bformee;
1329
1330 status = sme_cfg_set_int(hdd_ctx->hHal,
1331 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1332 pconfig->enableTxBF);
1333
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001334 if (status == QDF_STATUS_E_FAILURE)
1335 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001336
1337 /* Get VHT MU Beamformer cap */
1338 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1339 &value);
1340
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301341 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001342 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 value = 0;
1344 }
1345
1346 /* set VHT MU Beamformer cap */
1347 if (value && !cfg->vht_mu_bformer) {
1348 status = sme_cfg_set_int(hdd_ctx->hHal,
1349 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1350 cfg->vht_mu_bformer);
1351
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001352 if (status == QDF_STATUS_E_FAILURE)
1353 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 }
1355
1356 /* Get VHT MU Beamformee cap */
1357 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1358 &value);
1359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301360 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001361 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 value = 0;
1363 }
1364
1365 /* set VHT MU Beamformee cap */
1366 if (value && !cfg->vht_mu_bformee) {
1367 status = sme_cfg_set_int(hdd_ctx->hHal,
1368 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1369 cfg->vht_mu_bformee);
1370
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001371 if (status == QDF_STATUS_E_FAILURE)
1372 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 }
1374
1375 /* Get VHT MAX AMPDU Len exp */
1376 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1377 &value);
1378
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301379 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001380 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 value = 0;
1382 }
1383
1384 /*
1385 * VHT max AMPDU len exp:
1386 * override if user configured value is too high
1387 * that the target cannot support.
1388 * Even though Rome publish ampdu_len=7, it can
1389 * only support 4 because of some h/w bug.
1390 */
1391
1392 if (value > cfg->vht_max_ampdu_len_exp) {
1393 status = sme_cfg_set_int(hdd_ctx->hHal,
1394 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1395 cfg->vht_max_ampdu_len_exp);
1396
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001397 if (status == QDF_STATUS_E_FAILURE)
1398 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 }
1400
1401 /* Get VHT TXOP PS CAP */
1402 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1403
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301404 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001405 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 value = 0;
1407 }
1408
1409 /* set VHT TXOP PS cap */
1410 if (value && !cfg->vht_txop_ps) {
1411 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1412 cfg->vht_txop_ps);
1413
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001414 if (status == QDF_STATUS_E_FAILURE)
1415 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416 }
1417
1418 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1419 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1420 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1421 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1422 else
1423 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1424
1425
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001426 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1427 status = sme_cfg_set_int(hdd_ctx->hHal,
1428 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1429 VHT_CAP_160_AND_80P80_SUPP);
1430 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001431 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 band_5g->vht_cap.cap |=
1433 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001434 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1435 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1436 status = sme_cfg_set_int(hdd_ctx->hHal,
1437 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1438 VHT_CAP_160_SUPP);
1439 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001440 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 band_5g->vht_cap.cap |=
1442 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001443 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1444 }
1445 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1446 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301447 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001448 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301449 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001450 &value);
1451 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301452 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001453 value = 0;
1454 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301455 /* set the Guard interval 160MHz */
1456 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001457 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301458 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1459 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001460
1461 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301462 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001463 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464
1465 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1466 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1467
1468 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1469 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1470 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1471 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1472
1473 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1474 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1475
1476 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1477 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1478 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1479 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1480 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1481 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1482
1483 band_5g->vht_cap.cap |=
1484 (cfg->vht_max_ampdu_len_exp <<
1485 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1486
1487 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1488 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1489 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1490 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1491 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1492 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1493 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1494 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1495
1496 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1497 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1498
1499}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001501/**
1502 * hdd_generate_macaddr_auto() - Auto-generate mac address
1503 * @hdd_ctx: Pointer to the HDD context
1504 *
1505 * Auto-generate mac address using device serial number.
1506 * Keep the first 3 bytes of OUI as before and replace
1507 * the last 3 bytes with the lower 3 bytes of serial number.
1508 *
1509 * Return: 0 for success
1510 * Non zero failure code for errors
1511 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001512static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001513{
1514 unsigned int serialno = 0;
1515 struct qdf_mac_addr mac_addr = {
1516 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1517 };
1518
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001519 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001520 if (serialno == 0)
1521 return -EINVAL;
1522
1523 serialno &= 0x00ffffff;
1524
1525 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1526 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1527 mac_addr.bytes[5] = serialno & 0xff;
1528
1529 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1530 return 0;
1531}
1532
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301533/**
1534 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1535 * configuration to cfg_ini in HDD
1536 * @hdd_ctx: Pointer to hdd_ctx
1537 * @cfg: target configuration
1538 *
1539 * Return: None
1540 */
1541#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001542static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301543 struct wma_tgt_cfg *cfg)
1544{
1545 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1546}
1547#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001548static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301549 struct wma_tgt_cfg *cfg)
1550{
1551}
1552#endif
1553
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554void hdd_update_tgt_cfg(void *context, void *param)
1555{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001556 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001557 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 struct wma_tgt_cfg *cfg = param;
1559 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001560 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301561 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301562
Yue Mae3e86ab2017-05-08 10:48:24 -07001563 /* Reuse same pdev for module start/stop or SSR */
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301564 if (((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1565 (hdd_get_conparam() == QDF_GLOBAL_MONITOR_MODE) ||
1566 !cds_is_driver_loading()) && (hdd_ctx->hdd_pdev != NULL)) {
1567 hdd_debug("Reuse pdev for module start/stop or SSR pdev_id = %u",
1568 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Yue Mae3e86ab2017-05-08 10:48:24 -07001569 /* Restore pdev to MAC/WMA contexts */
1570 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001571 } else {
1572 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1573 if (ret) {
1574 hdd_err("pdev creation fails!");
1575 QDF_BUG(0);
Ashish Kumar Dhanotiyafd758ec2017-08-04 12:03:18 +05301576 } else
1577 hdd_debug("New pdev has been created with pdev_id = %u",
1578 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301579 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001580
Naveen Rawat64e477e2016-05-20 10:34:56 -07001581 if (cds_cfg) {
1582 if (hdd_ctx->config->enable_sub_20_channel_width !=
1583 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1584 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1585 cds_cfg->sub_20_channel_width =
1586 WLAN_SUB_20_CH_WIDTH_NONE;
1587 } else {
1588 cds_cfg->sub_20_channel_width =
1589 hdd_ctx->config->enable_sub_20_channel_width;
1590 }
1591 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001592
1593 /* first store the INI band capability */
1594 temp_band_cap = hdd_ctx->config->nBandCapability;
1595
1596 hdd_ctx->config->nBandCapability = cfg->band_cap;
1597
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001598 /*
1599 * now overwrite the target band capability with INI
1600 * setting if INI setting is a subset
1601 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602
1603 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1604 (temp_band_cap != eCSR_BAND_ALL))
1605 hdd_ctx->config->nBandCapability = temp_band_cap;
1606 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1607 (temp_band_cap != eCSR_BAND_ALL) &&
1608 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001609 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 }
1611
Amar Singhal58b45ef2017-08-01 13:43:54 -07001612 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1613
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301614 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1616 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1617 }
1618
1619 /* This can be extended to other configurations like ht, vht cap... */
1620
Anurag Chouhanc5548422016-02-24 18:33:27 +05301621 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001623 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001625 static struct qdf_mac_addr default_mac_addr = {
1626 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1627 };
1628 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1629 &default_mac_addr)) {
1630 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1631 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1632 MAC_ADDRESS_STR,
1633 MAC_ADDR_ARRAY(hdd_ctx->config->
1634 intfMacAddr[0].bytes));
1635 } else {
1636 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1637 MAC_ADDRESS_STR,
1638 MAC_ADDR_ARRAY(hdd_ctx->config->
1639 intfMacAddr[0].bytes));
1640 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001641 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 }
1643
1644 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001645 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646
1647 hdd_ctx->max_intf_count = cfg->max_intf_count;
1648
Jeff Johnsonc875e242016-09-23 18:12:34 -07001649 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001650 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1653 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1654
1655 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1656
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001658 if (cfg->services.en_11ax) {
1659 hdd_info("11AX: 11ax is enabled - update HDD config");
1660 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1661 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001662
1663 hdd_update_vdev_nss(hdd_ctx);
1664
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301665 hdd_update_hw_dbs_capable(hdd_ctx);
1666
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001667 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001668 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001669 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001670 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001671
Nitesh Shahe50711f2017-04-26 16:30:45 +05301672 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1673 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1674 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001675 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001676 hdd_ctx->current_antenna_mode);
1677
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001678 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1679 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301680 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301681
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301682 if ((hdd_ctx->config->txBFCsnValue >
1683 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1684 !cfg->tx_bfee_8ss_enabled)
1685 hdd_ctx->config->txBFCsnValue =
1686 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1687
1688 if (sme_cfg_set_int(hdd_ctx->hHal,
1689 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1690 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1691 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1692
1693
1694 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1695 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1696 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301697
1698 /*
1699 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1700 */
1701 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301702 /*
1703 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1704 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1705 * configure the STA mode wow pattern.
1706 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301707 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301708 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301709
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301710 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1711
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001712 /* Configure NAN datapath features */
1713 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001714 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715}
1716
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001717bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1720 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301721 QDF_STATUS status;
Jeff Johnson87251032017-08-29 13:31:11 -07001722 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723
Arif Hussaincd151632017-02-11 16:57:19 -08001724 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
1725 hdd_info("skip tx block hdd_ctx=%p, disableDFSChSwitch=%d",
1726 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301727 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001728 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729
Arif Hussaincd151632017-02-11 16:57:19 -08001730 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1731 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1732 adapter = adapterNode->pAdapter;
1733 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1734
1735 if ((QDF_SAP_MODE == adapter->device_mode ||
1736 QDF_P2P_GO_MODE == adapter->device_mode) &&
1737 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1738 ap_ctx->operatingChannel))) {
1739 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1740 true;
1741 hdd_info("tx blocked for session: %d",
1742 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301743 }
Arif Hussaincd151632017-02-11 16:57:19 -08001744 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1745 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301747
1748 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750
1751/**
1752 * hdd_is_valid_mac_address() - validate MAC address
1753 * @pMacAddr: Pointer to the input MAC address
1754 *
1755 * This function validates whether the given MAC address is valid or not
1756 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1757 * where X is the hexa decimal digit character and separated by ':'
1758 * This algorithm works even if MAC address is not separated by ':'
1759 *
1760 * This code checks given input string mac contains exactly 12 hexadecimal
1761 * digits and a separator colon : appears in the input string only after
1762 * an even number of hex digits.
1763 *
1764 * Return: 1 for valid and 0 for invalid
1765 */
1766bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1767{
1768 int xdigit = 0;
1769 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771 while (*pMacAddr) {
1772 if (isxdigit(*pMacAddr)) {
1773 xdigit++;
1774 } else if (':' == *pMacAddr) {
1775 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1776 break;
1777
1778 ++separator;
1779 } else {
1780 /* Invalid MAC found */
1781 return 0;
1782 }
1783 ++pMacAddr;
1784 }
1785 return xdigit == 12 && (separator == 5 || separator == 0);
1786}
1787
1788/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301789 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1790 * @dev: Handle to struct net_device to be updated.
1791 *
1792 * Return: None
1793 */
1794static void hdd_mon_mode_ether_setup(struct net_device *dev)
1795{
1796 dev->header_ops = NULL;
1797 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1798 dev->hard_header_len = ETH_HLEN;
1799 dev->mtu = ETH_DATA_LEN;
1800 dev->addr_len = ETH_ALEN;
1801 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1802 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1803 dev->priv_flags |= IFF_TX_SKB_SHARING;
1804
1805 memset(dev->broadcast, 0xFF, ETH_ALEN);
1806}
1807
1808/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001809 * __hdd__mon_open() - HDD Open function
1810 * @dev: Pointer to net_device structure
1811 *
1812 * This is called in response to ifconfig up
1813 *
1814 * Return: 0 for success; non-zero for failure
1815 */
1816static int __hdd_mon_open(struct net_device *dev)
1817{
1818 int ret;
1819
1820 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301821 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001822 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001823
1824 if (!ret)
1825 ret = hdd_enable_monitor_mode(dev);
1826
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001827 return ret;
1828}
1829
1830/**
1831 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1832 * @dev: Pointer to net_device structure
1833 *
1834 * This is called in response to ifconfig up
1835 *
1836 * Return: 0 for success; non-zero for failure
1837 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001838static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001839{
1840 int ret;
1841
1842 cds_ssr_protect(__func__);
1843 ret = __hdd_mon_open(dev);
1844 cds_ssr_unprotect(__func__);
1845
1846 return ret;
1847}
1848
1849/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301850 * hdd_start_adapter() - Wrapper function for device specific adapter
1851 * @adapter: pointer to HDD adapter
1852 *
1853 * This function is called to start the device specific adapter for
1854 * the mode passed in the adapter's device_mode.
1855 *
1856 * Return: 0 for success; non-zero for failure
1857 */
1858int hdd_start_adapter(hdd_adapter_t *adapter)
1859{
1860
1861 int ret;
1862 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1863
1864 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001865 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301866
1867 switch (device_mode) {
1868 case QDF_P2P_CLIENT_MODE:
1869 case QDF_P2P_DEVICE_MODE:
1870 case QDF_OCB_MODE:
1871 case QDF_STA_MODE:
1872 case QDF_MONITOR_MODE:
1873 ret = hdd_start_station_adapter(adapter);
1874 if (ret)
1875 goto err_start_adapter;
1876 break;
1877 case QDF_P2P_GO_MODE:
1878 case QDF_SAP_MODE:
1879 ret = hdd_start_ap_adapter(adapter);
1880 if (ret)
1881 goto err_start_adapter;
1882 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301883 case QDF_IBSS_MODE:
1884 /*
1885 * For IBSS interface is initialized as part of
1886 * hdd_init_station_mode()
1887 */
1888 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301889 case QDF_FTM_MODE:
1890 ret = hdd_start_ftm_adapter(adapter);
1891 if (ret)
1892 goto err_start_adapter;
1893 break;
1894 default:
1895 hdd_err("Invalid session type %d", device_mode);
1896 QDF_ASSERT(0);
1897 goto err_start_adapter;
1898 }
1899 if (hdd_set_fw_params(adapter))
1900 hdd_err("Failed to set the FW params for the adapter!");
1901
1902 /*
1903 * Action frame registered in one adapter which will
1904 * applicable to all interfaces
1905 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301906 ret = wlan_hdd_cfg80211_register_frames(adapter);
1907 if (ret < 0) {
1908 hdd_err("Failed to register frames - ret %d", ret);
1909 goto err_start_adapter;
1910 }
1911
Arun Khandavallifae92942016-08-01 13:31:08 +05301912 EXIT();
1913 return 0;
1914err_start_adapter:
1915 return -EINVAL;
1916}
1917
1918/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301919 * hdd_enable_power_management() - API to Enable Power Management
1920 *
1921 * API invokes Bus Interface Layer power management functionality
1922 *
1923 * Return: None
1924 */
1925static void hdd_enable_power_management(void)
1926{
1927 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1928
1929 if (!hif_ctx) {
1930 hdd_err("Bus Interface Context is Invalid");
1931 return;
1932 }
1933
1934 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1935}
1936
1937/**
1938 * hdd_disable_power_management() - API to disable Power Management
1939 *
1940 * API disable Bus Interface Layer Power management functionality
1941 *
1942 * Return: None
1943 */
1944static void hdd_disable_power_management(void)
1945{
1946 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1947
1948 if (!hif_ctx) {
1949 hdd_err("Bus Interface Context is Invalid");
1950 return;
1951 }
1952
1953 hif_disable_power_management(hif_ctx);
1954}
1955
1956/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301957 * hdd_update_hw_sw_info() - API to update the HW/SW information
1958 *
1959 * API to update the HW and SW information in the driver
1960 *
1961 * Return: None
1962 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001963static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301964{
1965 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07001966 size_t target_hw_name_len;
1967 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301968
1969 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1970 if (!hif_sc) {
1971 hdd_err("HIF context is NULL");
1972 return;
1973 }
1974
1975 /*
1976 * target hw version/revision would only be retrieved after firmware
1977 * download
1978 */
Dustin Brown6f17a022017-07-19 13:40:55 -07001979 hif_get_hw_info(hif_sc,
1980 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301981 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07001982 &target_hw_name);
1983
1984 if (hdd_ctx->target_hw_name)
1985 qdf_mem_free(hdd_ctx->target_hw_name);
1986
1987 target_hw_name_len = strlen(target_hw_name) + 1;
1988 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
1989 if (hdd_ctx->target_hw_name)
1990 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
1991 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301992
1993 /* Get the wlan hw/fw version */
1994 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301995}
1996
1997/**
gbian62edd7e2017-03-07 13:12:13 +08001998 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1999 * @hdd_ctx: Pointer to hdd context
2000 *
2001 * Return: none
2002 */
2003static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002004hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002005{
2006 uint8_t num_entries = 0;
2007 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2008 uint8_t *tx_sched_wrr_ac;
2009 int i;
2010 cds_context_type *cds_ctx;
2011
2012 if (NULL == hdd_ctx)
2013 return;
2014
2015 if (NULL == hdd_ctx->config) {
2016 /* Do nothing if hdd_ctx is invalid */
2017 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2018 return;
2019 }
2020
2021 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2022
2023 if (!cds_ctx) {
2024 hdd_err("Invalid CDS Context");
2025 return;
2026 }
2027
2028 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2029 switch (i) {
2030 case OL_TX_WMM_AC_BE:
2031 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2032 break;
2033 case OL_TX_WMM_AC_BK:
2034 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2035 break;
2036 case OL_TX_WMM_AC_VI:
2037 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2038 break;
2039 case OL_TX_WMM_AC_VO:
2040 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2041 break;
2042 default:
2043 tx_sched_wrr_ac = NULL;
2044 break;
2045 }
2046
2047 hdd_string_to_u8_array(tx_sched_wrr_ac,
2048 tx_sched_wrr_param,
2049 &num_entries,
2050 sizeof(tx_sched_wrr_param));
2051
2052 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2053 cds_ctx->ac_specs[i].wrr_skip_weight =
2054 tx_sched_wrr_param[0];
2055 cds_ctx->ac_specs[i].credit_threshold =
2056 tx_sched_wrr_param[1];
2057 cds_ctx->ac_specs[i].send_limit =
2058 tx_sched_wrr_param[2];
2059 cds_ctx->ac_specs[i].credit_reserve =
2060 tx_sched_wrr_param[3];
2061 cds_ctx->ac_specs[i].discard_weight =
2062 tx_sched_wrr_param[4];
2063 }
2064
2065 num_entries = 0;
2066 }
2067}
2068
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002069#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002070static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2071 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2072{
2073 hdd_adapter_t *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002074 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002075
2076 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2077 if (!adapter) {
2078 hdd_err("Adapter is NULL");
2079 return PM_MAX_NUM_OF_MODE;
2080 }
2081
2082 return policy_mgr_convert_device_mode_to_qdf_type(
2083 adapter->device_mode);
2084}
2085
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002086static void hdd_register_policy_manager_callback(
2087 struct wlan_objmgr_psoc *psoc)
2088{
2089 struct policy_mgr_hdd_cbacks hdd_cbacks;
2090 hdd_cbacks.sap_restart_chan_switch_cb =
2091 sap_restart_chan_switch_cb;
2092 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2093 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002094 hdd_cbacks.get_mode_for_non_connected_vdev =
2095 wlan_hdd_get_mode_for_non_connected_vdev;
2096
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002097 if (QDF_STATUS_SUCCESS !=
2098 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2099 hdd_err("HDD callback registration with policy manager failed");
2100 }
2101}
2102#else
2103static void hdd_register_policy_manager_callback(
2104 struct wlan_objmgr_psoc *psoc)
2105{
2106}
2107#endif
2108
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002109#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002110static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002111{
2112 struct nan_callbacks cb_obj = {0};
2113
2114 cb_obj.ndi_open = hdd_ndi_open;
2115 cb_obj.ndi_close = hdd_ndi_close;
2116 cb_obj.ndi_start = hdd_ndi_start;
2117 cb_obj.ndi_delete = hdd_ndi_delete;
2118 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2119 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2120
Naveen Rawat37f62c82017-03-26 22:24:43 -07002121 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2122 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002123 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002124
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002125 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2126}
2127#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002128static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002129{
2130}
2131#endif
2132
gbian62edd7e2017-03-07 13:12:13 +08002133/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302134 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2135 * @hdd_ctx: HDD context
2136 * @adapter: HDD adapter
2137 * @reinit: flag to indicate from SSR or normal path
2138 *
2139 * This function maintains the driver state machine it will be invoked from
2140 * startup, reinit and change interface. Depending on the driver state shall
2141 * perform the opening of the modules.
2142 *
2143 * Return: 0 for success; non-zero for failure
2144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002145int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302146 bool reinit)
2147{
2148 int ret;
2149 qdf_device_t qdf_dev;
2150 QDF_STATUS status;
2151 p_cds_contextType p_cds_context;
2152 bool unint = false;
2153 void *hif_ctx;
2154
2155 ENTER();
2156
2157 p_cds_context = cds_get_global_context();
2158 if (!p_cds_context) {
2159 hdd_err("Global Context is NULL");
2160 QDF_ASSERT(0);
2161 return -EINVAL;
2162 }
2163
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002164 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302165 hdd_ctx->driver_status, reinit);
2166
2167 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2168 if (!qdf_dev) {
2169 hdd_err("QDF Device Context is Invalid return");
2170 return -EINVAL;
2171 }
2172
2173 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302174 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302175
2176 if (QDF_TIMER_STATE_RUNNING ==
2177 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2178
2179 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002180 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302181 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2182 }
2183
2184 switch (hdd_ctx->driver_status) {
2185 case DRIVER_MODULES_UNINITIALIZED:
2186 unint = true;
2187 /* Fall through dont add break here */
2188 case DRIVER_MODULES_CLOSED:
2189 if (!reinit && !unint) {
2190 ret = pld_power_on(qdf_dev->dev);
2191 if (ret) {
2192 hdd_err("Failed to Powerup the device: %d", ret);
2193 goto release_lock;
2194 }
2195 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002196
2197 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2198 hdd_ctx->config->enable_fw_log);
2199
Arun Khandavallifae92942016-08-01 13:31:08 +05302200 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2201 qdf_dev->bus_type,
2202 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2203 HIF_ENABLE_TYPE_PROBE);
2204 if (ret) {
2205 hdd_err("Failed to open hif: %d", ret);
2206 goto power_down;
2207 }
2208
2209 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302210 if (!hif_ctx) {
2211 hdd_err("hif context is null!!");
2212 goto power_down;
2213 }
2214
Arun Khandavallifae92942016-08-01 13:31:08 +05302215 status = ol_cds_init(qdf_dev, hif_ctx);
2216 if (status != QDF_STATUS_SUCCESS) {
2217 hdd_err("No Memory to Create BMI Context :%d", status);
2218 goto hif_close;
2219 }
2220
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002221 ret = hdd_update_config(hdd_ctx);
2222 if (ret) {
2223 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302224 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002225 }
2226
gbian62edd7e2017-03-07 13:12:13 +08002227 hdd_update_cds_ac_specs_params(hdd_ctx);
2228
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302229 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302230 if (!QDF_IS_STATUS_SUCCESS(status)) {
2231 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302232 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302233 }
2234
Mukul Sharma9d797a02017-01-05 20:26:03 +05302235 /* initalize components configurations after psoc open */
2236 ret = hdd_update_components_config(hdd_ctx);
2237 if (ret) {
2238 hdd_err("Failed to update components configs :%d",
2239 ret);
2240 goto close;
2241 }
2242
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002243 /*
2244 * NAN compoenet requires certian operations like, open adapter,
2245 * close adapter, etc. to be initiated by HDD, for those
2246 * register HDD callbacks with UMAC's NAN componenet.
2247 */
2248 hdd_nan_register_callbacks(hdd_ctx);
2249
Arun Khandavallifae92942016-08-01 13:31:08 +05302250 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2251
2252 status = cds_pre_enable(hdd_ctx->pcds_context);
2253 if (!QDF_IS_STATUS_SUCCESS(status)) {
2254 hdd_err("Failed to pre-enable CDS: %d", status);
2255 goto close;
2256 }
2257
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002258 hdd_register_policy_manager_callback(
2259 hdd_ctx->hdd_psoc);
2260
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302261 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302262 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302263
Arun Khandavallifae92942016-08-01 13:31:08 +05302264 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2265 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2266 hdd_ftm_mc_process_msg);
2267 break;
2268 }
2269 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002270 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302271 break;
2272 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302273
2274 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002275 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2276 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002277 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002278 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302279 }
2280
Arun Khandavallifae92942016-08-01 13:31:08 +05302281 /* Fall through dont add break here */
2282 case DRIVER_MODULES_OPENED:
2283 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002284 hdd_alert("adapter is Null");
2285 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302286 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302287 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2288 hdd_err("in ftm mode, no need to configure cds modules");
2289 break;
2290 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302291 if (hdd_configure_cds(hdd_ctx, adapter)) {
2292 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002293 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302294 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302295 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302296 hdd_info("Driver Modules Successfully Enabled");
2297 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2298 break;
2299 case DRIVER_MODULES_ENABLED:
2300 hdd_info("Driver modules already Enabled");
2301 break;
2302 default:
2303 hdd_err("WLAN start invoked in wrong state! :%d\n",
2304 hdd_ctx->driver_status);
2305 goto release_lock;
2306 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302307 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302308 mutex_unlock(&hdd_ctx->iface_change_lock);
2309 EXIT();
2310 return 0;
2311
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002312post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002313 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002314
Arun Khandavallifae92942016-08-01 13:31:08 +05302315close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002316 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302317 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302318
2319ol_cds_free:
2320 ol_cds_free();
2321
2322hif_close:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302323 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302324power_down:
2325 if (!reinit && !unint)
2326 pld_power_off(qdf_dev->dev);
2327release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302328 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302329 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302330 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002331
Arun Khandavallifae92942016-08-01 13:31:08 +05302332 return -EINVAL;
2333}
2334
Naveen Rawat910726a2017-03-06 11:42:51 -08002335#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002336static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002337{
2338 int ret = os_if_wifi_pos_register_nl();
2339
2340 if (ret)
2341 hdd_err("os_if_wifi_pos_register_nl failed");
2342
2343 return ret;
2344}
2345
2346static int hdd_deactivate_wifi_pos(void)
2347{
2348 int ret = os_if_wifi_pos_deregister_nl();
2349
2350 if (ret)
2351 hdd_err("os_if_wifi_pos_deregister_nl failed");
2352
2353 return ret;
2354}
2355
2356/**
2357 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2358 * @hdd_ctx: hdd context
2359 *
2360 * Return: status of operation
2361 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002362static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002363{
2364 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2365 struct hdd_config *cfg = hdd_ctx->config;
2366
2367 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2368 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2369 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2370 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2371 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2372 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2373 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2374 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2375}
2376#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002377static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002378{
2379 return oem_activate_service(hdd_ctx);
2380}
2381
2382static int hdd_deactivate_wifi_pos(void)
2383{
2384 return 0;
2385}
2386
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002387static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002388{
2389}
2390#endif
2391
Arun Khandavallifae92942016-08-01 13:31:08 +05302392/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002393 * __hdd_open() - HDD Open function
2394 * @dev: Pointer to net_device structure
2395 *
2396 * This is called in response to ifconfig up
2397 *
2398 * Return: 0 for success; non-zero for failure
2399 */
2400static int __hdd_open(struct net_device *dev)
2401{
2402 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002403 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 int ret;
2405
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002406 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302407 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302408 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002409
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302410 /* Nothing to be done if device is unloading */
2411 if (cds_is_driver_unloading()) {
2412 hdd_err("Driver is unloading can not open the hdd");
2413 return -EBUSY;
2414 }
2415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302417 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002420
Arun Khandavallifae92942016-08-01 13:31:08 +05302421 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2422 if (ret) {
2423 hdd_err("Failed to start WLAN modules return");
2424 return -ret;
2425 }
2426
2427
2428 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2429 ret = hdd_start_adapter(adapter);
2430 if (ret) {
2431 hdd_err("Failed to start adapter :%d",
2432 adapter->device_mode);
2433 return ret;
2434 }
2435 }
2436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002437 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2438 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002439 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002440 /* Enable TX queues only when we are connected */
2441 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302442 WLAN_START_ALL_NETIF_QUEUE,
2443 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002444 }
2445
Naveen Rawat286def52016-09-23 15:38:02 -07002446 /* Enable carrier and transmit queues for NDI */
2447 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002448 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002449 wlan_hdd_netif_queue_control(adapter,
2450 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2451 WLAN_CONTROL_PATH);
2452 }
2453
Naveen Rawat910726a2017-03-06 11:42:51 -08002454 hdd_populate_wifi_pos_cfg(hdd_ctx);
2455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002456 return ret;
2457}
2458
Arun Khandavallifae92942016-08-01 13:31:08 +05302459
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002460/**
2461 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2462 * @dev: Pointer to net_device structure
2463 *
2464 * This is called in response to ifconfig up
2465 *
2466 * Return: 0 for success; non-zero for failure
2467 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002468static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002469{
2470 int ret;
2471
2472 cds_ssr_protect(__func__);
2473 ret = __hdd_open(dev);
2474 cds_ssr_unprotect(__func__);
2475
2476 return ret;
2477}
2478
2479/**
2480 * __hdd_stop() - HDD stop function
2481 * @dev: Pointer to net_device structure
2482 *
2483 * This is called in response to ifconfig down
2484 *
2485 * Return: 0 for success; non-zero for failure
2486 */
2487static int __hdd_stop(struct net_device *dev)
2488{
2489 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002490 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 int ret;
2492
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002493 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002494
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302495 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002496 adapter->sessionId, adapter->device_mode));
2497
2498 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302499 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002500 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002501
2502 /* Nothing to be done if the interface is not opened */
2503 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002504 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002505 return -ENODEV;
2506 }
2507
2508 /* Make sure the interface is marked as closed */
2509 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302510
2511 hdd_debug("Disabling Auto Power save timer");
2512 sme_ps_disable_auto_ps_timer(
2513 WLAN_HDD_GET_HAL_CTX(adapter),
2514 adapter->sessionId);
2515
2516 /*
2517 * Disable TX on the interface, after this hard_start_xmit() will not
2518 * be called on that interface
2519 */
2520 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302521 wlan_hdd_netif_queue_control(adapter,
2522 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2523 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002524
2525 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002526 * NAN data interface is different in some sense. The traffic on NDI is
2527 * bursty in nature and depends on the need to transfer. The service
2528 * layer may down the interface after the usage and up again when
2529 * required. In some sense, the NDI is expected to be available
2530 * (like SAP) iface until NDI delete request is issued by the service
2531 * layer. Skip BSS termination and adapter deletion for NAN Data
2532 * interface (NDI).
2533 */
2534 if (WLAN_HDD_IS_NDI(adapter))
2535 return 0;
2536
2537 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002538 * The interface is marked as down for outside world (aka kernel)
2539 * But the driver is pretty much alive inside. The driver needs to
2540 * tear down the existing connection on the netdev (session)
2541 * cleanup the data pipes and wait until the control plane is stabilized
2542 * for this interface. The call also needs to wait until the above
2543 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002544 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002545 * That is intentional to be able to scan if it is a STA/P2P interface
2546 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302547 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548
2549 /* DeInit the adapter. This ensures datapath cleanup as well */
2550 hdd_deinit_adapter(hdd_ctx, adapter, true);
2551
Arun Khandavallifae92942016-08-01 13:31:08 +05302552
2553 /*
2554 * Find if any iface is up. If any iface is up then can't put device to
2555 * sleep/power save mode
2556 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302557 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002558 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302559 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302560 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302561 }
2562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002563 EXIT();
2564 return 0;
2565}
2566
2567/**
2568 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2569 * @dev: pointer to net_device structure
2570 *
2571 * This is called in response to ifconfig down
2572 *
2573 * Return: 0 for success and error number for failure
2574 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002575static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002576{
2577 int ret;
2578
2579 cds_ssr_protect(__func__);
2580 ret = __hdd_stop(dev);
2581 cds_ssr_unprotect(__func__);
2582
2583 return ret;
2584}
2585
2586/**
2587 * __hdd_uninit() - HDD uninit function
2588 * @dev: Pointer to net_device structure
2589 *
2590 * This is called during the netdev unregister to uninitialize all data
2591 * associated with the device
2592 *
2593 * Return: None
2594 */
2595static void __hdd_uninit(struct net_device *dev)
2596{
2597 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2598
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002599 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600
2601 do {
2602 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002603 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002604 break;
2605 }
2606
2607 if (NULL == adapter->pHddCtx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002608 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 break;
2610 }
2611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002612 if (dev != adapter->dev)
2613 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614
2615 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2616
2617 /* after uninit our adapter structure will no longer be valid */
2618 adapter->dev = NULL;
2619 adapter->magic = 0;
2620 } while (0);
2621
2622 EXIT();
2623}
2624
2625/**
2626 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2627 * @dev: pointer to net_device structure
2628 *
2629 * This is called during the netdev unregister to uninitialize all data
2630 * associated with the device
2631 *
2632 * Return: none
2633 */
2634static void hdd_uninit(struct net_device *dev)
2635{
2636 cds_ssr_protect(__func__);
2637 __hdd_uninit(dev);
2638 cds_ssr_unprotect(__func__);
2639}
2640
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002641static int hdd_open_cesium_nl_sock(void)
2642{
2643#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2644 struct netlink_kernel_cfg cfg = {
2645 .groups = WLAN_NLINK_MCAST_GRP_ID,
2646 .input = NULL
2647 };
2648#endif
2649 int ret = 0;
2650
2651#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2652 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2653#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2654 THIS_MODULE,
2655#endif
2656 &cfg);
2657#else
2658 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2659 WLAN_NLINK_MCAST_GRP_ID,
2660 NULL, NULL, THIS_MODULE);
2661#endif
2662
2663 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002664 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002665 ret = -ECONNREFUSED;
2666 }
2667
2668 return ret;
2669}
2670
2671static void hdd_close_cesium_nl_sock(void)
2672{
2673 if (NULL != cesium_nl_srv_sock) {
2674 netlink_kernel_release(cesium_nl_srv_sock);
2675 cesium_nl_srv_sock = NULL;
2676 }
2677}
2678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679/**
2680 * __hdd_set_mac_address() - set the user specified mac address
2681 * @dev: Pointer to the net device.
2682 * @addr: Pointer to the sockaddr.
2683 *
2684 * This function sets the user specified mac address using
2685 * the command ifconfig wlanX hw ether <mac adress>.
2686 *
2687 * Return: 0 for success, non zero for failure
2688 */
2689static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2690{
2691 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002692 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302694 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 int ret;
2696
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002697 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698
2699 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2700 ret = wlan_hdd_validate_context(hdd_ctx);
2701 if (0 != ret)
2702 return ret;
2703
2704 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2705 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2706
2707 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302708 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709}
2710
2711/**
2712 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2713 * function from SSR
2714 * @dev: pointer to net_device structure
2715 * @addr: Pointer to the sockaddr
2716 *
2717 * This function sets the user specified mac address using
2718 * the command ifconfig wlanX hw ether <mac adress>.
2719 *
2720 * Return: 0 for success.
2721 */
2722static int hdd_set_mac_address(struct net_device *dev, void *addr)
2723{
2724 int ret;
2725
2726 cds_ssr_protect(__func__);
2727 ret = __hdd_set_mac_address(dev, addr);
2728 cds_ssr_unprotect(__func__);
2729
2730 return ret;
2731}
2732
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002733uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734{
2735 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002736
Anurag Chouhan6d760662016-02-20 16:05:43 +05302737 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2739 break;
2740 }
2741
Anurag Chouhan6d760662016-02-20 16:05:43 +05302742 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 return NULL;
2744
2745 hdd_ctx->config->intfAddrMask |= (1 << i);
2746 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2747}
2748
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002749void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002750{
2751 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002752
Anurag Chouhan6d760662016-02-20 16:05:43 +05302753 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754 if (!memcmp(releaseAddr,
2755 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2756 6)) {
2757 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2758 break;
2759 }
2760 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761}
2762
2763#ifdef WLAN_FEATURE_PACKET_FILTERING
2764/**
2765 * __hdd_set_multicast_list() - set the multicast address list
2766 * @dev: Pointer to the WLAN device.
2767 * @skb: Pointer to OS packet (sk_buff).
2768 *
2769 * This funciton sets the multicast address list.
2770 *
2771 * Return: None
2772 */
2773static void __hdd_set_multicast_list(struct net_device *dev)
2774{
2775 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776 int i = 0, status;
2777 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002778 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302779 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2780 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2781 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002783 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302784 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302785 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302786
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302788 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302789 goto out;
2790
Dustin Brownc788acb2017-08-01 17:43:51 -07002791 status = hdd_validate_adapter(adapter);
2792 if (status)
2793 goto out;
2794
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302795 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2796 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002797 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302798 goto out;
2799 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002800
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302801 /* Delete already configured multicast address list */
2802 if (adapter->mc_addr_list.mc_cnt > 0) {
2803 hdd_info("clear previously configured MC address list");
2804 hdd_disable_and_flush_mc_addr_list(adapter,
2805 pmo_mc_list_change_notify);
2806 }
2807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002808 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002809 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302810 hdd_disable_and_flush_mc_addr_list(adapter,
2811 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002812 } else {
2813 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302814 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002815 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302816 pmo_ucfg_max_mc_addr_supported(psoc));
2817 hdd_disable_and_flush_mc_addr_list(adapter,
2818 pmo_mc_list_change_notify);
2819 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002822 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302823 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824 if (i == mc_count)
2825 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302826 memset(&(mc_list_request->mc_addr[i].bytes),
2827 0, ETH_ALEN);
2828 memcpy(&(mc_list_request->mc_addr[i].bytes),
2829 ha->addr, ETH_ALEN);
2830 hdd_info("mlist[%d] = %pM", i,
2831 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 i++;
2833 }
2834 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302835
2836 mc_list_request->psoc = psoc;
2837 mc_list_request->vdev_id = adapter->sessionId;
2838 mc_list_request->count = mc_count;
2839 status = hdd_cache_mc_addr_list(mc_list_request);
2840 if (status == 0) {
2841 hdd_enable_mc_addr_filtering(adapter,
2842 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302844 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302846out:
2847 if (mc_list_request)
2848 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302849 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850}
2851
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853/**
2854 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2855 * @dev: pointer to net_device
2856 *
2857 * Return: none
2858 */
2859static void hdd_set_multicast_list(struct net_device *dev)
2860{
2861 cds_ssr_protect(__func__);
2862 __hdd_set_multicast_list(dev);
2863 cds_ssr_unprotect(__func__);
2864}
2865#endif
2866
2867/**
2868 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2869 * @dev: Pointer to the WLAN device.
2870 * @skb: Pointer to OS packet (sk_buff).
2871 *
2872 * This function is registered with the Linux OS for network
2873 * core to decide which queue to use first.
2874 *
2875 * Return: ac, Queue Index/access category corresponding to UP in IP header
2876 */
2877static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2878#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2879 , void *accel_priv
2880#endif
2881#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2882 , select_queue_fallback_t fallback
2883#endif
2884)
2885{
2886 return hdd_wmm_select_queue(dev, skb);
2887}
2888
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002889static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002890 .ndo_open = hdd_open,
2891 .ndo_stop = hdd_stop,
2892 .ndo_uninit = hdd_uninit,
2893 .ndo_start_xmit = hdd_hard_start_xmit,
2894 .ndo_tx_timeout = hdd_tx_timeout,
2895 .ndo_get_stats = hdd_get_stats,
2896 .ndo_do_ioctl = hdd_ioctl,
2897 .ndo_set_mac_address = hdd_set_mac_address,
2898 .ndo_select_queue = hdd_select_queue,
2899#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901#endif
2902};
2903
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002904/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002905static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002906 .ndo_open = hdd_mon_open,
2907 .ndo_stop = hdd_stop,
2908 .ndo_get_stats = hdd_get_stats,
2909};
2910
2911/**
2912 * hdd_set_station_ops() - update net_device ops for monitor mode
2913 * @pWlanDev: Handle to struct net_device to be updated.
2914 * Return: None
2915 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916void hdd_set_station_ops(struct net_device *pWlanDev)
2917{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002918 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2919 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2920 else
2921 pWlanDev->netdev_ops = &wlan_drv_ops;
2922}
2923
Komal Seelama89be8d2016-09-29 11:09:26 +05302924#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302925/**
2926 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2927 * @hdd_ctx: HDD context
2928 *
2929 * Return: None
2930 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002931static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302932{
2933 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2934
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002935 qdf_runtime_lock_init(&ctx->roc);
2936 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05302937}
2938
2939/**
2940 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2941 * @hdd_ctx: HDD Context
2942 *
2943 * Return: None
2944 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002945static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302946{
2947 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2948
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002949 qdf_runtime_lock_deinit(&ctx->roc);
2950 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302951
2952 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302953}
2954
Komal Seelama89be8d2016-09-29 11:09:26 +05302955static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2956{
2957 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2958
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002959 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302960}
2961
2962static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2963{
2964 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2965
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002966 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302967}
2968#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002969static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
2970static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302971static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2972static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2973#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002974/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002975 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2976 * @hdd_ctx: global hdd context
2977 * @macAddr: mac address to assign to the interface
2978 * @name: User-visible name of the interface
2979 *
2980 * hdd adapter pointer would point to the netdev->priv space, this function
2981 * would retrive the pointer, and setup the hdd adapter configuration.
2982 *
2983 * Return: the pointer to hdd adapter, otherwise NULL
2984 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002985static hdd_adapter_t *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002987 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 const char *name)
2989{
2990 struct net_device *pWlanDev = NULL;
2991 hdd_adapter_t *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002992 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993 /*
2994 * cfg80211 initialization and registration....
2995 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002996 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2997#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2998 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002999#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003000 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3001 hdd_mon_mode_ether_setup : ether_setup),
3002 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003003
3004 if (pWlanDev != NULL) {
3005
3006 /* Save the pointer to the net_device in the HDD adapter */
3007 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
3008
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303009 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303010 sta_ctx = &adapter->sessionCtx.station;
3011 qdf_mem_set(sta_ctx->conn_info.staId,
3012 sizeof(sta_ctx->conn_info.staId),
3013 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 adapter->dev = pWlanDev;
3015 adapter->pHddCtx = hdd_ctx;
3016 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303017 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018
3019 init_completion(&adapter->session_open_comp_var);
3020 init_completion(&adapter->session_close_comp_var);
3021 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303022 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023 init_completion(&adapter->linkup_event_var);
3024 init_completion(&adapter->cancel_rem_on_chan_var);
3025 init_completion(&adapter->rem_on_chan_ready_event);
3026 init_completion(&adapter->sta_authorized_event);
3027 init_completion(&adapter->offchannel_tx_event);
3028 init_completion(&adapter->tx_action_cnf_event);
3029#ifdef FEATURE_WLAN_TDLS
3030 init_completion(&adapter->tdls_add_station_comp);
3031 init_completion(&adapter->tdls_del_station_comp);
3032 init_completion(&adapter->tdls_mgmt_comp);
3033 init_completion(&adapter->tdls_link_establish_req_comp);
3034#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003035 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003036 init_completion(&adapter->change_country_code);
3037
3038
3039 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303040 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003041
3042 adapter->offloads_configured = false;
3043 adapter->isLinkUpSvcNeeded = false;
3044 adapter->higherDtimTransition = true;
3045 /* Init the net_device structure */
3046 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3047
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303048 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303050 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051 sizeof(tSirMacAddr));
3052 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053
3054 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3055 pWlanDev->features |=
3056 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3057 pWlanDev->features |= NETIF_F_RXCSUM;
3058
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003059 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3060
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003061 hdd_set_station_ops(adapter->dev);
3062
3063 pWlanDev->destructor = free_netdev;
3064 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003065 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003066 adapter->wdev.wiphy = hdd_ctx->wiphy;
3067 adapter->wdev.netdev = pWlanDev;
3068 /* set pWlanDev's parent to underlying device */
3069 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3070 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303071 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003072 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303073 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 }
3075
3076 return adapter;
3077}
3078
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003079static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003081 struct net_device *dev = adapter->dev;
3082 int ret;
3083
3084 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003086 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003087 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3088
3089 ret = dev_alloc_name(dev, dev->name);
3090 if (ret < 0) {
3091 hdd_err(
3092 "unable to get dev name: %s, err = 0x%x",
3093 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303094 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 }
3096 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003097
3098 ret = register_netdevice(dev);
3099 if (ret) {
3100 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3101 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303102 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103 }
3104 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003105 ret = register_netdev(dev);
3106 if (ret) {
3107 hdd_err("register_netdev(%s) failed, err = 0x%x",
3108 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303109 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 }
3111 }
3112 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3113
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003114 EXIT();
3115
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303116 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117}
3118
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003119QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120{
3121 hdd_adapter_t *adapter = pContext;
3122
3123 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003124 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303125 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126 }
3127
3128 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003129 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303130 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131 }
3132
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003133 /*
3134 * For NAN Data interface, the close session results in the final
3135 * indication to the userspace
3136 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003137 if (adapter->device_mode == QDF_NDI_MODE)
3138 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003139
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142 /*
3143 * We can be blocked while waiting for scheduled work to be
3144 * flushed, and the adapter structure can potentially be freed, in
3145 * which case the magic will have been reset. So make sure the
3146 * magic is still good, and hence the adapter structure is still
3147 * valid, before signaling completion
3148 */
3149 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3150 complete(&adapter->session_close_comp_var);
3151
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303152 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153}
3154
Krunal Soni8c37e322016-02-03 16:08:37 -08003155/**
3156 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3157 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003158 *
3159 * This routine will check the mode of adapter and if it is required then it
3160 * will initialize the TDLS operations
3161 *
3162 * Return: QDF_STATUS
3163 */
3164#ifdef FEATURE_WLAN_TDLS
Dustin Brownd28772b2017-03-17 14:16:07 -07003165static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003166{
Dustin Brownd28772b2017-03-17 14:16:07 -07003167 if (adapter->device_mode == QDF_IBSS_MODE)
3168 return QDF_STATUS_SUCCESS;
3169
3170 if (wlan_hdd_tdls_init(adapter)) {
3171 hdd_err("wlan_hdd_tdls_init failed");
3172 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003173 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003174 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3175
Krunal Soni8c37e322016-02-03 16:08:37 -08003176 return QDF_STATUS_SUCCESS;
3177}
3178#else
Dustin Brownd28772b2017-03-17 14:16:07 -07003179static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003180{
3181 return QDF_STATUS_SUCCESS;
3182}
3183#endif
3184
Dustin Brownd28772b2017-03-17 14:16:07 -07003185int hdd_vdev_ready(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186{
Dustin Brownd28772b2017-03-17 14:16:07 -07003187 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188
Dustin Brownd28772b2017-03-17 14:16:07 -07003189 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003190 if (QDF_IS_STATUS_ERROR(status))
3191 return qdf_status_to_os_return(status);
3192
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003193 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003194 if (QDF_IS_STATUS_ERROR(status))
3195 return qdf_status_to_os_return(status);
3196
3197 if (wma_capability_enhanced_mcast_filter())
3198 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3199 else
3200 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003201
3202 return qdf_status_to_os_return(status);
3203}
3204
3205int hdd_vdev_destroy(hdd_adapter_t *adapter)
3206{
3207 QDF_STATUS status;
3208 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003209 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003210 unsigned long rc;
3211
3212 hdd_info("destroying vdev %d", adapter->sessionId);
3213
3214 /* vdev created sanity check */
3215 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3216 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3217 return -EINVAL;
3218 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003219 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003220 /*
3221 * In SSR case, there is no need to destroy vdev in firmware since
3222 * it has already asserted. vdev can be released directly.
3223 */
3224 if (cds_is_driver_recovering())
3225 goto release_vdev;
3226
Dustin Brownd28772b2017-03-17 14:16:07 -07003227 /* close sme session (destroy vdev in firmware via legacy API) */
3228 INIT_COMPLETION(adapter->session_close_comp_var);
3229 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3230 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3231 hdd_sme_close_session_callback, adapter);
3232 if (QDF_IS_STATUS_ERROR(status)) {
3233 hdd_err("failed to close sme session: %d", status);
3234 return qdf_status_to_os_return(status);
3235 }
3236
3237 /* block on a completion variable until sme session is closed */
3238 rc = wait_for_completion_timeout(
3239 &adapter->session_close_comp_var,
3240 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3241 if (!rc) {
3242 hdd_err("timed out waiting for close sme session: %ld", rc);
3243 if (adapter->device_mode == QDF_NDI_MODE)
3244 hdd_ndp_session_end_handler(adapter);
3245 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3246 return -ETIMEDOUT;
3247 }
Yue Maf9782842017-05-08 12:49:49 -07003248release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003249 /* do vdev logical destroy via objmgr */
3250 errno = hdd_objmgr_destroy_vdev(adapter);
3251 if (errno) {
3252 hdd_err("failed to destroy objmgr vdev: %d", errno);
3253 return errno;
3254 }
3255
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003256 /* now that sme session is closed, allow physical vdev destroy */
3257 errno = hdd_objmgr_release_vdev(adapter);
3258 if (errno) {
3259 hdd_err("failed to release objmgr vdev: %d", errno);
3260 return errno;
3261 }
3262
Dustin Brownd28772b2017-03-17 14:16:07 -07003263 hdd_info("vdev destroyed successfully");
3264
3265 return 0;
3266}
3267
3268int hdd_vdev_create(hdd_adapter_t *adapter)
3269{
3270 QDF_STATUS status;
3271 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003272 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003273 uint32_t type;
3274 uint32_t sub_type;
3275 unsigned long rc;
3276
3277 hdd_info("creating new vdev");
3278
3279 /* determine vdev (sub)type */
3280 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303281 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003282 hdd_err("failed to get vdev type: %d", status);
3283 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003285
3286 /* do vdev create via objmgr */
3287 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003288 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003289 if (errno) {
3290 hdd_err("failed to create objmgr vdev: %d", errno);
3291 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003293
3294 /* Open a SME session (prepare vdev in firmware via legacy API) */
3295 INIT_COMPLETION(adapter->session_open_comp_var);
3296 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3297 (uint8_t *)&adapter->macAddressCurrent,
3298 adapter->sessionId, type, sub_type);
3299 if (QDF_IS_STATUS_ERROR(status)) {
3300 hdd_err("failed to open sme session: %d", status);
3301 errno = qdf_status_to_os_return(status);
3302 goto objmgr_vdev_destroy;
3303 }
3304
3305 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306 rc = wait_for_completion_timeout(
3307 &adapter->session_open_comp_var,
3308 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3309 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003310 hdd_err("timed out waiting for open sme session: %ld", rc);
3311 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303312 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3313 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003314 }
3315
3316 /* firmware ready for component communication, raise vdev_ready event */
3317 errno = hdd_vdev_ready(adapter);
3318 if (errno) {
3319 hdd_err("failed to dispatch vdev ready event: %d", errno);
3320 goto hdd_vdev_destroy;
3321 }
3322
3323 hdd_info("vdev %d created successfully", adapter->sessionId);
3324
3325 return 0;
3326
3327 /*
3328 * Due to legacy constraints, we need to destroy in the same order as
3329 * create. So, split error handling into 2 cases to accommodate.
3330 */
3331
3332objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003333 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003334
3335 return errno;
3336
3337hdd_vdev_destroy:
3338 QDF_BUG(!hdd_vdev_destroy(adapter));
3339
3340 return errno;
3341}
3342
3343QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
3344{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003345 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003346 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003347 QDF_STATUS status;
3348 int ret_val;
3349
3350 ret_val = hdd_vdev_create(adapter);
3351 if (ret_val) {
3352 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303353 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354 }
3355
Dustin Brownd28772b2017-03-17 14:16:07 -07003356 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3357 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3358 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003359 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003362 status = hdd_register_wext(adapter->dev);
3363 if (QDF_IS_STATUS_ERROR(status)) {
3364 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 goto error_register_wext;
3366 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003367 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303369 qdf_mem_set(pHddStaCtx->conn_info.staId,
3370 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3371
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003372 /* set fast roaming capability in sme session */
3373 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3374 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 /* Set the default operation channel */
3376 pHddStaCtx->conn_info.operationChannel =
3377 hdd_ctx->config->OperatingChannel;
3378
3379 /* Make the default Auth Type as OPEN */
3380 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3381
3382 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303383 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003384 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 status, status);
3386 goto error_init_txrx;
3387 }
3388
3389 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3390
3391 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303392 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003393 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 status, status);
3395 goto error_wmm_init;
3396 }
3397
3398 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3399
Naveen Rawat247a8682017-06-05 15:00:31 -07003400 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401 WMI_PDEV_PARAM_BURST_ENABLE,
3402 hdd_ctx->config->enableSifsBurst,
3403 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003404 if (ret_val)
3405 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406
Dustin Brownd28772b2017-03-17 14:16:07 -07003407 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003408 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003411 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303412 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414error_tdls_init:
3415 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3416 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417error_wmm_init:
3418 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3419 hdd_deinit_tx_rx(adapter);
3420error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003421 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003423 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 return status;
3426}
3427
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003428void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429{
3430 hdd_cfg80211_state_t *cfgState;
3431
3432 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3433
3434 if (NULL != cfgState->buf) {
3435 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 rc = wait_for_completion_timeout(
3438 &adapter->tx_action_cnf_event,
3439 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3440 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003441 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303442 /*
3443 * Inform tx status as FAILURE to upper layer and free
3444 * cfgState->buf
3445 */
3446 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 }
3448 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449}
3450
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303451/**
3452 * hdd_station_adapter_deinit() - De-initialize the station adapter
3453 * @hdd_ctx: global hdd context
3454 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003455 * @rtnl_held: Used to indicate whether or not the caller is holding
3456 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303457 *
3458 * This function De-initializes the STA/P2P/OCB adapter.
3459 *
3460 * Return: None.
3461 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003462static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003463 hdd_adapter_t *adapter,
3464 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303465{
3466 ENTER_DEV(adapter->dev);
3467
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303468 if (adapter->dev) {
3469 if (rtnl_held)
3470 adapter->dev->wireless_handlers = NULL;
3471 else {
3472 rtnl_lock();
3473 adapter->dev->wireless_handlers = NULL;
3474 rtnl_unlock();
3475 }
3476 }
3477
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303478 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3479 hdd_deinit_tx_rx(adapter);
3480 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3481 }
3482
3483 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3484 hdd_wmm_adapter_close(adapter);
3485 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3486 }
3487
3488 hdd_cleanup_actionframe(hdd_ctx, adapter);
3489 wlan_hdd_tdls_exit(adapter);
3490
3491 EXIT();
3492}
3493
3494/**
3495 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3496 * @hdd_ctx: global hdd context
3497 * @adapter: HDD adapter
3498 * @rtnl_held: the rtnl lock hold flag
3499 * This function De-initializes the AP/P2PGo adapter.
3500 *
3501 * Return: None.
3502 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003503static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003504 hdd_adapter_t *adapter,
3505 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303506{
3507 ENTER_DEV(adapter->dev);
3508
3509 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3510 hdd_wmm_adapter_close(adapter);
3511 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3512 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003513 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303514
3515 hdd_cleanup_actionframe(hdd_ctx, adapter);
3516
3517 hdd_unregister_hostapd(adapter, rtnl_held);
3518
3519 EXIT();
3520}
3521
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003522void hdd_deinit_adapter(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523 bool rtnl_held)
3524{
3525 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003528 case QDF_STA_MODE:
3529 case QDF_P2P_CLIENT_MODE:
3530 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303532 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533 break;
3534 }
3535
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003536 case QDF_SAP_MODE:
3537 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 {
3539
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303540 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541 break;
3542 }
3543
3544 default:
3545 break;
3546 }
3547
3548 EXIT();
3549}
3550
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003551static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003552 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553{
3554 struct net_device *pWlanDev = NULL;
3555
3556 if (adapter)
3557 pWlanDev = adapter->dev;
3558 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003559 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 return;
3561 }
3562
Rajeev Kumardca5f812016-02-04 17:28:06 -08003563 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303564
3565 if (adapter->scan_info.default_scan_ies) {
3566 qdf_mem_free(adapter->scan_info.default_scan_ies);
3567 adapter->scan_info.default_scan_ies = NULL;
3568 }
3569
Komal Seelama89be8d2016-09-29 11:09:26 +05303570 hdd_adapter_runtime_suspend_denit(adapter);
3571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 /*
3573 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3574 * the driver is almost closed and cannot handle either control
3575 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003576 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3577 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 * is not right. Setting this flag helps hdd_stop() to recognize that
3579 * the interface is closed and restricts any operations on that
3580 */
3581 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3582
3583 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003584 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003586 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 /*
3589 * Note that the adapter is no longer valid at this point
3590 * since the memory has been reclaimed
3591 */
3592 }
3593}
3594
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003595static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003596 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597{
3598 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3599 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303600 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303603 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 adapter = adapterNode->pAdapter;
3605 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303606 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303608 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 }
3610 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3611 adapterNode = pNext;
3612 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303613 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003615
Arun Khandavalli2358d522016-05-16 18:05:37 +05303616#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3617/**
3618 * hdd_set_fw_log_params() - Set log parameters to FW
3619 * @hdd_ctx: HDD Context
3620 * @adapter: HDD Adapter
3621 *
3622 * This function set the FW Debug log level based on the INI.
3623 *
3624 * Return: None
3625 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003626static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Arun Khandavalli2358d522016-05-16 18:05:37 +05303627 hdd_adapter_t *adapter)
3628{
3629 uint8_t count = 0, numentries = 0,
3630 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3631 uint32_t value = 0;
3632 int ret;
3633
Arun Khandavallifae92942016-08-01 13:31:08 +05303634 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3635 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003636 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303637 return;
3638 }
3639
Arun Khandavallifae92942016-08-01 13:31:08 +05303640 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303641 hdd_ctx->fw_log_settings.dl_type =
3642 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003643 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303644 WMI_DBGLOG_TYPE,
3645 hdd_ctx->config->enableFwLogType,
3646 DBG_CMD);
3647 if (ret != 0)
3648 hdd_err("Failed to enable FW log type ret %d",
3649 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303650
3651 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303652 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003653 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303654 WMI_DBGLOG_LOG_LEVEL,
3655 hdd_ctx->config->enableFwLogLevel,
3656 DBG_CMD);
3657 if (ret != 0)
3658 hdd_err("Failed to enable FW log level ret %d",
3659 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303660
3661 hdd_string_to_u8_array(
3662 hdd_ctx->config->enableFwModuleLogLevel,
3663 moduleloglevel,
3664 &numentries,
3665 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3666
3667 while (count < numentries) {
3668 /*
3669 * FW module log level input string looks like
3670 * below:
3671 * gFwDebugModuleLoglevel=<FW Module ID>,
3672 * <Log Level>,...
3673 * For example:
3674 * gFwDebugModuleLoglevel=
3675 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3676 * Above input string means :
3677 * For FW module ID 1 enable log level 0
3678 * For FW module ID 2 enable log level 1
3679 * For FW module ID 3 enable log level 2
3680 * For FW module ID 4 enable log level 3
3681 * For FW module ID 5 enable log level 4
3682 * For FW module ID 6 enable log level 5
3683 * For FW module ID 7 enable log level 6
3684 */
3685
Nishank Aggarwale239d962017-03-03 12:26:02 +05303686 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3687 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3688 hdd_err("Module id %d and dbglog level %d input length is more than max",
3689 moduleloglevel[count],
3690 moduleloglevel[count + 1]);
3691 return;
3692 }
3693
3694 value = moduleloglevel[count] << 16;
3695 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003696 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303697 WMI_DBGLOG_MOD_LOG_LEVEL,
3698 value, DBG_CMD);
3699 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303700 hdd_err("Failed to enable FW module log level %d ret %d",
3701 value, ret);
3702
3703 count += 2;
3704 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303705
Arun Khandavalli2358d522016-05-16 18:05:37 +05303706}
3707#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003708static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Arun Khandavalli2358d522016-05-16 18:05:37 +05303709 hdd_adapter_t *adapter)
3710{
3711}
3712
3713#endif
3714
3715/**
3716 * hdd_set_fw_params() - Set parameters to firmware
3717 * @adapter: HDD adapter
3718 *
3719 * This function Sets various parameters to fw once the
3720 * adapter is started.
3721 *
3722 * Return: 0 on success or errno on failure
3723 */
3724int hdd_set_fw_params(hdd_adapter_t *adapter)
3725{
3726 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003727 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303728
3729 ENTER_DEV(adapter->dev);
3730
3731 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3732 if (!hdd_ctx)
3733 return -EINVAL;
3734
Dustin Brown732ab9c2017-06-15 13:24:09 -07003735 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3736 hdd_debug("FTM Mode is active; nothing to do");
3737 return 0;
3738 }
3739
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303740 ret = sme_cli_set_command(adapter->sessionId,
3741 WMI_PDEV_PARAM_DTIM_SYNTH,
3742 hdd_ctx->config->enable_lprx, PDEV_CMD);
3743 if (ret) {
3744 hdd_err("Failed to set LPRx");
3745 goto error;
3746 }
3747
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303748 if (adapter->device_mode == QDF_STA_MODE) {
3749 sme_set_smps_cfg(adapter->sessionId,
3750 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3751 hdd_ctx->config->upper_brssi_thresh);
3752
3753 sme_set_smps_cfg(adapter->sessionId,
3754 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3755 hdd_ctx->config->lower_brssi_thresh);
3756
3757 sme_set_smps_cfg(adapter->sessionId,
3758 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3759 hdd_ctx->config->enable_dtim_1chrx);
3760 }
3761
Dustin Brown732ab9c2017-06-15 13:24:09 -07003762 if (hdd_ctx->config->enable2x2) {
3763 hdd_debug("configuring 2x2 mode fw params");
3764
Naveen Rawat247a8682017-06-05 15:00:31 -07003765 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003766 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3767 hdd_ctx->config->enable_cck_tx_fir_override,
3768 PDEV_CMD);
3769 if (ret) {
3770 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3771 ret);
3772 goto error;
3773 }
3774 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303775#define HDD_DTIM_1CHAIN_RX_ID 0x5
3776#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003777 hdd_debug("configuring 1x1 mode fw params");
3778
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003779 /*
3780 * Disable DTIM 1 chain Rx when in 1x1,
3781 * we are passing two value
3782 * as param_id << 29 | param_value.
3783 * Below param_value = 0(disable)
3784 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003785 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003786 WMI_STA_SMPS_PARAM_CMDID,
3787 HDD_DTIM_1CHAIN_RX_ID <<
3788 HDD_SMPS_PARAM_VALUE_S,
3789 VDEV_CMD);
3790 if (ret) {
3791 hdd_err("DTIM 1 chain set failed %d", ret);
3792 goto error;
3793 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303794
Naveen Rawat247a8682017-06-05 15:00:31 -07003795 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003796 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3797 hdd_ctx->config->txchainmask1x1,
3798 PDEV_CMD);
3799 if (ret) {
3800 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3801 ret);
3802 goto error;
3803 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303804
Naveen Rawat247a8682017-06-05 15:00:31 -07003805 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003806 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3807 hdd_ctx->config->rxchainmask1x1,
3808 PDEV_CMD);
3809 if (ret) {
3810 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3811 ret);
3812 goto error;
3813 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303814#undef HDD_DTIM_1CHAIN_RX_ID
3815#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003816 }
3817
Naveen Rawat247a8682017-06-05 15:00:31 -07003818 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003819 WMI_PDEV_PARAM_HYST_EN,
3820 hdd_ctx->config->enableMemDeepSleep,
3821 PDEV_CMD);
3822 if (ret) {
3823 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3824 goto error;
3825 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303826
Naveen Rawat247a8682017-06-05 15:00:31 -07003827 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003828 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3829 hdd_ctx->config->rts_profile,
3830 VDEV_CMD);
3831 if (ret) {
3832 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3833 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303834 }
3835
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003836 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3837
3838 ret = wma_cli_set_command(adapter->sessionId,
3839 GEN_VDEV_PARAM_AMSDU,
3840 hdd_ctx->config->max_amsdu_num,
3841 GEN_CMD);
3842 if (ret != 0) {
3843 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3844 goto error;
3845 }
3846
Arun Khandavalli2358d522016-05-16 18:05:37 +05303847 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303848 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003849
Arun Khandavalli2358d522016-05-16 18:05:37 +05303850 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303851
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852error:
3853 return -EINVAL;
3854}
3855
Ryan Hsu07495ea2016-01-21 15:25:39 -08003856/**
3857 * hdd_open_adapter() - open and setup the hdd adatper
3858 * @hdd_ctx: global hdd context
3859 * @session_type: type of the interface to be created
3860 * @iface_name: User-visible name of the interface
3861 * @macAddr: MAC address to assign to the interface
3862 * @name_assign_type: the name of assign type of the netdev
3863 * @rtnl_held: the rtnl lock hold flag
3864 *
3865 * This function open and setup the hdd adpater according to the device
3866 * type request, assign the name, the mac address assigned, and then prepared
3867 * the hdd related parameters, queue, lock and ready to start.
3868 *
3869 * Return: the pointer of hdd adapter, otherwise NULL.
3870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003871hdd_adapter_t *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003873 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003874 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875{
3876 hdd_adapter_t *adapter = NULL;
3877 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303878 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881
3882 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3883 /*
3884 * Max limit reached on the number of vdevs configured by the
3885 * host. Return error
3886 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303887 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3888 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 return NULL;
3890 }
3891
3892 if (macAddr == NULL) {
3893 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303894 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003895 return NULL;
3896 }
3897 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303898 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303899 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3900 " already exists",
3901 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 return NULL;
3903 }
3904
3905 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003906 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 /* Reset locally administered bit if the device mode is STA */
3908 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3909 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003910 case QDF_P2P_CLIENT_MODE:
3911 case QDF_P2P_DEVICE_MODE:
3912 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003913 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303914 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003915 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3916 name_assign_type,
3917 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918
3919 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303920 hdd_err("failed to allocate adapter for session %d",
3921 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922 return NULL;
3923 }
3924
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003925 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003927 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303929 else if (QDF_MONITOR_MODE == session_type)
3930 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 else
3932 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3933
3934 adapter->device_mode = session_type;
3935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 /*
3938 * Workqueue which gets scheduled in IPv4 notification
3939 * callback
3940 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003941 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3942 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943
3944#ifdef WLAN_NS_OFFLOAD
3945 /*
3946 * Workqueue which gets scheduled in IPv6
3947 * notification callback.
3948 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3950 hdd_ipv6_notifier_work_queue);
3951#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303953 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303955 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 }
3957
3958 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003959 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303961 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3962 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303963
Ravi Joshi1a292562017-05-18 16:28:54 -07003964 /* Initialize NAN Data Interface */
3965 if (QDF_NDI_MODE == session_type) {
3966 status = hdd_init_nan_data_mode(adapter);
3967 if (QDF_STATUS_SUCCESS != status)
3968 goto err_free_netdev;
3969 }
3970
3971 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003973 case QDF_P2P_GO_MODE:
3974 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003975 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3976 name_assign_type,
3977 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003979 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303980 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 return NULL;
3982 }
3983
3984 adapter->wdev.iftype =
3985 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003986 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 NL80211_IFTYPE_P2P_GO;
3988 adapter->device_mode = session_type;
3989
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003990 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303991 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3993 goto err_free_netdev;
3994 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003995 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 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);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304000 case QDF_FTM_MODE:
4001 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4002 name_assign_type,
4003 "wlan0");
4004 if (NULL == adapter) {
4005 hdd_err("Failed to allocate adapter for FTM mode");
4006 return NULL;
4007 }
4008 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4009 adapter->device_mode = session_type;
4010 status = hdd_register_interface(adapter, rtnl_held);
4011 if (QDF_STATUS_SUCCESS != status) {
4012 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4013 goto err_free_netdev;
4014 }
4015 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004016 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304017 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304018 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4019 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304020 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004022 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304023 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 return NULL;
4025 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026
hqueaa33ee2017-05-04 17:56:35 +08004027 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4030 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4031
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304032 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 /* Add it to the hdd's session list. */
4034 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304035 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304037 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 } else {
4039 pHddAdapterNode->pAdapter = adapter;
4040 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4041 }
4042 }
4043
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304044 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 if (NULL != adapter) {
4046 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4047 adapter = NULL;
4048 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004049 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304050 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 return NULL;
4053 }
4054
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304055 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004056 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4057 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059 /* Adapter successfully added. Increment the vdev count */
4060 hdd_ctx->current_intf_count++;
4061
Jeff Johnson5880d792016-08-15 13:32:30 -07004062 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063 hdd_ctx->current_intf_count);
4064
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004065 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 }
4067
Rajeev Kumardca5f812016-02-04 17:28:06 -08004068 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004069 hdd_err("Interface %s wow debug_fs init failed",
4070 netdev_name(adapter->dev));
4071
4072 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4073 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074
4075 return adapter;
4076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304079 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080
4081 return NULL;
4082}
4083
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004084QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004085 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086{
4087 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304088 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089
4090 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304091 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004092 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093 status);
4094 return status;
4095 }
4096
4097 while (pCurrent->pAdapter != adapter) {
4098 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304099 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 break;
4101
4102 pCurrent = pNext;
4103 }
4104 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304105 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004106 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004107 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304108 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004109
4110 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004111 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4112 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004113 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304115 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 adapterNode = NULL;
4117
Dustin Brown5ec6b552017-03-31 12:11:40 -07004118 /* conditionally restart the bw timer */
4119 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 /* Adapter removed. Decrement vdev count */
4122 if (hdd_ctx->current_intf_count != 0)
4123 hdd_ctx->current_intf_count--;
4124
4125 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304126 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304129 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130}
4131
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004132/**
4133 * hdd_close_all_adapters - Close all open adapters
4134 * @hdd_ctx: Hdd context
4135 * rtnl_held: True if RTNL lock held
4136 *
4137 * Close all open adapters.
4138 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304139 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004140 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004141QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142{
4143 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304144 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145
4146 ENTER();
4147
4148 do {
4149 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304150 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304151 wlan_hdd_release_intf_addr(hdd_ctx,
4152 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004154 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304155 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304156 /* Adapter removed. Decrement vdev count */
4157 if (hdd_ctx->current_intf_count != 0)
4158 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304160 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161
4162 EXIT();
4163
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304164 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165}
4166
4167void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
4168{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304169 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004173 case QDF_STA_MODE:
4174 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004176 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004178 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 break;
4180 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004181 case QDF_SAP_MODE:
4182 case QDF_P2P_GO_MODE:
4183 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004185 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 break;
4187 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004188 case QDF_FTM_MODE:
4189 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 default:
4191 /*
4192 * wlan_hdd_reset_prob_rspies should not have been called
4193 * for these kind of devices
4194 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004195 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196 pHostapdAdapter->device_mode);
4197 return;
4198 }
4199
Anurag Chouhanc5548422016-02-24 18:33:27 +05304200 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4202 updateIE.ieBufferlength = 0;
4203 updateIE.pAdditionIEBuffer = NULL;
4204 updateIE.append = true;
4205 updateIE.notify = false;
4206 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4207 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304208 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004209 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 }
4211}
4212
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004213QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214 const bool bCloseSession)
4215{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304216 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4218 union iwreq_data wrqu;
4219 tSirUpdateIE updateIE;
4220 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004221 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222
4223 ENTER();
4224
Sachin Ahuja988fd102016-09-15 17:16:25 +05304225 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004226 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304227 wlan_hdd_netif_queue_control(adapter,
4228 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4229 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004231 case QDF_STA_MODE:
4232 case QDF_P2P_CLIENT_MODE:
4233 case QDF_IBSS_MODE:
4234 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004235 case QDF_NDI_MODE:
4236 if ((QDF_NDI_MODE == adapter->device_mode) ||
4237 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4239 hdd_is_connecting(
4240 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004241 INIT_COMPLETION(adapter->disconnect_comp_var);
4242 /*
4243 * For NDI do not use pWextState from sta_ctx, if needed
4244 * extract from ndi_ctx.
4245 */
4246 if (QDF_NDI_MODE == adapter->device_mode)
4247 qdf_ret_status = sme_roam_disconnect(
4248 hdd_ctx->hHal,
4249 adapter->sessionId,
4250 eCSR_DISCONNECT_REASON_NDI_DELETE);
4251 else if (pWextState->roamProfile.BSSType ==
4252 eCSR_BSS_TYPE_START_IBSS)
4253 qdf_ret_status = sme_roam_disconnect(
4254 hdd_ctx->hHal,
4255 adapter->sessionId,
4256 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004257 else if (QDF_STA_MODE == adapter->device_mode)
4258 qdf_ret_status =
4259 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004261 qdf_ret_status = sme_roam_disconnect(
4262 hdd_ctx->hHal,
4263 adapter->sessionId,
4264 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004265 /* success implies disconnect command got
4266 * queued up successfully
4267 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004268 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4269 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 rc = wait_for_completion_timeout(
4271 &adapter->disconnect_comp_var,
4272 msecs_to_jiffies
4273 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004274 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004275 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004277 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4278 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 memset(&wrqu, '\0', sizeof(wrqu));
4280 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4281 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4282 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4283 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304284 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004285 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304286 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004287
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304288 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304289 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290
4291#ifdef WLAN_OPEN_SOURCE
4292 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4293#endif
4294
4295 hdd_deregister_tx_flow_control(adapter);
4296
4297#ifdef WLAN_NS_OFFLOAD
4298#ifdef WLAN_OPEN_SOURCE
4299 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4300#endif
4301#endif
4302
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304303 if (adapter->device_mode == QDF_STA_MODE)
4304 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4305 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004306 /*
4307 * It is possible that the caller of this function does not
4308 * wish to close the session
4309 */
Krunal Soni985b8132017-02-10 18:49:08 -08004310 if (true == bCloseSession) {
4311 if (0 != wlan_hdd_try_disconnect(adapter)) {
4312 hdd_err("Error: Can't disconnect adapter");
4313 return QDF_STATUS_E_FAILURE;
4314 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004315 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004316 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 break;
4318
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004319 case QDF_SAP_MODE:
4320 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004322 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4324
4325 hdd_deregister_tx_flow_control(adapter);
4326
Kapil Guptac1224bf2017-06-22 21:22:40 +05304327 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 mutex_lock(&hdd_ctx->sap_lock);
4329 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304330 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304331 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332
4333 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334 status = wlansap_stop_bss(
4335 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004336
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304337 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 hdd_hostapd_state_t *hostapd_state =
4339 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304340 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304341 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304342 qdf_status =
4343 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004344 qdf_stop_bss_event,
4345 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346
Anurag Chouhance0dc992016-02-16 18:18:03 +05304347 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004348 hdd_err("failure waiting for wlansap_stop_bss %d",
4349 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 }
4351 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004352 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 }
4354 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004355 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4356 adapter->device_mode,
4357 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358
Anurag Chouhanc5548422016-02-24 18:33:27 +05304359 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004360 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 updateIE.smeSessionId = adapter->sessionId;
4362 updateIE.ieBufferlength = 0;
4363 updateIE.pAdditionIEBuffer = NULL;
4364 updateIE.append = false;
4365 updateIE.notify = false;
4366 /* Probe bcn reset */
4367 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4368 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304369 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004370 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371 }
4372 /* Assoc resp reset */
4373 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4374 &updateIE,
4375 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304376 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004377 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004378 }
4379 /* Reset WNI_CFG_PROBE_RSP Flags */
4380 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004382 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4383 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304384 /*
4385 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4386 */
4387 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4388 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4389
Peng Xu66162de2016-02-11 17:01:20 -08004390 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004391 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004392 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004394 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004395 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004396 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004397 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 break;
4399 default:
4400 break;
4401 }
4402
4403 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304404 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405}
4406
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304407/**
4408 * hdd_deinit_all_adapters - deinit all adapters
4409 * @hdd_ctx: HDD context
4410 * @rtnl_held: True if RTNL lock held
4411 *
4412 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004413void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304414{
4415 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4416 QDF_STATUS status;
4417 hdd_adapter_t *adapter;
4418
4419 ENTER();
4420
4421 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4422
4423 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4424 adapter = adapter_node->pAdapter;
4425 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4426 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4427 adapter_node = next;
4428 }
4429
4430 EXIT();
4431}
4432
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004433QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434{
4435 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304436 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437 hdd_adapter_t *adapter;
4438
4439 ENTER();
4440
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304441 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4444
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304445 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 adapter = adapterNode->pAdapter;
4447 hdd_stop_adapter(hdd_ctx, adapter, true);
4448 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4449 adapterNode = pNext;
4450 }
4451
4452 EXIT();
4453
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304454 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455}
4456
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004457QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458{
4459 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304460 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461 hdd_adapter_t *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004462 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004463 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464
4465 ENTER();
4466
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304467 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4470
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304471 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004472 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004473 hdd_notice("Disabling queues for adapter type: %d",
4474 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304475
4476 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004477 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304478 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004479 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304480
Arun Khandavallicc544b32017-01-30 19:52:16 +05304481 if (hdd_ctx->config->sap_internal_restart &&
4482 adapter->device_mode == QDF_SAP_MODE) {
4483 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304484 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304485 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004486 if (test_bit(SOFTAP_BSS_STARTED,
4487 &adapter->event_flags)) {
4488 hdd_sap_indicate_disconnect_for_sta(adapter);
4489 hdd_cleanup_actionframe(hdd_ctx, adapter);
4490 hdd_sap_destroy_events(adapter);
4491 }
4492 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4493 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304494 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304495 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004496 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004497 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498
4499 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4500
4501 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004502 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4503 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4505 hdd_wmm_adapter_close(adapter);
4506 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4507 }
4508
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304509 hdd_clear_fils_connection_info(adapter);
Wu Gao3545e642017-07-14 19:24:41 +08004510 if (adapter->device_mode == QDF_SAP_MODE) {
4511 /*
4512 * If adapter is SAP, set session ID to invalid
4513 * since SAP session will be cleanup during SSR.
4514 */
Wu Gao36717432016-11-21 15:09:48 +08004515 wlansap_set_invalid_session(
4516 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4517
Wu Gao3545e642017-07-14 19:24:41 +08004518 wlansap_cleanup_cac_timer(
4519 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4520 }
4521
Yue Mad5b4b9f2017-05-26 16:23:40 -07004522 /* Delete peers if any for STA and P2P client modes */
4523 if (adapter->device_mode == QDF_STA_MODE ||
4524 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4525 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4526 qdf_copy_macaddr(&peerMacAddr,
4527 &pHddStaCtx->conn_info.bssId);
4528
4529 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4530 peerMacAddr.bytes);
4531 }
4532
Yue Maf9782842017-05-08 12:49:49 -07004533 /* Destroy vdev which will be recreated during reinit. */
4534 hdd_vdev_destroy(adapter);
4535
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4537 adapterNode = pNext;
4538 }
4539
4540 EXIT();
4541
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304542 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004543}
4544
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004545bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304546{
4547 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4548 QDF_STATUS status;
4549 bool close_modules = true;
4550
Arun Khandavalliba479c42017-07-26 21:29:40 +05304551 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4552 hdd_info("FTM mode, don't close the module");
4553 return false;
4554 }
4555
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304556 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4557 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4558 if (test_bit(DEVICE_IFACE_OPENED,
4559 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004560 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304561 close_modules = false;
4562 break;
4563 }
4564 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4565 adapter_node = next;
4566 }
4567
4568 return close_modules;
4569}
4570
Arun Khandavallifae92942016-08-01 13:31:08 +05304571/**
4572 * hdd_is_interface_up()- Checkfor interface up before ssr
4573 * @hdd_ctx: HDD context
4574 *
4575 * check if there are any wlan interfaces before SSR accordingly start
4576 * the interface.
4577 *
4578 * Return: 0 if interface was opened else false
4579 */
4580static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4581{
4582 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4583 return true;
4584 else
4585 return false;
4586}
4587
Anurag Chouhanc4092922016-09-08 15:56:11 +05304588#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004589 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304590struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4591 struct ieee80211_channel *channel,
4592 const u8 *bssid, const u8 *ssid,
4593 size_t ssid_len)
4594{
4595 return cfg80211_get_bss(wiphy, channel, bssid,
4596 ssid, ssid_len,
4597 WLAN_CAPABILITY_ESS,
4598 WLAN_CAPABILITY_ESS);
4599}
4600#else
4601struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4602 struct ieee80211_channel *channel,
4603 const u8 *bssid, const u8 *ssid,
4604 size_t ssid_len)
4605{
4606 return cfg80211_get_bss(wiphy, channel, bssid,
4607 ssid, ssid_len,
4608 IEEE80211_BSS_TYPE_ESS,
4609 IEEE80211_PRIVACY_ANY);
4610}
4611#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304612
Abhishek Singha84d3952016-09-13 13:45:05 +05304613#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304614#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4615 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4616/**
4617 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4618 * @timeout_reason: reason for connect timeout
4619 *
4620 * This function is used to convert host timeout
4621 * reason enum to kernel specific enum.
4622 *
4623 * Return: nl timeout enum
4624 */
4625static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4626 tSirResultCodes timeout_reason)
4627{
4628 switch (timeout_reason) {
4629 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4630 return NL80211_TIMEOUT_SCAN;
4631 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4632 return NL80211_TIMEOUT_AUTH;
4633 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4634 return NL80211_TIMEOUT_ASSOC;
4635 default:
4636 return NL80211_TIMEOUT_UNSPECIFIED;
4637 }
4638}
4639
4640/**
4641 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4642 * @dev: network device
4643 * @bssid: bssid to which we want to associate
4644 * @timeout_reason: reason for connect timeout
4645 *
4646 * This API is used to send connection timeout reason to supplicant
4647 *
4648 * Return: void
4649 */
4650static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4651 const u8 *bssid,
4652 tSirResultCodes timeout_reason)
4653{
4654 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004655
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304656 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4657
4658 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4659 nl_timeout_reason);
4660}
4661
4662/**
4663 * __hdd_connect_bss() - API to send connection status to supplicant
4664 * @dev: network device
4665 * @bssid: bssid to which we want to associate
4666 * @req_ie: Request Information Element
4667 * @req_ie_len: len of the req IE
4668 * @resp_ie: Response IE
4669 * @resp_ie_len: len of ht response IE
4670 * @status: status
4671 * @gfp: Kernel Flag
4672 * @timeout_reason: reason for connect timeout
4673 *
4674 * Return: void
4675 */
4676static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4677 struct cfg80211_bss *bss, const u8 *req_ie,
4678 size_t req_ie_len, const u8 *resp_ie,
4679 size_t resp_ie_len, int status, gfp_t gfp,
4680 tSirResultCodes timeout_reason)
4681{
4682 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004683
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304684 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4685
4686 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4687 resp_ie, resp_ie_len, status, gfp,
4688 nl_timeout_reason);
4689}
4690#else
4691#if defined CFG80211_CONNECT_TIMEOUT
4692static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4693 const u8 *bssid,
4694 tSirResultCodes timeout_reason)
4695{
4696 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4697}
4698#endif
4699
4700static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4701 struct cfg80211_bss *bss, const u8 *req_ie,
4702 size_t req_ie_len, const u8 *resp_ie,
4703 size_t resp_ie_len, int status, gfp_t gfp,
4704 tSirResultCodes timeout_reason)
4705{
4706 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4707 resp_ie, resp_ie_len, status, gfp);
4708}
4709#endif
4710
Abhishek Singha84d3952016-09-13 13:45:05 +05304711/**
4712 * hdd_connect_bss() - API to send connection status to supplicant
4713 * @dev: network device
4714 * @bssid: bssid to which we want to associate
4715 * @req_ie: Request Information Element
4716 * @req_ie_len: len of the req IE
4717 * @resp_ie: Response IE
4718 * @resp_ie_len: len of ht response IE
4719 * @status: status
4720 * @gfp: Kernel Flag
4721 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304722 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304723 *
4724 * The API is a wrapper to send connection status to supplicant
4725 *
4726 * Return: Void
4727 */
4728#if defined CFG80211_CONNECT_TIMEOUT
4729static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4730 struct cfg80211_bss *bss, const u8 *req_ie,
4731 size_t req_ie_len, const u8 *resp_ie,
4732 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304733 bool connect_timeout,
4734 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304735{
4736 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304737 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304738 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304739 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4740 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304741}
4742#else
4743static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4744 struct cfg80211_bss *bss, const u8 *req_ie,
4745 size_t req_ie_len, const u8 *resp_ie,
4746 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304747 bool connect_timeout,
4748 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304749{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304750 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4751 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304752}
4753#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304754
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304755#ifdef WLAN_FEATURE_FILS_SK
4756#ifdef CFG80211_CONNECT_DONE
4757#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4758/**
4759 * hdd_populate_fils_params() - Populate FILS keys to connect response
4760 * @fils_params: connect response to supplicant
4761 * @fils_kek: FILS kek
4762 * @fils_kek_len: FILS kek length
4763 * @pmk: FILS PMK
4764 * @pmk_len: FILS PMK length
4765 * @pmkid: PMKID
4766 * @fils_seq_num: FILS Seq number
4767 *
4768 * Return: None
4769 */
4770static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4771 *fils_params, const uint8_t *fils_kek,
4772 size_t fils_kek_len, const uint8_t *pmk,
4773 size_t pmk_len, const uint8_t *pmkid,
4774 uint16_t fils_seq_num)
4775{
4776 /* Increament seq number to be used for next FILS */
4777 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4778 fils_params->update_erp_next_seq_num = true;
4779 fils_params->fils_kek = fils_kek;
4780 fils_params->fils_kek_len = fils_kek_len;
4781 fils_params->pmk = pmk;
4782 fils_params->pmk_len = pmk_len;
4783 fils_params->pmkid = pmkid;
4784}
4785#else
4786static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4787 *fils_params, const uint8_t
4788 *fils_kek, size_t fils_kek_len,
4789 const uint8_t *pmk, size_t pmk_len,
4790 const uint8_t *pmkid,
4791 uint16_t fils_seq_num)
4792{ }
4793#endif
4794
4795/**
4796 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4797 * @dev: network device
4798 * @bssid: bssid to which we want to associate
4799 * @bss: cfg80211 bss info
4800 * @roam_info: information about connected bss
4801 * @req_ie: Request Information Element
4802 * @req_ie_len: len of the req IE
4803 * @resp_ie: Response IE
4804 * @resp_ie_len: len of ht response IE
4805 * @status: status
4806 * @gfp: allocation flags
4807 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4808 * @timeout_reason: reason for connect timeout
4809 * @roam_fils_params: FILS join response params
4810 *
4811 * This API is used as wrapper to send FILS key/sequence number
4812 * params etc. to supplicant in case of FILS connection
4813 *
4814 * Return: None
4815 */
4816static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4817 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4818 const u8 *req_ie, size_t req_ie_len,
4819 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4820 gfp_t gfp, bool connect_timeout, tSirResultCodes
4821 timeout_reason, struct fils_join_rsp_params
4822 *roam_fils_params)
4823{
4824 struct cfg80211_connect_resp_params fils_params;
4825 qdf_mem_zero(&fils_params, sizeof(fils_params));
4826
4827 if (!roam_fils_params) {
4828 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4829 } else {
4830 fils_params.status = status;
4831 fils_params.bssid = bssid;
4832 fils_params.timeout_reason = timeout_reason;
4833 fils_params.req_ie = req_ie;
4834 fils_params.req_ie_len = req_ie_len;
4835 fils_params.resp_ie = resp_ie;
4836 fils_params.resp_ie_len = resp_ie_len;
4837 fils_params.bss = bss;
4838 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4839 roam_fils_params->kek_len,
4840 roam_fils_params->fils_pmk,
4841 roam_fils_params->fils_pmk_len,
4842 roam_fils_params->fils_pmkid,
4843 roam_info->fils_seq_num);
4844 }
4845 hdd_debug("FILS indicate connect status %d seq no %d",
4846 fils_params.status,
4847 fils_params.fils_erp_next_seq_num);
4848
4849 cfg80211_connect_done(dev, &fils_params, gfp);
4850
4851 /* Clear all the FILS key info */
4852 if (roam_fils_params && roam_fils_params->fils_pmk)
4853 qdf_mem_free(roam_fils_params->fils_pmk);
4854 if (roam_fils_params)
4855 qdf_mem_free(roam_fils_params);
4856 roam_info->fils_join_rsp = NULL;
4857}
4858#else
4859static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4860 struct cfg80211_bss *bss, tCsrRoamInfo
4861 *roam_info, const u8 *req_ie,
4862 size_t req_ie_len, const u8 *resp_ie,
4863 size_t resp_ie_len, u16 status, gfp_t gfp,
4864 bool connect_timeout, tSirResultCodes
4865 timeout_reason, struct fils_join_rsp_params
4866 *roam_fils_params)
4867{ }
4868#endif
4869#endif
4870
4871#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4872/**
4873 * hdd_fils_update_connect_results() - API to send fils connection status to
4874 * supplicant.
4875 * @dev: network device
4876 * @bssid: bssid to which we want to associate
4877 * @bss: cfg80211 bss info
4878 * @roam_info: information about connected bss
4879 * @req_ie: Request Information Element
4880 * @req_ie_len: len of the req IE
4881 * @resp_ie: Response IE
4882 * @resp_ie_len: len of ht response IE
4883 * @status: status
4884 * @gfp: allocation flags
4885 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4886 * @timeout_reason: reason for connect timeout
4887 *
4888 * The API is a wrapper to send connection status to supplicant
4889 *
4890 * Return: 0 if success else failure
4891 */
4892static int hdd_fils_update_connect_results(struct net_device *dev,
4893 const u8 *bssid,
4894 struct cfg80211_bss *bss,
4895 tCsrRoamInfo *roam_info, const u8 *req_ie,
4896 size_t req_ie_len, const u8 *resp_ie,
4897 size_t resp_ie_len, u16 status, gfp_t gfp,
4898 bool connect_timeout,
4899 tSirResultCodes timeout_reason)
4900{
4901 ENTER();
4902 if (!roam_info || !roam_info->is_fils_connection)
4903 return -EINVAL;
4904
4905 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4906 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4907 timeout_reason, roam_info->fils_join_rsp);
4908 return 0;
4909}
4910#else
4911static inline int hdd_fils_update_connect_results(struct net_device *dev,
4912 const u8 *bssid,
4913 struct cfg80211_bss *bss,
4914 tCsrRoamInfo *roam_info, const u8 *req_ie,
4915 size_t req_ie_len, const u8 *resp_ie,
4916 size_t resp_ie_len, u16 status, gfp_t gfp,
4917 bool connect_timeout,
4918 tSirResultCodes timeout_reason)
4919{
4920 return -EINVAL;
4921}
4922#endif
4923
Anurag Chouhanc4092922016-09-08 15:56:11 +05304924/**
4925 * hdd_connect_result() - API to send connection status to supplicant
4926 * @dev: network device
4927 * @bssid: bssid to which we want to associate
4928 * @roam_info: information about connected bss
4929 * @req_ie: Request Information Element
4930 * @req_ie_len: len of the req IE
4931 * @resp_ie: Response IE
4932 * @resp_ie_len: len of ht response IE
4933 * @status: status
4934 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304935 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304936 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304937 *
4938 * The API is a wrapper to send connection status to supplicant
4939 * and allow runtime suspend
4940 *
4941 * Return: Void
4942 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304943void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4944 tCsrRoamInfo *roam_info, const u8 *req_ie,
4945 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304946 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304947 bool connect_timeout,
4948 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304949{
4950 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4951 struct cfg80211_bss *bss = NULL;
4952
4953 if (WLAN_STATUS_SUCCESS == status) {
4954 struct ieee80211_channel *chan;
4955 int freq;
4956 int chan_no = roam_info->pBssDesc->channelId;
4957
4958 if (chan_no <= 14)
4959 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004960 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304961 else
4962 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004963 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304964
4965 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4966 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4967 roam_info->u.pConnectedProfile->SSID.ssId,
4968 roam_info->u.pConnectedProfile->SSID.length);
4969 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304970
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304971 if (hdd_fils_update_connect_results(dev, bssid, bss,
4972 roam_info, req_ie, req_ie_len, resp_ie,
4973 resp_ie_len, status, gfp, connect_timeout,
4974 timeout_reason) != 0) {
4975 hdd_connect_bss(dev, bssid, bss, req_ie,
4976 req_ie_len, resp_ie, resp_ie_len,
4977 status, gfp, connect_timeout, timeout_reason);
4978 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304979
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004980 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004981 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304982}
4983#else
4984void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4985 tCsrRoamInfo *roam_info, const u8 *req_ie,
4986 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304987 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304988 bool connect_timeout,
4989 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304990{
Komal Seelama89be8d2016-09-29 11:09:26 +05304991 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4992
Anurag Chouhanc4092922016-09-08 15:56:11 +05304993 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4994 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004995
4996 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004997 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304998}
4999#endif
5000
5001
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005002QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005003{
5004 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305005 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006 hdd_adapter_t *adapter;
5007#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305008 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009#endif
5010 eConnectionState connState;
5011
5012 ENTER();
5013
5014 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305015 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005016 adapter = adapterNode->pAdapter;
5017
Arun Khandavallifae92942016-08-01 13:31:08 +05305018 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305019 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005021 hdd_wmm_init(adapter);
5022
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005023 adapter->scan_info.mScanPending = false;
5024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005025 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005026 case QDF_STA_MODE:
5027 case QDF_P2P_CLIENT_MODE:
5028 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029
5030 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5031 ->conn_info.connState;
5032
5033 hdd_init_station_mode(adapter);
5034 /* Open the gates for HDD to receive Wext commands */
5035 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005036
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005037 /* Indicate disconnect event to supplicant
5038 * if associated previously
5039 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005040 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005041 eConnectionState_IbssConnected == connState ||
5042 eConnectionState_NotConnected == connState ||
5043 eConnectionState_IbssDisconnected == connState ||
5044 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047 memset(&wrqu, '\0', sizeof(wrqu));
5048 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5049 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5050 wireless_send_event(adapter->dev, SIOCGIWAP,
5051 &wrqu, NULL);
5052 adapter->sessionCtx.station.
5053 hdd_ReassocScenario = false;
5054
5055 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305056 wlan_hdd_cfg80211_indicate_disconnect(
5057 adapter->dev, false,
5058 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059 } else if (eConnectionState_Connecting == connState) {
5060 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005061 * Indicate connect failure to supplicant if we
5062 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005063 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305064 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305065 NULL, 0, NULL, 0,
5066 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005067 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 }
5069
5070 hdd_register_tx_flow_control(adapter,
5071 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005072 hdd_tx_resume_cb,
5073 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005074
5075 break;
5076
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005077 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005078 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305079 hdd_init_ap_mode(adapter, true);
5080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 break;
5082
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005083 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005085 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5087#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005088 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 /* event supplicant to restart */
5090 cfg80211_del_sta(adapter->dev,
5091 (const u8 *)&bcastMac.bytes[0],
5092 GFP_KERNEL);
5093#endif
5094 break;
5095
5096 default:
5097 break;
5098 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005099 /*
5100 * Action frame registered in one adapter which will
5101 * applicable to all interfaces
5102 */
5103 wlan_hdd_cfg80211_register_frames(adapter);
5104
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305105get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5107 adapterNode = pNext;
5108 }
5109
5110 EXIT();
5111
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305112 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113}
5114
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005115QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 hdd_adapter_list_node_t **padapterNode)
5117{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305118 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005119
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005120 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305121 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5122 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005123 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 return status;
5125}
5126
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005127QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128 hdd_adapter_list_node_t *adapterNode,
5129 hdd_adapter_list_node_t **pNextAdapterNode)
5130{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305131 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005132
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005133 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305134 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5135 (qdf_list_node_t *) adapterNode,
5136 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005138 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139 return status;
5140}
5141
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005142QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 hdd_adapter_list_node_t *adapterNode)
5144{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305145 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005146
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005147 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305148 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005150 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 return status;
5152}
5153
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005154QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155 hdd_adapter_list_node_t **padapterNode)
5156{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305157 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005158
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005159 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305160 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5161 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005162 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 return status;
5164}
5165
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005166QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 hdd_adapter_list_node_t *adapterNode)
5168{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305169 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005170
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005171 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305172 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5173 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005174 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175 return status;
5176}
5177
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005178QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179 hdd_adapter_list_node_t *adapterNode)
5180{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305181 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005182
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005183 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305184 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5185 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005186 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187 return status;
5188}
5189
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005190hdd_adapter_t *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 tSirMacAddr macAddr)
5192{
5193 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5194 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305195 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196
5197 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5198
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305199 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200 adapter = adapterNode->pAdapter;
5201
5202 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305203 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005204 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5208 adapterNode = pNext;
5209 }
5210
5211 return NULL;
5212
5213}
5214
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005215hdd_adapter_t *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 uint32_t vdev_id)
5217{
5218 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5219 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305220 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305222 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305224 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 adapter = adapterNode->pAdapter;
5226
5227 if (adapter->sessionId == vdev_id)
5228 return adapter;
5229
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305230 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5232 adapterNode = pNext;
5233 }
5234
Jeff Johnson5880d792016-08-15 13:32:30 -07005235 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236
5237 return NULL;
5238}
5239
Abhishek Singh7996eb72015-12-30 17:24:02 +05305240/**
5241 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5242 * the sessionid
5243 * @hdd_ctx: hdd context.
5244 * @sme_session_id: sme session is for the adapter to get.
5245 *
5246 * This function is used to get the adapter with provided session id
5247 *
5248 * Return: adapter pointer if found
5249 *
5250 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005251hdd_adapter_t *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305252 uint32_t sme_session_id)
5253{
5254 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5255 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305256 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305257
5258
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305259 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305260
5261 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305262 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305263 adapter = adapter_node->pAdapter;
5264
5265 if (adapter &&
5266 adapter->sessionId == sme_session_id)
5267 return adapter;
5268
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305269 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305270 hdd_get_next_adapter(hdd_ctx,
5271 adapter_node, &next);
5272 adapter_node = next;
5273 }
5274 return NULL;
5275}
5276
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005277hdd_adapter_t *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005278 const char *iface_name)
5279{
5280 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
5281 hdd_adapter_t *adapter;
5282 QDF_STATUS qdf_status;
5283
5284 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5285
5286 while ((NULL != adapter_node) &&
5287 (QDF_STATUS_SUCCESS == qdf_status)) {
5288 adapter = adapter_node->pAdapter;
5289
5290 if (adapter &&
5291 !qdf_str_cmp(adapter->dev->name, iface_name))
5292 return adapter;
5293
5294 qdf_status =
5295 hdd_get_next_adapter(hdd_ctx,
5296 adapter_node, &next);
5297 adapter_node = next;
5298 }
5299 return NULL;
5300}
5301
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005302/**
5303 * hdd_get_adapter() - to get adapter matching the mode
5304 * @hdd_ctx: hdd context
5305 * @mode: adapter mode
5306 *
5307 * This routine will return the pointer to adapter matching
5308 * with the passed mode.
5309 *
5310 * Return: pointer to adapter or null
5311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005312hdd_adapter_t *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005313 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314{
5315 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5316 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305317 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318
5319 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5320
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305321 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 adapter = adapterNode->pAdapter;
5323
5324 if (adapter && (mode == adapter->device_mode))
5325 return adapter;
5326
5327 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5328 adapterNode = pNext;
5329 }
5330
5331 return NULL;
5332
5333}
5334
5335/**
5336 * hdd_get_operating_channel() - return operating channel of the device mode
5337 * @hdd_ctx: Pointer to the HDD context.
5338 * @mode: Device mode for which operating channel is required.
5339 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005340 * QDF_STA_MODE,
5341 * QDF_P2P_CLIENT_MODE,
5342 * QDF_SAP_MODE,
5343 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344 *
5345 * This API returns the operating channel of the requested device mode
5346 *
5347 * Return: channel number. "0" id the requested device is not found OR it is
5348 * not connected.
5349 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005350uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005351 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352{
5353 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305354 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 hdd_adapter_t *adapter;
5356 uint8_t operatingChannel = 0;
5357
5358 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305360 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361 adapter = adapterNode->pAdapter;
5362
5363 if (mode == adapter->device_mode) {
5364 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005365 case QDF_STA_MODE:
5366 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367 if (hdd_conn_is_connected
5368 (WLAN_HDD_GET_STATION_CTX_PTR
5369 (adapter))) {
5370 operatingChannel =
5371 (WLAN_HDD_GET_STATION_CTX_PTR
5372 (adapter))->conn_info.
5373 operationChannel;
5374 }
5375 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005376 case QDF_SAP_MODE:
5377 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378 /* softap connection info */
5379 if (test_bit
5380 (SOFTAP_BSS_STARTED,
5381 &adapter->event_flags))
5382 operatingChannel =
5383 (WLAN_HDD_GET_AP_CTX_PTR
5384 (adapter))->operatingChannel;
5385 break;
5386 default:
5387 break;
5388 }
5389
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005390 /* Found the device of interest. break the loop */
5391 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 }
5393
5394 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5395 adapterNode = pNext;
5396 }
5397 return operatingChannel;
5398}
5399
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005400static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005401 hdd_ctx)
5402{
5403 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305404 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405 hdd_adapter_t *adapter;
5406
5407 ENTER();
5408
5409 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5410
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305411 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005413 if ((adapter->device_mode == QDF_STA_MODE) ||
5414 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5415 (adapter->device_mode == QDF_IBSS_MODE) ||
5416 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5417 (adapter->device_mode == QDF_SAP_MODE) ||
5418 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005419 wlan_hdd_cfg80211_deregister_frames(adapter);
5420 hdd_unregister_wext(adapter->dev);
5421 }
5422 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5423 adapterNode = pNext;
5424 }
5425
5426 EXIT();
5427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305428 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005429}
5430
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005431QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432{
5433 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305434 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435 hdd_adapter_t *adapter;
5436
5437 ENTER();
5438
5439 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5440
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305441 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005442 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005443 if ((adapter->device_mode == QDF_STA_MODE) ||
5444 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5445 (adapter->device_mode == QDF_IBSS_MODE) ||
5446 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5447 (adapter->device_mode == QDF_SAP_MODE) ||
5448 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305449 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5450 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005451 }
5452 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5453 adapterNode = pNext;
5454 }
5455
5456 EXIT();
5457
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305458 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005459}
5460
Dustin Brownf27bce82016-11-03 12:52:27 -07005461/**
5462 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5463 * adapters
5464 * @hdd_ctx: The HDD context containing the adapters to operate on
5465 *
5466 * return: QDF_STATUS_SUCCESS
5467 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005468static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005469{
5470 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5471 QDF_STATUS status;
5472 hdd_adapter_t *adapter;
5473 int err;
5474
5475 ENTER();
5476
5477 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5478
5479 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5480 adapter = adapter_node->pAdapter;
5481 if ((adapter->device_mode == QDF_STA_MODE) ||
5482 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5483 (adapter->device_mode == QDF_IBSS_MODE) ||
5484 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5485 (adapter->device_mode == QDF_SAP_MODE) ||
5486 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5487 err = wlan_hdd_sched_scan_stop(adapter->dev);
5488 if (err)
5489 hdd_err("Unable to stop scheduled scan");
5490 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005491 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5492 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005493 adapter_node = next_node;
5494 }
5495
5496 EXIT();
5497
5498 return QDF_STATUS_SUCCESS;
5499}
5500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501#ifdef WLAN_NS_OFFLOAD
5502/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005503 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504 * @hdd_ctx: Pointer to hdd context
5505 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005506 * Unregister for IPv6 address change notifications.
5507 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508 * Return: None
5509 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005510static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005511{
5512 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513}
5514
5515/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005516 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517 * @hdd_ctx: Pointer to hdd context
5518 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005519 * Register for IPv6 address change notifications.
5520 *
5521 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005522 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005523static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524{
5525 int ret;
5526
5527 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5528 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005529 if (ret) {
5530 hdd_err("Failed to register IPv6 notifier: %d", ret);
5531 goto out;
5532 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005534 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005535out:
5536 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537}
5538#else
5539/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005540 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005541 * @hdd_ctx: Pointer to hdd context
5542 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005543 * Unregister for IPv6 address change notifications.
5544 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005545 * Return: None
5546 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005547static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548{
5549}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005550
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005551/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005552 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553 * @hdd_ctx: Pointer to hdd context
5554 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005555 * Register for IPv6 address change notifications.
5556 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005557 * Return: None
5558 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005559static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005560{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005561 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562}
5563#endif
5564
5565/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005566 * hdd_register_notifiers - Register netdev notifiers.
5567 * @hdd_ctx: HDD context
5568 *
5569 * Register netdev notifiers like IPv4 and IPv6.
5570 *
5571 * Return: 0 on success and errno on failure
5572 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005573static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005574{
5575 int ret;
5576
5577 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5578 if (ret) {
5579 hdd_err("register_netdevice_notifier failed: %d", ret);
5580 goto out;
5581 }
5582
5583 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5584 if (ret)
5585 goto unregister_notifier;
5586
5587 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5588 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5589 if (ret) {
5590 hdd_err("Failed to register IPv4 notifier: %d", ret);
5591 goto unregister_ip6_notifier;
5592 }
5593
5594 return 0;
5595
5596unregister_ip6_notifier:
5597 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5598unregister_notifier:
5599 unregister_netdevice_notifier(&hdd_netdev_notifier);
5600out:
5601 return ret;
5602
5603}
5604
5605/**
5606 * hdd_unregister_notifiers - Unregister netdev notifiers.
5607 * @hdd_ctx: HDD context
5608 *
5609 * Unregister netdev notifiers like IPv4 and IPv6.
5610 *
5611 * Return: None.
5612 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005613void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005614{
5615 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5616
5617 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5618
5619 unregister_netdevice_notifier(&hdd_netdev_notifier);
5620}
5621
5622/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005623 * hdd_exit_netlink_services - Exit netlink services
5624 * @hdd_ctx: HDD context
5625 *
5626 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5627 * nl service.
5628 *
5629 * Return: None.
5630 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005631static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005632{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005633 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005634 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005635 ptt_sock_deactivate_svc();
5636
5637 nl_srv_exit();
5638}
5639
5640/**
5641 * hdd_init_netlink_services- Init netlink services
5642 * @hdd_ctx: HDD context
5643 *
5644 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5645 * nl service.
5646 *
5647 * Return: 0 on success and errno on failure.
5648 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005649static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005650{
5651 int ret;
5652
Ryan Hsuceddceb2016-04-28 10:20:14 -07005653 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005654 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005655 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005656 goto out;
5657 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005658 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005659
Naveen Rawat910726a2017-03-06 11:42:51 -08005660 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005661 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005662 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005663 goto err_nl_srv;
5664 }
5665
5666 ret = ptt_sock_activate_svc();
5667 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005668 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005669 goto err_nl_srv;
5670 }
5671
5672 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005673 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005674 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005675
5676 ret = cnss_diag_activate_service();
5677 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005678 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005679 goto err_close_cesium;
5680 }
5681
5682 return 0;
5683
5684err_close_cesium:
5685 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005686 ptt_sock_deactivate_svc();
5687err_nl_srv:
5688 nl_srv_exit();
5689out:
5690 return ret;
5691}
5692
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005693/**
5694 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5695 * @hdd_ctx: HDD context.
5696 *
5697 * Destroy RX wakelock.
5698 *
5699 * Return: None.
5700 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005701static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005702{
5703 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5704}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005705
5706/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005707 * hdd_rx_wake_lock_create() - Create RX wakelock
5708 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005709 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005710 * Create RX wakelock.
5711 *
5712 * Return: None.
5713 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005714static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005715{
5716 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5717}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005718
5719/**
5720 * hdd_roc_context_init() - Init ROC context
5721 * @hdd_ctx: HDD context.
5722 *
5723 * Initialize ROC context.
5724 *
5725 * Return: 0 on success and errno on failure.
5726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005727static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005728{
5729 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5730 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5731
5732 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5733
5734 return 0;
5735}
5736
5737/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305738 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5739 * @hdd_ctx: HDD context.
5740 *
5741 * Free memory allocations made in ROC Req Queue nodes.
5742 *
5743 * Return: None.
5744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005745static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305746{
5747 hdd_roc_req_t *hdd_roc_req;
5748 QDF_STATUS status;
5749
5750 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5751
5752 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5753 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5754 (qdf_list_node_t **) &hdd_roc_req);
5755
5756 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305757 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5758 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305759 QDF_ASSERT(0);
5760 return;
5761 }
5762
5763 if (hdd_roc_req->pRemainChanCtx)
5764 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5765
5766 qdf_mem_free(hdd_roc_req);
5767 }
5768
5769 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5770}
5771
5772/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005773 * hdd_roc_context_destroy() - Destroy ROC context
5774 * @hdd_ctx: HDD context.
5775 *
5776 * Destroy roc list and flush the pending roc work.
5777 *
5778 * Return: None.
5779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005780static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005781{
5782 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305783 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005784 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005785}
5786
5787/**
Houston Hoffman160db392016-10-10 17:37:51 -07005788 * hdd_context_deinit() - Deinitialize HDD context
5789 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005790 *
Houston Hoffman160db392016-10-10 17:37:51 -07005791 * Deinitialize HDD context along with all the feature specific contexts but
5792 * do not free hdd context itself. Caller of this API is supposed to free
5793 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005794 *
Houston Hoffman160db392016-10-10 17:37:51 -07005795 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005796 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005797static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005798{
Houston Hoffman160db392016-10-10 17:37:51 -07005799 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005800
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005801 hdd_roc_context_destroy(hdd_ctx);
5802
5803 hdd_sap_context_destroy(hdd_ctx);
5804
5805 hdd_rx_wake_lock_destroy(hdd_ctx);
5806
5807 hdd_tdls_context_destroy(hdd_ctx);
5808
5809 hdd_scan_context_destroy(hdd_ctx);
5810
5811 qdf_list_destroy(&hdd_ctx->hddAdapters);
5812
Houston Hoffman160db392016-10-10 17:37:51 -07005813 return 0;
5814}
5815
5816/**
5817 * hdd_context_destroy() - Destroy HDD context
5818 * @hdd_ctx: HDD context to be destroyed.
5819 *
5820 * Free config and HDD context as well as destroy all the resources.
5821 *
5822 * Return: None
5823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005824static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005825{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305826
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305827 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5828
Houston Hoffman160db392016-10-10 17:37:51 -07005829 hdd_context_deinit(hdd_ctx);
5830
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305831 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005832 hdd_ctx->config = NULL;
5833
5834 wiphy_free(hdd_ctx->wiphy);
5835}
5836
5837/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305838 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5839 *
5840 * This function is used to destroy bug report lock
5841 *
5842 * Return: None
5843 */
5844static void wlan_destroy_bug_report_lock(void)
5845{
5846 p_cds_contextType p_cds_context;
5847
5848 p_cds_context = cds_get_global_context();
5849 if (!p_cds_context) {
5850 hdd_err("cds context is NULL");
5851 return;
5852 }
5853
5854 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5855}
5856
5857/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858 * hdd_wlan_exit() - HDD WLAN exit function
5859 * @hdd_ctx: Pointer to the HDD Context
5860 *
5861 * This is the driver exit point (invoked during rmmod)
5862 *
5863 * Return: None
5864 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005865static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866{
5867 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305868 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305870 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005871
5872 ENTER();
5873
Arun Khandavallifae92942016-08-01 13:31:08 +05305874 if (QDF_TIMER_STATE_RUNNING ==
5875 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005876 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305877 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878 }
5879
Arun Khandavallifae92942016-08-01 13:31:08 +05305880 if (!QDF_IS_STATUS_SUCCESS
5881 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5882 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005883
Arun Khandavallifae92942016-08-01 13:31:08 +05305884
5885 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005886
Nitesh Shah61c10d92016-10-19 19:29:15 +05305887 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5888
Prashanth Bhattaab004382016-10-11 16:08:11 -07005889 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005890
5891#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305892 if (QDF_TIMER_STATE_RUNNING ==
5893 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5894 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005895 }
5896
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305897 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305898 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005899 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005900 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005901 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5902 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5903 hdd_ctx->last_acs_channel_list = NULL;
5904 hdd_ctx->num_of_channels = 0;
5905 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005906#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005907
Arun Khandavallifae92942016-08-01 13:31:08 +05305908 mutex_lock(&hdd_ctx->iface_change_lock);
5909 driver_status = hdd_ctx->driver_status;
5910 mutex_unlock(&hdd_ctx->iface_change_lock);
5911
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005912 /*
5913 * Powersave Offload Case
5914 * Disable Idle Power Save Mode
5915 */
5916 hdd_set_idle_ps_config(hdd_ctx, false);
5917
Arun Khandavallifae92942016-08-01 13:31:08 +05305918 if (driver_status != DRIVER_MODULES_CLOSED) {
5919 hdd_unregister_wext_all_adapters(hdd_ctx);
5920 /*
5921 * Cancel any outstanding scan requests. We are about to close
5922 * all of our adapters, but an adapter structure is what SME
5923 * passes back to our callback function. Hence if there
5924 * are any outstanding scan requests then there is a
5925 * race condition between when the adapter is closed and
5926 * when the callback is invoked. We try to resolve that
5927 * race condition here by canceling any outstanding scans
5928 * before we close the adapters.
5929 * Note that the scans may be cancelled in an asynchronous
5930 * manner, so ideally there needs to be some kind of
5931 * synchronization. Rather than introduce a new
5932 * synchronization here, we will utilize the fact that we are
5933 * about to Request Full Power, and since that is synchronized,
5934 * the expectation is that by the time Request Full Power has
5935 * completed, all scans will be cancelled
5936 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005937 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305938 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005939 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305940 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 }
5942
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305943 wlan_destroy_bug_report_lock();
5944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305946 * Close the scheduler before calling cds_close to make sure
5947 * no thread is scheduled after the each module close is
5948 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005949 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305950 qdf_status = cds_sched_close(p_cds_context);
5951 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305952 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305953 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005956 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305957
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305958 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5959 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5960 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962 /*
5963 * Close CDS
5964 * This frees pMac(HAL) context. There should not be any call
5965 * that requires pMac access after this.
5966 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005967
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005968 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005969 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005970
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005971 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005972
5973 hdd_ipa_cleanup(hdd_ctx);
5974
5975 /* Free up RoC request queue and flush workqueue */
5976 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005977
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305978 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305979 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305980 /*
5981 * If there is re_init failure wiphy would have already de-registered
5982 * check the wiphy status before un-registering again
5983 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305984 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305985 wiphy_unregister(wiphy);
5986 wlan_hdd_cfg80211_deinit(wiphy);
5987 hdd_lpass_notify_stop(hdd_ctx);
5988 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005989
Arun Khandavallifae92942016-08-01 13:31:08 +05305990 hdd_exit_netlink_services(hdd_ctx);
5991 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05305992#ifdef FEATURE_WLAN_CH_AVOID
5993 mutex_destroy(&hdd_ctx->avoid_freq_lock);
5994#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05305995
5996 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5997 if (driver_status)
5998 hdd_err("Pdev delete failed");
5999
6000 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6001 if (driver_status)
6002 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006003
6004 qdf_mem_free(hdd_ctx->target_hw_name);
6005
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006006 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007}
6008
6009void __hdd_wlan_exit(void)
6010{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006011 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012
6013 ENTER();
6014
Anurag Chouhan6d760662016-02-20 16:05:43 +05306015 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006016 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006017 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018 EXIT();
6019 return;
6020 }
6021
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006022 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306023 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 /* Do all the cleanup before deregistering the driver */
6026 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028 EXIT();
6029}
6030
6031#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006032/**
6033 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006034 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006035 *
6036 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6037 * Then new ACS request will do a fresh scan without reusing the cached
6038 * scan information.
6039 *
6040 * Return: void
6041 */
Tang Yingying523322d2017-01-17 23:28:43 +08006042static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006043{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006044 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006045
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006046 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006048 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6049 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6050 hdd_ctx->last_acs_channel_list = NULL;
6051 hdd_ctx->num_of_channels = 0;
6052 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053
6054 if (!hdd_ctx->hHal)
6055 return;
6056 sme_scan_flush_result(hdd_ctx->hHal);
6057}
6058#endif
6059
6060#ifdef QCA_HT_2040_COEX
6061/**
6062 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6063 * @adapter: pointer to adapter
6064 * @staId: station id
6065 * @macAddrSTA: station MAC address
6066 * @channel_type: channel type
6067 *
6068 * This function notifies FW with HT20/HT40 mode
6069 *
6070 * Return: 0 if successful, error number otherwise
6071 */
6072int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306073 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006074{
6075 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306076 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006077 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078
6079 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6080
6081 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306082 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006085 if (!hdd_ctx->hHal)
6086 return -EINVAL;
6087
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306088 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306090 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006091 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092 return -EINVAL;
6093 }
6094
6095 return 0;
6096}
6097#endif
6098
6099/**
6100 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6101 * @state: state
6102 *
6103 * This function notifies FW with modem power status
6104 *
6105 * Return: 0 if successful, error number otherwise
6106 */
6107int hdd_wlan_notify_modem_power_state(int state)
6108{
6109 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306110 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006111 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006112
Anurag Chouhan6d760662016-02-20 16:05:43 +05306113 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006114 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306115 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006116 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006118 if (!hdd_ctx->hHal)
6119 return -EINVAL;
6120
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306121 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6122 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006123 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006124 state);
6125 return -EINVAL;
6126 }
6127 return 0;
6128}
6129
6130/**
6131 *
6132 * hdd_post_cds_enable_config() - HDD post cds start config helper
6133 * @adapter - Pointer to the HDD
6134 *
6135 * Return: None
6136 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006137QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006138{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306139 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006140
6141 /*
6142 * Send ready indication to the HDD. This will kick off the MAC
6143 * into a 'running' state and should kick off an initial scan.
6144 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306145 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6146 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006147 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6148 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306149 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006150 }
6151
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306152 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153}
6154
6155/* wake lock APIs for HDD */
6156void hdd_prevent_suspend(uint32_t reason)
6157{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306158 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006159}
6160
6161void hdd_allow_suspend(uint32_t reason)
6162{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306163 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006164}
6165
6166void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6167{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306168 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6169 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006170}
6171
6172/**
6173 * hdd_exchange_version_and_caps() - exchange version and capability with target
6174 * @hdd_ctx: Pointer to HDD context
6175 *
6176 * This is the HDD function to exchange version and capability information
6177 * between Host and Target
6178 *
6179 * This function gets reported version of FW.
6180 * It also finds the version of target headers used to compile the host;
6181 * It compares the above two and prints a warning if they are different;
6182 * It gets the SW and HW version string;
6183 * Finally, it exchanges capabilities between host and target i.e. host
6184 * and target exchange a msg indicating the features they support through a
6185 * bitmap
6186 *
6187 * Return: None
6188 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006189void hdd_exchange_version_and_caps(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190{
6191
6192 tSirVersionType versionCompiled;
6193 tSirVersionType versionReported;
6194 tSirVersionString versionString;
6195 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306196 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197
6198 memset(&versionCompiled, 0, sizeof(versionCompiled));
6199 memset(&versionReported, 0, sizeof(versionReported));
6200
6201 /* retrieve and display WCNSS version information */
6202 do {
6203
6204 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
6205 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306206 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006207 hdd_err("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 break;
6209 }
6210
6211 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
6212 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306213 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006214 hdd_err("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 break;
6216 }
6217
6218 if ((versionCompiled.major != versionReported.major) ||
6219 (versionCompiled.minor != versionReported.minor) ||
6220 (versionCompiled.version != versionReported.version) ||
6221 (versionCompiled.revision != versionReported.revision)) {
6222 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
6223 "Host expected %u.%u.%u.%u\n",
6224 WLAN_MODULE_NAME,
6225 (int)versionReported.major,
6226 (int)versionReported.minor,
6227 (int)versionReported.version,
6228 (int)versionReported.revision,
6229 (int)versionCompiled.major,
6230 (int)versionCompiled.minor,
6231 (int)versionCompiled.version,
6232 (int)versionCompiled.revision);
6233 } else {
6234 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
6235 WLAN_MODULE_NAME,
6236 (int)versionReported.major,
6237 (int)versionReported.minor,
6238 (int)versionReported.version,
6239 (int)versionReported.revision);
6240 }
6241
6242 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
6243 versionString,
6244 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306245 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006246 hdd_err("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247 break;
6248 }
6249
6250 pr_info("%s: WCNSS software version %s\n",
6251 WLAN_MODULE_NAME, versionString);
6252
6253 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
6254 versionString,
6255 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306256 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006257 hdd_err("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006258 break;
6259 }
6260
6261 pr_info("%s: WCNSS hardware version %s\n",
6262 WLAN_MODULE_NAME, versionString);
6263
6264 /*
6265 * 1.Check if FW version is greater than 0.1.1.0. Only then
6266 * send host-FW capability exchange message
6267 * 2.Host-FW capability exchange message is only present on
6268 * target 1.1 so send the message only if it the target is 1.1
6269 * minor numbers for different target branches:
6270 * 0 -> (1.0)Mainline Build
6271 * 1 -> (1.1)Mainline Build
6272 * 2->(1.04) Stability Build
6273 */
6274 if (((versionReported.major > 0) || (versionReported.minor > 1)
6275 || ((versionReported.minor >= 1)
6276 && (versionReported.version >= 1)))
6277 && ((versionReported.major == 1)
6278 && (versionReported.minor >= 1)))
6279 fwFeatCapsMsgSupported = 1;
6280
6281 if (fwFeatCapsMsgSupported) {
6282 /*
6283 * Indicate if IBSS heartbeat monitoring needs to be
6284 * offloaded
6285 */
6286 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
6287 sme_disable_feature_capablity
6288 (IBSS_HEARTBEAT_OFFLOAD);
6289 }
6290
6291 sme_feature_caps_exchange(hdd_ctx->hHal);
6292 }
6293
6294 } while (0);
6295
6296}
6297
6298/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006299QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006301
Amar Singhal6f8592b2017-04-26 14:31:58 -07006302 return sme_init_chan_list(hdd_ctx->hHal,
6303 hdd_ctx->reg.alpha2,
6304 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305}
6306
6307/**
6308 * hdd_is_5g_supported() - check if hardware supports 5GHz
6309 * @hdd_ctx: Pointer to the hdd context
6310 *
6311 * HDD function to know if hardware supports 5GHz
6312 *
6313 * Return: true if hardware supports 5GHz
6314 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006315bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006317 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006318 return true;
6319
Amar Singhal58b45ef2017-08-01 13:43:54 -07006320 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006321 return true;
6322 else
6323 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006324}
6325
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006326static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327{
6328 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006329 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330
6331 wiphy = hdd_ctx->wiphy;
6332
6333 /*
6334 * The channel information in
6335 * wiphy needs to be initialized before wiphy registration
6336 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006337 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6338 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006339 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006340 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341 }
6342
6343#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6344 wiphy->wowlan = &wowlan_support_reg_init;
6345#else
6346 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6347 WIPHY_WOWLAN_MAGIC_PKT |
6348 WIPHY_WOWLAN_DISCONNECT |
6349 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6350 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6351 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6352 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6353 WIPHY_WOWLAN_RFKILL_RELEASE;
6354
6355 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6356 WOW_MAX_FILTERS_PER_LIST);
6357 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6358 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6359#endif
6360
6361 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006362 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306363 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006364 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306365 return ret_val;
6366 }
6367
Amar Singhal5cccafe2017-02-15 12:42:58 -08006368 if (!hdd_ctx->reg_offload)
6369 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370
Amar Singhale4f28ee2015-10-21 14:36:56 -07006371 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372}
6373
Ravi Joshie2331e82015-07-01 18:18:54 -07006374/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006375 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006376 * @hdd_ctx - handle to hdd context
6377 * @tx_packets - transmit packet count
6378 * @rx_packets - receive packet count
6379 *
6380 * The function controls the bus bandwidth and dynamic control of
6381 * tcp delayed ack configuration
6382 *
6383 * Returns: None
6384 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006386static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006387 const uint64_t tx_packets,
6388 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006391 uint64_t temp_rx = 0;
6392 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006393 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006394 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006395 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006396 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006397 uint16_t index = 0;
6398 bool vote_level_change = false;
6399 bool rx_level_change = false;
6400 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006403 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006404 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006405 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006406 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006407 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006408 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006409 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006411 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006412 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6413 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006414 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006415 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006416 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306417 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306418 if (hdd_ctx->hbw_requested) {
6419 pld_remove_pm_qos(hdd_ctx->parent_dev);
6420 hdd_ctx->hbw_requested = false;
6421 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306422 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006423 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306424 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306425 if (!hdd_ctx->hbw_requested) {
6426 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6427 hdd_ctx->hbw_requested = true;
6428 }
6429
Nirav Shah3bbfa512016-05-12 16:43:49 +05306430 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006431 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306432 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006433 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006434 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006435
6436 /* fine-tuning parameters for RX Flows */
6437 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006439 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006440
Ravi Joshifed83572016-10-07 16:20:37 -07006441 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6442 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6443 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6444 next_rx_level = WLAN_SVC_TP_HIGH;
6445 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006446 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006447 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006448 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006449 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006451 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006452 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006453 next_rx_level, temp_rx);
6454 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006455 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006456 /* Send throughput indication only if it is enabled.
6457 * Disabling tcp_del_ack will revert the tcp stack behavior
6458 * to default delayed ack. Note that this will disable the
6459 * dynamic delayed ack mechanism across the system
6460 */
6461 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306462 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6463 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006464 &next_rx_level,
6465 sizeof(next_rx_level));
6466 }
6467
Mohit Khannae71e2262015-11-10 09:37:24 -08006468 /* fine-tuning parameters for TX Flows */
6469 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6470 hdd_ctx->prev_tx = tx_packets;
6471 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6472 next_tx_level = WLAN_SVC_TP_HIGH;
6473 else
6474 next_tx_level = WLAN_SVC_TP_LOW;
6475
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006476 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006477 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6478 next_tx_level, temp_tx);
6479 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006480 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306481 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6482 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006483 &next_tx_level,
6484 sizeof(next_tx_level));
6485 }
6486
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006487 index = hdd_ctx->hdd_txrx_hist_idx;
6488
6489 if (vote_level_change || tx_level_change || rx_level_change) {
6490 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6491 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6492 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6493 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6494 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6495 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6496 hdd_ctx->hdd_txrx_hist_idx++;
6497 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6498 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499}
6500
6501#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306502static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006504 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306505 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306507 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306508 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6509 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510 uint64_t total_tx = 0, total_rx = 0;
6511 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306512 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306513 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514 bool connected = false;
6515 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6516
Prashanth Bhattaab004382016-10-11 16:08:11 -07006517 if (wlan_hdd_validate_context(hdd_ctx))
6518 return;
6519
Jingxiang Gec64e1932017-08-22 14:38:59 +08006520 if (hdd_ctx->isWiphySuspended)
6521 goto restart_timer;
6522
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306524 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525 status =
6526 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6527
6528 if (adapterNode->pAdapter == NULL)
6529 continue;
6530 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306531 /*
6532 * Validate magic so we don't end up accessing
6533 * an invalid adapter.
6534 */
6535 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6536 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006537
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006538 if ((adapter->device_mode == QDF_STA_MODE ||
6539 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6541 != eConnectionState_Associated) {
6542
6543 continue;
6544 }
6545
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006546 if ((adapter->device_mode == QDF_SAP_MODE ||
6547 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006548 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6549
6550 continue;
6551 }
6552
6553 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6554 adapter->prev_tx_packets);
6555 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6556 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306557
6558 if (adapter->device_mode == QDF_SAP_MODE ||
6559 adapter->device_mode == QDF_P2P_GO_MODE ||
6560 adapter->device_mode == QDF_IBSS_MODE) {
6561
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006562 ret = cdp_get_intra_bss_fwd_pkts_count(
6563 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306564 adapter->sessionId,
6565 &fwd_tx_packets, &fwd_rx_packets);
6566 if (ret == A_OK) {
6567 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6568 fwd_tx_packets,
6569 adapter->prev_fwd_tx_packets);
6570 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6571 fwd_tx_packets,
6572 adapter->prev_fwd_rx_packets);
6573 }
6574 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575
6576 total_rx += adapter->stats.rx_packets;
6577 total_tx += adapter->stats.tx_packets;
6578
6579 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6580 adapter->prev_tx_packets = adapter->stats.tx_packets;
6581 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306582 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6583 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6585 connected = true;
6586 }
6587
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306588 /* add intra bss forwarded tx and rx packets */
6589 tx_packets += fwd_tx_packets_diff;
6590 rx_packets += fwd_rx_packets_diff;
6591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6593 tx_packets += (uint64_t)ipa_tx_packets;
6594 rx_packets += (uint64_t)ipa_rx_packets;
6595
6596 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006597 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598 return;
6599 }
6600
Yuanyuan Liu13738502016-04-06 17:41:37 -07006601 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602
6603 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6604 hdd_ipa_uc_stat_request(adapter, 2);
6605
Jingxiang Gec64e1932017-08-22 14:38:59 +08006606restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006607 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006608 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006609 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306610 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006611 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006612 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006614
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306615/**
6616 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6617 * @arg: Argument of timer function
6618 *
6619 * Schedule a workqueue in this function where all the processing is done.
6620 *
6621 * Return: None.
6622 */
6623static void __hdd_bus_bw_cbk(void *arg)
6624{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006625 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306626
6627 if (wlan_hdd_validate_context(hdd_ctx))
6628 return;
6629
6630 schedule_work(&hdd_ctx->bus_bw_work);
6631}
6632
6633/**
6634 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6635 * @arg: Argument of timer function
6636 *
6637 * Return: None.
6638 */
6639static void hdd_bus_bw_cbk(void *arg)
6640{
6641 cds_ssr_protect(__func__);
6642 __hdd_bus_bw_cbk(arg);
6643 cds_ssr_unprotect(__func__);
6644}
6645
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006646int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006647{
6648 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306649 INIT_WORK(&hdd_ctx->bus_bw_work,
6650 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006651 hdd_ctx->bus_bw_timer_running = false;
6652 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306653 qdf_timer_init(NULL,
6654 &hdd_ctx->bus_bw_timer,
6655 hdd_bus_bw_cbk, (void *)hdd_ctx,
6656 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006657
6658 return 0;
6659}
6660
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006661void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006662{
Dustin Brownfce08d12017-01-17 16:29:38 -08006663 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006664 hdd_reset_tcp_delack(hdd_ctx);
6665
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006666 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306667 cancel_work_sync(&hdd_ctx->bus_bw_work);
6668 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006669 hdd_ctx->bus_bw_timer_running = false;
6670 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006671}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672#endif
6673
6674/**
Nirav Shahed34b212016-04-25 10:59:16 +05306675 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6676 * @hdd_ctx: hdd context
6677 *
6678 * Return: 0 for success or error code
6679 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006680static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306681{
6682 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6683 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6684 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006685 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306686 return -ENOMEM;
6687 }
6688 return 0;
6689}
6690
6691/**
6692 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6693 * @hdd_ctx: hdd context
6694 *
6695 * Return: none
6696 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006697void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306698{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306699 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6700 return;
6701
6702 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6703 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306704}
6705
Nirav Shahda008342016-05-17 18:50:40 +05306706static uint8_t *convert_level_to_string(uint32_t level)
6707{
6708 switch (level) {
6709 /* initialize the wlan sub system */
6710 case WLAN_SVC_TP_NONE:
6711 return "NONE";
6712 case WLAN_SVC_TP_LOW:
6713 return "LOW";
6714 case WLAN_SVC_TP_MEDIUM:
6715 return "MED";
6716 case WLAN_SVC_TP_HIGH:
6717 return "HIGH";
6718 default:
6719 return "INVAL";
6720 }
6721}
6722
Nirav Shahed34b212016-04-25 10:59:16 +05306723
6724/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6726 * @hdd_ctx: hdd context
6727 *
6728 * Return: none
6729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006730void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731{
6732 int i;
6733
6734#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006735 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306736 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006737 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006738 hdd_ctx->config->busBandwidthHighThreshold,
6739 hdd_ctx->config->busBandwidthMediumThreshold,
6740 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006741 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306742 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006743 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744 hdd_ctx->config->tcpDelackThresholdHigh,
6745 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006746 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306747 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006748#endif
6749
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006750 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306751 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6752
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006753 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754
6755 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006756 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006757 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006758 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006759 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6760 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006761 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006762 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6763 convert_level_to_string(
6764 hdd_ctx->hdd_txrx_hist[i].
6765 next_vote_level),
6766 convert_level_to_string(
6767 hdd_ctx->hdd_txrx_hist[i].
6768 next_rx_level),
6769 convert_level_to_string(
6770 hdd_ctx->hdd_txrx_hist[i].
6771 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006773
6774 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775}
6776
6777/**
6778 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6779 * @hdd_ctx: hdd context
6780 *
6781 * Return: none
6782 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006783void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006784{
6785 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306786 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6787 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788}
6789
6790/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006791 * wlan_hdd_display_netif_queue_history() - display netif queue history
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006792 * @pHddCtx: hdd context
6793 *
6794 * Return: none
6795 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006796void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797{
6798
6799 hdd_adapter_t *adapter = NULL;
6800 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306801 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006802 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306803 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804
6805 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306806 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807 adapter = adapter_node->pAdapter;
6808
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006809 hdd_debug("Netif queue operation statistics:");
6810 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306811 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006812 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306813 curr_time = qdf_system_ticks();
6814 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306815 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306816 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306817 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306818 unpause = adapter->total_unpause_time;
6819 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306820 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306821 pause = adapter->total_pause_time;
6822 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006823 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306824 qdf_system_ticks_to_msecs(total),
6825 qdf_system_ticks_to_msecs(pause),
6826 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006827 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006828
Nirav Shahda008342016-05-17 18:50:40 +05306829 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6830 qdf_time_t pause_delta = 0;
6831
6832 if (adapter->pause_map & (1 << i))
6833 pause_delta = delta;
6834
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006835 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006836 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006837 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006838 hdd_reason_type_to_string(i),
6839 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306840 adapter->queue_oper_stats[i].unpause_count,
6841 qdf_system_ticks_to_msecs(
6842 adapter->queue_oper_stats[i].total_pause_time +
6843 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844 }
6845
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006846 hdd_debug("Netif queue operation history:");
6847 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306848 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6849
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006850 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851
6852 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006853 /* using hdd_log to avoid printing function name */
6854 if (adapter->queue_oper_history[i].time == 0)
6855 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006856 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006857 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306858 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006859 adapter->queue_oper_history[i].time),
6860 hdd_action_type_to_string(
6861 adapter->queue_oper_history[i].netif_action),
6862 hdd_reason_type_to_string(
6863 adapter->queue_oper_history[i].netif_reason),
6864 adapter->queue_oper_history[i].pause_map);
6865 }
6866
6867 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6868 adapter_node = next;
6869 }
6870
6871
6872}
6873
6874/**
6875 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6876 * @hdd_ctx: hdd context
6877 *
6878 * Return: none
6879 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006880void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006881{
6882 hdd_adapter_t *adapter = NULL;
6883 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306884 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006885
6886 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306887 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006888 adapter = adapter_node->pAdapter;
6889
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306890 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006891 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306892 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306894 adapter->history_index = 0;
6895 adapter->start_time = adapter->last_time = qdf_system_ticks();
6896 adapter->total_pause_time = 0;
6897 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006898 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6899 adapter_node = next;
6900 }
6901}
6902
6903/**
6904 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6905 * @halHandle: Hal handle
6906 * @pContext: Pointer to the context
6907 * @sessionId: Session ID
6908 * @scanId: Scan ID
6909 * @status: Status
6910 *
6911 * This is the callback to be executed when 11d scan is completed to flush out
6912 * the scan results
6913 *
6914 * 11d scan is done during driver load and is a passive scan on all
6915 * channels supported by the device, 11d scans may find some APs on
6916 * frequencies which are forbidden to be used in the regulatory domain
6917 * the device is operating in. If these APs are notified to the supplicant
6918 * it may try to connect to these APs, thus flush out all the scan results
6919 * which are present in SME after 11d scan is done.
6920 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306921 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306923static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924 uint8_t sessionId, uint32_t scanId,
6925 eCsrScanStatus status)
6926{
6927 ENTER();
6928
6929 sme_scan_flush_result(halHandle);
6930
6931 EXIT();
6932
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306933 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934}
6935
6936#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6937/**
6938 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6939 * @hdd_ctx: hdd global context
6940 *
6941 * Return: none
6942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006943static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006944{
6945 uint8_t i;
6946
6947 mutex_init(&hdd_ctx->op_ctx.op_lock);
6948 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6949 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6950 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6951 }
6952}
6953#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006954static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955{
6956}
6957#endif
6958
Yingying Tang95409972016-10-20 15:16:15 +08006959#ifdef WLAN_FEATURE_WOW_PULSE
6960/**
6961 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006962 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006963 * @enable: enable or disable this behaviour
6964 *
6965 * Return: int
6966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006967static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006968{
6969 struct hdd_config *pcfg_ini = phddctx->config;
6970 struct wow_pulse_mode wow_pulse_set_info;
6971 QDF_STATUS status;
6972
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006973 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006974
6975 if (false == phddctx->config->wow_pulse_support)
6976 return 0;
6977
6978 /* prepare the request to send to SME */
6979 if (enable == true) {
6980 wow_pulse_set_info.wow_pulse_enable = true;
6981 wow_pulse_set_info.wow_pulse_pin =
6982 pcfg_ini->wow_pulse_pin;
6983 wow_pulse_set_info.wow_pulse_interval_low =
6984 pcfg_ini->wow_pulse_interval_low;
6985 wow_pulse_set_info.wow_pulse_interval_high =
6986 pcfg_ini->wow_pulse_interval_high;
6987 } else {
6988 wow_pulse_set_info.wow_pulse_enable = false;
6989 wow_pulse_set_info.wow_pulse_pin = 0;
6990 wow_pulse_set_info.wow_pulse_interval_low = 0;
6991 wow_pulse_set_info.wow_pulse_interval_high = 0;
6992 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006993 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006994 wow_pulse_set_info.wow_pulse_enable,
6995 wow_pulse_set_info.wow_pulse_pin,
6996 wow_pulse_set_info.wow_pulse_interval_low,
6997 wow_pulse_set_info.wow_pulse_interval_high);
6998
6999 status = sme_set_wow_pulse(&wow_pulse_set_info);
7000 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007001 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007002 return -EIO;
7003 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007004 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007005 return 0;
7006}
7007#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007008static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007009{
7010 return 0;
7011}
7012#endif
7013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014#ifdef WLAN_FEATURE_FASTPATH
7015/**
7016 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7017 * @hdd_cfg: hdd config
7018 * @context: lower layer context
7019 *
7020 * Return: none
7021 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307022void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007023 void *context)
7024{
7025 if (hdd_cfg->fastpath_enable)
7026 hif_enable_fastpath(context);
7027}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007028#endif
7029
Yuanyuan Liu13738502016-04-06 17:41:37 -07007030#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007031/**
7032 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007033 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007034 * @level: thermal level
7035 *
7036 * Change IPA data path to SW path when the thermal throttle level greater
7037 * than 0, and restore the original data path when throttle level is 0
7038 *
7039 * Return: none
7040 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007041static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007042{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007043 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007045 /* Change IPA to SW path when throttle level greater than 0 */
7046 if (level > THROTTLE_LEVEL_0)
7047 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7048 else
7049 /* restore original concurrency mode */
7050 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7051}
7052
7053/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307054 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7055 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307056 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307058 * Get a safe channel to restart SAP. PCL already takes into account the
7059 * unsafe channels. So, the PCL is validated with the ACS range to provide
7060 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307062 * Return: Channel number to restart SAP in case of success. In case of any
7063 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007064 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307065static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
7066 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307068 struct sir_pcl_list pcl;
7069 QDF_STATUS status;
7070 uint32_t i, j;
7071 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007072 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307073 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307075 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7076 if (!hdd_ctx) {
7077 hdd_err("invalid HDD context");
7078 return INVALID_CHANNEL_ID;
7079 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307081 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7082 if (!hal_handle) {
7083 hdd_err("invalid HAL handle");
7084 return INVALID_CHANNEL_ID;
7085 }
7086
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007087 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7088 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007089 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7090 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307091 if (QDF_IS_STATUS_ERROR(status)) {
7092 hdd_err("Get PCL failed");
7093 return INVALID_CHANNEL_ID;
7094 }
7095
Frank Liudc2cefb2017-06-21 15:38:18 +08007096 /*
7097 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7098 * channel is unsafe channel, the pcl may be empty, instead of return,
7099 * try to choose a safe channel from acs range.
7100 */
7101 if (!pcl.pcl_len)
7102 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307103
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007104 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307105 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
7106 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
7107
7108 /* PCL already takes unsafe channel into account */
7109 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007110 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307111 if ((pcl.pcl_list[i] >=
7112 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7113 (pcl.pcl_list[i] <=
7114 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007115 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307116 return pcl.pcl_list[i];
7117 }
7118 }
7119
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007120 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307121
7122 /* Try for safe channel from all valid channel */
7123 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007124 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307125 &pcl.pcl_len);
7126 if (QDF_IS_STATUS_ERROR(status)) {
7127 hdd_err("error in getting valid channel list");
7128 return INVALID_CHANNEL_ID;
7129 }
7130
7131 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007132 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307133 found = false;
7134 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007135 if (pcl.pcl_list[i] ==
7136 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007137 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307138 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007139 break;
7140 }
7141 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307142
7143 if (found)
7144 continue;
7145
7146 if ((pcl.pcl_list[i] >=
7147 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7148 (pcl.pcl_list[i] <=
7149 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007150 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307151 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152 }
7153 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307154
7155 return INVALID_CHANNEL_ID;
7156}
7157
7158/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007159 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307160 * @adapter: AP adapter
7161 * @channel: Channel
7162 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007163 * Moves the SAP interface by invoking the function which
7164 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307165 *
7166 * Return: None
7167 */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007168void hdd_switch_sap_channel(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307169{
Jeff Johnson87251032017-08-29 13:31:11 -07007170 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307171 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007172 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307173
7174 if (!adapter) {
7175 hdd_err("invalid adapter");
7176 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007177 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307178
7179 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7180
7181 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7182 if (!hal_handle) {
7183 hdd_err("invalid HAL handle");
7184 return;
7185 }
7186
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007187 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7188
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307189 hdd_ap_ctx->sapConfig.channel = channel;
7190 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7191 hdd_ap_ctx->sapConfig.ch_width_orig;
7192
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007193 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307194 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7195
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007196 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7197 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307198 hdd_ap_ctx->sapConfig.sec_ch,
7199 &hdd_ap_ctx->sapConfig.ch_params);
7200
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007201 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7202 adapter->sessionId, channel,
7203 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007204}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307205
7206int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
7207{
7208 struct hdd_external_acs_timer_context *timer_context;
7209
7210 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7211
7212 if (QDF_TIMER_STATE_RUNNING ==
7213 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7214 ap.vendor_acs_timer)) {
7215 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7216 }
7217 timer_context = (struct hdd_external_acs_timer_context *)
7218 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7219 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307220 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307221 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307222 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7223 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307224 hdd_notice("Updated ACS config to nl with reason %d", reason);
7225
7226 return 0;
7227}
7228
Agrawal Ashish467dde42016-09-08 18:44:22 +05307229/**
7230 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7231 * @hdd_ctx: hdd context pointer
7232 *
7233 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7234 * and if ACS is enabled, driver will ask userspace to restart the
7235 * sap. User space on LTE coex indication restart driver.
7236 *
7237 * Return - none
7238 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007239void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307240{
7241 QDF_STATUS status;
7242 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
7243 hdd_adapter_t *adapter_temp;
7244 uint32_t i;
7245 bool found = false;
7246 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007247
Agrawal Ashish467dde42016-09-08 18:44:22 +05307248 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7249 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7250 adapter_temp = adapter_node->pAdapter;
7251
7252 if (!adapter_temp) {
7253 hdd_err("adapter is NULL, moving to next one");
7254 goto next_adapater;
7255 }
7256
7257 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7258 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007259 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307260 adapter_temp->device_mode,
7261 adapter_temp->sessionCtx.ap.sapConfig.
7262 acs_cfg.acs_mode);
7263 goto next_adapater;
7264 }
7265
7266 found = false;
7267 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007268 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307269 hdd_ctxt->unsafe_channel_list[i]) {
7270 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007271 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307272 adapter_temp->sessionCtx.ap.operatingChannel);
7273 break;
7274 }
7275 }
7276
7277 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007278 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307279 adapter_temp->sessionCtx.ap.operatingChannel);
7280 goto next_adapater;
7281 }
7282
Kapil Gupta8878ad92017-02-13 11:56:04 +05307283 if (hdd_ctxt->config->vendor_acs_support &&
7284 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7285 hdd_update_acs_timer_reason(adapter_temp,
7286 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7287 goto next_adapater;
7288 } else
7289 restart_chan =
7290 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307291 adapter_temp);
7292 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007293 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307294 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007295 /*
7296 * SAP restart due to unsafe channel. While
7297 * restarting the SAP, make sure to clear
7298 * acs_channel, channel to reset to
7299 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307300 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007301 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307302 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7303 adapter_temp->sessionCtx.ap.sapConfig.channel =
7304 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007305 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307306 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7307 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007308 hdd_debug("driver to start sap: %d",
7309 hdd_ctxt->config->sap_internal_restart);
7310 if (hdd_ctxt->config->sap_internal_restart)
7311 hdd_switch_sap_channel(adapter_temp, restart_chan);
7312 else
7313 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307314 }
7315
7316next_adapater:
7317 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7318 adapter_node = next;
7319 }
7320}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007322/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007323 * hdd_init_channel_avoidance() - Initialize channel avoidance
7324 * @hdd_ctx: HDD global context
7325 *
7326 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007327 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328 * down to the lower layers. Then subscribe to subsequent channel
7329 * avoidance events.
7330 *
7331 * Return: None
7332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007333static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334{
7335 uint16_t unsafe_channel_count;
7336 int index;
7337
Yuanyuan Liu13738502016-04-06 17:41:37 -07007338 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7339 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007340 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007341 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007343 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 hdd_ctx->unsafe_channel_count);
7345
Anurag Chouhan6d760662016-02-20 16:05:43 +05307346 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007347 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007348
7349 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007350 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351 hdd_ctx->unsafe_channel_list[index]);
7352
7353 }
7354
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355}
Dustin Brown676a2322017-08-15 13:16:13 -07007356
7357static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007358 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007359{
7360 uint8_t restart_chan;
7361
7362 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7363 if (!restart_chan) {
7364 hdd_alert("fail to restart SAP");
7365 return;
7366 }
7367
7368 /* SAP restart due to unsafe channel. While restarting
7369 * the SAP, make sure to clear acs_channel, channel to
7370 * reset to 0. Otherwise these settings will override
7371 * the ACS while restart.
7372 */
7373 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7374 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7375
7376 hdd_debug("sending coex indication");
7377
7378 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7379 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7380 hdd_switch_sap_channel(adapter, restart_chan);
7381}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007382
7383int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7384 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7385{
7386 uint32_t size;
7387 uint16_t *unsafe_list;
7388 uint16_t chan_count;
7389
7390 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7391 return -EINVAL;
7392
7393 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7394 NUM_CHANNELS);
7395 if (chan_count) {
7396 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7397 unsafe_list = qdf_mem_malloc(size);
7398 if (!unsafe_list) {
7399 hdd_err("No memory for unsafe chan list size%d",
7400 size);
7401 return -ENOMEM;
7402 }
7403 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7404 } else {
7405 unsafe_list = NULL;
7406 }
7407
7408 *local_unsafe_list = unsafe_list;
7409 *local_unsafe_list_count = chan_count;
7410
7411 return 0;
7412}
7413
7414bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7415 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7416{
7417 int i, j;
7418
7419 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7420 return true;
7421 if (local_unsafe_list_count == 0)
7422 return false;
7423 for (i = 0; i < local_unsafe_list_count; i++) {
7424 for (j = 0; j < local_unsafe_list_count; j++)
7425 if (local_unsafe_list[i] ==
7426 hdd_ctx->unsafe_channel_list[j])
7427 break;
7428 if (j >= local_unsafe_list_count)
7429 break;
7430 }
7431 if (i >= local_unsafe_list_count) {
7432 hdd_info("unsafe chan list same");
7433 return false;
7434 }
7435
7436 return true;
7437}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007438#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007439static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007440{
7441}
Dustin Brown676a2322017-08-15 13:16:13 -07007442
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007443static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444{
7445}
Dustin Brown676a2322017-08-15 13:16:13 -07007446
7447static inline void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007448 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007449{
7450 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7451}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007452#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007453
7454/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007455 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7456 * user space
7457 * @frame_ind: Management frame data to be informed.
7458 *
7459 * This function is used to indicate management frame to
7460 * user space
7461 *
7462 * Return: None
7463 *
7464 */
7465void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7466{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007467 struct hdd_context *hdd_ctx = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007468 hdd_adapter_t *adapter = NULL;
7469 void *cds_context = NULL;
7470 int i;
7471
7472 /* Get the global VOSS context.*/
7473 cds_context = cds_get_global_context();
7474 if (!cds_context) {
7475 hdd_err("Global CDS context is Null");
7476 return;
7477 }
7478 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007479 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007480
7481 if (0 != wlan_hdd_validate_context(hdd_ctx))
7482 return;
7483
7484 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7485 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7486 adapter =
7487 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7488 if (adapter)
7489 break;
7490 }
7491 } else {
7492 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7493 frame_ind->sessionId);
7494 }
7495
7496 if ((NULL != adapter) &&
7497 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7498 __hdd_indicate_mgmt_frame(adapter,
7499 frame_ind->frame_len,
7500 frame_ind->frameBuf,
7501 frame_ind->frameType,
7502 frame_ind->rxChan,
7503 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007504}
7505
Kapil Gupta8878ad92017-02-13 11:56:04 +05307506void hdd_acs_response_timeout_handler(void *context)
7507{
7508 struct hdd_external_acs_timer_context *timer_context =
7509 (struct hdd_external_acs_timer_context *)context;
7510 hdd_adapter_t *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007511 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307512 uint8_t reason;
7513
7514 ENTER();
7515 if (!timer_context) {
7516 hdd_err("invlaid timer context");
7517 return;
7518 }
7519 adapter = timer_context->adapter;
7520 reason = timer_context->reason;
7521
7522
7523 if ((!adapter) ||
7524 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7525 hdd_err("invalid adapter or adapter has invalid magic");
7526 return;
7527 }
7528 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7529 if (wlan_hdd_validate_context(hdd_ctx))
7530 return;
7531
7532 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7533 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7534 else
7535 return;
7536
7537 hdd_err("ACS timeout happened for %s reason %d",
7538 adapter->dev->name, reason);
7539 switch (reason) {
7540 /* SAP init case */
7541 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7542 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7543 false);
7544 wlan_hdd_cfg80211_start_acs(adapter);
7545 break;
7546 /* DFS detected on current channel */
7547 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7548 wlan_sap_update_next_channel(
7549 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7550 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7551 adapter->sessionId);
7552 break;
7553 /* LTE coex event on current channel */
7554 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7555 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7556 break;
7557 default:
7558 hdd_info("invalid reason for timer invoke");
7559
7560 }
7561}
7562
Rajeev Kumard004abc2016-02-17 12:09:56 -08007563/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7565 * @hdd_ctx: HDD context
7566 *
7567 * Disables all the dual mac features like DBS, Agile DFS etc.
7568 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307569 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007571static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007572{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007573 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307574 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575
7576 if (!hdd_ctx) {
7577 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307578 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007579 }
7580
7581 cfg.scan_config = 0;
7582 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007583 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007584
7585 hdd_debug("Disabling all dual mac features...");
7586
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007587 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307588 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007589 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7590 return status;
7591 }
7592
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307593 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007594}
7595
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007596static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007597wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007598{
7599 struct policy_mgr_dual_mac_config cfg = {0};
7600 QDF_STATUS status;
7601
7602 if (!hdd_ctx) {
7603 hdd_err("HDD context is NULL");
7604 return QDF_STATUS_E_FAILURE;
7605 }
7606
7607 cfg.scan_config = 0;
7608 cfg.fw_mode_config = 0;
7609 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7610 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7611 hdd_ctx->hdd_psoc, &cfg.scan_config,
7612 &cfg.fw_mode_config,
7613 hdd_ctx->config->dual_mac_feature_disable);
7614
7615 if (status != QDF_STATUS_SUCCESS) {
7616 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7617 status);
7618 return status;
7619 }
7620
7621 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7622 cfg.scan_config, cfg.fw_mode_config);
7623
7624 status = sme_soc_set_dual_mac_config(cfg);
7625 if (status != QDF_STATUS_SUCCESS) {
7626 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7627 return status;
7628 }
7629
7630 return QDF_STATUS_SUCCESS;
7631}
7632
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007634 * hdd_override_ini_config - Override INI config
7635 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007637 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007638 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007639 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007640 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007641static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007642{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007644 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7645 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007646 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007647 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007649 if (0 == enable_11d || 1 == enable_11d) {
7650 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007651 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007652 }
Leo Chang11545d62016-10-17 14:53:50 -07007653
7654 if (!hdd_ipa_is_present(hdd_ctx))
7655 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007656}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007657
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007658/**
7659 * hdd_set_trace_level_for_each - Set trace level for each INI config
7660 * @hdd_ctx - HDD context
7661 *
7662 * Set trace level for each module based on INI config.
7663 *
7664 * Return: None
7665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007666static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007667{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307668 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7669 hdd_ctx->config->qdf_trace_enable_wdi);
7670 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7671 hdd_ctx->config->qdf_trace_enable_hdd);
7672 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7673 hdd_ctx->config->qdf_trace_enable_sme);
7674 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7675 hdd_ctx->config->qdf_trace_enable_pe);
7676 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7677 hdd_ctx->config->qdf_trace_enable_wma);
7678 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7679 hdd_ctx->config->qdf_trace_enable_sys);
7680 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7681 hdd_ctx->config->qdf_trace_enable_qdf);
7682 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7683 hdd_ctx->config->qdf_trace_enable_sap);
7684 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7685 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7686 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7687 hdd_ctx->config->qdf_trace_enable_bmi);
7688 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7689 hdd_ctx->config->qdf_trace_enable_cfg);
7690 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7691 hdd_ctx->config->qdf_trace_enable_epping);
7692 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7693 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7694 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05307695 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307696 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7697 hdd_ctx->config->qdf_trace_enable_htc);
7698 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7699 hdd_ctx->config->qdf_trace_enable_hif);
7700 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7701 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7702 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7703 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007704 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7705 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007706 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7707 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007708 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7709 hdd_ctx->config->qdf_trace_enable_regulatory);
7710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007711 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007712}
7713
7714/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007715 * hdd_context_init() - Initialize HDD context
7716 * @hdd_ctx: HDD context.
7717 *
7718 * Initialize HDD context along with all the feature specific contexts.
7719 *
7720 * return: 0 on success and errno on failure.
7721 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007722static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007723{
7724 int ret;
7725
7726 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7727 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7728
7729 hdd_init_ll_stats_ctx();
7730
7731 init_completion(&hdd_ctx->mc_sus_event_var);
7732 init_completion(&hdd_ctx->ready_to_suspend);
7733
7734 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307735 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007736 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307737
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007738 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7739
7740 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7741
7742 ret = hdd_scan_context_init(hdd_ctx);
7743 if (ret)
7744 goto list_destroy;
7745
Nitesh Shahd1266d72017-01-25 22:07:07 +05307746 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007747
7748 hdd_rx_wake_lock_create(hdd_ctx);
7749
7750 ret = hdd_sap_context_init(hdd_ctx);
7751 if (ret)
7752 goto scan_destroy;
7753
7754 ret = hdd_roc_context_init(hdd_ctx);
7755 if (ret)
7756 goto sap_destroy;
7757
7758 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7759
7760 hdd_init_offloaded_packets_ctx(hdd_ctx);
7761
7762 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7763 hdd_ctx->config);
7764 if (ret)
7765 goto roc_destroy;
7766
7767 return 0;
7768
7769roc_destroy:
7770 hdd_roc_context_destroy(hdd_ctx);
7771
7772sap_destroy:
7773 hdd_sap_context_destroy(hdd_ctx);
7774
7775scan_destroy:
7776 hdd_scan_context_destroy(hdd_ctx);
7777 hdd_rx_wake_lock_destroy(hdd_ctx);
7778 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007779list_destroy:
7780 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007781
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007782 return ret;
7783}
7784
7785/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307786 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7787 * @hdd_ctx: pointer to hdd context
7788 *
7789 * Return: status of initialization
7790 * 0 - success
7791 * negative value - failure
7792 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007793static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307794{
7795 int ret;
7796
7797 if (!hdd_ctx->config->probe_req_ie_whitelist)
7798 return 0;
7799
7800 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7801 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7802 hdd_ctx->config->probe_req_ie_whitelist = false;
7803 return -EINVAL;
7804 }
7805
7806 /* parse ini string probe req oui */
7807 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7808 if (ret) {
7809 hdd_err("parsing error: disable ie whitelisting");
7810 hdd_ctx->config->probe_req_ie_whitelist = false;
7811 }
7812
7813 return ret;
7814}
7815
7816/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007817 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307818 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007819 *
7820 * Allocate and initialize HDD context. HDD context is allocated as part of
7821 * wiphy allocation and then context is initialized.
7822 *
7823 * Return: HDD context on success and ERR_PTR on failure
7824 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007825static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007826{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307827 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007828 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007829 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007830 v_CONTEXT_t p_cds_context;
7831
7832 ENTER();
7833
7834 p_cds_context = cds_get_global_context();
7835 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007836 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007837 ret = -EINVAL;
7838 goto err_out;
7839 }
7840
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007841 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007842
7843 if (hdd_ctx == NULL) {
7844 ret = -ENOMEM;
7845 goto err_out;
7846 }
7847
7848 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007849 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307850 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007851
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307852 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007853 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007854 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007855 ret = -ENOMEM;
7856 goto err_free_hdd_context;
7857 }
7858
7859 /* Read and parse the qcom_cfg.ini file */
7860 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307861 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307862 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007863 WLAN_INI_FILE);
7864 ret = -EINVAL;
7865 goto err_free_config;
7866 }
7867
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307868 ie_whitelist_attrs_init(hdd_ctx);
7869
Dustin Brown7f939932017-05-18 15:02:17 -07007870 hdd_debug("setting timer multiplier: %u",
7871 hdd_ctx->config->timer_multiplier);
7872 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7873
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007874
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307875 if (hdd_ctx->config->fhostNSOffload)
7876 hdd_ctx->ns_offload_enable = true;
7877
Abhishek Singh5ea86532016-04-27 14:10:53 +05307878 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7879
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007880 hdd_override_ini_config(hdd_ctx);
7881
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007882 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007883
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007884 ret = hdd_context_init(hdd_ctx);
7885
7886 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007887 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007888
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007889 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307890 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007891
Anurag Chouhan6d760662016-02-20 16:05:43 +05307892 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007893 goto skip_multicast_logging;
7894
7895 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7896
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007897 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7898 if (ret)
7899 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307900
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007901 ret = hdd_init_netlink_services(hdd_ctx);
7902 if (ret)
7903 goto err_deinit_txrx_histogram;
7904
Dustin Brown7b3dea22017-07-10 13:02:47 -07007905 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7906 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307907
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007908skip_multicast_logging:
7909 hdd_set_trace_level_for_each(hdd_ctx);
7910
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007911 EXIT();
7912
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007913 return hdd_ctx;
7914
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007915err_deinit_txrx_histogram:
7916 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7917
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007918err_deinit_hdd_context:
7919 hdd_context_deinit(hdd_ctx);
7920
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007921err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307922 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007923
7924err_free_hdd_context:
7925 wiphy_free(hdd_ctx->wiphy);
7926
7927err_out:
7928 return ERR_PTR(ret);
7929}
7930
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007931#ifdef WLAN_OPEN_P2P_INTERFACE
7932/**
7933 * hdd_open_p2p_interface - Open P2P interface
7934 * @hdd_ctx: HDD context
7935 * @rtnl_held: True if RTNL lock held
7936 *
7937 * Open P2P interface during probe. This function called to open the P2P
7938 * interface at probe along with STA interface.
7939 *
7940 * Return: 0 on success and errno on failure
7941 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007942static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007943{
7944 hdd_adapter_t *adapter;
7945 uint8_t *p2p_dev_addr;
7946
7947 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7948 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307949 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007950 hdd_ctx->config->intfMacAddr[0].bytes,
7951 sizeof(tSirMacAddr));
7952
7953 /*
7954 * Generate the P2P Device Address. This consists of
7955 * the device's primary MAC address with the locally
7956 * administered bit set.
7957 */
7958 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7959 } else {
7960 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7961 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007962 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007963 return -ENOSPC;
7964 }
7965
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307966 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307967 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007968 }
7969
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007970 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007971 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007972 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007973
7974 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007975 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007976 return -ENOSPC;
7977 }
7978
7979 return 0;
7980}
7981#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007982static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007983 bool rtnl_held)
7984{
7985 return 0;
7986}
7987#endif
7988
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007989static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007990{
7991 hdd_adapter_t *adapter;
7992 int ret = 0;
7993
7994 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7995 wlan_hdd_get_intf_addr(hdd_ctx),
7996 NET_NAME_UNKNOWN, rtnl_held);
7997 if (adapter == NULL) {
7998 hdd_err("Failed to open 802.11p interface");
7999 ret = -ENOSPC;
8000 }
8001
8002 return ret;
8003}
8004
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008005/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308006 * hdd_start_station_adapter()- Start the Station Adapter
8007 * @adapter: HDD adapter
8008 *
8009 * This function initializes the adapter for the station mode.
8010 *
8011 * Return: 0 on success or errno on failure.
8012 */
8013int hdd_start_station_adapter(hdd_adapter_t *adapter)
8014{
8015 QDF_STATUS status;
8016
8017 ENTER_DEV(adapter->dev);
8018
8019 status = hdd_init_station_mode(adapter);
8020
8021 if (QDF_STATUS_SUCCESS != status) {
8022 hdd_err("Error Initializing station mode: %d", status);
8023 return qdf_status_to_os_return(status);
8024 }
8025
Arun Khandavallifae92942016-08-01 13:31:08 +05308026 hdd_register_tx_flow_control(adapter,
8027 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008028 hdd_tx_resume_cb,
8029 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308030
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308031 EXIT();
8032 return 0;
8033}
8034
8035/**
8036 * hdd_start_ap_adapter()- Start AP Adapter
8037 * @adapter: HDD adapter
8038 *
8039 * This function initializes the adapter for the AP mode.
8040 *
8041 * Return: 0 on success errno on failure.
8042 */
8043int hdd_start_ap_adapter(hdd_adapter_t *adapter)
8044{
8045 QDF_STATUS status;
8046
8047 ENTER();
8048
Arun Khandavallicc544b32017-01-30 19:52:16 +05308049 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308050
8051 if (QDF_STATUS_SUCCESS != status) {
8052 hdd_err("Error Initializing the AP mode: %d", status);
8053 return qdf_status_to_os_return(status);
8054 }
8055
Arun Khandavallifae92942016-08-01 13:31:08 +05308056 hdd_register_tx_flow_control(adapter,
8057 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008058 hdd_softap_tx_resume_cb,
8059 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308060
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308061 EXIT();
8062 return 0;
8063}
8064
8065/**
8066 * hdd_start_ftm_adapter()- Start FTM adapter
8067 * @adapter: HDD adapter
8068 *
8069 * This function initializes the adapter for the FTM mode.
8070 *
8071 * Return: 0 on success or errno on failure.
8072 */
8073int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
8074{
8075 QDF_STATUS qdf_status;
8076
8077 ENTER_DEV(adapter->dev);
8078
8079 qdf_status = hdd_init_tx_rx(adapter);
8080
8081 if (QDF_STATUS_SUCCESS != qdf_status) {
8082 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8083 return qdf_status_to_os_return(qdf_status);
8084 }
8085
8086 return 0;
8087 EXIT();
8088}
8089
8090/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008091 * hdd_open_interfaces - Open all required interfaces
8092 * hdd_ctx: HDD context
8093 * rtnl_held: True if RTNL lock is held
8094 *
8095 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8096 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008097 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008099static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008100{
Jeff Johnson957bc272017-02-02 08:54:48 -08008101 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008102 int ret;
8103
Jeff Johnson957bc272017-02-02 08:54:48 -08008104 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308105 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008106 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008107
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008108 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008109 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008110 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008111
8112 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008113 return -ENOSPC;
8114
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008115 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8116 adapter->fast_roaming_allowed = true;
8117
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008118 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8119 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008120 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008121
8122 /* Open 802.11p Interface */
8123 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008124 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8125 if (ret)
8126 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008127 }
8128
Jeff Johnson957bc272017-02-02 08:54:48 -08008129 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008130
Jeff Johnson957bc272017-02-02 08:54:48 -08008131err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008132 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008133 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008134}
8135
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008136/**
8137 * hdd_update_country_code - Update country code
8138 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008139 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008140 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008141 *
8142 * Return: 0 on success and errno on failure
8143 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008144static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008145{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008146 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008147 return 0;
8148
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008149 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008150}
8151
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308152#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8153/**
8154 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8155 * @cds_cfg: CDS Configuration
8156 * @hdd_ctx: Pointer to hdd context
8157 *
8158 * Return: none
8159 */
8160static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8161 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008162 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308163{
8164 cds_cfg->tx_flow_stop_queue_th =
8165 hdd_ctx->config->TxFlowStopQueueThreshold;
8166 cds_cfg->tx_flow_start_queue_offset =
8167 hdd_ctx->config->TxFlowStartQueueOffset;
8168}
8169#else
8170static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8171 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008172 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308173{
8174}
8175#endif
8176
8177#ifdef FEATURE_WLAN_RA_FILTERING
8178/**
8179 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8180 * @cds_cfg: CDS Configuration
8181 * @hdd_ctx: Pointer to hdd context
8182 *
8183 * Return: none
8184 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308185static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008186 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308187{
8188 cds_cfg->ra_ratelimit_interval =
8189 hdd_ctx->config->RArateLimitInterval;
8190 cds_cfg->is_ra_ratelimit_enabled =
8191 hdd_ctx->config->IsRArateLimitEnabled;
8192}
8193#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308194static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008195 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308196{
8197}
8198#endif
8199
8200/**
8201 * hdd_update_cds_config() - API to update cds configuration parameters
8202 * @hdd_ctx: HDD Context
8203 *
8204 * Return: 0 for Success, errno on failure
8205 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008206static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308207{
8208 struct cds_config_info *cds_cfg;
8209
8210 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8211 if (!cds_cfg) {
8212 hdd_err("failed to allocate cds config");
8213 return -ENOMEM;
8214 }
8215
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008216 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008217 if (!hdd_ctx->config->nMaxPsPoll ||
8218 !hdd_ctx->config->enablePowersaveOffload) {
8219 cds_cfg->powersave_offload_enabled =
8220 hdd_ctx->config->enablePowersaveOffload;
8221 } else {
8222 if ((hdd_ctx->config->enablePowersaveOffload ==
8223 PS_QPOWER_NODEEPSLEEP) ||
8224 (hdd_ctx->config->enablePowersaveOffload ==
8225 PS_LEGACY_NODEEPSLEEP))
8226 cds_cfg->powersave_offload_enabled =
8227 PS_LEGACY_NODEEPSLEEP;
8228 else
8229 cds_cfg->powersave_offload_enabled =
8230 PS_LEGACY_DEEPSLEEP;
8231 hdd_info("Qpower disabled in cds config, %d",
8232 cds_cfg->powersave_offload_enabled);
8233 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308234 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8235 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8236 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8237 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8238 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8239
8240 /* Here ol_ini_info is used to store ini status of arp offload
8241 * ns offload and others. Currently 1st bit is used for arp
8242 * off load and 2nd bit for ns offload currently, rest bits are unused
8243 */
8244 if (hdd_ctx->config->fhostArpOffload)
8245 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8246 if (hdd_ctx->config->fhostNSOffload)
8247 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8248
8249 /*
8250 * Copy the DFS Phyerr Filtering Offload status.
8251 * This parameter reflects the value of the
8252 * dfs_phyerr_filter_offload flag as set in the ini.
8253 */
8254 cds_cfg->dfs_phyerr_filter_offload =
8255 hdd_ctx->config->fDfsPhyerrFilterOffload;
8256 if (hdd_ctx->config->ssdp)
8257 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8258
8259 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8260 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8261
8262 cds_cfg->ap_maxoffload_reorderbuffs =
8263 hdd_ctx->config->apMaxOffloadReorderBuffs;
8264
8265 cds_cfg->ap_disable_intrabss_fwd =
8266 hdd_ctx->config->apDisableIntraBssFwd;
8267
8268 cds_cfg->dfs_pri_multiplier =
8269 hdd_ctx->config->dfsRadarPriMultiplier;
8270 cds_cfg->reorder_offload =
8271 hdd_ctx->config->reorderOffloadSupport;
8272
8273 /* IPA micro controller data path offload resource config item */
8274 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008275 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8276 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008277 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008278 hdd_ctx->config->IpaUcTxBufCount);
8279 hdd_ctx->config->IpaUcTxBufCount =
8280 rounddown_pow_of_two(
8281 hdd_ctx->config->IpaUcTxBufCount);
8282 if (!hdd_ctx->config->IpaUcTxBufCount) {
8283 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308284 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008285 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008286 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008287 hdd_ctx->config->IpaUcTxBufCount);
8288 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308289 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8290 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008291 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8292 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008293 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008294 hdd_ctx->config->IpaUcRxIndRingCount);
8295 hdd_ctx->config->IpaUcRxIndRingCount =
8296 rounddown_pow_of_two(
8297 hdd_ctx->config->IpaUcRxIndRingCount);
8298 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8299 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308300 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008301 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008302 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008303 hdd_ctx->config->IpaUcRxIndRingCount);
8304 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308305 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008306 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308307 cds_cfg->uc_tx_partition_base =
8308 hdd_ctx->config->IpaUcTxPartitionBase;
8309 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8310
8311 cds_cfg->ip_tcp_udp_checksum_offload =
8312 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308313 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308314 cds_cfg->ce_classify_enabled =
8315 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008316 cds_cfg->bpf_packet_filter_enable =
8317 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308318 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8319 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8320 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008321 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008322 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008323 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008324 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308325 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8326 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308327 cds_cfg->auto_power_save_fail_mode =
8328 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308329
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308330 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8331
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308332 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8333 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8334 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008335 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308336 cds_init_ini_config(cds_cfg);
8337 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308338
8339exit:
8340 qdf_mem_free(cds_cfg);
8341 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308342}
8343
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008344/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008345 * hdd_update_user_config() - API to update user configuration
8346 * parameters to obj mgr which are used by multiple components
8347 * @hdd_ctx: HDD Context
8348 *
8349 * Return: 0 for Success, errno on failure
8350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008351static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008352{
8353 struct wlan_objmgr_psoc_user_config *user_config;
8354
8355 user_config = qdf_mem_malloc(sizeof(*user_config));
8356 if (user_config == NULL) {
8357 hdd_alert("Failed to alloc memory for user_config!");
8358 return -ENOMEM;
8359 }
8360
8361 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8362 user_config->dual_mac_feature_disable =
8363 hdd_ctx->config->dual_mac_feature_disable;
8364 user_config->indoor_channel_support =
8365 hdd_ctx->config->indoor_channel_support;
8366 user_config->is_11d_support_enabled =
8367 hdd_ctx->config->Is11dSupportEnabled;
8368 user_config->is_11h_support_enabled =
8369 hdd_ctx->config->Is11hSupportEnabled;
8370 user_config->optimize_chan_avoid_event =
8371 hdd_ctx->config->goptimize_chan_avoid_event;
8372 user_config->skip_dfs_chnl_in_p2p_search =
8373 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008374 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008375 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8376
8377 qdf_mem_free(user_config);
8378 return 0;
8379}
8380
8381/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008382 * hdd_init_thermal_info - Initialize thermal level
8383 * @hdd_ctx: HDD context
8384 *
8385 * Initialize thermal level at SME layer and set the thermal level callback
8386 * which would be called when a configured thermal threshold is hit.
8387 *
8388 * Return: 0 on success and errno on failure
8389 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008390static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008391{
8392 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308393 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008394
8395 thermal_param.smeThermalMgmtEnabled =
8396 hdd_ctx->config->thermalMitigationEnable;
8397 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8398
Poddar, Siddarth83905022016-04-16 17:56:08 -07008399 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8400 hdd_ctx->config->throttle_dutycycle_level0;
8401 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8402 hdd_ctx->config->throttle_dutycycle_level1;
8403 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8404 hdd_ctx->config->throttle_dutycycle_level2;
8405 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8406 hdd_ctx->config->throttle_dutycycle_level3;
8407
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008408 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8409 hdd_ctx->config->thermalTempMinLevel0;
8410 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8411 hdd_ctx->config->thermalTempMaxLevel0;
8412 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8413 hdd_ctx->config->thermalTempMinLevel1;
8414 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8415 hdd_ctx->config->thermalTempMaxLevel1;
8416 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8417 hdd_ctx->config->thermalTempMinLevel2;
8418 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8419 hdd_ctx->config->thermalTempMaxLevel2;
8420 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8421 hdd_ctx->config->thermalTempMinLevel3;
8422 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8423 hdd_ctx->config->thermalTempMaxLevel3;
8424
8425 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8426
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308427 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308428 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008429
8430 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8431 hdd_set_thermal_level_cb);
8432
8433 return 0;
8434
8435}
8436
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008437#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8438/**
8439 * hdd_hold_rtnl_lock - Hold RTNL lock
8440 *
8441 * Hold RTNL lock
8442 *
8443 * Return: True if held and false otherwise
8444 */
8445static inline bool hdd_hold_rtnl_lock(void)
8446{
8447 rtnl_lock();
8448 return true;
8449}
8450
8451/**
8452 * hdd_release_rtnl_lock - Release RTNL lock
8453 *
8454 * Release RTNL lock
8455 *
8456 * Return: None
8457 */
8458static inline void hdd_release_rtnl_lock(void)
8459{
8460 rtnl_unlock();
8461}
8462#else
8463static inline bool hdd_hold_rtnl_lock(void) { return false; }
8464static inline void hdd_release_rtnl_lock(void) { }
8465#endif
8466
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008467#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008468
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308469/* MAX iwpriv command support */
8470#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308471#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308472#define MAX_PKTLOG_SIZE 16
8473
8474/**
8475 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8476 * @hdd_ctx: hdd context
8477 * @set_value2: pktlog buffer size value
8478 *
8479 *
8480 * Return: 0 for success or error.
8481 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008482static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308483{
8484 struct sir_wifi_start_log start_log = { 0 };
8485 QDF_STATUS status;
8486
8487 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8488 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8489 start_log.ini_triggered = cds_is_packet_log_enabled();
8490 start_log.user_triggered = 1;
8491 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308492 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308493
8494 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8495 if (!QDF_IS_STATUS_SUCCESS(status)) {
8496 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8497 EXIT();
8498 return -EINVAL;
8499 }
8500
8501 return 0;
8502}
8503
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008504/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308505 * hdd_pktlog_clear_buff() - clear pktlog buffer
8506 * @hdd_ctx: hdd context
8507 *
8508 * Return: 0 for success or error.
8509 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008510static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308511{
8512 struct sir_wifi_start_log start_log;
8513 QDF_STATUS status;
8514
8515 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8516 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8517 start_log.ini_triggered = cds_is_packet_log_enabled();
8518 start_log.user_triggered = 1;
8519 start_log.size = 0;
8520 start_log.is_pktlog_buff_clear = true;
8521
8522 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8523 if (!QDF_IS_STATUS_SUCCESS(status)) {
8524 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8525 EXIT();
8526 return -EINVAL;
8527 }
8528
8529 return 0;
8530}
8531
8532
8533/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008534 * hdd_process_pktlog_command() - process pktlog command
8535 * @hdd_ctx: hdd context
8536 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308537 * @set_value2: pktlog buffer size value
8538 *
8539 * This function process pktlog command.
8540 * set_value2 only matters when set_value is 3 (set buff size)
8541 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008542 *
8543 * Return: 0 for success or error.
8544 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008545int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308546 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008547{
8548 int ret;
8549 bool enable;
8550 uint8_t user_triggered = 0;
8551
8552 ret = wlan_hdd_validate_context(hdd_ctx);
8553 if (0 != ret)
8554 return ret;
8555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008556 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008557
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308558 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008559 hdd_err("invalid pktlog value %d", set_value);
8560 return -EINVAL;
8561 }
8562
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308563 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8564 if (set_value2 <= 0) {
8565 hdd_err("invalid pktlog size %d", set_value2);
8566 return -EINVAL;
8567 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8568 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8569 return -EINVAL;
8570 }
8571 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308572 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8573 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308574 }
8575
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008576 /*
8577 * set_value = 0 then disable packetlog
8578 * set_value = 1 enable packetlog forcefully
8579 * set_vlaue = 2 then disable packetlog if disabled through ini or
8580 * enable packetlog with AUTO type.
8581 */
8582 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8583 true : false;
8584
8585 if (1 == set_value) {
8586 enable = true;
8587 user_triggered = 1;
8588 }
8589
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308590 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008591}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008592/**
8593 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8594 * @hdd_ctx: HDD context
8595 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308596 * @user_triggered: triggered through iwpriv
8597 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008598 *
8599 * Return: 0 on success; error number otherwise
8600 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008601int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308602 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008603{
8604 struct sir_wifi_start_log start_log;
8605 QDF_STATUS status;
8606
8607 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8608 start_log.verbose_level =
8609 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008610 start_log.ini_triggered = cds_is_packet_log_enabled();
8611 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308612 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308613 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308614 /*
8615 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8616 * commands. Host uses this flag to decide whether to send pktlog
8617 * disable command to fw without sending pktlog enable command
8618 * previously. For eg, If vendor sends pktlog disable command without
8619 * sending pktlog enable command, then host discards the packet
8620 * but for iwpriv command, host will send it to fw.
8621 */
8622 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008623 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8624 if (!QDF_IS_STATUS_SUCCESS(status)) {
8625 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8626 EXIT();
8627 return -EINVAL;
8628 }
8629
8630 return 0;
8631}
8632#endif /* REMOVE_PKT_LOG */
8633
Komal Seelam92fff912016-03-24 11:51:41 +05308634/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008635 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8636 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308637 * @dev: Device Pointer
8638 * @num: Number of Valid Mac address
8639 *
8640 * Return: Pointer to MAC address buffer
8641 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008642static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8643 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308644{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008645 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308646}
Komal Seelam92fff912016-03-24 11:51:41 +05308647
8648/**
8649 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8650 * @hdd_ctx: HDD Context
8651 * @num: Number of random mac addresses needed
8652 *
8653 * Generate random addresses using bit manipulation on the base mac address
8654 *
8655 * Return: None
8656 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008657void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308658{
8659 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8660 uint32_t iter;
8661 struct hdd_config *ini = hdd_ctx->config;
8662 uint8_t *buf = NULL;
8663 uint8_t macaddr_b3, tmp_br3;
8664 uint8_t *src = ini->intfMacAddr[0].bytes;
8665
8666 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8667 buf = ini->intfMacAddr[iter].bytes;
8668 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8669 macaddr_b3 = buf[3];
8670 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8671 INTF_MACADDR_MASK;
8672 macaddr_b3 += tmp_br3;
8673 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8674 buf[0] |= 0x02;
8675 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008676 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308677 }
8678}
8679
8680/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008681 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308682 * @hdd_ctx: HDD Context
8683 *
8684 * API to get mac addresses from platform driver and update the driver
8685 * structures and configure FW with the base mac address.
8686 * Return: int
8687 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008688static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308689{
8690 uint32_t no_of_mac_addr, iter;
8691 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8692 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8693 uint8_t *addr, *buf;
8694 struct device *dev = hdd_ctx->parent_dev;
8695 struct hdd_config *ini = hdd_ctx->config;
8696 tSirMacAddr mac_addr;
8697 QDF_STATUS status;
8698
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008699 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308700
8701 if (no_of_mac_addr == 0 || !addr) {
8702 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8703 return -EINVAL;
8704 }
8705
8706 if (no_of_mac_addr > max_mac_addr)
8707 no_of_mac_addr = max_mac_addr;
8708
8709 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8710
8711 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8712 buf = ini->intfMacAddr[iter].bytes;
8713 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008714 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308715 }
8716
8717 status = sme_set_custom_mac_addr(mac_addr);
8718
8719 if (!QDF_IS_STATUS_SUCCESS(status))
8720 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008721
Komal Seelam92fff912016-03-24 11:51:41 +05308722 if (no_of_mac_addr < max_mac_addr)
8723 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8724 no_of_mac_addr);
8725 return 0;
8726}
8727
8728/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008729 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8730 * @hdd_ctx: HDD Context
8731 *
8732 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8733 * will generate its own MAC and update it to FW.
8734 *
8735 * Return: 0 for success
8736 * Non-zero error code for failure
8737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008738static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008739{
8740 tSirMacAddr customMacAddr;
8741 QDF_STATUS status;
8742
8743 qdf_mem_copy(&customMacAddr,
8744 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8745 sizeof(tSirMacAddr));
8746 status = sme_set_custom_mac_addr(customMacAddr);
8747 if (!QDF_IS_STATUS_SUCCESS(status))
8748 return -EAGAIN;
8749 return 0;
8750}
8751
8752/**
Komal Seelam92fff912016-03-24 11:51:41 +05308753 * hdd_initialize_mac_address() - API to get wlan mac addresses
8754 * @hdd_ctx: HDD Context
8755 *
8756 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8757 * is provisioned with mac addresses, driver uses it, else it will use
8758 * wlan_mac.bin to update HW MAC addresses.
8759 *
8760 * Return: None
8761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008762static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308763{
8764 QDF_STATUS status;
8765 int ret;
8766
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008767 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308768 if (ret == 0)
8769 return;
8770
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008771 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8772 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308773
8774 status = hdd_update_mac_config(hdd_ctx);
8775
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008776 if (QDF_IS_STATUS_SUCCESS(status))
8777 return;
8778
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008779 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8780 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008781
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008782 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008783 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008784 if (ret != 0) {
8785 hdd_err("MAC address out-of-sync, ret:%d", ret);
8786 QDF_ASSERT(ret);
8787 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008788 }
Komal Seelam92fff912016-03-24 11:51:41 +05308789}
8790
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008791static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008792{
8793 int vdev_id = 0;
8794 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8795 int value = hdd_ctx->config->smart_chainmask_enabled;
8796 int vpdev = PDEV_CMD;
8797 int ret;
8798
Naveen Rawat247a8682017-06-05 15:00:31 -07008799 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008800 if (ret)
8801 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8802
8803 return ret;
8804}
8805
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008806static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008807{
8808 int vdev_id = 0;
8809 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8810 int value = hdd_ctx->config->alternative_chainmask_enabled;
8811 int vpdev = PDEV_CMD;
8812 int ret;
8813
Naveen Rawat247a8682017-06-05 15:00:31 -07008814 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008815 if (ret)
8816 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8817 ret);
8818
8819 return ret;
8820}
8821
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008822static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008823{
8824 int vdev_id = 0;
8825 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8826 int value = hdd_ctx->config->ani_enabled;
8827 int vpdev = PDEV_CMD;
8828 int ret;
8829
Naveen Rawat247a8682017-06-05 15:00:31 -07008830 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008831 if (ret)
8832 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8833
8834 return ret;
8835}
8836
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008837/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008838 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8839 * @hdd_ctx: HDD context
8840 *
8841 * Pre configurations to be done at lower layer before calling cds enable.
8842 *
8843 * Return: 0 on success and errno on failure.
8844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008845static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008846{
8847 int ret;
8848 QDF_STATUS status;
8849 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008850 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008851
Leo Changfdb45c32016-10-28 11:09:23 -07008852 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008853 /*
8854 * Set 802.11p config
8855 * TODO-OCB: This has been temporarily added here to ensure this
8856 * parameter is set in CSR when we init the channel list. This should
8857 * be removed once the 5.9 GHz channels are added to the regulatory
8858 * domain.
8859 */
8860 hdd_set_dot11p_config(hdd_ctx);
8861
8862 /*
8863 * Note that the cds_pre_enable() sequence triggers the cfg download.
8864 * The cfg download must occur before we update the SME config
8865 * since the SME config operation must access the cfg database
8866 */
8867 status = hdd_set_sme_config(hdd_ctx);
8868
8869 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008870 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008871 ret = qdf_status_to_os_return(status);
8872 goto out;
8873 }
8874
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008875 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8876 if (QDF_STATUS_SUCCESS != status) {
8877 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8878 ret = qdf_status_to_os_return(status);
8879 goto out;
8880 }
8881
Naveen Rawat247a8682017-06-05 15:00:31 -07008882 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008883 hdd_ctx->config->tx_chain_mask_1ss,
8884 PDEV_CMD);
8885 if (0 != ret) {
8886 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8887 goto out;
8888 }
8889
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008890 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8891 if (ret)
8892 goto out;
8893
8894 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8895 if (ret)
8896 goto out;
8897
Jeff Johnson12a744b2017-04-04 08:19:37 -07008898 ret = hdd_set_ani_enabled(hdd_ctx);
8899 if (ret)
8900 goto out;
8901
Naveen Rawat247a8682017-06-05 15:00:31 -07008902 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008903 hdd_ctx->config->arp_ac_category,
8904 PDEV_CMD);
8905 if (0 != ret) {
8906 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8907 hdd_ctx->config->arp_ac_category, ret);
8908 goto out;
8909 }
8910
8911
Prashanth Bhatta07998752016-04-28 12:35:33 -07008912 status = hdd_set_sme_chan_list(hdd_ctx);
8913 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008914 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008915 ret = qdf_status_to_os_return(status);
8916 goto out;
8917 }
8918
8919 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008920 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008921 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008922 ret = -EINVAL;
8923 goto out;
8924 }
8925
Prashanth Bhatta07998752016-04-28 12:35:33 -07008926 /*
8927 * Set the MAC Address Currently this is used by HAL to add self sta.
8928 * Remove this once self sta is added as part of session open.
8929 */
8930 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8931 hdd_ctx->config->intfMacAddr[0].bytes,
8932 sizeof(hdd_ctx->config->intfMacAddr[0]));
8933
8934 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8935 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8936 hal_status, hal_status);
8937 ret = -EINVAL;
8938 goto out;
8939 }
8940
8941 hdd_init_channel_avoidance(hdd_ctx);
8942
8943out:
8944 return ret;
8945}
8946
8947/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008948 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8949 * @context_ptr - hdd context pointer
8950 * @event_ptr - event structure pointer
8951 *
8952 * This is the p2p listen offload stop event handler, it sends vendor
8953 * event back to supplicant to notify the stop reason.
8954 *
8955 * Return: None
8956 */
8957static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8958 void *event_ptr)
8959{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008960 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008961 struct sir_p2p_lo_event *evt = event_ptr;
8962 struct sk_buff *vendor_event;
Peng Xu5c682812017-08-06 07:39:13 -07008963 hdd_adapter_t *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008964
8965 ENTER();
8966
8967 if (hdd_ctx == NULL) {
8968 hdd_err("Invalid HDD context pointer");
8969 return;
8970 }
8971
Peng Xu5c682812017-08-06 07:39:13 -07008972 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8973 if (!adapter) {
8974 hdd_err("Cannot find adapter by vdev_id = %d",
8975 evt->vdev_id);
8976 return;
8977 }
8978
Peng Xu8fdaa492016-06-22 10:20:47 -07008979 vendor_event =
8980 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008981 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008982 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8983 GFP_KERNEL);
8984
8985 if (!vendor_event) {
8986 hdd_err("cfg80211_vendor_event_alloc failed");
8987 return;
8988 }
8989
8990 if (nla_put_u32(vendor_event,
8991 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8992 evt->reason_code)) {
8993 hdd_err("nla put failed");
8994 kfree_skb(vendor_event);
8995 return;
8996 }
8997
8998 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008999 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9000 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009001}
9002
9003/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309004 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9005 * @hdd_ctx: HDD context
9006 *
9007 * This function sends the adaptive dwell time config configuration to the
9008 * firmware via WMA
9009 *
9010 * Return: 0 - success, < 0 - failure
9011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009012static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309013{
9014 QDF_STATUS status;
9015 struct adaptive_dwelltime_params dwelltime_params;
9016
9017 dwelltime_params.is_enabled =
9018 hdd_ctx->config->adaptive_dwell_mode_enabled;
9019 dwelltime_params.dwelltime_mode =
9020 hdd_ctx->config->global_adapt_dwelltime_mode;
9021 dwelltime_params.lpf_weight =
9022 hdd_ctx->config->adapt_dwell_lpf_weight;
9023 dwelltime_params.passive_mon_intval =
9024 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9025 dwelltime_params.wifi_act_threshold =
9026 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9027
9028 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9029 &dwelltime_params);
9030
9031 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9032 if (!QDF_IS_STATUS_SUCCESS(status)) {
9033 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9034 return -EAGAIN;
9035 }
9036 return 0;
9037}
9038
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009039int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309040{
9041 QDF_STATUS status;
9042 struct wmi_dbs_scan_sel_params dbs_scan_params;
9043 uint32_t i = 0;
9044 uint8_t count = 0, numentries = 0;
9045 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9046 * CDS_DBS_SCAN_CLIENTS_MAX];
9047
9048 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009049 if (hdd_ctx->config->dual_mac_feature_disable ==
9050 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309051 return -EINVAL;
9052
9053 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9054 dbs_scan_config, &numentries,
9055 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9056 * CDS_DBS_SCAN_CLIENTS_MAX));
9057
9058 hdd_info("numentries %hu", numentries);
9059 if (!numentries) {
9060 hdd_info("Donot send scan_selection_config");
9061 return 0;
9062 }
9063
9064 /* hdd_set_fw_log_params */
9065 dbs_scan_params.num_clients = 0;
9066 while (count < (numentries - 2)) {
9067 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9068 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9069 dbs_scan_params.num_non_dbs_scans[i] =
9070 dbs_scan_config[count + 2];
9071 dbs_scan_params.num_clients++;
9072 hdd_debug("module:%d NDS:%d NNDS:%d",
9073 dbs_scan_params.module_id[i],
9074 dbs_scan_params.num_dbs_scans[i],
9075 dbs_scan_params.num_non_dbs_scans[i]);
9076 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9077 i++;
9078 }
9079
9080 dbs_scan_params.pdev_id = 0;
9081
9082 hdd_debug("clients:%d pdev:%d",
9083 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9084
9085 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9086 &dbs_scan_params);
9087 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9088 if (!QDF_IS_STATUS_SUCCESS(status)) {
9089 hdd_err("Failed to send DBS Scan selection configuration!");
9090 return -EAGAIN;
9091 }
9092 return 0;
9093}
9094
Arun Khandavallid4349a92016-07-25 11:10:43 +05309095#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9096/**
9097 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9098 * @hdd_ctx: HDD context
9099 *
9100 * Set auto shutdown callback to get indications from firmware to indicate
9101 * userspace to shutdown WLAN after a configured amount of inactivity.
9102 *
9103 * Return: 0 on success and errno on failure.
9104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009105static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309106{
9107 QDF_STATUS status;
9108
9109 if (!hdd_ctx->config->WlanAutoShutdown)
9110 return 0;
9111
9112 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9113 wlan_hdd_auto_shutdown_cb);
9114 if (status != QDF_STATUS_SUCCESS)
9115 hdd_err("Auto shutdown feature could not be enabled: %d",
9116 status);
9117
9118 return qdf_status_to_os_return(status);
9119}
9120#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009121static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309122{
9123 return 0;
9124}
9125#endif
9126
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009127static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009128{
9129 QDF_STATUS status = QDF_STATUS_SUCCESS;
9130
9131 switch (hdd_ctx->config->dual_mac_feature_disable) {
9132 case DISABLE_DBS_CXN_AND_SCAN:
9133 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9134 if (status != QDF_STATUS_SUCCESS)
9135 hdd_err("Failed to disable dual mac features");
9136 break;
9137 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9138 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9139 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9140 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9141 if (status != QDF_STATUS_SUCCESS)
9142 hdd_err("Failed to set dbs scan and fw mode config");
9143 break;
9144 default:
9145 break;
9146 }
9147
9148 return status;
9149}
9150
Arun Khandavallid4349a92016-07-25 11:10:43 +05309151/**
9152 * hdd_features_init() - Init features
9153 * @hdd_ctx: HDD context
9154 * @adapter: Primary adapter context
9155 *
9156 * Initialize features and their feature context after WLAN firmware is up.
9157 *
9158 * Return: 0 on success and errno on failure.
9159 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009160static int hdd_features_init(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309161{
9162 tSirTxPowerLimit hddtxlimit;
9163 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309164 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309165 int ret;
9166
9167 ENTER();
9168
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009169 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309170 if (ret) {
9171 hdd_err("Failed to update country code: %d", ret);
9172 goto out;
9173 }
9174
9175 /* FW capabilities received, Set the Dot11 mode */
9176 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009177 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9178 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309179
Arun Khandavallid4349a92016-07-25 11:10:43 +05309180
9181 if (hdd_ctx->config->fIsImpsEnabled)
9182 hdd_set_idle_ps_config(hdd_ctx, true);
9183 else
9184 hdd_set_idle_ps_config(hdd_ctx, false);
9185
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309186 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009187 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309188
Arun Khandavallid4349a92016-07-25 11:10:43 +05309189 if (hdd_lro_init(hdd_ctx))
9190 hdd_err("Unable to initialize LRO in fw");
9191
9192 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9193 hdd_err("Unable to send adaptive dwelltime setting to FW");
9194
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309195 if (hdd_dbs_scan_selection_init(hdd_ctx))
9196 hdd_err("Unable to send DBS scan selection setting to FW");
9197
Arun Khandavallid4349a92016-07-25 11:10:43 +05309198 ret = hdd_init_thermal_info(hdd_ctx);
9199 if (ret) {
9200 hdd_err("Error while initializing thermal information");
9201 goto deregister_frames;
9202 }
9203
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309204 if (cds_is_packet_log_enabled())
9205 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9206
Arun Khandavallid4349a92016-07-25 11:10:43 +05309207 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9208 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9209 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9210 if (!QDF_IS_STATUS_SUCCESS(status))
9211 hdd_err("Error setting txlimit in sme: %d", status);
9212
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009213 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309214
Arun Khandavallid4349a92016-07-25 11:10:43 +05309215 ret = hdd_register_cb(hdd_ctx);
9216 if (ret) {
9217 hdd_err("Failed to register HDD callbacks!");
9218 goto deregister_frames;
9219 }
9220
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009221 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9222 if (!QDF_IS_STATUS_SUCCESS(status)) {
9223 hdd_err("Failed to set dbs scan and fw mode cfg");
9224 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309225 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009226
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309227 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9228 status = sme_enable_disable_chanavoidind_event(
9229 hdd_ctx->hHal, 0);
9230 if (!QDF_IS_STATUS_SUCCESS(status)) {
9231 hdd_err("Failed to disable Chan Avoidance Indication");
9232 goto deregister_cb;
9233 }
9234 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309235
Manjeet Singha9cae432017-02-28 11:58:22 +05309236 if (hdd_ctx->config->enable_5g_band_pref) {
9237 band_pref_params.rssi_boost_threshold_5g =
9238 hdd_ctx->config->rssi_boost_threshold_5g;
9239 band_pref_params.rssi_boost_factor_5g =
9240 hdd_ctx->config->rssi_boost_factor_5g;
9241 band_pref_params.max_rssi_boost_5g =
9242 hdd_ctx->config->max_rssi_boost_5g;
9243 band_pref_params.rssi_penalize_threshold_5g =
9244 hdd_ctx->config->rssi_penalize_threshold_5g;
9245 band_pref_params.rssi_penalize_factor_5g =
9246 hdd_ctx->config->rssi_penalize_factor_5g;
9247 band_pref_params.max_rssi_penalize_5g =
9248 hdd_ctx->config->max_rssi_penalize_5g;
9249 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9250 }
9251
Arun Khandavallid4349a92016-07-25 11:10:43 +05309252 /* register P2P Listen Offload event callback */
9253 if (wma_is_p2p_lo_capable())
9254 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9255 wlan_hdd_p2p_lo_event_callback);
9256
9257 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9258
9259 if (ret)
9260 goto deregister_cb;
9261
9262 EXIT();
9263 return 0;
9264
9265deregister_cb:
9266 hdd_deregister_cb(hdd_ctx);
9267deregister_frames:
9268 wlan_hdd_cfg80211_deregister_frames(adapter);
9269out:
9270 return -EINVAL;
9271
9272}
9273
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009274/**
9275 * hdd_features_deinit() - Deinit features
9276 * @hdd_ctx: HDD context
9277 *
9278 * De-Initialize features and their feature context.
9279 *
9280 * Return: none.
9281 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009282static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009283{
9284 wlan_hdd_tsf_deinit(hdd_ctx);
9285}
9286
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309287/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009288 * hdd_register_bcn_cb() - register scan beacon callback
9289 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309290 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009291 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309292 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009293static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309294{
9295 QDF_STATUS status;
9296
9297 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9298 wlan_cfg80211_inform_bss_frame,
9299 SCAN_CB_TYPE_INFORM_BCN);
9300 if (!QDF_IS_STATUS_SUCCESS(status)) {
9301 hdd_err("failed with status code %08d [x%08x]",
9302 status, status);
9303 return status;
9304 }
9305
9306 return QDF_STATUS_SUCCESS;
9307}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309308
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309309/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309310 * hdd_configure_cds() - Configure cds modules
9311 * @hdd_ctx: HDD context
9312 * @adapter: Primary adapter context
9313 *
9314 * Enable Cds modules after WLAN firmware is up.
9315 *
9316 * Return: 0 on success and errno on failure.
9317 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009318int hdd_configure_cds(struct hdd_context *hdd_ctx, hdd_adapter_t *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309319{
9320 int ret;
9321 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309322
9323 ret = hdd_pre_enable_configure(hdd_ctx);
9324 if (ret) {
9325 hdd_err("Failed to pre-configure cds");
9326 goto out;
9327 }
9328
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009329 /* Always get latest IPA resources allocated from cds_open and configure
9330 * IPA module before configuring them to FW. Sequence required as crash
9331 * observed otherwise.
9332 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009333 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9334 hdd_err("Failed to setup pipes");
9335 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009336 }
9337
Arun Khandavallifae92942016-08-01 13:31:08 +05309338 /*
9339 * Start CDS which starts up the SME/MAC/HAL modules and everything
9340 * else
9341 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309342 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309343
9344 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009345 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309346 goto out;
9347 }
9348
9349 status = hdd_post_cds_enable_config(hdd_ctx);
9350 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009351 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009352 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309353 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309354 status = hdd_register_bcn_cb(hdd_ctx);
9355 if (!QDF_IS_STATUS_SUCCESS(status)) {
9356 hdd_alert("hdd_post_cds_enable_config failed");
9357 goto cds_disable;
9358 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309359
9360 ret = hdd_features_init(hdd_ctx, adapter);
9361 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009362 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309363
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309364 if (hdd_enable_egap(hdd_ctx))
9365 hdd_debug("enhance green ap is not enabled");
9366
Nachiket Kukadedd302662017-07-13 17:31:44 +05309367 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9368 hdd_debug("Failed to set wow pulse");
9369
Arun Khandavallifae92942016-08-01 13:31:08 +05309370 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009371
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009372cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309373 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009374
Arun Khandavallifae92942016-08-01 13:31:08 +05309375out:
9376 return -EINVAL;
9377}
9378
9379/**
9380 * hdd_deconfigure_cds() -De-Configure cds
9381 * @hdd_ctx: HDD context
9382 *
9383 * Deconfigure Cds modules before WLAN firmware is down.
9384 *
9385 * Return: 0 on success and errno on failure.
9386 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009387static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309388{
9389 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009390 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309391
9392 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009393
9394 /* De-init features */
9395 hdd_features_deinit(hdd_ctx);
9396
Arun Khandavallifae92942016-08-01 13:31:08 +05309397 /* De-register the SME callbacks */
9398 hdd_deregister_cb(hdd_ctx);
9399
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309400 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9402 hdd_err("Failed to Disable the CDS Modules! :%d",
9403 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009404 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309405 }
9406
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309407 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9408 hdd_err("Failed to disconnect pipes");
9409 ret = -EINVAL;
9410 }
9411
Arun Khandavallifae92942016-08-01 13:31:08 +05309412 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009413 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309414}
9415
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009416#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9417static void hdd_deregister_policy_manager_callback(
9418 struct wlan_objmgr_psoc *psoc)
9419{
9420 if (QDF_STATUS_SUCCESS !=
9421 policy_mgr_deregister_hdd_cb(psoc)) {
9422 hdd_err("HDD callback deregister with policy manager failed");
9423 }
9424}
9425#else
9426static void hdd_deregister_policy_manager_callback(
9427 struct wlan_objmgr_psoc *psoc)
9428{
9429}
9430#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309431
9432/**
9433 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9434 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009435 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309436 *
9437 * This function maintains the driver state machine it will be invoked from
9438 * exit, shutdown and con_mode change handler. Depending on the driver state
9439 * shall perform the stopping/closing of the modules.
9440 *
9441 * Return: 0 for success; non-zero for failure
9442 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009443int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309444{
9445 void *hif_ctx;
9446 qdf_device_t qdf_ctx;
9447 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309448 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009449 bool is_idle_stop = !cds_is_driver_unloading() &&
9450 !cds_is_driver_recovering();
9451 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309452
9453 ENTER();
9454
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009455 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9456
Arun Khandavallifae92942016-08-01 13:31:08 +05309457 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9458 if (!qdf_ctx) {
9459 hdd_err("QDF device context NULL");
9460 return -EINVAL;
9461 }
9462
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309463 mutex_lock(&hdd_ctx->iface_change_lock);
9464 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309465
Dustin Brown70111822017-03-30 15:31:40 -07009466 active_threads = cds_return_external_threads_count();
9467 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009468 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009469 active_threads, hdd_ctx->isWiphySuspended);
9470
9471 cds_print_external_threads();
9472
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009473 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009474 mutex_unlock(&hdd_ctx->iface_change_lock);
9475 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009476 hdd_ctx->config->iface_change_wait_time);
9477 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009478 return 0;
9479 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009480 }
9481
Arun Khandavallifae92942016-08-01 13:31:08 +05309482 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9483
9484 switch (hdd_ctx->driver_status) {
9485 case DRIVER_MODULES_UNINITIALIZED:
9486 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309487 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309488 case DRIVER_MODULES_CLOSED:
9489 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309490 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309491 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309492 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309493 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009494 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309495 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309496 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309497 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009498 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309499 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9500 break;
9501 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009502 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309503 break;
9504 default:
9505 hdd_err("Trying to stop wlan in a wrong state: %d",
9506 hdd_ctx->driver_status);
9507 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309508 ret = -EINVAL;
9509 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309510 }
9511
Rajeev Kumarbe021242017-02-16 16:12:23 -08009512 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309513 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9514 hdd_err("Failed to process post CDS disable Modules! :%d",
9515 qdf_status);
9516 ret = -EINVAL;
9517 QDF_ASSERT(0);
9518 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309519 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309520 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009521 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309522 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309523 QDF_ASSERT(0);
9524 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009525
Arun Khandavallifae92942016-08-01 13:31:08 +05309526 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9527 if (!hif_ctx) {
9528 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309529 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309530 }
9531
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309532 hdd_runtime_suspend_context_deinit(hdd_ctx);
9533
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309534 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309535
9536 ol_cds_free();
9537
Dustin Brown70111822017-03-30 15:31:40 -07009538 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309539 ret = pld_power_off(qdf_ctx->dev);
9540 if (ret)
9541 hdd_err("CNSS power down failed put device into Low power mode:%d",
9542 ret);
9543 }
9544 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009545 /*
9546 * Reset total mac phy during module stop such that during
9547 * next module start same psoc is used to populate new service
9548 * ready data
9549 */
9550 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309551
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309552done:
9553 hdd_ctx->stop_modules_in_progress = false;
9554 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309555 EXIT();
9556
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309557 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309558
9559}
9560
9561/**
9562 * hdd_iface_change_callback() - Function invoked when stop modules expires
9563 * @priv: pointer to hdd context
9564 *
9565 * This function is invoked when the timer waiting for the interface change
9566 * expires, it shall cut-down the power to wlan and stop all the modules.
9567 *
9568 * Return: void
9569 */
9570static void hdd_iface_change_callback(void *priv)
9571{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009572 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309573 int ret;
9574 int status = wlan_hdd_validate_context(hdd_ctx);
9575
9576 if (status)
9577 return;
9578
9579 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009580 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009581 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309582 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009583 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309584 EXIT();
9585}
9586
9587/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309588 * hdd_state_info_dump() - prints state information of hdd layer
9589 * @buf: buffer pointer
9590 * @size: size of buffer to be filled
9591 *
9592 * This function is used to dump state information of hdd layer
9593 *
9594 * Return: None
9595 */
9596static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9597{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009598 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309599 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9600 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009601 struct hdd_station_ctx *hdd_sta_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309602 hdd_adapter_t *adapter;
9603 uint16_t len = 0;
9604 char *buf = *buf_ptr;
9605
9606 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9607 if (!hdd_ctx) {
9608 hdd_err("Failed to get hdd context ");
9609 return;
9610 }
9611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009612 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309613
9614 len += scnprintf(buf + len, *size - len,
9615 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9616 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009617 "\n is_scheduler_suspended %d",
9618 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309619
9620 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9621
9622 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9623 adapter = adapter_node->pAdapter;
9624 if (adapter->dev)
9625 len += scnprintf(buf + len, *size - len,
9626 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009627 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309628 "\n device_mode: %d", adapter->device_mode);
9629 switch (adapter->device_mode) {
9630 case QDF_STA_MODE:
9631 case QDF_P2P_CLIENT_MODE:
9632 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9633 len += scnprintf(buf + len, *size - len,
9634 "\n connState: %d",
9635 hdd_sta_ctx->conn_info.connState);
9636 break;
9637
9638 default:
9639 break;
9640 }
9641 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9642 adapter_node = next;
9643 }
9644
9645 *size -= len;
9646 *buf_ptr += len;
9647}
9648
9649/**
9650 * hdd_register_debug_callback() - registration function for hdd layer
9651 * to print hdd state information
9652 *
9653 * Return: None
9654 */
9655static void hdd_register_debug_callback(void)
9656{
9657 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9658}
9659
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309660/*
9661 * wlan_init_bug_report_lock() - Initialize bug report lock
9662 *
9663 * This function is used to create bug report lock
9664 *
9665 * Return: None
9666 */
9667static void wlan_init_bug_report_lock(void)
9668{
9669 p_cds_contextType p_cds_context;
9670
9671 p_cds_context = cds_get_global_context();
9672 if (!p_cds_context) {
9673 hdd_err("cds context is NULL");
9674 return;
9675 }
9676
9677 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9678}
9679
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309680/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009681 * hdd_wlan_startup() - HDD init function
9682 * @dev: Pointer to the underlying device
9683 *
9684 * This is the driver startup code executed once a WLAN device has been detected
9685 *
9686 * Return: 0 for success, < 0 for failure
9687 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309688int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009689{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309690 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009691 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009692 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009693 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309694 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009695 uint32_t num_abg_tx_chains = 0;
9696 uint32_t num_11b_tx_chains = 0;
9697 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009698
9699 ENTER();
9700
Arun Khandavallifae92942016-08-01 13:31:08 +05309701 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009702
9703 if (IS_ERR(hdd_ctx))
9704 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009705
Abhishek Singhe9068f12017-03-31 14:14:52 +05309706 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9707 DEFAULT_PSOC_ID);
9708 if (ret) {
9709 hdd_err("Psoc creation fails!");
9710 QDF_BUG(0);
9711 goto err_hdd_free_context;
9712 }
9713
Arun Khandavallifae92942016-08-01 13:31:08 +05309714 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9715 hdd_iface_change_callback, (void *)hdd_ctx);
9716
9717 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309718#ifdef FEATURE_WLAN_CH_AVOID
9719 mutex_init(&hdd_ctx->avoid_freq_lock);
9720#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309721
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009722 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009723 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309724
Jeff Johnson957bc272017-02-02 08:54:48 -08009725 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309726 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009727 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009728 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009729 }
9730
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309731 wlan_init_bug_report_lock();
9732
Yingying Tang80e15f32016-09-27 18:23:01 +08009733 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009734
Anurag Chouhan6d760662016-02-20 16:05:43 +05309735 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009736
9737 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009738 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309739 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009740 }
9741
Prashanth Bhatta07998752016-04-28 12:35:33 -07009742 ret = hdd_wiphy_init(hdd_ctx);
9743 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009744 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309745 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009746 }
9747
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309748 if (hdd_ctx->config->enable_dp_trace)
9749 qdf_dp_trace_init();
9750
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309751 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009752 goto err_wiphy_unregister;
9753
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309754 wlan_hdd_init_chan_info(hdd_ctx);
9755
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009756 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009757
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009758 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009759
Jeff Johnson957bc272017-02-02 08:54:48 -08009760 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9761 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009762 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009763 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009764 }
9765
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009766 hdd_release_rtnl_lock();
9767 rtnl_held = false;
9768
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009769 wlan_hdd_update_11n_mode(hdd_ctx->config);
9770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009771#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309772 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309773 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009774 hdd_skip_acs_scan_timer_handler,
9775 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309776 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009777 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009778 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009779#endif
9780
Nitesh Shah61c10d92016-10-19 19:29:15 +05309781 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9782 QDF_TIMER_TYPE_SW,
9783 wlan_hdd_change_tdls_mode,
9784 hdd_ctx);
9785
Prashanth Bhattaab004382016-10-11 16:08:11 -07009786 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009787
Jeff Johnson9afc5012016-09-23 13:56:27 -07009788 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009789
Nirav Shahbd36b062016-07-18 11:12:59 +05309790 if (hdd_ctx->rps)
9791 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009792
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009793 ret = hdd_register_notifiers(hdd_ctx);
9794 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009795 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309796
9797 status = wlansap_global_init();
9798 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009799 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009800
Komal Seelam8634b772016-09-29 12:12:24 +05309801 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009802 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309803 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009804
Arun Khandavallifae92942016-08-01 13:31:08 +05309805 if (hdd_ctx->config->fIsImpsEnabled)
9806 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309807
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309808 if (hdd_ctx->config->sifs_burst_duration) {
9809 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9810 hdd_ctx->config->sifs_burst_duration;
9811
9812 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009813 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309814 set_value, PDEV_CMD);
9815 }
9816
Paul Zhang42dade02017-05-12 19:20:37 +08009817 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009818 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009819 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309820 /* set chip power save failure detected callback */
9821 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9822 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009823
lifeng959a04c2017-05-10 14:21:28 +08009824 if (hdd_ctx->config->max_mpdus_inampdu) {
9825 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009826 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009827 set_value, PDEV_CMD);
9828 }
9829
9830 if (hdd_ctx->config->enable_rts_sifsbursting) {
9831 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009832 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009833 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9834 set_value, PDEV_CMD);
9835 }
9836
Will Huang496b36c2017-07-11 16:38:50 +08009837 if (hdd_ctx->config->sap_get_peer_info) {
9838 set_value = hdd_ctx->config->sap_get_peer_info;
9839 sme_cli_set_command(0,
9840 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9841 set_value, PDEV_CMD);
9842 }
9843
Naveen Rawat247a8682017-06-05 15:00:31 -07009844 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9845 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9846 if (!hdd_ctx->config->enable2x2) {
9847 if (num_11b_tx_chains > 1)
9848 num_11b_tx_chains = 1;
9849 if (num_11ag_tx_chains > 1)
9850 num_11ag_tx_chains = 1;
9851 }
9852 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9853 num_11b_tx_chains);
9854 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9855 num_11ag_tx_chains);
9856 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9857 num_abg_tx_chains, PDEV_CMD);
9858
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309859 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9860 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309861 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309862
Sachin Ahujadddd2632017-03-07 19:07:24 +05309863 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009864 goto success;
9865
Jeff Johnson957bc272017-02-02 08:54:48 -08009866err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009867 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009868
Jeff Johnson46bde382017-02-01 15:31:16 -08009869err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309870 if (rtnl_held)
9871 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009872
Anurag Chouhance6a4052016-09-14 18:20:42 +05309873 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009875err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009876 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009877
Arun Khandavallifae92942016-08-01 13:31:08 +05309878err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009879 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309880
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009881err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309882 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
9883 status = cds_sched_close(hdd_ctx->pcds_context);
9884 if (!QDF_IS_STATUS_SUCCESS(status)) {
9885 hdd_err("Failed to close CDS Scheduler");
9886 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9887 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009888 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889
Houston Hoffman47a4a052016-11-14 23:22:44 -08009890 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009891 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009892 hdd_exit_netlink_services(hdd_ctx);
9893
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309894 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009895
Dustin Brown20912462017-06-07 13:48:25 -07009896 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9897
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009898err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309899 if (cds_is_fw_down())
9900 hdd_err("Not setting the complete event as fw is down");
9901 else
9902 hdd_start_complete(ret);
9903
Arun Khandavallifae92942016-08-01 13:31:08 +05309904 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9905 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009906 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009907 return -EIO;
9908
9909success:
9910 EXIT();
9911 return 0;
9912}
9913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009914/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309915 * hdd_wlan_update_target_info() - update target type info
9916 * @hdd_ctx: HDD context
9917 * @context: hif context
9918 *
9919 * Update target info received from firmware in hdd context
9920 * Return:None
9921 */
9922
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009923void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309924{
9925 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9926
9927 if (!tgt_info) {
9928 hdd_err("Target info is Null");
9929 return;
9930 }
9931
9932 hdd_ctx->target_type = tgt_info->target_type;
9933}
9934
9935/**
9936 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309937 * @hdd_ctx: HDD context
9938 *
9939 * Register the HDD callbacks to CDS/SME.
9940 *
9941 * Return: 0 for success or Error code for failure
9942 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009943int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309944{
9945 QDF_STATUS status;
9946 int ret = 0;
9947
9948 ENTER();
9949
9950 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9951
9952 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9953 hdd_send_oem_data_rsp_msg);
9954
9955 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9956 wlan_hdd_cfg80211_fw_mem_dump_cb);
9957 if (!QDF_IS_STATUS_SUCCESS(status)) {
9958 hdd_err("Failed to register memdump callback");
9959 ret = -EINVAL;
9960 return ret;
9961 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309962 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9963 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309964 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9965 sme_nan_register_callback(hdd_ctx->hHal,
9966 wlan_hdd_cfg80211_nan_callback);
9967 sme_stats_ext_register_callback(hdd_ctx->hHal,
9968 wlan_hdd_cfg80211_stats_ext_callback);
9969
9970 sme_ext_scan_register_callback(hdd_ctx->hHal,
9971 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009972 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9973 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309974
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309975 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9976 hdd_rssi_threshold_breached);
9977
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309978 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9979 wlan_hdd_cfg80211_link_layer_stats_callback);
9980
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309981 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9982
Zhang Qianca38fb12016-12-23 11:10:48 +08009983 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9984 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9985
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309986 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9987 hdd_lost_link_info_cb);
9988 /* print error and not block the startup process */
9989 if (!QDF_IS_STATUS_SUCCESS(status))
9990 hdd_err("set lost link info callback failed");
9991
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309992 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9993
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009994 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009995 hdd_set_connection_in_progress,
9996 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309997
9998 status = sme_congestion_register_callback(hdd_ctx->hHal,
9999 hdd_update_cca_info_cb);
10000 if (!QDF_IS_STATUS_SUCCESS(status))
10001 hdd_err("set congestion callback failed");
10002
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010003 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10004 hdd_bt_activity_cb);
10005 if (!QDF_IS_STATUS_SUCCESS(status))
10006 hdd_err("set bt activity info callback failed");
10007
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010008 EXIT();
10009
10010 return ret;
10011}
10012
10013/**
10014 * hdd_deregister_cb() - De-Register HDD callbacks.
10015 * @hdd_ctx: HDD context
10016 *
10017 * De-Register the HDD callbacks to CDS/SME.
10018 *
10019 * Return: void
10020 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010021void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010022{
10023 QDF_STATUS status;
10024
10025 ENTER();
10026
10027 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10028 if (!QDF_IS_STATUS_SUCCESS(status))
10029 hdd_err("De-register of dcc stats callback failed: %d",
10030 status);
10031
10032 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010033 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10034
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010035 sme_stats_ext_register_callback(hdd_ctx->hHal,
10036 wlan_hdd_cfg80211_stats_ext_callback);
10037
10038 sme_nan_deregister_callback(hdd_ctx->hHal);
10039 status = sme_reset_tsfcb(hdd_ctx->hHal);
10040 if (!QDF_IS_STATUS_SUCCESS(status))
10041 hdd_err("Failed to de-register tsfcb the callback:%d",
10042 status);
10043 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10044 if (!QDF_IS_STATUS_SUCCESS(status))
10045 hdd_err("Failed to de-register the fw mem dump callback: %d",
10046 status);
10047
10048 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10049 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10050
10051 EXIT();
10052}
10053
10054/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010055 * hdd_softap_sta_deauth() - handle deauth req from HDD
10056 * @adapter: Pointer to the HDD
10057 * @enable: bool value
10058 *
10059 * This to take counter measure to handle deauth req from HDD
10060 *
10061 * Return: None
10062 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010063QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010064 struct tagCsrDelStaParams *pDelStaParams)
10065{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010066 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010067
10068 ENTER();
10069
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010070 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010071 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10072
10073 /* Ignore request to deauth bcmc station */
10074 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010075 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010076
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010077 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010078 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10079 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010080
10081 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010082 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010083}
10084
10085/**
10086 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10087 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010088 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010089 *
10090 * This to take counter measure to handle deauth req from HDD
10091 *
10092 * Return: None
10093 */
10094void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010095 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010096{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010097 ENTER();
10098
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010099 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010100 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10101
10102 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010103 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010104 return;
10105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010106 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010107 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010108}
10109
10110void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
10111 bool enable)
10112{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010113 ENTER();
10114
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010115 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010116 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010118 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10119 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010120}
10121
10122/**
10123 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10124 * @hdd_ctx: HDD Context
10125 *
10126 * API to find if there is any STA or P2P-Client is connected
10127 *
10128 * Return: true if connected; false otherwise
10129 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010130QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010131{
10132 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10133}
10134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010135/**
10136 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10137 * @adapter: HDD adapter pointer
10138 *
10139 * This function loop through each adapter and disable roaming on each STA
10140 * device mode except the input adapter.
10141 *
10142 * Note: On the input adapter roaming is not enabled yet hence no need to
10143 * disable.
10144 *
10145 * Return: None
10146 */
10147void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
10148{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010149 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010150 hdd_adapter_t *adapterIdx = NULL;
10151 hdd_adapter_list_node_t *adapterNode = NULL;
10152 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010153 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010154
10155 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010156 hdd_ctx->config->isRoamOffloadScanEnabled &&
10157 QDF_STA_MODE == adapter->device_mode &&
10158 policy_mgr_is_sta_active_connection_exists(
10159 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010160 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010161 adapter->sessionId);
10162 /*
10163 * Loop through adapter and disable roaming for each STA device
10164 * mode except the input adapter.
10165 */
10166 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10167
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010168 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010169 adapterIdx = adapterNode->pAdapter;
10170
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010171 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010172 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010173 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010174 adapterIdx->sessionId);
10175 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10176 (adapterIdx),
10177 adapterIdx->sessionId, 0);
10178 }
10179
10180 status = hdd_get_next_adapter(hdd_ctx,
10181 adapterNode,
10182 &pNext);
10183 adapterNode = pNext;
10184 }
10185 }
10186}
10187
10188/**
10189 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10190 * @adapter: HDD adapter pointer
10191 *
10192 * This function loop through each adapter and enable roaming on each STA
10193 * device mode except the input adapter.
10194 * Note: On the input adapter no need to enable roaming because link got
10195 * disconnected on this.
10196 *
10197 * Return: None
10198 */
10199void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
10200{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010201 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010202 hdd_adapter_t *adapterIdx = NULL;
10203 hdd_adapter_list_node_t *adapterNode = NULL;
10204 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010205 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206
10207 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010208 hdd_ctx->config->isRoamOffloadScanEnabled &&
10209 QDF_STA_MODE == adapter->device_mode &&
10210 policy_mgr_is_sta_active_connection_exists(
10211 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010212 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010213 adapter->sessionId);
10214 /*
10215 * Loop through adapter and enable roaming for each STA device
10216 * mode except the input adapter.
10217 */
10218 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10219
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010220 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010221 adapterIdx = adapterNode->pAdapter;
10222
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010223 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010224 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010225 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226 adapterIdx->sessionId);
10227 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10228 (adapterIdx),
10229 adapterIdx->sessionId,
10230 REASON_CONNECT);
10231 }
10232
10233 status = hdd_get_next_adapter(hdd_ctx,
10234 adapterNode,
10235 &pNext);
10236 adapterNode = pNext;
10237 }
10238 }
10239}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010240
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010241/**
10242 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10243 * @skb: sk buffer pointer
10244 *
10245 * Sends the bcast message to SVC multicast group with generic nl socket
10246 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10247 *
10248 * Return: None
10249 */
10250static void nl_srv_bcast_svc(struct sk_buff *skb)
10251{
10252#ifdef CNSS_GENL
10253 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10254#else
10255 nl_srv_bcast(skb);
10256#endif
10257}
10258
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010259void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010260{
10261 struct sk_buff *skb;
10262 struct nlmsghdr *nlh;
10263 tAniMsgHdr *ani_hdr;
10264 void *nl_data = NULL;
10265 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010266 struct radio_index_tlv *radio_info;
10267 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268
10269 if (in_interrupt() || irqs_disabled() || in_atomic())
10270 flags = GFP_ATOMIC;
10271
10272 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10273
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010274 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010275 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010276
10277 nlh = (struct nlmsghdr *)skb->data;
10278 nlh->nlmsg_pid = 0; /* from kernel */
10279 nlh->nlmsg_flags = 0;
10280 nlh->nlmsg_seq = 0;
10281 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10282
10283 ani_hdr = NLMSG_DATA(nlh);
10284 ani_hdr->type = type;
10285
10286 switch (type) {
10287 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010288 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010289 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010290 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010291 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010292 ani_hdr->length = 0;
10293 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010294 break;
10295 case WLAN_SVC_WLAN_STATUS_IND:
10296 case WLAN_SVC_WLAN_VERSION_IND:
10297 case WLAN_SVC_DFS_CAC_START_IND:
10298 case WLAN_SVC_DFS_CAC_END_IND:
10299 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10300 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10301 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010302 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010303 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010304 ani_hdr->length = len;
10305 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10306 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10307 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010308 break;
10309
10310 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010311 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010312 type);
10313 kfree_skb(skb);
10314 return;
10315 }
10316
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010317 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010318 * Add radio index at the end of the svc event in TLV format
10319 * to maintain the backward compatibility with userspace
10320 * applications.
10321 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010322
10323 tlv_len = 0;
10324
10325 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10326 < WLAN_NL_MAX_PAYLOAD) {
10327 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10328 sizeof(*ani_hdr) + len);
10329 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10330 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10331 radio_info->radio = radio;
10332 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010333 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010334 "Added radio index tlv - radio index %d",
10335 radio_info->radio);
10336 }
10337
10338 nlh->nlmsg_len += tlv_len;
10339 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10340
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010341 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010342}
10343
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010344#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10345void wlan_hdd_auto_shutdown_cb(void)
10346{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010347 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010348
10349 if (!hdd_ctx)
10350 return;
10351
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010352 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010353 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10354 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010355}
10356
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010357void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010358{
10359 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010360 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010361 hdd_adapter_t *adapter;
10362 bool ap_connected = false, sta_connected = false;
10363 tHalHandle hal_handle;
10364
10365 hal_handle = hdd_ctx->hHal;
10366 if (hal_handle == NULL)
10367 return;
10368
10369 if (hdd_ctx->config->WlanAutoShutdown == 0)
10370 return;
10371
10372 if (enable == false) {
10373 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010374 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010375 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010376 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010377 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010378 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010379 return;
10380 }
10381
10382 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010383 if (policy_mgr_concurrent_open_sessions_running(
10384 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010385 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10386
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010387 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010388 adapter = adapterNode->pAdapter;
10389 if (adapter
10390 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010391 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010392 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10393 conn_info.connState ==
10394 eConnectionState_Associated) {
10395 sta_connected = true;
10396 break;
10397 }
10398 }
10399 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010400 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010401 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10402 bApActive == true) {
10403 ap_connected = true;
10404 break;
10405 }
10406 }
10407 status = hdd_get_next_adapter(hdd_ctx,
10408 adapterNode,
10409 &pNext);
10410 adapterNode = pNext;
10411 }
10412 }
10413
10414 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010415 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010416 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010417 }
Jeff Johnson68755312017-02-10 11:46:55 -080010418
10419 if (sme_set_auto_shutdown_timer(hal_handle,
10420 hdd_ctx->config->WlanAutoShutdown)
10421 != QDF_STATUS_SUCCESS)
10422 hdd_err("Failed to start wlan auto shutdown timer");
10423 else
10424 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10425 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010426}
10427#endif
10428
10429hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
10430 bool check_start_bss)
10431{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010432 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010434 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10436
10437 con_sap_adapter = NULL;
10438
10439 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010440 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010441 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010442 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10443 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010444 adapter != this_sap_adapter) {
10445 if (check_start_bss) {
10446 if (test_bit(SOFTAP_BSS_STARTED,
10447 &adapter->event_flags)) {
10448 con_sap_adapter = adapter;
10449 break;
10450 }
10451 } else {
10452 con_sap_adapter = adapter;
10453 break;
10454 }
10455 }
10456 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10457 adapterNode = pNext;
10458 }
10459
10460 return con_sap_adapter;
10461}
10462
10463#ifdef MSM_PLATFORM
Dustin Brown5ec6b552017-03-31 12:11:40 -070010464static inline bool hdd_adapter_is_sta(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010465{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010466 return adapter->device_mode == QDF_STA_MODE ||
10467 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010468}
10469
Dustin Brown5ec6b552017-03-31 12:11:40 -070010470static inline bool hdd_adapter_is_ap(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010471{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010472 return adapter->device_mode == QDF_SAP_MODE ||
10473 adapter->device_mode == QDF_P2P_GO_MODE;
10474}
10475
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010476static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010477{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010478 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010479 hdd_adapter_list_node_t *node;
10480
10481 status = hdd_get_front_adapter(hdd_ctx, &node);
10482 while (QDF_IS_STATUS_SUCCESS(status) && node) {
10483 hdd_adapter_t *adapter = node->pAdapter;
10484
10485 if (adapter &&
10486 hdd_adapter_is_sta(adapter) &&
10487 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10488 conn_info.connState == eConnectionState_Associated) {
10489 return true;
10490 }
10491
10492 if (adapter &&
10493 hdd_adapter_is_ap(adapter) &&
10494 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10495 return true;
10496 }
10497
10498 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10499 }
10500
10501 return false;
10502}
10503
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010504static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010505{
10506 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010507
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010508 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010509 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010510 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010511
Dustin Brown5ec6b552017-03-31 12:11:40 -070010512 return is_running;
10513}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010514
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010515static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010516{
10517 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10518 hdd_ctx->bus_bw_timer_running = true;
10519 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10520 hdd_ctx->config->busBandwidthComputeInterval);
10521 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10522}
10523
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010524void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010525{
10526 ENTER();
10527
10528 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10529 hdd_debug("Bandwidth compute timer already started");
10530 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010531 }
10532
Dustin Brown5ec6b552017-03-31 12:11:40 -070010533 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10534
10535 EXIT();
10536}
10537
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010538void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010539{
10540 ENTER();
10541
10542 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10543 hdd_debug("Bandwidth compute timer already started");
10544 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010545 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010546
10547 if (hdd_any_adapter_is_assoc(hdd_ctx))
10548 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10549
10550 EXIT();
10551}
10552
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010553static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010554{
10555 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10556
10557 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10558 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10559 hdd_ctx->bus_bw_timer_running = false;
10560 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10561
10562 hdd_reset_tcp_delack(hdd_ctx);
10563}
10564
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010565void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010566{
10567 ENTER();
10568
10569 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10570 hdd_debug("Bandwidth compute timer already stopped");
10571 return;
10572 }
10573
10574 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10575
10576 EXIT();
10577}
10578
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010579void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010580{
10581 ENTER();
10582
10583 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10584 hdd_debug("Bandwidth compute timer already stopped");
10585 return;
10586 }
10587
10588 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10589 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10590
10591 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010592}
10593#endif
10594
10595/**
10596 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10597 * and sta's operating channel.
10598 * @sta_adapter: Describe the first argument to foobar.
10599 * @ap_adapter: Describe the second argument to foobar.
10600 * @roam_profile: Roam profile of AP to which STA wants to connect.
10601 * @concurrent_chnl_same: If both SAP and STA channels are same then
10602 * set this flag to true else false.
10603 *
10604 * This function checks the sap's operating channel and sta's operating channel.
10605 * if both are same then it will return false else it will restart the sap in
10606 * sta's channel and return true.
10607 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010608 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010609 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010610QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611 hdd_adapter_t *ap_adapter,
10612 tCsrRoamProfile *roam_profile,
10613 tScanResultHandle *scan_cache,
10614 bool *concurrent_chnl_same)
10615{
Jeff Johnson87251032017-08-29 13:31:11 -070010616 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010617 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010618 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010619 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010620 *concurrent_chnl_same = true;
10621
10622 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10623 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010624 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010625 scan_cache,
10626 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010627 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010628 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010629 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10630 if (hdd_ap_ctx->operatingChannel != channel_id) {
10631 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010632 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010633 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010634 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010635 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10636 if (hdd_ap_ctx->operatingChannel != channel_id) {
10637 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010638 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 }
10640 }
10641 } else {
10642 /*
10643 * Lets handle worst case scenario here, Scan cache lookup is
10644 * failed so we have to stop the SAP to avoid any channel
10645 * discrepancy between SAP's channel and STA's channel.
10646 * Return the status as failure so caller function could know
10647 * that scan look up is failed.
10648 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010649 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010650 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010651 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010652 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010653}
10654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655/**
10656 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10657 * @ap_adapter: SAP adapter
10658 *
10659 * This function will process the stopping of sap adapter.
10660 *
10661 * Return: None
10662 */
10663void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
10664{
Jeff Johnson87251032017-08-29 13:31:11 -070010665 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010666 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010667 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010668 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010669
10670 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010671 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010672 return;
10673 }
10674
10675 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10676 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010677 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010678 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010679
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010680 mutex_lock(&hdd_ctx->sap_lock);
10681 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010682 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10684 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010685 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010686 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010687 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010688 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010689 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010690 qdf_stop_bss_event,
10691 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010692 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010693 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010694 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010695 return;
10696 }
10697 }
10698 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010699 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10700 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010701 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010702 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010703 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010704 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010705 }
10706 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707}
10708
10709/**
10710 * wlan_hdd_start_sap() - this function starts bss of SAP.
10711 * @ap_adapter: SAP adapter
10712 *
10713 * This function will process the starting of sap adapter.
10714 *
10715 * Return: None
10716 */
Arun Khandavallicc544b32017-01-30 19:52:16 +053010717void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010718{
Jeff Johnson87251032017-08-29 13:31:11 -070010719 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010720 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010721 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010722 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010723 tsap_Config_t *sap_config;
10724
10725 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010726 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010727 return;
10728 }
10729
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010730 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010731 hdd_err("SoftAp role has not been enabled");
10732 return;
10733 }
10734
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10736 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10737 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10738 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740 mutex_lock(&hdd_ctx->sap_lock);
10741 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10742 goto end;
10743
10744 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010745 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010746 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10747 goto end;
10748 }
10749
Wei Song2f76f642016-11-18 16:32:53 +080010750 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010751 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10752 &hdd_ap_ctx->sapConfig,
10753 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010754 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010755 goto end;
10756
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010757 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010758 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010759 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010760 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010761 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010762 goto end;
10763 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010764 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010765 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010766 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010767 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10768 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769 ap_adapter->sessionId);
10770 hostapd_state->bCommit = true;
10771
10772end:
10773 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010774 /* SAP context and beacon cleanup will happen during driver unload
10775 * in hdd_stop_adapter
10776 */
10777 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010779}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010780
10781/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010782 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10783 * mac scan config
10784 * @status: Status of set antenna mode
10785 *
10786 * Callback on setting the dual mac configuration
10787 *
10788 * Return: None
10789 */
10790void wlan_hdd_soc_set_antenna_mode_cb(
10791 enum set_antenna_mode_status status)
10792{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010793 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010794
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010795 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010796
10797 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10798 if (0 != wlan_hdd_validate_context(hdd_ctx))
10799 return;
10800
10801 /* Signal the completion of set dual mac config */
10802 complete(&hdd_ctx->set_antenna_mode_cmpl);
10803}
10804
10805/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010806 * hdd_get_fw_version() - Get FW version
10807 * @hdd_ctx: pointer to HDD context.
10808 * @major_spid: FW version - major spid.
10809 * @minor_spid: FW version - minor spid
10810 * @ssid: FW version - ssid
10811 * @crmid: FW version - crmid
10812 *
10813 * This function is called to get the firmware build version stored
10814 * as part of the HDD context
10815 *
10816 * Return: None
10817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010818void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010819 uint32_t *major_spid, uint32_t *minor_spid,
10820 uint32_t *siid, uint32_t *crmid)
10821{
10822 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10823 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10824 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10825 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10826}
10827
10828#ifdef QCA_CONFIG_SMP
10829/**
10830 * wlan_hdd_get_cpu() - get cpu_index
10831 *
10832 * Return: cpu_index
10833 */
10834int wlan_hdd_get_cpu(void)
10835{
10836 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010837
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010838 put_cpu();
10839 return cpu_index;
10840}
10841#endif
10842
10843/**
10844 * hdd_get_fwpath() - get framework path
10845 *
10846 * This function is used to get the string written by
10847 * userspace to start the wlan driver
10848 *
10849 * Return: string
10850 */
10851const char *hdd_get_fwpath(void)
10852{
10853 return fwpath.string;
10854}
10855
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010856static int hdd_qdf_print_init(void)
10857{
10858 int qdf_print_idx;
10859 QDF_STATUS status;
10860
10861 status = qdf_print_setup();
10862 if (status != QDF_STATUS_SUCCESS) {
10863 pr_err("qdf_print_setup failed\n");
10864 return -EINVAL;
10865 }
10866
10867 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10868
10869 if (qdf_print_idx < 0) {
10870 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10871 qdf_print_idx);
10872 return -EINVAL;
10873 }
10874
10875 qdf_set_pidx(qdf_print_idx);
10876
10877 return 0;
10878}
10879
10880static void hdd_qdf_print_deinit(void)
10881{
10882 int qdf_print_idx;
10883
10884 qdf_print_idx = qdf_get_pidx();
10885 qdf_print_ctrl_cleanup(qdf_print_idx);
10886}
10887
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010888/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010889 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010890 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010891 * This function initilizes CDS global context with the help of cds_init. This
10892 * has to be the first function called after probe to get a valid global
10893 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010894 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010895 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010896 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010897int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010898{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010899 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010900 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010901
Houston Hoffman9e06e542016-12-12 12:06:26 -080010902 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010903#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10904 wlan_logging_sock_init_svc();
10905#endif
10906
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010907 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010908 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010909 ret = -ENOMEM;
10910 goto err_out;
10911 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010912
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010913 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010914 hdd_qdf_print_init();
10915
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010916 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010917
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010918err_out:
10919 return ret;
10920}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010921
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010922/**
10923 * hdd_deinit() - Deinitialize Driver
10924 *
10925 * This function frees CDS global context with the help of cds_deinit. This
10926 * has to be the last function call in remove callback to free the global
10927 * context.
10928 */
10929void hdd_deinit(void)
10930{
Dustin Brownedce4a52017-05-10 11:59:15 -070010931 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010932 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010933
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010934 hdd_qdf_print_deinit();
10935
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010936#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10937 wlan_logging_sock_deinit_svc();
10938#endif
10939}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010940
Yue Ma6e7b1a02017-04-03 14:17:46 -070010941#ifdef QCA_WIFI_NAPIER_EMULATION
10942#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10943#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010944#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010945#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010946
Sachin Ahujadddd2632017-03-07 19:07:24 +053010947static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10948 struct file *file)
10949{
10950 return 0;
10951}
10952
10953static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10954 const char __user *user_buf,
10955 size_t count,
10956 loff_t *f_pos)
10957{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010958 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010959 static const char wlan_off_str[] = "OFF";
10960 static const char wlan_on_str[] = "ON";
10961 int ret;
10962 unsigned long rc;
10963
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010964 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010965 pr_err("Failed to read buffer\n");
10966 return -EINVAL;
10967 }
10968
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010969 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010970 pr_debug("Wifi turning off from UI\n");
10971 goto exit;
10972 }
10973
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010974 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010975 pr_err("Invalid value received from framework");
10976 goto exit;
10977 }
10978
10979 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010980 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010981 rc = wait_for_completion_timeout(&wlan_start_comp,
10982 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10983 if (!rc) {
10984 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10985 ret = -EINVAL;
10986 hdd_start_complete(ret);
10987 return ret;
10988 }
10989
10990 hdd_start_complete(0);
10991 }
10992
10993exit:
10994 return count;
10995}
10996
10997
10998const struct file_operations wlan_hdd_state_fops = {
10999 .owner = THIS_MODULE,
11000 .open = wlan_hdd_state_ctrl_param_open,
11001 .write = wlan_hdd_state_ctrl_param_write,
11002};
11003
11004static int wlan_hdd_state_ctrl_param_create(void)
11005{
11006 unsigned int wlan_hdd_state_major = 0;
11007 int ret;
11008 struct device *dev;
11009
11010 device = MKDEV(wlan_hdd_state_major, 0);
11011
11012 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11013 if (ret) {
11014 pr_err("Failed to register qcwlanstate");
11015 goto dev_alloc_err;
11016 }
11017 wlan_hdd_state_major = MAJOR(device);
11018
11019 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11020 if (IS_ERR(class)) {
11021 pr_err("wlan_hdd_state class_create error");
11022 goto class_err;
11023 }
11024
11025 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11026 if (IS_ERR(dev)) {
11027 pr_err("wlan_hdd_statedevice_create error");
11028 goto err_class_destroy;
11029 }
11030
11031 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11032 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11033 if (ret) {
11034 pr_err("Failed to add cdev error");
11035 goto cdev_add_err;
11036 }
11037
11038 pr_info("wlan_hdd_state %s major(%d) initialized",
11039 WLAN_MODULE_NAME, wlan_hdd_state_major);
11040
11041 return 0;
11042
11043cdev_add_err:
11044 device_destroy(class, device);
11045err_class_destroy:
11046 class_destroy(class);
11047class_err:
11048 unregister_chrdev_region(device, dev_num);
11049dev_alloc_err:
11050 return -ENODEV;
11051}
11052
11053static void wlan_hdd_state_ctrl_param_destroy(void)
11054{
11055 cdev_del(&wlan_hdd_state_cdev);
11056 device_destroy(class, device);
11057 class_destroy(class);
11058 unregister_chrdev_region(device, dev_num);
11059
11060 pr_info("Device node unregistered");
11061}
11062
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011063/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011064 * component_init - API to init cld component's
11065 *
11066 * Return: None
11067 */
11068static void component_init(void)
11069{
11070 pmo_init();
11071}
11072
11073/**
11074 * component_deinit - API to deinit cld component's
11075 *
11076 * Return: None
11077 */
11078static void component_deinit(void)
11079{
11080 pmo_deinit();
11081}
11082
11083/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011084 * __hdd_module_init - Module init helper
11085 *
11086 * Module init helper function used by both module and static driver.
11087 *
11088 * Return: 0 for success, errno on failure
11089 */
11090static int __hdd_module_init(void)
11091{
11092 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011093
Dustin Brownab482ac2017-06-09 17:00:44 -070011094 pr_err("%s: Loading driver v%s (%s)%s\n",
11095 WLAN_MODULE_NAME,
11096 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011097 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011098 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011099
Sachin Ahujadddd2632017-03-07 19:07:24 +053011100 ret = wlan_hdd_state_ctrl_param_create();
11101 if (ret) {
11102 pr_err("wlan_hdd_state_create:%x\n", ret);
11103 goto err_dev_state;
11104 }
11105
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011106 pld_init();
11107
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011108 ret = hdd_init();
11109 if (ret) {
11110 pr_err("hdd_init failed %x\n", ret);
11111 goto err_hdd_init;
11112 }
11113
Rajeev Kumar97767a02016-11-30 11:20:40 -080011114 dispatcher_init();
11115
Mukul Sharmad75a6672017-06-22 15:40:53 +053011116 /* Ensure to call post objmgr init */
11117 component_init();
11118
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011119 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011120
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011121 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011122
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011123 ret = wlan_hdd_register_driver();
11124 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011125 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11126 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011127 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011128 }
11129
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011130 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011131
11132 return 0;
11133out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011134 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011135 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011136 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011137
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011138err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011139 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011140 wlan_hdd_state_ctrl_param_destroy();
11141err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011142 return ret;
11143}
11144
11145/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011146 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
11147 *
11148 * Block the unloading of the driver until the cds recovery is completed
11149 *
11150 * Return: None
11151 */
11152static void hdd_wait_for_recovery_completion(void)
11153{
11154 int retry = 0;
11155
11156 /* Wait for recovery to complete */
11157 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011158 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011159 msleep(1000);
11160 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011161 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011162 QDF_BUG(0);
11163 }
11164 }
11165}
11166
11167/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011168 * __hdd_module_exit - Module exit helper
11169 *
11170 * Module exit helper function used by both module and static driver.
11171 */
11172static void __hdd_module_exit(void)
11173{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011174
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011175 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11176 QWLAN_VERSIONSTR);
11177
bings6028ee82017-03-29 07:51:40 +080011178 cds_set_unload_in_progress(true);
11179
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011180 hdd_wait_for_recovery_completion();
11181
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011182 wlan_hdd_unregister_driver();
11183
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011184 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011185
Mukul Sharmad75a6672017-06-22 15:40:53 +053011186 /* Ensure to call prior to objmgr deinit */
11187 component_deinit();
11188
Rajeev Kumar97767a02016-11-30 11:20:40 -080011189 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011190 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011191 pld_deinit();
11192
Sachin Ahujadddd2632017-03-07 19:07:24 +053011193 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011194}
11195
Arun Khandavallifae92942016-08-01 13:31:08 +053011196#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011197/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011198 * wlan_boot_cb() - Wlan boot callback
11199 * @kobj: object whose directory we're creating the link in.
11200 * @attr: attribute the user is interacting with
11201 * @buff: the buffer containing the user data
11202 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011203 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011204 * This callback is invoked when the fs is ready to start the
11205 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011206 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011207 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011208 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011209static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011210 struct kobj_attribute *attr,
11211 const char *buf,
11212 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011213{
Arun Khandavallifae92942016-08-01 13:31:08 +053011214
Arun Khandavallifae92942016-08-01 13:31:08 +053011215 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011216 pr_err("%s: wlan driver already initialized\n", __func__);
11217 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011218 }
11219
Arun Khandavallifae92942016-08-01 13:31:08 +053011220 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011221 pr_err("%s: wlan driver initialization failed\n", __func__);
11222 return -EIO;
11223 }
11224
11225 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011226
11227 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011228}
Arun Khandavallifae92942016-08-01 13:31:08 +053011229
11230/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011231 * hdd_sysfs_cleanup() - cleanup sysfs
11232 *
11233 * Return: None
11234 *
11235 */
11236static void hdd_sysfs_cleanup(void)
11237{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011238 /* remove from group */
11239 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11240 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11241 wlan_loader->attr_group);
11242
11243 /* unlink the object from parent */
11244 kobject_del(wlan_loader->boot_wlan_obj);
11245
11246 /* free the object */
11247 kobject_put(wlan_loader->boot_wlan_obj);
11248
11249 kfree(wlan_loader->attr_group);
11250 kfree(wlan_loader);
11251
11252 wlan_loader = NULL;
11253}
11254
11255/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011256 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11257 * ready
11258 *
11259 * This is creates the syfs entry boot_wlan. Which shall be invoked
11260 * when the filesystem is ready.
11261 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011262 * QDF API cannot be used here since this function is called even before
11263 * initializing WLAN driver.
11264 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011265 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011266 */
11267static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011268{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011269 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011270
11271 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011272 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011273 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011274
11275 wlan_loader->boot_wlan_obj = NULL;
11276 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11277 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011278 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011279 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011280
11281 wlan_loader->loaded_state = 0;
11282 wlan_loader->attr_group->attrs = attrs;
11283
11284 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11285 kernel_kobj);
11286 if (!wlan_loader->boot_wlan_obj) {
11287 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011288 goto error_return;
11289 }
11290
11291 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11292 wlan_loader->attr_group);
11293 if (ret) {
11294 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11295 goto error_return;
11296 }
11297
11298 return 0;
11299
11300error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011301 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011302
11303 return ret;
11304}
11305
11306/**
11307 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11308 *
11309 * Return: 0 on success or errno on failure
11310 */
11311static int wlan_deinit_sysfs(void)
11312{
Arun Khandavallifae92942016-08-01 13:31:08 +053011313 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011314 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011315 return -EINVAL;
11316 }
11317
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011318 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011319 return 0;
11320}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011321
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011322#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011323
11324#ifdef MODULE
11325/**
11326 * __hdd_module_init - Module init helper
11327 *
11328 * Module init helper function used by both module and static driver.
11329 *
11330 * Return: 0 for success, errno on failure
11331 */
11332static int hdd_module_init(void)
11333{
Arun Khandavallifae92942016-08-01 13:31:08 +053011334 if (__hdd_module_init()) {
11335 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011336 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011337 }
11338
Dustin Brownab482ac2017-06-09 17:00:44 -070011339 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011340}
11341#else
11342static int __init hdd_module_init(void)
11343{
11344 int ret = -EINVAL;
11345
11346 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011347 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011348 pr_err("Failed to create sysfs entry for loading wlan");
11349
11350 return ret;
11351}
11352#endif
11353
11354
11355#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011356/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011357 * hdd_module_exit() - Exit function
11358 *
11359 * This is the driver exit point (invoked when module is unloaded using rmmod)
11360 *
11361 * Return: None
11362 */
11363static void __exit hdd_module_exit(void)
11364{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011365 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011366}
Arun Khandavallifae92942016-08-01 13:31:08 +053011367#else
11368static void __exit hdd_module_exit(void)
11369{
11370 __hdd_module_exit();
11371 wlan_deinit_sysfs();
11372}
11373#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011374
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011375static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11376{
11377 return param_set_copystring(kmessage, kp);
11378}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011379
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011380/**
11381 * is_con_mode_valid() check con mode is valid or not
11382 * @mode: global con mode
11383 *
11384 * Return: TRUE on success FALSE on failure
11385 */
11386static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11387{
11388 switch (mode) {
11389 case QDF_GLOBAL_MONITOR_MODE:
11390 case QDF_GLOBAL_FTM_MODE:
11391 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011392 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011393 return true;
11394 default:
11395 return false;
11396 }
11397}
11398
11399/**
11400 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11401 * @mode: global con mode
11402 *
11403 * Return: adapter mode
11404 */
11405static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11406 enum tQDF_GLOBAL_CON_MODE mode)
11407{
11408
11409 switch (mode) {
11410 case QDF_GLOBAL_MISSION_MODE:
11411 return QDF_STA_MODE;
11412 case QDF_GLOBAL_MONITOR_MODE:
11413 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011414 case QDF_GLOBAL_EPPING_MODE:
11415 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011416 case QDF_GLOBAL_FTM_MODE:
11417 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011418 case QDF_GLOBAL_QVIT_MODE:
11419 return QDF_QVIT_MODE;
11420 default:
11421 return QDF_MAX_NO_OF_MODE;
11422 }
11423}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011424
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011425static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011426 enum tQDF_GLOBAL_CON_MODE curr_mode)
11427{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011428 int driver_status;
11429
11430 driver_status = hdd_ctx->driver_status;
11431
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011432 switch (curr_mode) {
11433 case QDF_GLOBAL_MISSION_MODE:
11434 case QDF_GLOBAL_MONITOR_MODE:
11435 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011436 if (driver_status != DRIVER_MODULES_CLOSED) {
11437 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11438 hdd_stop_all_adapters(hdd_ctx);
11439 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011440 hdd_deinit_all_adapters(hdd_ctx, false);
11441 hdd_close_all_adapters(hdd_ctx, false);
11442 break;
11443 case QDF_GLOBAL_EPPING_MODE:
11444 epping_disable();
11445 epping_close();
11446 break;
11447 default:
11448 return;
11449 }
11450}
11451
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011452static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011453 enum tQDF_GLOBAL_CON_MODE mode)
11454{
11455 hdd_adapter_t *adapter;
11456 int ret = 0;
11457 bool rtnl_held;
11458 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11459 QDF_STATUS status;
11460
11461 if (!qdf_dev) {
11462 hdd_err("qdf device context is Null return!");
11463 return -EINVAL;
11464 }
11465
11466 rtnl_held = hdd_hold_rtnl_lock();
11467 switch (mode) {
11468 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011469 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11470 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011471 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011472 break;
11473 case QDF_GLOBAL_FTM_MODE:
11474 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11475 wlan_hdd_get_intf_addr(hdd_ctx),
11476 NET_NAME_UNKNOWN, rtnl_held);
11477 if (adapter == NULL)
11478 ret = -EINVAL;
11479 break;
11480 case QDF_GLOBAL_MONITOR_MODE:
11481 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11482 wlan_hdd_get_intf_addr(hdd_ctx),
11483 NET_NAME_UNKNOWN, rtnl_held);
11484 if (adapter == NULL)
11485 ret = -EINVAL;
11486 break;
11487 case QDF_GLOBAL_EPPING_MODE:
11488 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011489 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011490 hdd_err("Failed to open in eeping mode: %d", status);
11491 ret = -EINVAL;
11492 break;
11493 }
11494 ret = epping_enable(qdf_dev->dev);
11495 if (ret) {
11496 hdd_err("Failed to enable in epping mode : %d", ret);
11497 epping_close();
11498 }
11499 break;
11500 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011501 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011502 ret = -ENOTSUPP;
11503 break;
11504 }
11505 hdd_release_rtnl_lock();
11506 rtnl_held = false;
11507 return ret;
11508}
11509
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011510/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011511 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011512 * @kmessage: con mode name on which driver to be bring up
11513 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011514 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011515 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011516 * This function is invoked when user updates con mode using sys entry,
11517 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011518 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011519 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011520 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011521static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011522 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011523{
11524 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011525 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011526 enum tQDF_GLOBAL_CON_MODE curr_mode;
11527 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011528
Dustin Brownab6029b2017-05-24 13:04:19 -070011529 hdd_info("con_mode handler: %s", kmessage);
11530
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011531 ret = wlan_hdd_validate_context(hdd_ctx);
11532 if (ret)
11533 return ret;
11534
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011535 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011536
11537 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011538
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011539 if (!(is_con_mode_valid(con_mode))) {
11540 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011541 ret = -EINVAL;
11542 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011543 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011544
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011545 curr_mode = hdd_get_conparam();
11546 if (curr_mode == con_mode) {
11547 hdd_err("curr mode: %d is same as user triggered mode %d",
11548 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011549 ret = 0;
11550 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011551 }
11552
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011553 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011554 if (ret) {
11555 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011556 goto reset_flags;
11557 }
11558
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011559 /* Cleanup present mode before switching to new mode */
11560 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11561
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011562 hdd_set_conparam(con_mode);
11563
11564 /* Register for new con_mode & then kick_start modules again */
11565 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11566 if (ret) {
11567 hdd_err("Failed to register for new mode");
11568 goto reset_flags;
11569 }
11570
11571 adapter_mode = hdd_get_adpter_mode(con_mode);
11572 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11573 hdd_err("invalid adapter");
11574 ret = -EINVAL;
11575 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011576 }
11577
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011578 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011579 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011580 hdd_err("Failed to get adapter:%d", adapter_mode);
11581 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011582 }
11583
11584 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11585 if (ret) {
11586 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011587 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011588 }
11589
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011590 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11591 con_mode == QDF_GLOBAL_FTM_MODE) {
11592 if (hdd_start_adapter(adapter)) {
11593 hdd_err("Failed to start %s adapter", kmessage);
11594 ret = -EINVAL;
11595 goto reset_flags;
11596 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011597 }
11598
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011599 hdd_info("Mode successfully changed to %s", kmessage);
11600 ret = 0;
11601
11602reset_flags:
11603 cds_set_load_in_progress(false);
11604 return ret;
11605}
11606
11607
11608static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11609{
11610 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011611 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011612
11613 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11614 ret = wlan_hdd_validate_context(hdd_ctx);
11615 if (ret)
11616 return ret;
11617
11618 cds_ssr_protect(__func__);
11619 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11620 cds_ssr_unprotect(__func__);
11621
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011622 return ret;
11623}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011624
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011625static int con_mode_handler_ftm(const char *kmessage,
11626 struct kernel_param *kp)
11627{
11628 int ret;
11629
11630 ret = param_set_int(kmessage, kp);
11631
11632 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11633 pr_err("Only FTM mode supported!");
11634 return -ENOTSUPP;
11635 }
11636
11637 hdd_set_conparam(con_mode_ftm);
11638 con_mode = con_mode_ftm;
11639
11640 return ret;
11641}
11642
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011643/**
11644 * hdd_get_conparam() - driver exit point
11645 *
11646 * This is the driver exit point (invoked when module is unloaded using rmmod)
11647 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011648 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011649 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011650enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011651{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011652 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011653}
11654
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011655void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011656{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011657 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011658}
11659
Komal Seelamc11bb222016-01-27 18:57:10 +053011660/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011661 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11662 * @hdd_ctx: HDD context
11663 *
11664 * Cleans up the pre cac interface, if it exists
11665 *
11666 * Return: None
11667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011668void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011669{
11670 uint8_t session_id;
11671 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011672 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011673
11674 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11675 if (QDF_IS_STATUS_ERROR(status)) {
11676 hdd_err("failed to get pre cac vdev id");
11677 return;
11678 }
11679
11680 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11681 if (!precac_adapter) {
11682 hdd_err("invalid pre cac adapater");
11683 return;
11684 }
11685
11686 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11687 wlan_hdd_sap_pre_cac_failure,
11688 (void *)precac_adapter);
11689 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11690
11691}
11692
11693/**
Komal Seelamec702b02016-02-24 18:42:16 +053011694 * hdd_update_ol_config - API to update ol configuration parameters
11695 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011696 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011697 * Return: void
11698 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011699static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011700{
Komal Seelamec702b02016-02-24 18:42:16 +053011701 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011702 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011703
Komal Seelamec702b02016-02-24 18:42:16 +053011704 if (!ol_ctx)
11705 return;
11706
11707 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11708 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11709 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11710 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011711 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011712
11713 ol_init_ini_config(ol_ctx, &cfg);
11714}
11715
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011716#ifdef FEATURE_RUNTIME_PM
11717/**
11718 * hdd_populate_runtime_cfg() - populate runtime configuration
11719 * @hdd_ctx: hdd context
11720 * @cfg: pointer to the configuration memory being populated
11721 *
11722 * Return: void
11723 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011724static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011725 struct hif_config_info *cfg)
11726{
11727 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11728 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11729}
11730#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011731static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011732 struct hif_config_info *cfg)
11733{
11734}
11735#endif
11736
Komal Seelamec702b02016-02-24 18:42:16 +053011737/**
11738 * hdd_update_hif_config - API to update HIF configuration parameters
11739 * @hdd_ctx: HDD Context
11740 *
11741 * Return: void
11742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011743static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011744{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011745 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011746 struct hif_config_info cfg;
11747
11748 if (!scn)
11749 return;
11750
11751 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011752 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011753 hif_init_ini_config(scn, &cfg);
11754}
11755
11756/**
11757 * hdd_update_config() - Initialize driver per module ini parameters
11758 * @hdd_ctx: HDD Context
11759 *
11760 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011761 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011763int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011764{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011765 int ret;
11766
Komal Seelamec702b02016-02-24 18:42:16 +053011767 hdd_update_ol_config(hdd_ctx);
11768 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011769 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11770 ret = hdd_update_cds_config_ftm(hdd_ctx);
11771 else
11772 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011773 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011774
11775 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011776}
11777
Mukul Sharma9d797a02017-01-05 20:26:03 +053011778#ifdef FEATURE_WLAN_RA_FILTERING
11779/**
11780 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11781 * @psoc_cfg: pmo psoc Configuration
11782 * @hdd_ctx: Pointer to hdd context
11783 *
11784 * Return: none
11785 */
11786static inline void hdd_ra_populate_pmo_config(
11787 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011788 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011789{
11790 psoc_cfg->ra_ratelimit_interval =
11791 hdd_ctx->config->RArateLimitInterval;
11792 psoc_cfg->ra_ratelimit_enable =
11793 hdd_ctx->config->IsRArateLimitEnabled;
11794}
11795#else
11796static inline void hdd_ra_populate_pmo_config(
11797 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011798 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011799{
11800}
11801#endif
11802/**
11803 * hdd_update_pmo_config - API to update pmo configuration parameters
11804 * @hdd_ctx: HDD context
11805 *
11806 * Return: void
11807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011808static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011809{
11810 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11811 struct pmo_psoc_cfg psoc_cfg;
11812 QDF_STATUS status;
11813
11814 /*
11815 * Value of hdd_ctx->wowEnable can be,
11816 * 0 - Disable both magic pattern match and pattern byte match.
11817 * 1 - Enable magic pattern match on all interfaces.
11818 * 2 - Enable pattern byte match on all interfaces.
11819 * 3 - Enable both magic patter and pattern byte match on
11820 * all interfaces.
11821 */
11822 psoc_cfg.magic_ptrn_enable =
11823 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11824 psoc_cfg.ptrn_match_enable_all_vdev =
11825 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11826 psoc_cfg.bpf_enable =
11827 hdd_ctx->config->bpf_packet_filter_enable;
11828 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011829 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011830 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11831 if (hdd_ctx->config->fhostNSOffload)
11832 psoc_cfg.ns_offload_enable_dynamic = true;
11833 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11834 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11835 psoc_cfg.active_mode_offload =
11836 hdd_ctx->config->active_mode_offload;
11837 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11838 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011839 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11840 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11841 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11842 psoc_cfg.power_save_mode =
11843 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011844 psoc_cfg.auto_power_save_fail_mode =
11845 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011846
11847 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011848 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11849 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011850 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11851 if (status != QDF_STATUS_SUCCESS) {
11852 hdd_err("failed pmo psoc configuration");
11853 return -EINVAL;
11854 }
11855
11856 return 0;
11857}
11858
Abhishek Singhb20db962017-03-03 21:28:46 +053011859#ifdef FEATURE_WLAN_SCAN_PNO
11860static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11861 struct hdd_config *cfg)
11862{
11863 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11864 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11865 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11866 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11867 pno_cfg->channel_prediction_full_scan =
11868 cfg->channel_prediction_full_scan;
11869}
11870#else
11871static inline void
11872hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11873 struct hdd_config *cfg)
11874{
11875 return;
11876}
11877#endif
11878
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011879void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11880 struct hdd_config *cfg)
11881{
11882 uint8_t i = 0;
11883
11884 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11885 if (!ie_whitelist->white_list)
11886 return;
11887
11888 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11889 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11890 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11891 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11892 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11893 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11894 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11895 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11896
11897 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11898 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11899 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11900}
11901
Abhishek Singh257a9482017-03-06 16:52:39 +053011902/**
11903 * hdd_update_scan_config - API to update scan configuration parameters
11904 * @hdd_ctx: HDD context
11905 *
11906 * Return: 0 if success else err
11907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011908static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011909{
11910 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11911 struct scan_user_cfg scan_cfg;
11912 struct hdd_config *cfg = hdd_ctx->config;
11913 QDF_STATUS status;
11914
11915 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11916 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11917 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11918 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11919 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11920 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11921 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011922 /* convert to ms */
11923 scan_cfg.scan_cache_aging_time =
11924 cfg->scanAgingTimeout * 1000;
11925 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11926 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11927 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11928 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011929 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011930 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011931
Abhishek Singhb20db962017-03-03 21:28:46 +053011932 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011933 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011934
Abhishek Singh257a9482017-03-06 16:52:39 +053011935 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11936 if (status != QDF_STATUS_SUCCESS) {
11937 hdd_err("failed pmo psoc configuration");
11938 return -EINVAL;
11939 }
11940
11941 return 0;
11942}
Abhishek Singh257a9482017-03-06 16:52:39 +053011943
Frank Liud4b2fa02017-03-29 11:46:48 +080011944#ifdef CONVERGED_TDLS_ENABLE
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011945static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080011946{
11947 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11948 struct tdls_start_params tdls_cfg;
11949 struct tdls_user_config *config = &tdls_cfg.config;
11950 struct hdd_config *cfg = hdd_ctx->config;
11951 QDF_STATUS status;
11952
11953 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11954 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11955 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11956 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11957 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11958 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11959 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11960 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11961 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11962 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11963 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11964 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11965 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11966 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11967 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11968 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11969 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11970 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11971 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11972 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11973 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11974 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11975 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11976 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11977 (cfg->fEnableTDLSImplicitTrigger ?
11978 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11979 (cfg->fTDLSExternalControl ?
11980 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11981
11982 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11983 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11984 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11985 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011986 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011987 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011988 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11989 tdls_cfg.tdls_evt_cb_data = psoc;
11990 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11991 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11992 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011993 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11994 tdls_cfg.tdls_wmm_cb_data = psoc;
11995 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11996 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011997 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011998
11999 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
12000 if (status != QDF_STATUS_SUCCESS) {
12001 hdd_err("failed pmo psoc configuration");
12002 return -EINVAL;
12003 }
12004
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012005 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012006 /* disable napier specific tdls data path */
12007 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012008
Frank Liud4b2fa02017-03-29 11:46:48 +080012009 return 0;
12010}
12011#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012012static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080012013{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070012014 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070012015 /* disable napier specific tdls data path */
12016 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080012017 return 0;
12018}
12019#endif
12020
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012021int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012022{
12023 int ret;
12024
12025 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012026 if (ret)
12027 return ret;
12028 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012029 if (ret)
12030 return ret;
12031 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012032
12033 return ret;
12034}
12035
Agrawal Ashish65634612016-08-18 13:24:32 +053012036/**
12037 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12038 * @mode : cfg80211 DFS mode
12039 *
12040 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12041 */
12042enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12043{
12044 switch (mode) {
12045 case DFS_MODE_ENABLE:
12046 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012047 case DFS_MODE_DISABLE:
12048 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012049 case DFS_MODE_DEPRIORITIZE:
12050 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012051 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012052 hdd_debug("ACS dfs mode is NONE");
12053 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012054 }
12055}
12056
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012057/**
12058 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12059 * @hddctx: pointer to hdd context
12060 * @set_value: enable/disable
12061 *
12062 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12063 * Host(even though it is duplicate). When Host send vendor command
12064 * disable,FW doesn't perform any action. Whenever any change in
12065 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12066 *
12067 * return - 0 on success, appropriate error values on failure.
12068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012069int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012070{
12071 QDF_STATUS status;
12072
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012073 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012074 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012075
12076 if (!hddctx->config->goptimize_chan_avoid_event) {
12077 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12078 return -EINVAL;
12079 }
12080
12081 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12082 if (!QDF_IS_STATUS_SUCCESS(status)) {
12083 hdd_err("Failed to send chan avoid command to SME");
12084 return -EINVAL;
12085 }
12086 return 0;
12087}
Agrawal Ashish65634612016-08-18 13:24:32 +053012088
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012089/**
12090 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12091 * @value: value to set
12092 *
12093 * This function will set the passed value to roaming in progress flag.
12094 *
12095 * Return: None
12096 */
12097void hdd_set_roaming_in_progress(bool value)
12098{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012099 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012100
12101 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12102 if (!hdd_ctx) {
12103 hdd_err("HDD context is NULL");
12104 return;
12105 }
12106
12107 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012108 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012109}
12110
12111/**
12112 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012113 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012114 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012115 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012116 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012117bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012118{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012119 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012120 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012121
12122 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12123 if (!hdd_ctx) {
12124 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012125 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012126 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012127 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12128 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012129 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12130 hdd_ctx->roaming_in_progress);
12131
12132 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012133}
12134
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012135/**
12136 * hdd_is_connection_in_progress() - check if connection is in
12137 * progress
12138 * @session_id: session id
12139 * @reason: scan reject reason
12140 *
12141 * Go through each adapter and check if Connection is in progress
12142 *
12143 * Return: true if connection is in progress else false
12144 */
12145bool hdd_is_connection_in_progress(uint8_t *session_id,
12146 enum scan_reject_states *reason)
12147{
12148 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012149 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012150 hdd_adapter_t *adapter = NULL;
12151 QDF_STATUS status = 0;
12152 uint8_t sta_id = 0;
12153 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012154 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012155
12156 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12157 if (!hdd_ctx) {
12158 hdd_err("HDD context is NULL");
12159 return false;
12160 }
12161
12162 if (true == hdd_ctx->btCoexModeSet) {
12163 hdd_info("BTCoex Mode operation in progress");
12164 return true;
12165 }
12166 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12167 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
12168 adapter = adapter_node->pAdapter;
12169 if (!adapter)
12170 goto end;
12171
12172 hdd_info("Adapter with device mode %s(%d) exists",
12173 hdd_device_mode_to_string(adapter->device_mode),
12174 adapter->device_mode);
12175 if (((QDF_STA_MODE == adapter->device_mode)
12176 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12177 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12178 && (eConnectionState_Connecting ==
12179 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12180 conn_info.connState)) {
12181 hdd_err("%p(%d) Connection is in progress",
12182 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12183 adapter->sessionId);
12184 if (session_id && reason) {
12185 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012186 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012187 }
12188 return true;
12189 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012190 /*
12191 * sme_neighbor_middle_of_roaming is for LFR2
12192 * hdd_is_roaming_in_progress is for LFR3
12193 */
12194 if (((QDF_STA_MODE == adapter->device_mode) &&
12195 sme_neighbor_middle_of_roaming(
12196 WLAN_HDD_GET_HAL_CTX(adapter),
12197 adapter->sessionId)) ||
12198 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012199 hdd_err("%p(%d) Reassociation in progress",
12200 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12201 adapter->sessionId);
12202 if (session_id && reason) {
12203 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012204 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012205 }
12206 return true;
12207 }
12208 if ((QDF_STA_MODE == adapter->device_mode) ||
12209 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12210 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12211 hdd_sta_ctx =
12212 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12213 if ((eConnectionState_Associated ==
12214 hdd_sta_ctx->conn_info.connState)
12215 && (false ==
12216 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12217 sta_mac = (uint8_t *)
12218 &(adapter->macAddressCurrent.bytes[0]);
12219 hdd_err("client " MAC_ADDRESS_STR
12220 " is in middle of WPS/EAPOL exchange.",
12221 MAC_ADDR_ARRAY(sta_mac));
12222 if (session_id && reason) {
12223 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012224 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012225 }
12226 return true;
12227 }
12228 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12229 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12230 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12231 sta_id++) {
12232 if (!((adapter->aStaInfo[sta_id].isUsed)
12233 && (OL_TXRX_PEER_STATE_CONN ==
12234 adapter->aStaInfo[sta_id].tlSTAState)))
12235 continue;
12236
12237 sta_mac = (uint8_t *)
12238 &(adapter->aStaInfo[sta_id].
12239 macAddrSTA.bytes[0]);
12240 hdd_err("client " MAC_ADDRESS_STR
12241 " of SAP/GO is in middle of WPS/EAPOL exchange",
12242 MAC_ADDR_ARRAY(sta_mac));
12243 if (session_id && reason) {
12244 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012245 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012246 }
12247 return true;
12248 }
12249 if (hdd_ctx->connection_in_progress) {
12250 hdd_err("AP/GO: connection is in progress");
12251 return true;
12252 }
12253 }
12254end:
12255 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12256 adapter_node = next;
12257 }
12258 return false;
12259}
12260
12261/**
12262 * hdd_restart_sap() - to restart SAP in driver internally
12263 * @ap_adapter: Pointer to SAP hdd_adapter_t structure
12264 *
12265 * Return: None
12266 */
12267void hdd_restart_sap(hdd_adapter_t *ap_adapter)
12268{
Jeff Johnson87251032017-08-29 13:31:11 -070012269 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012270 hdd_hostapd_state_t *hostapd_state;
12271 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012272 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012273 tsap_Config_t *sap_config;
12274 void *sap_ctx;
12275
12276 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12277 sap_config = &hdd_ap_ctx->sapConfig;
12278 sap_ctx = hdd_ap_ctx->sapContext;
12279
12280 mutex_lock(&hdd_ctx->sap_lock);
12281 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12282 wlan_hdd_del_station(ap_adapter);
12283 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12284 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12285 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12286 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12287 qdf_status =
12288 qdf_wait_single_event(&hostapd_state->
12289 qdf_stop_bss_event,
12290 SME_CMD_TIMEOUT_VALUE);
12291
12292 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12293 cds_err("SAP Stop Failed");
12294 goto end;
12295 }
12296 }
12297 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012298 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012299 ap_adapter->device_mode, ap_adapter->sessionId);
12300 cds_err("SAP Stop Success");
12301
12302 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12303 cds_err("SAP Not able to set AP IEs");
12304 wlansap_reset_sap_config_add_ie(sap_config,
12305 eUPDATE_IE_ALL);
12306 goto end;
12307 }
12308
12309 qdf_event_reset(&hostapd_state->qdf_event);
12310 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12311 sap_config,
12312 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12313 cds_err("SAP Start Bss fail");
12314 wlansap_reset_sap_config_add_ie(sap_config,
12315 eUPDATE_IE_ALL);
12316 goto end;
12317 }
12318
12319 cds_info("Waiting for SAP to start");
12320 qdf_status =
12321 qdf_wait_single_event(&hostapd_state->qdf_event,
12322 SME_CMD_TIMEOUT_VALUE);
12323 wlansap_reset_sap_config_add_ie(sap_config,
12324 eUPDATE_IE_ALL);
12325 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12326 cds_err("SAP Start failed");
12327 goto end;
12328 }
12329 cds_err("SAP Start Success");
12330 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12331 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012332 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12333 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012334 ap_adapter->sessionId);
12335 hostapd_state->bCommit = true;
12336 }
12337end:
12338 mutex_unlock(&hdd_ctx->sap_lock);
12339 return;
12340}
12341
12342/**
12343 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12344 * with non dfs acs
12345 *
12346 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12347 *
12348 * Return: None
12349 */
12350void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12351{
12352 hdd_adapter_t *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012353 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012354 cds_context_type *cds_ctx;
12355
12356 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12357 if (!hdd_ctx) {
12358 cds_err("HDD context is NULL");
12359 return;
12360 }
12361
12362 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12363 if (!cds_ctx) {
12364 cds_err("Invalid CDS Context");
12365 return;
12366 }
12367
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012368 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12369 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012370 cds_info("Concurrency mode is not SAP");
12371 return;
12372 }
12373
12374 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012375 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12376 &ap_adapter->event_flags) &&
12377 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12378 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012379
12380 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12381 ap_adapter->sessionCtx.ap.sapConfig.channel =
12382 AUTO_CHANNEL_SELECT;
12383 ap_adapter->sessionCtx.ap.sapConfig.
12384 acs_cfg.acs_mode = true;
12385
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012386 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012387 }
12388}
12389
12390/**
12391 * hdd_set_connection_in_progress() - to set the connection in
12392 * progress flag
12393 * @value: value to set
12394 *
12395 * This function will set the passed value to connection in progress flag.
12396 * If value is previously being set to true then no need to set it again.
12397 *
12398 * Return: true if value is being set correctly and false otherwise.
12399 */
12400bool hdd_set_connection_in_progress(bool value)
12401{
12402 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012403 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012404
12405 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12406 if (!hdd_ctx) {
12407 cds_err("HDD context is NULL");
12408 return false;
12409 }
12410
12411 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12412 /*
12413 * if the value is set to true previously and if someone is
12414 * trying to make it true again then it could be some race
12415 * condition being triggered. Avoid this situation by returning
12416 * false
12417 */
12418 if (hdd_ctx->connection_in_progress && value)
12419 status = false;
12420 else
12421 hdd_ctx->connection_in_progress = value;
12422 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12423 return status;
12424}
12425
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012426int wlan_hdd_send_p2p_quota(hdd_adapter_t *adapter, int set_value)
12427{
12428 if (!adapter) {
12429 hdd_err("Invalid adapter");
12430 return -EINVAL;
12431 }
12432 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012433 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012434 WMA_VDEV_MCC_SET_TIME_QUOTA,
12435 set_value, VDEV_CMD);
12436 return 0;
12437
12438}
12439
12440int wlan_hdd_send_mcc_latency(hdd_adapter_t *adapter, int set_value)
12441{
12442 if (!adapter) {
12443 hdd_err("Invalid adapter");
12444 return -EINVAL;
12445 }
12446
12447 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012448 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012449 WMA_VDEV_MCC_SET_TIME_LATENCY,
12450 set_value, VDEV_CMD);
12451 return 0;
12452}
12453
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012454hdd_adapter_t *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
12455 *psoc, uint8_t vdev_id)
12456{
12457 hdd_adapter_t *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012458 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012459
12460 /*
12461 * Currently PSOC is not being used. But this logic will
12462 * change once we have the converged implementation of
12463 * HDD context per PSOC in place. This would break if
12464 * multiple vdev objects reuse the vdev id.
12465 */
12466 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12467 if (!adapter)
12468 hdd_err("Get adapter by vdev id failed");
12469
12470 return adapter;
12471}
12472
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012473int hdd_get_rssi_snr_by_bssid(hdd_adapter_t *adapter, const uint8_t *bssid,
12474 int8_t *rssi, int8_t *snr)
12475{
12476 QDF_STATUS status;
12477 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12478 tCsrRoamProfile *profile = &wext_state->roamProfile;
12479
12480 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12481 profile, bssid, rssi, snr);
12482 if (QDF_STATUS_SUCCESS != status) {
12483 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12484 return -EINVAL;
12485 }
12486
12487 return 0;
12488}
12489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012490/* Register the module init/exit functions */
12491module_init(hdd_module_init);
12492module_exit(hdd_module_exit);
12493
12494MODULE_LICENSE("Dual BSD/GPL");
12495MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12496MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12497
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012498module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12499 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012500
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012501module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12502 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012504module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12505 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12506
12507module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12508
12509module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12510
12511module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);