blob: c96f09effb6535b0e9635a1768cc2b377d1ce3ea [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
96
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530103#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700104#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700105#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530106#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700107#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530108#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800109#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530111#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800112#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800113#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530114#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530115#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800116#include "os_if_wifi_pos.h"
117#include "wifi_pos_api.h"
118#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800119#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700120#include "os_if_nan.h"
121#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700122#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530124#include "sme_power_save_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800125
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530126#ifdef CNSS_GENL
127#include <net/cnss_nl.h>
128#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800129#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800131#ifdef MODULE
132#define WLAN_MODULE_NAME module_name(THIS_MODULE)
133#else
134#define WLAN_MODULE_NAME "wlan"
135#endif
136
137#ifdef TIMER_MANAGER
138#define TIMER_MANAGER_STR " +TIMER_MANAGER"
139#else
140#define TIMER_MANAGER_STR ""
141#endif
142
143#ifdef MEMORY_DEBUG
144#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
145#else
146#define MEMORY_DEBUG_STR ""
147#endif
148
Sachin Ahujadddd2632017-03-07 19:07:24 +0530149int wlan_start_ret_val;
150static DECLARE_COMPLETION(wlan_start_comp);
151static unsigned int dev_num = 1;
152static struct cdev wlan_hdd_state_cdev;
153static struct class *class;
154static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530155#ifndef MODULE
156static struct gwlan_loader *wlan_loader;
157static ssize_t wlan_boot_cb(struct kobject *kobj,
158 struct kobj_attribute *attr,
159 const char *buf, size_t count);
160struct gwlan_loader {
161 bool loaded_state;
162 struct kobject *boot_wlan_obj;
163 struct attribute_group *attr_group;
164};
165
166static struct kobj_attribute wlan_boot_attribute =
167 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
168
169static struct attribute *attrs[] = {
170 &wlan_boot_attribute.attr,
171 NULL,
172};
173
174#define MODULE_INITIALIZED 1
175#endif
176
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800177/* the Android framework expects this param even though we don't use it */
178#define BUF_LEN 20
179static char fwpath_buffer[BUF_LEN];
180static struct kparam_string fwpath = {
181 .string = fwpath_buffer,
182 .maxlen = BUF_LEN,
183};
184
185static char *country_code;
186static int enable_11d = -1;
187static int enable_dfs_chan_scan = -1;
188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800189/*
190 * spinlock for synchronizing asynchronous request/response
191 * (full description of use in wlan_hdd_main.h)
192 */
193DEFINE_SPINLOCK(hdd_context_lock);
194
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800195#define WLAN_NLINK_CESIUM 30
196
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530197static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800198
199#define WOW_MAX_FILTER_LISTS 1
200#define WOW_MAX_FILTERS_PER_LIST 4
201#define WOW_MIN_PATTERN_SIZE 6
202#define WOW_MAX_PATTERN_SIZE 64
203
204#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
205static const struct wiphy_wowlan_support wowlan_support_reg_init = {
206 .flags = WIPHY_WOWLAN_ANY |
207 WIPHY_WOWLAN_MAGIC_PKT |
208 WIPHY_WOWLAN_DISCONNECT |
209 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
210 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
211 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
212 WIPHY_WOWLAN_4WAY_HANDSHAKE |
213 WIPHY_WOWLAN_RFKILL_RELEASE,
214 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
215 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
216 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
217};
218#endif
219
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700220static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
221 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
222 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
223 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
224 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
225 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
226 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
227 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
228 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
229 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
230 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
231 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
232 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
233 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
234 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
235 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
236 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
237 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700255 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700256};
257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530259struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260
261struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700263static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800264#endif
265
Sachin Ahujadddd2632017-03-07 19:07:24 +0530266void hdd_start_complete(int ret)
267{
268 wlan_start_ret_val = ret;
269
270 complete(&wlan_start_comp);
271}
272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530274 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700275 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530276 *
277 * Return: none
278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700279static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530280{
Jeff Johnson9d295242017-08-29 14:39:48 -0700281 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530282 hdd_adapter_list_node_t *adapter_node, *next;
283 QDF_STATUS status = QDF_STATUS_SUCCESS;
284
285 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
286 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
287 adapter = adapter_node->pAdapter;
288 if (NULL != adapter)
289 hdd_send_rps_ind(adapter);
290 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
291 adapter_node = next;
292 }
293}
294
295/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
297 * @vdev_id: vdev_id
298 * @action: action type
299 * @reason: reason type
300 *
301 * Return: none
302 */
303void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
304 enum netif_action_type action, enum netif_reason_type reason)
305{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700306 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700307 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800308
309 if (!hdd_ctx) {
310 hdd_err("hdd ctx is NULL");
311 return;
312 }
313 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
314
315 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800316}
317
318/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700319 * Store WLAN driver version and timestamp info in global variables such that
320 * crash debugger can extract them from driver debug symbol and crashdump for
321 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 */
323uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700324
325#ifndef BUILD_TIMESTAMP
326#define BUILD_TIMESTAMP ""
327#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700328uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329
330/**
331 * hdd_device_mode_to_string() - return string conversion of device mode
332 * @device_mode: device mode
333 *
334 * This utility function helps log string conversion of device mode.
335 *
336 * Return: string conversion of device mode, if match found;
337 * "Unknown" otherwise.
338 */
339const char *hdd_device_mode_to_string(uint8_t device_mode)
340{
341 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800342 CASE_RETURN_STRING(QDF_STA_MODE);
343 CASE_RETURN_STRING(QDF_SAP_MODE);
344 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
345 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
346 CASE_RETURN_STRING(QDF_FTM_MODE);
347 CASE_RETURN_STRING(QDF_IBSS_MODE);
348 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
349 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700350 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800351 default:
352 return "Unknown";
353 }
354}
355
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530356/**
357 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
358 * @adapter: HDD adapter
359 * @chan_number: Channel number
360 * @chan_bw: Bandwidth
361 *
362 * Checks if the given bandwidth is valid for the given channel number.
363 *
364 * Return: 0 for success, non-zero for failure
365 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700366int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530367 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800368 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530369{
370 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
371 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
372 bool found = false;
373 tHalHandle hal;
374
375 hal = WLAN_HDD_GET_HAL_CTX(adapter);
376 if (!hal) {
377 hdd_err("Invalid HAL context");
378 return -EINVAL;
379 }
380
381 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
382 hdd_err("No valid channel list");
383 return -EOPNOTSUPP;
384 }
385
386 for (i = 0; i < len; i++) {
387 if (chan[i] == chan_number) {
388 found = true;
389 break;
390 }
391 }
392
393 if (found == false) {
394 hdd_err("Channel not in driver's valid channel list");
395 return -EOPNOTSUPP;
396 }
397
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700398 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
399 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530400 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
401 return -EINVAL;
402 }
403
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700404 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530405 if (chan_bw == CH_WIDTH_80MHZ) {
406 hdd_err("BW80 not possible in 2.4GHz band");
407 return -EINVAL;
408 }
409 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
410 (chan_bw != CH_WIDTH_MAX)) {
411 hdd_err("Only BW20 possible on channel 14");
412 return -EINVAL;
413 }
414 }
415
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700416 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530417 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
418 (chan_bw != CH_WIDTH_MAX)) {
419 hdd_err("Only BW20 possible on channel 165");
420 return -EINVAL;
421 }
422 }
423
424 return 0;
425}
426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427static int __hdd_netdev_notifier_call(struct notifier_block *nb,
428 unsigned long state, void *data)
429{
430#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
431 struct netdev_notifier_info *dev_notif_info = data;
432 struct net_device *dev = dev_notif_info->dev;
433#else
434 struct net_device *dev = data;
435#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700436 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700437 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800438
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800439 ENTER_DEV(dev);
440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 /* Make sure that this callback corresponds to our device. */
442 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
443 return NOTIFY_DONE;
444
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530445 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700447 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 return NOTIFY_DONE;
449 }
450
451 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700452 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 return NOTIFY_DONE;
454 }
455
456 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
457 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800458 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530459 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 return NOTIFY_DONE;
461 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530462 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800463 return NOTIFY_DONE;
464
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800465 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 dev->name, state);
467
468 switch (state) {
469 case NETDEV_REGISTER:
470 break;
471
472 case NETDEV_UNREGISTER:
473 break;
474
475 case NETDEV_UP:
476 sme_ch_avoid_update_req(hdd_ctx->hHal);
477 break;
478
479 case NETDEV_DOWN:
480 break;
481
482 case NETDEV_CHANGE:
483 if (true == adapter->isLinkUpSvcNeeded)
484 complete(&adapter->linkup_event_var);
485 break;
486
487 case NETDEV_GOING_DOWN:
488 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530489 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
490 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 } else {
hqueaa33ee2017-05-04 17:56:35 +0800492 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800493 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 }
495 break;
496
497 default:
498 break;
499 }
500
501 return NOTIFY_DONE;
502}
503
504/**
505 * hdd_netdev_notifier_call() - netdev notifier callback function
506 * @nb: pointer to notifier block
507 * @state: state
508 * @ndev: ndev pointer
509 *
510 * Return: 0 on success, error number otherwise.
511 */
512static int hdd_netdev_notifier_call(struct notifier_block *nb,
513 unsigned long state,
514 void *ndev)
515{
516 int ret;
517
518 cds_ssr_protect(__func__);
519 ret = __hdd_netdev_notifier_call(nb, state, ndev);
520 cds_ssr_unprotect(__func__);
521
522 return ret;
523}
524
525struct notifier_block hdd_netdev_notifier = {
526 .notifier_call = hdd_netdev_notifier_call,
527};
528
529/* variable to hold the insmod parameters */
530static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800531
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530532static int con_mode_ftm;
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
Jeff Johnson9d295242017-08-29 14:39:48 -0700715int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700716{
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.
Jeff Johnson9d295242017-08-29 14:39:48 -0700775 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800776 *
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 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700784QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *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;
Jeff Johnson9d295242017-08-29 14:39:48 -07001720 struct hdd_adapter *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 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001858int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05301859{
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{
Jeff Johnson9d295242017-08-29 14:39:48 -07002073 struct hdd_adapter *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 Johnson9d295242017-08-29 14:39:48 -07002145int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, struct hdd_adapter *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
Jeff Johnson3a280122017-09-13 07:42:00 -07002252 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302253 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;
Jeff Johnsone4b14592017-09-13 14:23:33 -07002317 cds_close(hdd_ctx->hdd_psoc);
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{
Jeff Johnson9d295242017-08-29 14:39:48 -07002402 struct hdd_adapter *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{
Jeff Johnson9d295242017-08-29 14:39:48 -07002489 struct hdd_adapter *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{
Jeff Johnson9d295242017-08-29 14:39:48 -07002597 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002598 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002600 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002601
2602 do {
2603 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002604 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605 break;
2606 }
2607
Jeff Johnson399c6272017-08-30 10:51:00 -07002608 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2609 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002610 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 break;
2612 }
2613
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002614 if (dev != adapter->dev)
2615 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002616
Jeff Johnson399c6272017-08-30 10:51:00 -07002617 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618
2619 /* after uninit our adapter structure will no longer be valid */
2620 adapter->dev = NULL;
2621 adapter->magic = 0;
2622 } while (0);
2623
2624 EXIT();
2625}
2626
2627/**
2628 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2629 * @dev: pointer to net_device structure
2630 *
2631 * This is called during the netdev unregister to uninitialize all data
2632 * associated with the device
2633 *
2634 * Return: none
2635 */
2636static void hdd_uninit(struct net_device *dev)
2637{
2638 cds_ssr_protect(__func__);
2639 __hdd_uninit(dev);
2640 cds_ssr_unprotect(__func__);
2641}
2642
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002643static int hdd_open_cesium_nl_sock(void)
2644{
2645#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2646 struct netlink_kernel_cfg cfg = {
2647 .groups = WLAN_NLINK_MCAST_GRP_ID,
2648 .input = NULL
2649 };
2650#endif
2651 int ret = 0;
2652
2653#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2654 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2655#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2656 THIS_MODULE,
2657#endif
2658 &cfg);
2659#else
2660 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2661 WLAN_NLINK_MCAST_GRP_ID,
2662 NULL, NULL, THIS_MODULE);
2663#endif
2664
2665 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002666 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002667 ret = -ECONNREFUSED;
2668 }
2669
2670 return ret;
2671}
2672
2673static void hdd_close_cesium_nl_sock(void)
2674{
2675 if (NULL != cesium_nl_srv_sock) {
2676 netlink_kernel_release(cesium_nl_srv_sock);
2677 cesium_nl_srv_sock = NULL;
2678 }
2679}
2680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681/**
2682 * __hdd_set_mac_address() - set the user specified mac address
2683 * @dev: Pointer to the net device.
2684 * @addr: Pointer to the sockaddr.
2685 *
2686 * This function sets the user specified mac address using
2687 * the command ifconfig wlanX hw ether <mac adress>.
2688 *
2689 * Return: 0 for success, non zero for failure
2690 */
2691static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2692{
Jeff Johnson9d295242017-08-29 14:39:48 -07002693 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002694 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302696 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002697 int ret;
2698
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002699 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700
2701 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2702 ret = wlan_hdd_validate_context(hdd_ctx);
2703 if (0 != ret)
2704 return ret;
2705
2706 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2707 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2708
2709 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302710 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711}
2712
2713/**
2714 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2715 * function from SSR
2716 * @dev: pointer to net_device structure
2717 * @addr: Pointer to the sockaddr
2718 *
2719 * This function sets the user specified mac address using
2720 * the command ifconfig wlanX hw ether <mac adress>.
2721 *
2722 * Return: 0 for success.
2723 */
2724static int hdd_set_mac_address(struct net_device *dev, void *addr)
2725{
2726 int ret;
2727
2728 cds_ssr_protect(__func__);
2729 ret = __hdd_set_mac_address(dev, addr);
2730 cds_ssr_unprotect(__func__);
2731
2732 return ret;
2733}
2734
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002735uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002736{
2737 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002738
Anurag Chouhan6d760662016-02-20 16:05:43 +05302739 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2741 break;
2742 }
2743
Anurag Chouhan6d760662016-02-20 16:05:43 +05302744 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002745 return NULL;
2746
2747 hdd_ctx->config->intfAddrMask |= (1 << i);
2748 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2749}
2750
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002751void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx, uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002752{
2753 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002754
Anurag Chouhan6d760662016-02-20 16:05:43 +05302755 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756 if (!memcmp(releaseAddr,
2757 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2758 6)) {
2759 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2760 break;
2761 }
2762 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763}
2764
2765#ifdef WLAN_FEATURE_PACKET_FILTERING
2766/**
2767 * __hdd_set_multicast_list() - set the multicast address list
2768 * @dev: Pointer to the WLAN device.
2769 * @skb: Pointer to OS packet (sk_buff).
2770 *
2771 * This funciton sets the multicast address list.
2772 *
2773 * Return: None
2774 */
2775static void __hdd_set_multicast_list(struct net_device *dev)
2776{
Jeff Johnson9d295242017-08-29 14:39:48 -07002777 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 int i = 0, status;
2779 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002780 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302781 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2782 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2783 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002785 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302786 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302787 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302788
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302790 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302791 goto out;
2792
Dustin Brownc788acb2017-08-01 17:43:51 -07002793 status = hdd_validate_adapter(adapter);
2794 if (status)
2795 goto out;
2796
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302797 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2798 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002799 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302800 goto out;
2801 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302803 /* Delete already configured multicast address list */
2804 if (adapter->mc_addr_list.mc_cnt > 0) {
2805 hdd_info("clear previously configured MC address list");
2806 hdd_disable_and_flush_mc_addr_list(adapter,
2807 pmo_mc_list_change_notify);
2808 }
2809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002810 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002811 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302812 hdd_disable_and_flush_mc_addr_list(adapter,
2813 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 } else {
2815 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302816 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002817 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302818 pmo_ucfg_max_mc_addr_supported(psoc));
2819 hdd_disable_and_flush_mc_addr_list(adapter,
2820 pmo_mc_list_change_notify);
2821 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002823 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002824 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302825 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826 if (i == mc_count)
2827 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302828 memset(&(mc_list_request->mc_addr[i].bytes),
2829 0, ETH_ALEN);
2830 memcpy(&(mc_list_request->mc_addr[i].bytes),
2831 ha->addr, ETH_ALEN);
2832 hdd_info("mlist[%d] = %pM", i,
2833 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834 i++;
2835 }
2836 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302837
2838 mc_list_request->psoc = psoc;
2839 mc_list_request->vdev_id = adapter->sessionId;
2840 mc_list_request->count = mc_count;
2841 status = hdd_cache_mc_addr_list(mc_list_request);
2842 if (status == 0) {
2843 hdd_enable_mc_addr_filtering(adapter,
2844 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302846 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002847 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302848out:
2849 if (mc_list_request)
2850 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302851 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852}
2853
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855/**
2856 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2857 * @dev: pointer to net_device
2858 *
2859 * Return: none
2860 */
2861static void hdd_set_multicast_list(struct net_device *dev)
2862{
2863 cds_ssr_protect(__func__);
2864 __hdd_set_multicast_list(dev);
2865 cds_ssr_unprotect(__func__);
2866}
2867#endif
2868
2869/**
2870 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2871 * @dev: Pointer to the WLAN device.
2872 * @skb: Pointer to OS packet (sk_buff).
2873 *
2874 * This function is registered with the Linux OS for network
2875 * core to decide which queue to use first.
2876 *
2877 * Return: ac, Queue Index/access category corresponding to UP in IP header
2878 */
2879static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2880#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2881 , void *accel_priv
2882#endif
2883#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2884 , select_queue_fallback_t fallback
2885#endif
2886)
2887{
2888 return hdd_wmm_select_queue(dev, skb);
2889}
2890
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002891static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892 .ndo_open = hdd_open,
2893 .ndo_stop = hdd_stop,
2894 .ndo_uninit = hdd_uninit,
2895 .ndo_start_xmit = hdd_hard_start_xmit,
2896 .ndo_tx_timeout = hdd_tx_timeout,
2897 .ndo_get_stats = hdd_get_stats,
2898 .ndo_do_ioctl = hdd_ioctl,
2899 .ndo_set_mac_address = hdd_set_mac_address,
2900 .ndo_select_queue = hdd_select_queue,
2901#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903#endif
2904};
2905
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002906/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002907static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002908 .ndo_open = hdd_mon_open,
2909 .ndo_stop = hdd_stop,
2910 .ndo_get_stats = hdd_get_stats,
2911};
2912
2913/**
2914 * hdd_set_station_ops() - update net_device ops for monitor mode
2915 * @pWlanDev: Handle to struct net_device to be updated.
2916 * Return: None
2917 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002918void hdd_set_station_ops(struct net_device *pWlanDev)
2919{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002920 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2921 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2922 else
2923 pWlanDev->netdev_ops = &wlan_drv_ops;
2924}
2925
Komal Seelama89be8d2016-09-29 11:09:26 +05302926#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302927/**
2928 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2929 * @hdd_ctx: HDD context
2930 *
2931 * Return: None
2932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002933static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302934{
2935 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2936
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002937 qdf_runtime_lock_init(&ctx->roc);
2938 qdf_runtime_lock_init(&ctx->dfs);
Komal Seelam8634b772016-09-29 12:12:24 +05302939}
2940
2941/**
2942 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2943 * @hdd_ctx: HDD Context
2944 *
2945 * Return: None
2946 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002947static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
Komal Seelam8634b772016-09-29 12:12:24 +05302948{
2949 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2950
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002951 qdf_runtime_lock_deinit(&ctx->roc);
2952 qdf_runtime_lock_deinit(&ctx->dfs);
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302953
2954 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302955}
2956
Jeff Johnson9d295242017-08-29 14:39:48 -07002957static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05302958{
2959 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2960
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002961 qdf_runtime_lock_init(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302962}
2963
Jeff Johnson9d295242017-08-29 14:39:48 -07002964static void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter)
Komal Seelama89be8d2016-09-29 11:09:26 +05302965{
2966 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2967
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08002968 qdf_runtime_lock_deinit(&ctx->connect);
Komal Seelama89be8d2016-09-29 11:09:26 +05302969}
2970#else /* FEATURE_RUNTIME_PM */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002971static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
2972static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Jeff Johnson9d295242017-08-29 14:39:48 -07002973static inline void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
2974static inline void hdd_adapter_runtime_suspend_denit(struct hdd_adapter *adapter) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302975#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002976/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002977 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2978 * @hdd_ctx: global hdd context
2979 * @macAddr: mac address to assign to the interface
2980 * @name: User-visible name of the interface
2981 *
2982 * hdd adapter pointer would point to the netdev->priv space, this function
2983 * would retrive the pointer, and setup the hdd adapter configuration.
2984 *
2985 * Return: the pointer to hdd adapter, otherwise NULL
2986 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002987static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002989 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002990 const char *name)
2991{
2992 struct net_device *pWlanDev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07002993 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002994 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995 /*
2996 * cfg80211 initialization and registration....
2997 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002998 pWlanDev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002999#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3000 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003001#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003002 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3003 hdd_mon_mode_ether_setup : ether_setup),
3004 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005
3006 if (pWlanDev != NULL) {
3007
3008 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson9d295242017-08-29 14:39:48 -07003009 adapter = (struct hdd_adapter *) netdev_priv(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010
Jeff Johnson9d295242017-08-29 14:39:48 -07003011 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303012 sta_ctx = &adapter->sessionCtx.station;
3013 qdf_mem_set(sta_ctx->conn_info.staId,
3014 sizeof(sta_ctx->conn_info.staId),
3015 HDD_WLAN_INVALID_STA_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016 adapter->dev = pWlanDev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003017 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05303019 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020
3021 init_completion(&adapter->session_open_comp_var);
3022 init_completion(&adapter->session_close_comp_var);
3023 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303024 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003025 init_completion(&adapter->linkup_event_var);
3026 init_completion(&adapter->cancel_rem_on_chan_var);
3027 init_completion(&adapter->rem_on_chan_ready_event);
3028 init_completion(&adapter->sta_authorized_event);
3029 init_completion(&adapter->offchannel_tx_event);
3030 init_completion(&adapter->tx_action_cnf_event);
3031#ifdef FEATURE_WLAN_TDLS
3032 init_completion(&adapter->tdls_add_station_comp);
3033 init_completion(&adapter->tdls_del_station_comp);
3034 init_completion(&adapter->tdls_mgmt_comp);
3035 init_completion(&adapter->tdls_link_establish_req_comp);
3036#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003037 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003038 init_completion(&adapter->change_country_code);
3039
3040
3041 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303042 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003043
3044 adapter->offloads_configured = false;
3045 adapter->isLinkUpSvcNeeded = false;
3046 adapter->higherDtimTransition = true;
3047 /* Init the net_device structure */
3048 strlcpy(pWlanDev->name, name, IFNAMSIZ);
3049
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303050 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303052 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053 sizeof(tSirMacAddr));
3054 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003055
3056 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3057 pWlanDev->features |=
3058 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3059 pWlanDev->features |= NETIF_F_RXCSUM;
3060
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003061 hdd_set_tso_flags(hdd_ctx, pWlanDev);
3062
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 hdd_set_station_ops(adapter->dev);
3064
3065 pWlanDev->destructor = free_netdev;
3066 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08003067 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003068 adapter->wdev.wiphy = hdd_ctx->wiphy;
3069 adapter->wdev.netdev = pWlanDev;
3070 /* set pWlanDev's parent to underlying device */
3071 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
3072 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303073 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303075 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 }
3077
3078 return adapter;
3079}
3080
Jeff Johnson9d295242017-08-29 14:39:48 -07003081static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003083 struct net_device *dev = adapter->dev;
3084 int ret;
3085
3086 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003088 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003089 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3090
3091 ret = dev_alloc_name(dev, dev->name);
3092 if (ret < 0) {
3093 hdd_err(
3094 "unable to get dev name: %s, err = 0x%x",
3095 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303096 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 }
3098 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003099
3100 ret = register_netdevice(dev);
3101 if (ret) {
3102 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3103 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303104 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 }
3106 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003107 ret = register_netdev(dev);
3108 if (ret) {
3109 hdd_err("register_netdev(%s) failed, err = 0x%x",
3110 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303111 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112 }
3113 }
3114 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3115
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003116 EXIT();
3117
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303118 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119}
3120
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003121QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122{
Jeff Johnson9d295242017-08-29 14:39:48 -07003123 struct hdd_adapter *adapter = pContext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124
3125 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003126 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303127 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 }
3129
3130 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003131 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303132 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 }
3134
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003135 /*
3136 * For NAN Data interface, the close session results in the final
3137 * indication to the userspace
3138 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003139 if (adapter->device_mode == QDF_NDI_MODE)
3140 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 /*
3145 * We can be blocked while waiting for scheduled work to be
3146 * flushed, and the adapter structure can potentially be freed, in
3147 * which case the magic will have been reset. So make sure the
3148 * magic is still good, and hence the adapter structure is still
3149 * valid, before signaling completion
3150 */
3151 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3152 complete(&adapter->session_close_comp_var);
3153
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303154 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155}
3156
Krunal Soni8c37e322016-02-03 16:08:37 -08003157/**
3158 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3159 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003160 *
3161 * This routine will check the mode of adapter and if it is required then it
3162 * will initialize the TDLS operations
3163 *
3164 * Return: QDF_STATUS
3165 */
3166#ifdef FEATURE_WLAN_TDLS
Jeff Johnson9d295242017-08-29 14:39:48 -07003167static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003168{
Dustin Brownd28772b2017-03-17 14:16:07 -07003169 if (adapter->device_mode == QDF_IBSS_MODE)
3170 return QDF_STATUS_SUCCESS;
3171
3172 if (wlan_hdd_tdls_init(adapter)) {
3173 hdd_err("wlan_hdd_tdls_init failed");
3174 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003175 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003176 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3177
Krunal Soni8c37e322016-02-03 16:08:37 -08003178 return QDF_STATUS_SUCCESS;
3179}
3180#else
Jeff Johnson9d295242017-08-29 14:39:48 -07003181static QDF_STATUS hdd_check_and_init_tdls(struct hdd_adapter *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003182{
3183 return QDF_STATUS_SUCCESS;
3184}
3185#endif
3186
Jeff Johnson9d295242017-08-29 14:39:48 -07003187int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188{
Dustin Brownd28772b2017-03-17 14:16:07 -07003189 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190
Dustin Brownd28772b2017-03-17 14:16:07 -07003191 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003192 if (QDF_IS_STATUS_ERROR(status))
3193 return qdf_status_to_os_return(status);
3194
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003195 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003196 if (QDF_IS_STATUS_ERROR(status))
3197 return qdf_status_to_os_return(status);
3198
3199 if (wma_capability_enhanced_mcast_filter())
3200 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3201 else
3202 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003203
3204 return qdf_status_to_os_return(status);
3205}
3206
Jeff Johnson9d295242017-08-29 14:39:48 -07003207int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003208{
3209 QDF_STATUS status;
3210 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003211 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003212 unsigned long rc;
3213
3214 hdd_info("destroying vdev %d", adapter->sessionId);
3215
3216 /* vdev created sanity check */
3217 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3218 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3219 return -EINVAL;
3220 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003221 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003222 /*
3223 * In SSR case, there is no need to destroy vdev in firmware since
3224 * it has already asserted. vdev can be released directly.
3225 */
3226 if (cds_is_driver_recovering())
3227 goto release_vdev;
3228
Dustin Brownd28772b2017-03-17 14:16:07 -07003229 /* close sme session (destroy vdev in firmware via legacy API) */
3230 INIT_COMPLETION(adapter->session_close_comp_var);
3231 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3232 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3233 hdd_sme_close_session_callback, adapter);
3234 if (QDF_IS_STATUS_ERROR(status)) {
3235 hdd_err("failed to close sme session: %d", status);
3236 return qdf_status_to_os_return(status);
3237 }
3238
3239 /* block on a completion variable until sme session is closed */
3240 rc = wait_for_completion_timeout(
3241 &adapter->session_close_comp_var,
3242 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3243 if (!rc) {
3244 hdd_err("timed out waiting for close sme session: %ld", rc);
3245 if (adapter->device_mode == QDF_NDI_MODE)
3246 hdd_ndp_session_end_handler(adapter);
3247 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3248 return -ETIMEDOUT;
3249 }
Yue Maf9782842017-05-08 12:49:49 -07003250release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003251 /* do vdev logical destroy via objmgr */
3252 errno = hdd_objmgr_destroy_vdev(adapter);
3253 if (errno) {
3254 hdd_err("failed to destroy objmgr vdev: %d", errno);
3255 return errno;
3256 }
3257
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003258 /* now that sme session is closed, allow physical vdev destroy */
3259 errno = hdd_objmgr_release_vdev(adapter);
3260 if (errno) {
3261 hdd_err("failed to release objmgr vdev: %d", errno);
3262 return errno;
3263 }
3264
Dustin Brownd28772b2017-03-17 14:16:07 -07003265 hdd_info("vdev destroyed successfully");
3266
3267 return 0;
3268}
3269
Jeff Johnson9d295242017-08-29 14:39:48 -07003270int hdd_vdev_create(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003271{
3272 QDF_STATUS status;
3273 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003274 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003275 uint32_t type;
3276 uint32_t sub_type;
3277 unsigned long rc;
3278
3279 hdd_info("creating new vdev");
3280
3281 /* determine vdev (sub)type */
3282 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303283 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003284 hdd_err("failed to get vdev type: %d", status);
3285 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003287
3288 /* do vdev create via objmgr */
3289 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003290 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003291 if (errno) {
3292 hdd_err("failed to create objmgr vdev: %d", errno);
3293 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003295
3296 /* Open a SME session (prepare vdev in firmware via legacy API) */
3297 INIT_COMPLETION(adapter->session_open_comp_var);
3298 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3299 (uint8_t *)&adapter->macAddressCurrent,
3300 adapter->sessionId, type, sub_type);
3301 if (QDF_IS_STATUS_ERROR(status)) {
3302 hdd_err("failed to open sme session: %d", status);
3303 errno = qdf_status_to_os_return(status);
3304 goto objmgr_vdev_destroy;
3305 }
3306
3307 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 rc = wait_for_completion_timeout(
3309 &adapter->session_open_comp_var,
3310 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3311 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003312 hdd_err("timed out waiting for open sme session: %ld", rc);
3313 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303314 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3315 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003316 }
3317
3318 /* firmware ready for component communication, raise vdev_ready event */
3319 errno = hdd_vdev_ready(adapter);
3320 if (errno) {
3321 hdd_err("failed to dispatch vdev ready event: %d", errno);
3322 goto hdd_vdev_destroy;
3323 }
3324
3325 hdd_info("vdev %d created successfully", adapter->sessionId);
3326
3327 return 0;
3328
3329 /*
3330 * Due to legacy constraints, we need to destroy in the same order as
3331 * create. So, split error handling into 2 cases to accommodate.
3332 */
3333
3334objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003335 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003336
3337 return errno;
3338
3339hdd_vdev_destroy:
3340 QDF_BUG(!hdd_vdev_destroy(adapter));
3341
3342 return errno;
3343}
3344
Jeff Johnson9d295242017-08-29 14:39:48 -07003345QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003346{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003347 struct hdd_station_ctx *pHddStaCtx = &adapter->sessionCtx.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003348 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003349 QDF_STATUS status;
3350 int ret_val;
3351
3352 ret_val = hdd_vdev_create(adapter);
3353 if (ret_val) {
3354 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303355 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 }
3357
Dustin Brownd28772b2017-03-17 14:16:07 -07003358 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3359 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3360 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003361 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003364 status = hdd_register_wext(adapter->dev);
3365 if (QDF_IS_STATUS_ERROR(status)) {
3366 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 goto error_register_wext;
3368 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003369 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003370
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303371 qdf_mem_set(pHddStaCtx->conn_info.staId,
3372 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3373
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003374 /* set fast roaming capability in sme session */
3375 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3376 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377 /* Set the default operation channel */
3378 pHddStaCtx->conn_info.operationChannel =
3379 hdd_ctx->config->OperatingChannel;
3380
3381 /* Make the default Auth Type as OPEN */
3382 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3383
3384 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303385 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003386 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 status, status);
3388 goto error_init_txrx;
3389 }
3390
3391 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3392
3393 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303394 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003395 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 status, status);
3397 goto error_wmm_init;
3398 }
3399
3400 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3401
Naveen Rawat247a8682017-06-05 15:00:31 -07003402 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403 WMI_PDEV_PARAM_BURST_ENABLE,
3404 hdd_ctx->config->enableSifsBurst,
3405 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003406 if (ret_val)
3407 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408
Dustin Brownd28772b2017-03-17 14:16:07 -07003409 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003410 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003413 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303414 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416error_tdls_init:
3417 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3418 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419error_wmm_init:
3420 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3421 hdd_deinit_tx_rx(adapter);
3422error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003423 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003424error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003425 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427 return status;
3428}
3429
Jeff Johnson9d295242017-08-29 14:39:48 -07003430void hdd_cleanup_actionframe(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431{
3432 hdd_cfg80211_state_t *cfgState;
3433
3434 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3435
3436 if (NULL != cfgState->buf) {
3437 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 rc = wait_for_completion_timeout(
3440 &adapter->tx_action_cnf_event,
3441 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3442 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003443 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303444 /*
3445 * Inform tx status as FAILURE to upper layer and free
3446 * cfgState->buf
3447 */
3448 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 }
3450 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451}
3452
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303453/**
3454 * hdd_station_adapter_deinit() - De-initialize the station adapter
3455 * @hdd_ctx: global hdd context
3456 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003457 * @rtnl_held: Used to indicate whether or not the caller is holding
3458 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303459 *
3460 * This function De-initializes the STA/P2P/OCB adapter.
3461 *
3462 * Return: None.
3463 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003464static void hdd_station_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003465 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003466 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303467{
3468 ENTER_DEV(adapter->dev);
3469
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303470 if (adapter->dev) {
3471 if (rtnl_held)
3472 adapter->dev->wireless_handlers = NULL;
3473 else {
3474 rtnl_lock();
3475 adapter->dev->wireless_handlers = NULL;
3476 rtnl_unlock();
3477 }
3478 }
3479
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303480 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3481 hdd_deinit_tx_rx(adapter);
3482 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3483 }
3484
3485 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3486 hdd_wmm_adapter_close(adapter);
3487 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3488 }
3489
3490 hdd_cleanup_actionframe(hdd_ctx, adapter);
3491 wlan_hdd_tdls_exit(adapter);
3492
3493 EXIT();
3494}
3495
3496/**
3497 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3498 * @hdd_ctx: global hdd context
3499 * @adapter: HDD adapter
3500 * @rtnl_held: the rtnl lock hold flag
3501 * This function De-initializes the AP/P2PGo adapter.
3502 *
3503 * Return: None.
3504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003505static void hdd_ap_adapter_deinit(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003506 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003507 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303508{
3509 ENTER_DEV(adapter->dev);
3510
3511 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3512 hdd_wmm_adapter_close(adapter);
3513 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3514 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003515 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303516
3517 hdd_cleanup_actionframe(hdd_ctx, adapter);
3518
3519 hdd_unregister_hostapd(adapter, rtnl_held);
3520
3521 EXIT();
3522}
3523
Jeff Johnson9d295242017-08-29 14:39:48 -07003524void hdd_deinit_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003525 bool rtnl_held)
3526{
3527 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303528
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003530 case QDF_STA_MODE:
3531 case QDF_P2P_CLIENT_MODE:
3532 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303534 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535 break;
3536 }
3537
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003538 case QDF_SAP_MODE:
3539 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 {
3541
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303542 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543 break;
3544 }
3545
3546 default:
3547 break;
3548 }
3549
3550 EXIT();
3551}
3552
Jeff Johnson9d295242017-08-29 14:39:48 -07003553static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003554 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555{
3556 struct net_device *pWlanDev = NULL;
3557
3558 if (adapter)
3559 pWlanDev = adapter->dev;
3560 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003561 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 return;
3563 }
3564
Rajeev Kumardca5f812016-02-04 17:28:06 -08003565 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303566
3567 if (adapter->scan_info.default_scan_ies) {
3568 qdf_mem_free(adapter->scan_info.default_scan_ies);
3569 adapter->scan_info.default_scan_ies = NULL;
3570 }
3571
Komal Seelama89be8d2016-09-29 11:09:26 +05303572 hdd_adapter_runtime_suspend_denit(adapter);
3573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 /*
3575 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3576 * the driver is almost closed and cannot handle either control
3577 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003578 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3579 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 * is not right. Setting this flag helps hdd_stop() to recognize that
3581 * the interface is closed and restricts any operations on that
3582 */
3583 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3584
3585 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003586 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003588 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 /*
3591 * Note that the adapter is no longer valid at this point
3592 * since the memory has been reclaimed
3593 */
3594 }
3595}
3596
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003597static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003598 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599{
3600 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003601 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303602 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303605 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003606 adapter = adapterNode->pAdapter;
3607 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303608 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303610 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 }
3612 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3613 adapterNode = pNext;
3614 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303615 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003617
Arun Khandavalli2358d522016-05-16 18:05:37 +05303618#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3619/**
3620 * hdd_set_fw_log_params() - Set log parameters to FW
3621 * @hdd_ctx: HDD Context
3622 * @adapter: HDD Adapter
3623 *
3624 * This function set the FW Debug log level based on the INI.
3625 *
3626 * Return: None
3627 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003628static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003629 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303630{
3631 uint8_t count = 0, numentries = 0,
3632 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3633 uint32_t value = 0;
3634 int ret;
3635
Arun Khandavallifae92942016-08-01 13:31:08 +05303636 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3637 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003638 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303639 return;
3640 }
3641
Arun Khandavallifae92942016-08-01 13:31:08 +05303642 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303643 hdd_ctx->fw_log_settings.dl_type =
3644 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003645 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303646 WMI_DBGLOG_TYPE,
3647 hdd_ctx->config->enableFwLogType,
3648 DBG_CMD);
3649 if (ret != 0)
3650 hdd_err("Failed to enable FW log type ret %d",
3651 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303652
3653 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303654 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003655 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303656 WMI_DBGLOG_LOG_LEVEL,
3657 hdd_ctx->config->enableFwLogLevel,
3658 DBG_CMD);
3659 if (ret != 0)
3660 hdd_err("Failed to enable FW log level ret %d",
3661 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303662
3663 hdd_string_to_u8_array(
3664 hdd_ctx->config->enableFwModuleLogLevel,
3665 moduleloglevel,
3666 &numentries,
3667 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3668
3669 while (count < numentries) {
3670 /*
3671 * FW module log level input string looks like
3672 * below:
3673 * gFwDebugModuleLoglevel=<FW Module ID>,
3674 * <Log Level>,...
3675 * For example:
3676 * gFwDebugModuleLoglevel=
3677 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3678 * Above input string means :
3679 * For FW module ID 1 enable log level 0
3680 * For FW module ID 2 enable log level 1
3681 * For FW module ID 3 enable log level 2
3682 * For FW module ID 4 enable log level 3
3683 * For FW module ID 5 enable log level 4
3684 * For FW module ID 6 enable log level 5
3685 * For FW module ID 7 enable log level 6
3686 */
3687
Nishank Aggarwale239d962017-03-03 12:26:02 +05303688 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3689 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3690 hdd_err("Module id %d and dbglog level %d input length is more than max",
3691 moduleloglevel[count],
3692 moduleloglevel[count + 1]);
3693 return;
3694 }
3695
3696 value = moduleloglevel[count] << 16;
3697 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003698 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303699 WMI_DBGLOG_MOD_LOG_LEVEL,
3700 value, DBG_CMD);
3701 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303702 hdd_err("Failed to enable FW module log level %d ret %d",
3703 value, ret);
3704
3705 count += 2;
3706 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303707
Arun Khandavalli2358d522016-05-16 18:05:37 +05303708}
3709#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003710static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003711 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303712{
3713}
3714
3715#endif
3716
3717/**
3718 * hdd_set_fw_params() - Set parameters to firmware
3719 * @adapter: HDD adapter
3720 *
3721 * This function Sets various parameters to fw once the
3722 * adapter is started.
3723 *
3724 * Return: 0 on success or errno on failure
3725 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003726int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303727{
3728 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003729 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303730
3731 ENTER_DEV(adapter->dev);
3732
3733 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3734 if (!hdd_ctx)
3735 return -EINVAL;
3736
Dustin Brown732ab9c2017-06-15 13:24:09 -07003737 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3738 hdd_debug("FTM Mode is active; nothing to do");
3739 return 0;
3740 }
3741
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303742 ret = sme_cli_set_command(adapter->sessionId,
3743 WMI_PDEV_PARAM_DTIM_SYNTH,
3744 hdd_ctx->config->enable_lprx, PDEV_CMD);
3745 if (ret) {
3746 hdd_err("Failed to set LPRx");
3747 goto error;
3748 }
3749
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303750 if (adapter->device_mode == QDF_STA_MODE) {
3751 sme_set_smps_cfg(adapter->sessionId,
3752 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3753 hdd_ctx->config->upper_brssi_thresh);
3754
3755 sme_set_smps_cfg(adapter->sessionId,
3756 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3757 hdd_ctx->config->lower_brssi_thresh);
3758
3759 sme_set_smps_cfg(adapter->sessionId,
3760 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3761 hdd_ctx->config->enable_dtim_1chrx);
3762 }
3763
Dustin Brown732ab9c2017-06-15 13:24:09 -07003764 if (hdd_ctx->config->enable2x2) {
3765 hdd_debug("configuring 2x2 mode fw params");
3766
Naveen Rawat247a8682017-06-05 15:00:31 -07003767 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003768 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3769 hdd_ctx->config->enable_cck_tx_fir_override,
3770 PDEV_CMD);
3771 if (ret) {
3772 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3773 ret);
3774 goto error;
3775 }
3776 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303777#define HDD_DTIM_1CHAIN_RX_ID 0x5
3778#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003779 hdd_debug("configuring 1x1 mode fw params");
3780
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003781 /*
3782 * Disable DTIM 1 chain Rx when in 1x1,
3783 * we are passing two value
3784 * as param_id << 29 | param_value.
3785 * Below param_value = 0(disable)
3786 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003787 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003788 WMI_STA_SMPS_PARAM_CMDID,
3789 HDD_DTIM_1CHAIN_RX_ID <<
3790 HDD_SMPS_PARAM_VALUE_S,
3791 VDEV_CMD);
3792 if (ret) {
3793 hdd_err("DTIM 1 chain set failed %d", ret);
3794 goto error;
3795 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303796
Naveen Rawat247a8682017-06-05 15:00:31 -07003797 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003798 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3799 hdd_ctx->config->txchainmask1x1,
3800 PDEV_CMD);
3801 if (ret) {
3802 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3803 ret);
3804 goto error;
3805 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303806
Naveen Rawat247a8682017-06-05 15:00:31 -07003807 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003808 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3809 hdd_ctx->config->rxchainmask1x1,
3810 PDEV_CMD);
3811 if (ret) {
3812 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3813 ret);
3814 goto error;
3815 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303816#undef HDD_DTIM_1CHAIN_RX_ID
3817#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003818 }
3819
Naveen Rawat247a8682017-06-05 15:00:31 -07003820 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003821 WMI_PDEV_PARAM_HYST_EN,
3822 hdd_ctx->config->enableMemDeepSleep,
3823 PDEV_CMD);
3824 if (ret) {
3825 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3826 goto error;
3827 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303828
Naveen Rawat247a8682017-06-05 15:00:31 -07003829 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003830 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3831 hdd_ctx->config->rts_profile,
3832 VDEV_CMD);
3833 if (ret) {
3834 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3835 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303836 }
3837
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003838 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3839
3840 ret = wma_cli_set_command(adapter->sessionId,
3841 GEN_VDEV_PARAM_AMSDU,
3842 hdd_ctx->config->max_amsdu_num,
3843 GEN_CMD);
3844 if (ret != 0) {
3845 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3846 goto error;
3847 }
3848
Arun Khandavalli2358d522016-05-16 18:05:37 +05303849 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303850 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003851
Arun Khandavalli2358d522016-05-16 18:05:37 +05303852 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303853
Arun Khandavalli2358d522016-05-16 18:05:37 +05303854error:
3855 return -EINVAL;
3856}
3857
Ryan Hsu07495ea2016-01-21 15:25:39 -08003858/**
3859 * hdd_open_adapter() - open and setup the hdd adatper
3860 * @hdd_ctx: global hdd context
3861 * @session_type: type of the interface to be created
3862 * @iface_name: User-visible name of the interface
3863 * @macAddr: MAC address to assign to the interface
3864 * @name_assign_type: the name of assign type of the netdev
3865 * @rtnl_held: the rtnl lock hold flag
3866 *
3867 * This function open and setup the hdd adpater according to the device
3868 * type request, assign the name, the mac address assigned, and then prepared
3869 * the hdd related parameters, queue, lock and ready to start.
3870 *
3871 * Return: the pointer of hdd adapter, otherwise NULL.
3872 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003873struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003875 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003876 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877{
Jeff Johnson9d295242017-08-29 14:39:48 -07003878 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303880 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883
3884 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3885 /*
3886 * Max limit reached on the number of vdevs configured by the
3887 * host. Return error
3888 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303889 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3890 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 return NULL;
3892 }
3893
3894 if (macAddr == NULL) {
3895 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303896 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 return NULL;
3898 }
3899 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303900 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303901 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3902 " already exists",
3903 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 return NULL;
3905 }
3906
3907 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003908 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 /* Reset locally administered bit if the device mode is STA */
3910 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3911 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003912 case QDF_P2P_CLIENT_MODE:
3913 case QDF_P2P_DEVICE_MODE:
3914 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003915 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303916 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003917 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3918 name_assign_type,
3919 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920
3921 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303922 hdd_err("failed to allocate adapter for session %d",
3923 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924 return NULL;
3925 }
3926
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003927 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003929 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303931 else if (QDF_MONITOR_MODE == session_type)
3932 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 else
3934 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3935
3936 adapter->device_mode = session_type;
3937
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 /*
3940 * Workqueue which gets scheduled in IPv4 notification
3941 * callback
3942 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3944 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945
3946#ifdef WLAN_NS_OFFLOAD
3947 /*
3948 * Workqueue which gets scheduled in IPv6
3949 * notification callback.
3950 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3952 hdd_ipv6_notifier_work_queue);
3953#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303955 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303957 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 }
3959
3960 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003961 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303963 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3964 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303965
Ravi Joshi1a292562017-05-18 16:28:54 -07003966 /* Initialize NAN Data Interface */
3967 if (QDF_NDI_MODE == session_type) {
3968 status = hdd_init_nan_data_mode(adapter);
3969 if (QDF_STATUS_SUCCESS != status)
3970 goto err_free_netdev;
3971 }
3972
3973 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003975 case QDF_P2P_GO_MODE:
3976 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003977 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3978 name_assign_type,
3979 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003981 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303982 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 return NULL;
3984 }
3985
3986 adapter->wdev.iftype =
3987 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003988 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 NL80211_IFTYPE_P2P_GO;
3990 adapter->device_mode = session_type;
3991
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003992 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303993 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3995 goto err_free_netdev;
3996 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003997 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303999 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4000 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304002 case QDF_FTM_MODE:
4003 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4004 name_assign_type,
4005 "wlan0");
4006 if (NULL == adapter) {
4007 hdd_err("Failed to allocate adapter for FTM mode");
4008 return NULL;
4009 }
4010 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4011 adapter->device_mode = session_type;
4012 status = hdd_register_interface(adapter, rtnl_held);
4013 if (QDF_STATUS_SUCCESS != status) {
4014 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4015 goto err_free_netdev;
4016 }
4017 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004018 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304019 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304020 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4021 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304022 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004024 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304025 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 return NULL;
4027 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028
hqueaa33ee2017-05-04 17:56:35 +08004029 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
4032 mutex_init(&cfgState->remain_on_chan_ctx_lock);
4033
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304034 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035 /* Add it to the hdd's session list. */
4036 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304037 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304039 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 } else {
4041 pHddAdapterNode->pAdapter = adapter;
4042 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
4043 }
4044 }
4045
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304046 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 if (NULL != adapter) {
4048 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4049 adapter = NULL;
4050 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004051 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304052 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 return NULL;
4055 }
4056
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304057 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004058 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4059 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 /* Adapter successfully added. Increment the vdev count */
4062 hdd_ctx->current_intf_count++;
4063
Jeff Johnson5880d792016-08-15 13:32:30 -07004064 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 hdd_ctx->current_intf_count);
4066
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004067 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 }
4069
Rajeev Kumardca5f812016-02-04 17:28:06 -08004070 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004071 hdd_err("Interface %s wow debug_fs init failed",
4072 netdev_name(adapter->dev));
4073
4074 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4075 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076
4077 return adapter;
4078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304081 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082
4083 return NULL;
4084}
4085
Jeff Johnson9d295242017-08-29 14:39:48 -07004086QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004087 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004088{
4089 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304090 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091
4092 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304093 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004094 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 status);
4096 return status;
4097 }
4098
4099 while (pCurrent->pAdapter != adapter) {
4100 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304101 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 break;
4103
4104 pCurrent = pNext;
4105 }
4106 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304107 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004108 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07004109 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05304110 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07004111
4112 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004113 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4114 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304117 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 adapterNode = NULL;
4119
Dustin Brown5ec6b552017-03-31 12:11:40 -07004120 /* conditionally restart the bw timer */
4121 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 /* Adapter removed. Decrement vdev count */
4124 if (hdd_ctx->current_intf_count != 0)
4125 hdd_ctx->current_intf_count--;
4126
4127 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304128 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304130
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304131 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132}
4133
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004134/**
4135 * hdd_close_all_adapters - Close all open adapters
4136 * @hdd_ctx: Hdd context
4137 * rtnl_held: True if RTNL lock held
4138 *
4139 * Close all open adapters.
4140 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304141 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004142 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004143QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144{
4145 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304146 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147
4148 ENTER();
4149
4150 do {
4151 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304152 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304153 wlan_hdd_release_intf_addr(hdd_ctx,
4154 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004156 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304157 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304158 /* Adapter removed. Decrement vdev count */
4159 if (hdd_ctx->current_intf_count != 0)
4160 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304162 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163
4164 EXIT();
4165
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304166 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004167}
4168
Jeff Johnson9d295242017-08-29 14:39:48 -07004169void wlan_hdd_reset_prob_rspies(struct hdd_adapter *pHostapdAdapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304171 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004175 case QDF_STA_MODE:
4176 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 {
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004178 struct hdd_station_ctx *pHddStaCtx =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004180 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181 break;
4182 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004183 case QDF_SAP_MODE:
4184 case QDF_P2P_GO_MODE:
4185 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004187 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 break;
4189 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004190 case QDF_FTM_MODE:
4191 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 default:
4193 /*
4194 * wlan_hdd_reset_prob_rspies should not have been called
4195 * for these kind of devices
4196 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004197 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 pHostapdAdapter->device_mode);
4199 return;
4200 }
4201
Anurag Chouhanc5548422016-02-24 18:33:27 +05304202 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4204 updateIE.ieBufferlength = 0;
4205 updateIE.pAdditionIEBuffer = NULL;
4206 updateIE.append = true;
4207 updateIE.notify = false;
4208 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4209 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304210 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004211 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 }
4213}
4214
Jeff Johnson9d295242017-08-29 14:39:48 -07004215QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004216 const bool bCloseSession)
4217{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304218 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4220 union iwreq_data wrqu;
4221 tSirUpdateIE updateIE;
4222 unsigned long rc;
Jeff Johnson37588942017-08-15 16:11:41 -07004223 struct hdd_scan_info *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224
4225 ENTER();
4226
Sachin Ahuja988fd102016-09-15 17:16:25 +05304227 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004228 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304229 wlan_hdd_netif_queue_control(adapter,
4230 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4231 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004233 case QDF_STA_MODE:
4234 case QDF_P2P_CLIENT_MODE:
4235 case QDF_IBSS_MODE:
4236 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004237 case QDF_NDI_MODE:
4238 if ((QDF_NDI_MODE == adapter->device_mode) ||
4239 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4241 hdd_is_connecting(
4242 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004243 INIT_COMPLETION(adapter->disconnect_comp_var);
4244 /*
4245 * For NDI do not use pWextState from sta_ctx, if needed
4246 * extract from ndi_ctx.
4247 */
4248 if (QDF_NDI_MODE == adapter->device_mode)
4249 qdf_ret_status = sme_roam_disconnect(
4250 hdd_ctx->hHal,
4251 adapter->sessionId,
4252 eCSR_DISCONNECT_REASON_NDI_DELETE);
4253 else if (pWextState->roamProfile.BSSType ==
4254 eCSR_BSS_TYPE_START_IBSS)
4255 qdf_ret_status = sme_roam_disconnect(
4256 hdd_ctx->hHal,
4257 adapter->sessionId,
4258 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004259 else if (QDF_STA_MODE == adapter->device_mode)
4260 qdf_ret_status =
4261 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004263 qdf_ret_status = sme_roam_disconnect(
4264 hdd_ctx->hHal,
4265 adapter->sessionId,
4266 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004267 /* success implies disconnect command got
4268 * queued up successfully
4269 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004270 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4271 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 rc = wait_for_completion_timeout(
4273 &adapter->disconnect_comp_var,
4274 msecs_to_jiffies
4275 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004276 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004277 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004279 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4280 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 memset(&wrqu, '\0', sizeof(wrqu));
4282 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4283 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4284 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4285 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304286 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004287 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304288 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004289
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304290 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304291 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292
4293#ifdef WLAN_OPEN_SOURCE
4294 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4295#endif
4296
4297 hdd_deregister_tx_flow_control(adapter);
4298
4299#ifdef WLAN_NS_OFFLOAD
4300#ifdef WLAN_OPEN_SOURCE
4301 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4302#endif
4303#endif
4304
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304305 if (adapter->device_mode == QDF_STA_MODE)
4306 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4307 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308 /*
4309 * It is possible that the caller of this function does not
4310 * wish to close the session
4311 */
Krunal Soni985b8132017-02-10 18:49:08 -08004312 if (true == bCloseSession) {
4313 if (0 != wlan_hdd_try_disconnect(adapter)) {
4314 hdd_err("Error: Can't disconnect adapter");
4315 return QDF_STATUS_E_FAILURE;
4316 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004317 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004318 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319 break;
4320
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004321 case QDF_SAP_MODE:
4322 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004324 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004325 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4326
4327 hdd_deregister_tx_flow_control(adapter);
4328
Kapil Guptac1224bf2017-06-22 21:22:40 +05304329 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 mutex_lock(&hdd_ctx->sap_lock);
4331 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304332 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304333 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334
4335 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004336 status = wlansap_stop_bss(
4337 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304339 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 hdd_hostapd_state_t *hostapd_state =
4341 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304342 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304343 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304344 qdf_status =
4345 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004346 qdf_stop_bss_event,
4347 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
Anurag Chouhance0dc992016-02-16 18:18:03 +05304349 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004350 hdd_err("failure waiting for wlansap_stop_bss %d",
4351 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352 }
4353 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004354 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355 }
4356 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004357 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4358 adapter->device_mode,
4359 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360
Anurag Chouhanc5548422016-02-24 18:33:27 +05304361 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004362 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 updateIE.smeSessionId = adapter->sessionId;
4364 updateIE.ieBufferlength = 0;
4365 updateIE.pAdditionIEBuffer = NULL;
4366 updateIE.append = false;
4367 updateIE.notify = false;
4368 /* Probe bcn reset */
4369 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4370 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304371 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004372 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373 }
4374 /* Assoc resp reset */
4375 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4376 &updateIE,
4377 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304378 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004379 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380 }
4381 /* Reset WNI_CFG_PROBE_RSP Flags */
4382 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004384 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4385 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304386 /*
4387 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4388 */
4389 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4390 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4391
Peng Xu66162de2016-02-11 17:01:20 -08004392 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004393 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004394 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004396 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004397 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004398 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004399 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 break;
4401 default:
4402 break;
4403 }
4404
4405 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304406 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407}
4408
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304409/**
4410 * hdd_deinit_all_adapters - deinit all adapters
4411 * @hdd_ctx: HDD context
4412 * @rtnl_held: True if RTNL lock held
4413 *
4414 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004415void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304416{
4417 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4418 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004419 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304420
4421 ENTER();
4422
4423 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4424
4425 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4426 adapter = adapter_node->pAdapter;
4427 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4428 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4429 adapter_node = next;
4430 }
4431
4432 EXIT();
4433}
4434
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004435QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436{
4437 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304438 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004439 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440
4441 ENTER();
4442
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304443 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004445 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4446
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304447 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 adapter = adapterNode->pAdapter;
4449 hdd_stop_adapter(hdd_ctx, adapter, true);
4450 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4451 adapterNode = pNext;
4452 }
4453
4454 EXIT();
4455
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304456 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004457}
4458
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004459QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460{
4461 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304462 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07004463 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07004464 struct hdd_station_ctx *pHddStaCtx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004465 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466
4467 ENTER();
4468
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304469 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4472
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304473 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004475 hdd_notice("Disabling queues for adapter type: %d",
4476 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304477
4478 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004479 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304480 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004481 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304482
Arun Khandavallicc544b32017-01-30 19:52:16 +05304483 if (hdd_ctx->config->sap_internal_restart &&
4484 adapter->device_mode == QDF_SAP_MODE) {
4485 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304486 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304487 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004488 if (test_bit(SOFTAP_BSS_STARTED,
4489 &adapter->event_flags)) {
4490 hdd_sap_indicate_disconnect_for_sta(adapter);
4491 hdd_cleanup_actionframe(hdd_ctx, adapter);
4492 hdd_sap_destroy_events(adapter);
4493 }
4494 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4495 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304496 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304497 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004499 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500
4501 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4502
4503 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004504 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4505 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4507 hdd_wmm_adapter_close(adapter);
4508 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4509 }
4510
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304511 hdd_clear_fils_connection_info(adapter);
Wu Gao3545e642017-07-14 19:24:41 +08004512 if (adapter->device_mode == QDF_SAP_MODE) {
4513 /*
4514 * If adapter is SAP, set session ID to invalid
4515 * since SAP session will be cleanup during SSR.
4516 */
Wu Gao36717432016-11-21 15:09:48 +08004517 wlansap_set_invalid_session(
4518 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4519
Wu Gao3545e642017-07-14 19:24:41 +08004520 wlansap_cleanup_cac_timer(
4521 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4522 }
4523
Yue Mad5b4b9f2017-05-26 16:23:40 -07004524 /* Delete peers if any for STA and P2P client modes */
4525 if (adapter->device_mode == QDF_STA_MODE ||
4526 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4527 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4528 qdf_copy_macaddr(&peerMacAddr,
4529 &pHddStaCtx->conn_info.bssId);
4530
4531 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4532 peerMacAddr.bytes);
4533 }
4534
Yue Maf9782842017-05-08 12:49:49 -07004535 /* Destroy vdev which will be recreated during reinit. */
4536 hdd_vdev_destroy(adapter);
4537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004538 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4539 adapterNode = pNext;
4540 }
4541
4542 EXIT();
4543
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304544 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545}
4546
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004547bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304548{
4549 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4550 QDF_STATUS status;
4551 bool close_modules = true;
4552
Arun Khandavalliba479c42017-07-26 21:29:40 +05304553 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4554 hdd_info("FTM mode, don't close the module");
4555 return false;
4556 }
4557
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304558 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4559 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4560 if (test_bit(DEVICE_IFACE_OPENED,
4561 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004562 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304563 close_modules = false;
4564 break;
4565 }
4566 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4567 adapter_node = next;
4568 }
4569
4570 return close_modules;
4571}
4572
Arun Khandavallifae92942016-08-01 13:31:08 +05304573/**
4574 * hdd_is_interface_up()- Checkfor interface up before ssr
4575 * @hdd_ctx: HDD context
4576 *
4577 * check if there are any wlan interfaces before SSR accordingly start
4578 * the interface.
4579 *
4580 * Return: 0 if interface was opened else false
4581 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004582static bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304583{
4584 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4585 return true;
4586 else
4587 return false;
4588}
4589
Anurag Chouhanc4092922016-09-08 15:56:11 +05304590#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004591 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304592struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4593 struct ieee80211_channel *channel,
4594 const u8 *bssid, const u8 *ssid,
4595 size_t ssid_len)
4596{
4597 return cfg80211_get_bss(wiphy, channel, bssid,
4598 ssid, ssid_len,
4599 WLAN_CAPABILITY_ESS,
4600 WLAN_CAPABILITY_ESS);
4601}
4602#else
4603struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4604 struct ieee80211_channel *channel,
4605 const u8 *bssid, const u8 *ssid,
4606 size_t ssid_len)
4607{
4608 return cfg80211_get_bss(wiphy, channel, bssid,
4609 ssid, ssid_len,
4610 IEEE80211_BSS_TYPE_ESS,
4611 IEEE80211_PRIVACY_ANY);
4612}
4613#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304614
Abhishek Singha84d3952016-09-13 13:45:05 +05304615#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304616#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4617 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4618/**
4619 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4620 * @timeout_reason: reason for connect timeout
4621 *
4622 * This function is used to convert host timeout
4623 * reason enum to kernel specific enum.
4624 *
4625 * Return: nl timeout enum
4626 */
4627static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4628 tSirResultCodes timeout_reason)
4629{
4630 switch (timeout_reason) {
4631 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4632 return NL80211_TIMEOUT_SCAN;
4633 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4634 return NL80211_TIMEOUT_AUTH;
4635 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4636 return NL80211_TIMEOUT_ASSOC;
4637 default:
4638 return NL80211_TIMEOUT_UNSPECIFIED;
4639 }
4640}
4641
4642/**
4643 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4644 * @dev: network device
4645 * @bssid: bssid to which we want to associate
4646 * @timeout_reason: reason for connect timeout
4647 *
4648 * This API is used to send connection timeout reason to supplicant
4649 *
4650 * Return: void
4651 */
4652static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4653 const u8 *bssid,
4654 tSirResultCodes timeout_reason)
4655{
4656 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004657
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304658 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4659
4660 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4661 nl_timeout_reason);
4662}
4663
4664/**
4665 * __hdd_connect_bss() - API to send connection status to supplicant
4666 * @dev: network device
4667 * @bssid: bssid to which we want to associate
4668 * @req_ie: Request Information Element
4669 * @req_ie_len: len of the req IE
4670 * @resp_ie: Response IE
4671 * @resp_ie_len: len of ht response IE
4672 * @status: status
4673 * @gfp: Kernel Flag
4674 * @timeout_reason: reason for connect timeout
4675 *
4676 * Return: void
4677 */
4678static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4679 struct cfg80211_bss *bss, const u8 *req_ie,
4680 size_t req_ie_len, const u8 *resp_ie,
4681 size_t resp_ie_len, int status, gfp_t gfp,
4682 tSirResultCodes timeout_reason)
4683{
4684 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004685
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304686 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4687
4688 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4689 resp_ie, resp_ie_len, status, gfp,
4690 nl_timeout_reason);
4691}
4692#else
4693#if defined CFG80211_CONNECT_TIMEOUT
4694static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4695 const u8 *bssid,
4696 tSirResultCodes timeout_reason)
4697{
4698 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4699}
4700#endif
4701
4702static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4703 struct cfg80211_bss *bss, const u8 *req_ie,
4704 size_t req_ie_len, const u8 *resp_ie,
4705 size_t resp_ie_len, int status, gfp_t gfp,
4706 tSirResultCodes timeout_reason)
4707{
4708 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4709 resp_ie, resp_ie_len, status, gfp);
4710}
4711#endif
4712
Abhishek Singha84d3952016-09-13 13:45:05 +05304713/**
4714 * hdd_connect_bss() - API to send connection status to supplicant
4715 * @dev: network device
4716 * @bssid: bssid to which we want to associate
4717 * @req_ie: Request Information Element
4718 * @req_ie_len: len of the req IE
4719 * @resp_ie: Response IE
4720 * @resp_ie_len: len of ht response IE
4721 * @status: status
4722 * @gfp: Kernel Flag
4723 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304724 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304725 *
4726 * The API is a wrapper to send connection status to supplicant
4727 *
4728 * Return: Void
4729 */
4730#if defined CFG80211_CONNECT_TIMEOUT
4731static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4732 struct cfg80211_bss *bss, const u8 *req_ie,
4733 size_t req_ie_len, const u8 *resp_ie,
4734 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304735 bool connect_timeout,
4736 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304737{
4738 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304739 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304740 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304741 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4742 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304743}
4744#else
4745static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4746 struct cfg80211_bss *bss, const u8 *req_ie,
4747 size_t req_ie_len, const u8 *resp_ie,
4748 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304749 bool connect_timeout,
4750 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304751{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304752 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4753 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304754}
4755#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304756
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304757#ifdef WLAN_FEATURE_FILS_SK
4758#ifdef CFG80211_CONNECT_DONE
4759#ifdef CFG80211_FILS_SK_OFFLOAD_SUPPORT
4760/**
4761 * hdd_populate_fils_params() - Populate FILS keys to connect response
4762 * @fils_params: connect response to supplicant
4763 * @fils_kek: FILS kek
4764 * @fils_kek_len: FILS kek length
4765 * @pmk: FILS PMK
4766 * @pmk_len: FILS PMK length
4767 * @pmkid: PMKID
4768 * @fils_seq_num: FILS Seq number
4769 *
4770 * Return: None
4771 */
4772static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4773 *fils_params, const uint8_t *fils_kek,
4774 size_t fils_kek_len, const uint8_t *pmk,
4775 size_t pmk_len, const uint8_t *pmkid,
4776 uint16_t fils_seq_num)
4777{
4778 /* Increament seq number to be used for next FILS */
4779 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
4780 fils_params->update_erp_next_seq_num = true;
4781 fils_params->fils_kek = fils_kek;
4782 fils_params->fils_kek_len = fils_kek_len;
4783 fils_params->pmk = pmk;
4784 fils_params->pmk_len = pmk_len;
4785 fils_params->pmkid = pmkid;
4786}
4787#else
4788static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
4789 *fils_params, const uint8_t
4790 *fils_kek, size_t fils_kek_len,
4791 const uint8_t *pmk, size_t pmk_len,
4792 const uint8_t *pmkid,
4793 uint16_t fils_seq_num)
4794{ }
4795#endif
4796
4797/**
4798 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
4799 * @dev: network device
4800 * @bssid: bssid to which we want to associate
4801 * @bss: cfg80211 bss info
4802 * @roam_info: information about connected bss
4803 * @req_ie: Request Information Element
4804 * @req_ie_len: len of the req IE
4805 * @resp_ie: Response IE
4806 * @resp_ie_len: len of ht response IE
4807 * @status: status
4808 * @gfp: allocation flags
4809 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4810 * @timeout_reason: reason for connect timeout
4811 * @roam_fils_params: FILS join response params
4812 *
4813 * This API is used as wrapper to send FILS key/sequence number
4814 * params etc. to supplicant in case of FILS connection
4815 *
4816 * Return: None
4817 */
4818static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4819 struct cfg80211_bss *bss, tCsrRoamInfo *roam_info,
4820 const u8 *req_ie, size_t req_ie_len,
4821 const u8 *resp_ie, size_t resp_ie_len, u16 status,
4822 gfp_t gfp, bool connect_timeout, tSirResultCodes
4823 timeout_reason, struct fils_join_rsp_params
4824 *roam_fils_params)
4825{
4826 struct cfg80211_connect_resp_params fils_params;
4827 qdf_mem_zero(&fils_params, sizeof(fils_params));
4828
4829 if (!roam_fils_params) {
4830 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
4831 } else {
4832 fils_params.status = status;
4833 fils_params.bssid = bssid;
4834 fils_params.timeout_reason = timeout_reason;
4835 fils_params.req_ie = req_ie;
4836 fils_params.req_ie_len = req_ie_len;
4837 fils_params.resp_ie = resp_ie;
4838 fils_params.resp_ie_len = resp_ie_len;
4839 fils_params.bss = bss;
4840 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
4841 roam_fils_params->kek_len,
4842 roam_fils_params->fils_pmk,
4843 roam_fils_params->fils_pmk_len,
4844 roam_fils_params->fils_pmkid,
4845 roam_info->fils_seq_num);
4846 }
4847 hdd_debug("FILS indicate connect status %d seq no %d",
4848 fils_params.status,
4849 fils_params.fils_erp_next_seq_num);
4850
4851 cfg80211_connect_done(dev, &fils_params, gfp);
4852
4853 /* Clear all the FILS key info */
4854 if (roam_fils_params && roam_fils_params->fils_pmk)
4855 qdf_mem_free(roam_fils_params->fils_pmk);
4856 if (roam_fils_params)
4857 qdf_mem_free(roam_fils_params);
4858 roam_info->fils_join_rsp = NULL;
4859}
4860#else
4861static inline void hdd_connect_done(struct net_device *dev, const u8 *bssid,
4862 struct cfg80211_bss *bss, tCsrRoamInfo
4863 *roam_info, const u8 *req_ie,
4864 size_t req_ie_len, const u8 *resp_ie,
4865 size_t resp_ie_len, u16 status, gfp_t gfp,
4866 bool connect_timeout, tSirResultCodes
4867 timeout_reason, struct fils_join_rsp_params
4868 *roam_fils_params)
4869{ }
4870#endif
4871#endif
4872
4873#if defined(CFG80211_CONNECT_DONE) && defined(WLAN_FEATURE_FILS_SK)
4874/**
4875 * hdd_fils_update_connect_results() - API to send fils connection status to
4876 * supplicant.
4877 * @dev: network device
4878 * @bssid: bssid to which we want to associate
4879 * @bss: cfg80211 bss info
4880 * @roam_info: information about connected bss
4881 * @req_ie: Request Information Element
4882 * @req_ie_len: len of the req IE
4883 * @resp_ie: Response IE
4884 * @resp_ie_len: len of ht response IE
4885 * @status: status
4886 * @gfp: allocation flags
4887 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
4888 * @timeout_reason: reason for connect timeout
4889 *
4890 * The API is a wrapper to send connection status to supplicant
4891 *
4892 * Return: 0 if success else failure
4893 */
4894static int hdd_fils_update_connect_results(struct net_device *dev,
4895 const u8 *bssid,
4896 struct cfg80211_bss *bss,
4897 tCsrRoamInfo *roam_info, const u8 *req_ie,
4898 size_t req_ie_len, const u8 *resp_ie,
4899 size_t resp_ie_len, u16 status, gfp_t gfp,
4900 bool connect_timeout,
4901 tSirResultCodes timeout_reason)
4902{
4903 ENTER();
4904 if (!roam_info || !roam_info->is_fils_connection)
4905 return -EINVAL;
4906
4907 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
4908 resp_ie, resp_ie_len, status, gfp, connect_timeout,
4909 timeout_reason, roam_info->fils_join_rsp);
4910 return 0;
4911}
4912#else
4913static inline int hdd_fils_update_connect_results(struct net_device *dev,
4914 const u8 *bssid,
4915 struct cfg80211_bss *bss,
4916 tCsrRoamInfo *roam_info, const u8 *req_ie,
4917 size_t req_ie_len, const u8 *resp_ie,
4918 size_t resp_ie_len, u16 status, gfp_t gfp,
4919 bool connect_timeout,
4920 tSirResultCodes timeout_reason)
4921{
4922 return -EINVAL;
4923}
4924#endif
4925
Anurag Chouhanc4092922016-09-08 15:56:11 +05304926/**
4927 * hdd_connect_result() - API to send connection status to supplicant
4928 * @dev: network device
4929 * @bssid: bssid to which we want to associate
4930 * @roam_info: information about connected bss
4931 * @req_ie: Request Information Element
4932 * @req_ie_len: len of the req IE
4933 * @resp_ie: Response IE
4934 * @resp_ie_len: len of ht response IE
4935 * @status: status
4936 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304937 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304938 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304939 *
4940 * The API is a wrapper to send connection status to supplicant
4941 * and allow runtime suspend
4942 *
4943 * Return: Void
4944 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304945void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4946 tCsrRoamInfo *roam_info, const u8 *req_ie,
4947 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304948 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304949 bool connect_timeout,
4950 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304951{
Jeff Johnson9d295242017-08-29 14:39:48 -07004952 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304953 struct cfg80211_bss *bss = NULL;
4954
4955 if (WLAN_STATUS_SUCCESS == status) {
4956 struct ieee80211_channel *chan;
4957 int freq;
4958 int chan_no = roam_info->pBssDesc->channelId;
4959
4960 if (chan_no <= 14)
4961 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004962 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304963 else
4964 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004965 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304966
4967 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4968 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4969 roam_info->u.pConnectedProfile->SSID.ssId,
4970 roam_info->u.pConnectedProfile->SSID.length);
4971 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304972
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05304973 if (hdd_fils_update_connect_results(dev, bssid, bss,
4974 roam_info, req_ie, req_ie_len, resp_ie,
4975 resp_ie_len, status, gfp, connect_timeout,
4976 timeout_reason) != 0) {
4977 hdd_connect_bss(dev, bssid, bss, req_ie,
4978 req_ie_len, resp_ie, resp_ie_len,
4979 status, gfp, connect_timeout, timeout_reason);
4980 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304981
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004982 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004983 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304984}
4985#else
4986void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4987 tCsrRoamInfo *roam_info, const u8 *req_ie,
4988 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304989 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304990 bool connect_timeout,
4991 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304992{
Jeff Johnson9d295242017-08-29 14:39:48 -07004993 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05304994
Anurag Chouhanc4092922016-09-08 15:56:11 +05304995 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4996 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08004997
4998 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004999 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305000}
5001#endif
5002
5003
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005004QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005{
5006 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305007 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005008 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305010 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011#endif
5012 eConnectionState connState;
5013
5014 ENTER();
5015
5016 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305017 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005018 adapter = adapterNode->pAdapter;
5019
Arun Khandavallifae92942016-08-01 13:31:08 +05305020 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305021 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05305022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 hdd_wmm_init(adapter);
5024
Dustin Browna7e6a5c2017-07-07 12:52:24 -07005025 adapter->scan_info.mScanPending = false;
5026
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005027 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005028 case QDF_STA_MODE:
5029 case QDF_P2P_CLIENT_MODE:
5030 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031
5032 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5033 ->conn_info.connState;
5034
5035 hdd_init_station_mode(adapter);
5036 /* Open the gates for HDD to receive Wext commands */
5037 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005039 /* Indicate disconnect event to supplicant
5040 * if associated previously
5041 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005043 eConnectionState_IbssConnected == connState ||
5044 eConnectionState_NotConnected == connState ||
5045 eConnectionState_IbssDisconnected == connState ||
5046 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049 memset(&wrqu, '\0', sizeof(wrqu));
5050 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5051 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5052 wireless_send_event(adapter->dev, SIOCGIWAP,
5053 &wrqu, NULL);
5054 adapter->sessionCtx.station.
5055 hdd_ReassocScenario = false;
5056
5057 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305058 wlan_hdd_cfg80211_indicate_disconnect(
5059 adapter->dev, false,
5060 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061 } else if (eConnectionState_Connecting == connState) {
5062 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005063 * Indicate connect failure to supplicant if we
5064 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305066 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305067 NULL, 0, NULL, 0,
5068 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005069 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070 }
5071
5072 hdd_register_tx_flow_control(adapter,
5073 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005074 hdd_tx_resume_cb,
5075 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076
5077 break;
5078
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005079 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005080 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05305081 hdd_init_ap_mode(adapter, true);
5082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 break;
5084
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005085 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005087 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5089#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005090 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 /* event supplicant to restart */
5092 cfg80211_del_sta(adapter->dev,
5093 (const u8 *)&bcastMac.bytes[0],
5094 GFP_KERNEL);
5095#endif
5096 break;
5097
5098 default:
5099 break;
5100 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005101 /*
5102 * Action frame registered in one adapter which will
5103 * applicable to all interfaces
5104 */
5105 wlan_hdd_cfg80211_register_frames(adapter);
5106
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05305107get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5109 adapterNode = pNext;
5110 }
5111
5112 EXIT();
5113
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305114 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115}
5116
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005117QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118 hdd_adapter_list_node_t **padapterNode)
5119{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305120 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005121
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005122 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305123 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
5124 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005125 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126 return status;
5127}
5128
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005129QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 hdd_adapter_list_node_t *adapterNode,
5131 hdd_adapter_list_node_t **pNextAdapterNode)
5132{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305133 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005134
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005135 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305136 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
5137 (qdf_list_node_t *) adapterNode,
5138 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005140 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005141 return status;
5142}
5143
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005144QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145 hdd_adapter_list_node_t *adapterNode)
5146{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305147 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005148
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005149 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305150 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005152 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153 return status;
5154}
5155
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005156QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 hdd_adapter_list_node_t **padapterNode)
5158{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305159 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005160
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005161 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305162 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
5163 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005164 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 return status;
5166}
5167
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005168QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005169 hdd_adapter_list_node_t *adapterNode)
5170{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305171 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005172
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005173 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305174 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
5175 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005176 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 return status;
5178}
5179
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005180QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 hdd_adapter_list_node_t *adapterNode)
5182{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305183 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005184
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005185 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05305186 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
5187 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005188 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 return status;
5190}
5191
Jeff Johnson9d295242017-08-29 14:39:48 -07005192struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 tSirMacAddr macAddr)
5194{
5195 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005196 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305197 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198
5199 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5200
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305201 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 adapter = adapterNode->pAdapter;
5203
5204 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305205 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005206 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5210 adapterNode = pNext;
5211 }
5212
5213 return NULL;
5214
5215}
5216
Jeff Johnson9d295242017-08-29 14:39:48 -07005217struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 uint32_t vdev_id)
5219{
5220 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005221 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305222 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305224 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305226 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227 adapter = adapterNode->pAdapter;
5228
5229 if (adapter->sessionId == vdev_id)
5230 return adapter;
5231
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305232 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5234 adapterNode = pNext;
5235 }
5236
Jeff Johnson5880d792016-08-15 13:32:30 -07005237 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238
5239 return NULL;
5240}
5241
Abhishek Singh7996eb72015-12-30 17:24:02 +05305242/**
5243 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5244 * the sessionid
5245 * @hdd_ctx: hdd context.
5246 * @sme_session_id: sme session is for the adapter to get.
5247 *
5248 * This function is used to get the adapter with provided session id
5249 *
5250 * Return: adapter pointer if found
5251 *
5252 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005253struct hdd_adapter *hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
Abhishek Singh7996eb72015-12-30 17:24:02 +05305254 uint32_t sme_session_id)
5255{
5256 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005257 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305258 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305259
5260
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305261 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05305262
5263 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305264 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05305265 adapter = adapter_node->pAdapter;
5266
5267 if (adapter &&
5268 adapter->sessionId == sme_session_id)
5269 return adapter;
5270
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305271 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05305272 hdd_get_next_adapter(hdd_ctx,
5273 adapter_node, &next);
5274 adapter_node = next;
5275 }
5276 return NULL;
5277}
5278
Jeff Johnson9d295242017-08-29 14:39:48 -07005279struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005280 const char *iface_name)
5281{
5282 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005283 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005284 QDF_STATUS qdf_status;
5285
5286 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5287
5288 while ((NULL != adapter_node) &&
5289 (QDF_STATUS_SUCCESS == qdf_status)) {
5290 adapter = adapter_node->pAdapter;
5291
5292 if (adapter &&
5293 !qdf_str_cmp(adapter->dev->name, iface_name))
5294 return adapter;
5295
5296 qdf_status =
5297 hdd_get_next_adapter(hdd_ctx,
5298 adapter_node, &next);
5299 adapter_node = next;
5300 }
5301 return NULL;
5302}
5303
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005304/**
5305 * hdd_get_adapter() - to get adapter matching the mode
5306 * @hdd_ctx: hdd context
5307 * @mode: adapter mode
5308 *
5309 * This routine will return the pointer to adapter matching
5310 * with the passed mode.
5311 *
5312 * Return: pointer to adapter or null
5313 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005314struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005315 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005316{
5317 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005318 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305319 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320
5321 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5322
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305323 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005324 adapter = adapterNode->pAdapter;
5325
5326 if (adapter && (mode == adapter->device_mode))
5327 return adapter;
5328
5329 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5330 adapterNode = pNext;
5331 }
5332
5333 return NULL;
5334
5335}
5336
5337/**
5338 * hdd_get_operating_channel() - return operating channel of the device mode
5339 * @hdd_ctx: Pointer to the HDD context.
5340 * @mode: Device mode for which operating channel is required.
5341 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005342 * QDF_STA_MODE,
5343 * QDF_P2P_CLIENT_MODE,
5344 * QDF_SAP_MODE,
5345 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346 *
5347 * This API returns the operating channel of the requested device mode
5348 *
5349 * Return: channel number. "0" id the requested device is not found OR it is
5350 * not connected.
5351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005352uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005353 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354{
5355 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305356 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005357 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 uint8_t operatingChannel = 0;
5359
5360 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5361
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305362 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005363 adapter = adapterNode->pAdapter;
5364
5365 if (mode == adapter->device_mode) {
5366 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005367 case QDF_STA_MODE:
5368 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 if (hdd_conn_is_connected
5370 (WLAN_HDD_GET_STATION_CTX_PTR
5371 (adapter))) {
5372 operatingChannel =
5373 (WLAN_HDD_GET_STATION_CTX_PTR
5374 (adapter))->conn_info.
5375 operationChannel;
5376 }
5377 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005378 case QDF_SAP_MODE:
5379 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380 /* softap connection info */
5381 if (test_bit
5382 (SOFTAP_BSS_STARTED,
5383 &adapter->event_flags))
5384 operatingChannel =
5385 (WLAN_HDD_GET_AP_CTX_PTR
5386 (adapter))->operatingChannel;
5387 break;
5388 default:
5389 break;
5390 }
5391
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005392 /* Found the device of interest. break the loop */
5393 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394 }
5395
5396 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5397 adapterNode = pNext;
5398 }
5399 return operatingChannel;
5400}
5401
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005402static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005403 hdd_ctx)
5404{
5405 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305406 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005407 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408
5409 ENTER();
5410
5411 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5412
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305413 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005415 if ((adapter->device_mode == QDF_STA_MODE) ||
5416 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5417 (adapter->device_mode == QDF_IBSS_MODE) ||
5418 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5419 (adapter->device_mode == QDF_SAP_MODE) ||
5420 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421 wlan_hdd_cfg80211_deregister_frames(adapter);
5422 hdd_unregister_wext(adapter->dev);
5423 }
5424 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5425 adapterNode = pNext;
5426 }
5427
5428 EXIT();
5429
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305430 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005431}
5432
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005433QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005434{
5435 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305436 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005437 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005438
5439 ENTER();
5440
5441 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5442
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305443 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005444 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005445 if ((adapter->device_mode == QDF_STA_MODE) ||
5446 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5447 (adapter->device_mode == QDF_IBSS_MODE) ||
5448 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5449 (adapter->device_mode == QDF_SAP_MODE) ||
5450 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305451 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5452 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453 }
5454 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5455 adapterNode = pNext;
5456 }
5457
5458 EXIT();
5459
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305460 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005461}
5462
Dustin Brownf27bce82016-11-03 12:52:27 -07005463/**
5464 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5465 * adapters
5466 * @hdd_ctx: The HDD context containing the adapters to operate on
5467 *
5468 * return: QDF_STATUS_SUCCESS
5469 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005470static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005471{
5472 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5473 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -07005474 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005475 int err;
5476
5477 ENTER();
5478
5479 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5480
5481 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5482 adapter = adapter_node->pAdapter;
5483 if ((adapter->device_mode == QDF_STA_MODE) ||
5484 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5485 (adapter->device_mode == QDF_IBSS_MODE) ||
5486 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5487 (adapter->device_mode == QDF_SAP_MODE) ||
5488 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5489 err = wlan_hdd_sched_scan_stop(adapter->dev);
5490 if (err)
5491 hdd_err("Unable to stop scheduled scan");
5492 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005493 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5494 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005495 adapter_node = next_node;
5496 }
5497
5498 EXIT();
5499
5500 return QDF_STATUS_SUCCESS;
5501}
5502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005503#ifdef WLAN_NS_OFFLOAD
5504/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005505 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506 * @hdd_ctx: Pointer to hdd context
5507 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005508 * Unregister for IPv6 address change notifications.
5509 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510 * Return: None
5511 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005512static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513{
5514 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005515}
5516
5517/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005518 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519 * @hdd_ctx: Pointer to hdd context
5520 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005521 * Register for IPv6 address change notifications.
5522 *
5523 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005525static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005526{
5527 int ret;
5528
5529 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5530 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005531 if (ret) {
5532 hdd_err("Failed to register IPv6 notifier: %d", ret);
5533 goto out;
5534 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005536 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005537out:
5538 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005539}
5540#else
5541/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005542 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 * @hdd_ctx: Pointer to hdd context
5544 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005545 * Unregister for IPv6 address change notifications.
5546 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005547 * Return: None
5548 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005549static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005550{
5551}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005554 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555 * @hdd_ctx: Pointer to hdd context
5556 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005557 * Register for IPv6 address change notifications.
5558 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 * Return: None
5560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005561static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005563 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005564}
5565#endif
5566
5567/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005568 * hdd_register_notifiers - Register netdev notifiers.
5569 * @hdd_ctx: HDD context
5570 *
5571 * Register netdev notifiers like IPv4 and IPv6.
5572 *
5573 * Return: 0 on success and errno on failure
5574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005575static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005576{
5577 int ret;
5578
5579 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5580 if (ret) {
5581 hdd_err("register_netdevice_notifier failed: %d", ret);
5582 goto out;
5583 }
5584
5585 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5586 if (ret)
5587 goto unregister_notifier;
5588
5589 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5590 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5591 if (ret) {
5592 hdd_err("Failed to register IPv4 notifier: %d", ret);
5593 goto unregister_ip6_notifier;
5594 }
5595
5596 return 0;
5597
5598unregister_ip6_notifier:
5599 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5600unregister_notifier:
5601 unregister_netdevice_notifier(&hdd_netdev_notifier);
5602out:
5603 return ret;
5604
5605}
5606
5607/**
5608 * hdd_unregister_notifiers - Unregister netdev notifiers.
5609 * @hdd_ctx: HDD context
5610 *
5611 * Unregister netdev notifiers like IPv4 and IPv6.
5612 *
5613 * Return: None.
5614 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005615void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005616{
5617 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5618
5619 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5620
5621 unregister_netdevice_notifier(&hdd_netdev_notifier);
5622}
5623
5624/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005625 * hdd_exit_netlink_services - Exit netlink services
5626 * @hdd_ctx: HDD context
5627 *
5628 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5629 * nl service.
5630 *
5631 * Return: None.
5632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005633static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005634{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005635 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005636 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005637 ptt_sock_deactivate_svc();
5638
5639 nl_srv_exit();
5640}
5641
5642/**
5643 * hdd_init_netlink_services- Init netlink services
5644 * @hdd_ctx: HDD context
5645 *
5646 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5647 * nl service.
5648 *
5649 * Return: 0 on success and errno on failure.
5650 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005651static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005652{
5653 int ret;
5654
Ryan Hsuceddceb2016-04-28 10:20:14 -07005655 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005656 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005657 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005658 goto out;
5659 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005660 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005661
Naveen Rawat910726a2017-03-06 11:42:51 -08005662 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005663 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005664 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005665 goto err_nl_srv;
5666 }
5667
5668 ret = ptt_sock_activate_svc();
5669 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005670 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005671 goto err_nl_srv;
5672 }
5673
5674 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005675 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005676 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005677
5678 ret = cnss_diag_activate_service();
5679 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005680 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005681 goto err_close_cesium;
5682 }
5683
5684 return 0;
5685
5686err_close_cesium:
5687 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005688 ptt_sock_deactivate_svc();
5689err_nl_srv:
5690 nl_srv_exit();
5691out:
5692 return ret;
5693}
5694
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005695/**
5696 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5697 * @hdd_ctx: HDD context.
5698 *
5699 * Destroy RX wakelock.
5700 *
5701 * Return: None.
5702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005703static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005704{
5705 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5706}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005707
5708/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005709 * hdd_rx_wake_lock_create() - Create RX wakelock
5710 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005711 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005712 * Create RX wakelock.
5713 *
5714 * Return: None.
5715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005716static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005717{
5718 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5719}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005720
5721/**
5722 * hdd_roc_context_init() - Init ROC context
5723 * @hdd_ctx: HDD context.
5724 *
5725 * Initialize ROC context.
5726 *
5727 * Return: 0 on success and errno on failure.
5728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005729static int hdd_roc_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005730{
5731 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5732 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5733
5734 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5735
5736 return 0;
5737}
5738
5739/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305740 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5741 * @hdd_ctx: HDD context.
5742 *
5743 * Free memory allocations made in ROC Req Queue nodes.
5744 *
5745 * Return: None.
5746 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005747static void hdd_destroy_roc_req_q(struct hdd_context *hdd_ctx)
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305748{
5749 hdd_roc_req_t *hdd_roc_req;
5750 QDF_STATUS status;
5751
5752 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5753
5754 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5755 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5756 (qdf_list_node_t **) &hdd_roc_req);
5757
5758 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305759 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5760 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305761 QDF_ASSERT(0);
5762 return;
5763 }
5764
5765 if (hdd_roc_req->pRemainChanCtx)
5766 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5767
5768 qdf_mem_free(hdd_roc_req);
5769 }
5770
5771 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5772}
5773
5774/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005775 * hdd_roc_context_destroy() - Destroy ROC context
5776 * @hdd_ctx: HDD context.
5777 *
5778 * Destroy roc list and flush the pending roc work.
5779 *
5780 * Return: None.
5781 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005782static void hdd_roc_context_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005783{
5784 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305785 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005786 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005787}
5788
5789/**
Houston Hoffman160db392016-10-10 17:37:51 -07005790 * hdd_context_deinit() - Deinitialize HDD context
5791 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005792 *
Houston Hoffman160db392016-10-10 17:37:51 -07005793 * Deinitialize HDD context along with all the feature specific contexts but
5794 * do not free hdd context itself. Caller of this API is supposed to free
5795 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005796 *
Houston Hoffman160db392016-10-10 17:37:51 -07005797 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005799static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005800{
Houston Hoffman160db392016-10-10 17:37:51 -07005801 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005802
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005803 hdd_roc_context_destroy(hdd_ctx);
5804
5805 hdd_sap_context_destroy(hdd_ctx);
5806
5807 hdd_rx_wake_lock_destroy(hdd_ctx);
5808
5809 hdd_tdls_context_destroy(hdd_ctx);
5810
5811 hdd_scan_context_destroy(hdd_ctx);
5812
5813 qdf_list_destroy(&hdd_ctx->hddAdapters);
5814
Houston Hoffman160db392016-10-10 17:37:51 -07005815 return 0;
5816}
5817
5818/**
5819 * hdd_context_destroy() - Destroy HDD context
5820 * @hdd_ctx: HDD context to be destroyed.
5821 *
5822 * Free config and HDD context as well as destroy all the resources.
5823 *
5824 * Return: None
5825 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005826static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07005827{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305828
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305829 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5830
Houston Hoffman160db392016-10-10 17:37:51 -07005831 hdd_context_deinit(hdd_ctx);
5832
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305833 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005834 hdd_ctx->config = NULL;
5835
5836 wiphy_free(hdd_ctx->wiphy);
5837}
5838
5839/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305840 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5841 *
5842 * This function is used to destroy bug report lock
5843 *
5844 * Return: None
5845 */
5846static void wlan_destroy_bug_report_lock(void)
5847{
5848 p_cds_contextType p_cds_context;
5849
5850 p_cds_context = cds_get_global_context();
5851 if (!p_cds_context) {
5852 hdd_err("cds context is NULL");
5853 return;
5854 }
5855
5856 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5857}
5858
5859/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005860 * hdd_wlan_exit() - HDD WLAN exit function
5861 * @hdd_ctx: Pointer to the HDD Context
5862 *
5863 * This is the driver exit point (invoked during rmmod)
5864 *
5865 * Return: None
5866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005867static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005868{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305869 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305871 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005872
5873 ENTER();
5874
Arun Khandavallifae92942016-08-01 13:31:08 +05305875 if (QDF_TIMER_STATE_RUNNING ==
5876 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005877 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305878 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005879 }
5880
Arun Khandavallifae92942016-08-01 13:31:08 +05305881 if (!QDF_IS_STATUS_SUCCESS
5882 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5883 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005884
Arun Khandavallifae92942016-08-01 13:31:08 +05305885
5886 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005887
Nitesh Shah61c10d92016-10-19 19:29:15 +05305888 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5889
Prashanth Bhattaab004382016-10-11 16:08:11 -07005890 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891
5892#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305893 if (QDF_TIMER_STATE_RUNNING ==
5894 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5895 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005896 }
5897
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305898 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305899 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005900 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005902 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5903 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5904 hdd_ctx->last_acs_channel_list = NULL;
5905 hdd_ctx->num_of_channels = 0;
5906 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005907#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908
Arun Khandavallifae92942016-08-01 13:31:08 +05305909 mutex_lock(&hdd_ctx->iface_change_lock);
5910 driver_status = hdd_ctx->driver_status;
5911 mutex_unlock(&hdd_ctx->iface_change_lock);
5912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005913 /*
5914 * Powersave Offload Case
5915 * Disable Idle Power Save Mode
5916 */
5917 hdd_set_idle_ps_config(hdd_ctx, false);
5918
Arun Khandavallifae92942016-08-01 13:31:08 +05305919 if (driver_status != DRIVER_MODULES_CLOSED) {
5920 hdd_unregister_wext_all_adapters(hdd_ctx);
5921 /*
5922 * Cancel any outstanding scan requests. We are about to close
5923 * all of our adapters, but an adapter structure is what SME
5924 * passes back to our callback function. Hence if there
5925 * are any outstanding scan requests then there is a
5926 * race condition between when the adapter is closed and
5927 * when the callback is invoked. We try to resolve that
5928 * race condition here by canceling any outstanding scans
5929 * before we close the adapters.
5930 * Note that the scans may be cancelled in an asynchronous
5931 * manner, so ideally there needs to be some kind of
5932 * synchronization. Rather than introduce a new
5933 * synchronization here, we will utilize the fact that we are
5934 * about to Request Full Power, and since that is synchronized,
5935 * the expectation is that by the time Request Full Power has
5936 * completed, all scans will be cancelled
5937 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005938 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305939 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005940 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305941 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 }
5943
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305944 wlan_destroy_bug_report_lock();
5945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305947 * Close the scheduler before calling cds_close to make sure
5948 * no thread is scheduled after the each module close is
5949 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 */
Jeff Johnson7d562272017-09-13 15:12:54 -07005951 qdf_status = cds_sched_close();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305952 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305953 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305954 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005956
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005957 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305958
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305959 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5960 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5961 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5962
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963 /*
5964 * Close CDS
5965 * This frees pMac(HAL) context. There should not be any call
5966 * that requires pMac access after this.
5967 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005969 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005970 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005972 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005973
5974 hdd_ipa_cleanup(hdd_ctx);
5975
5976 /* Free up RoC request queue and flush workqueue */
5977 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005978
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305979 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305980 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305981 /*
5982 * If there is re_init failure wiphy would have already de-registered
5983 * check the wiphy status before un-registering again
5984 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305985 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305986 wiphy_unregister(wiphy);
5987 wlan_hdd_cfg80211_deinit(wiphy);
5988 hdd_lpass_notify_stop(hdd_ctx);
5989 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005990
Arun Khandavallifae92942016-08-01 13:31:08 +05305991 hdd_exit_netlink_services(hdd_ctx);
5992 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05305993#ifdef FEATURE_WLAN_CH_AVOID
5994 mutex_destroy(&hdd_ctx->avoid_freq_lock);
5995#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05305996
5997 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5998 if (driver_status)
5999 hdd_err("Pdev delete failed");
6000
6001 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6002 if (driver_status)
6003 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006004
6005 qdf_mem_free(hdd_ctx->target_hw_name);
6006
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006007 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006008}
6009
6010void __hdd_wlan_exit(void)
6011{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006012 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013
6014 ENTER();
6015
Anurag Chouhan6d760662016-02-20 16:05:43 +05306016 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006018 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 EXIT();
6020 return;
6021 }
6022
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006023 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05306024 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08006025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 /* Do all the cleanup before deregistering the driver */
6027 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006029 EXIT();
6030}
6031
6032#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006033/**
6034 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006035 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006036 *
6037 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6038 * Then new ACS request will do a fresh scan without reusing the cached
6039 * scan information.
6040 *
6041 * Return: void
6042 */
Tang Yingying523322d2017-01-17 23:28:43 +08006043static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006045 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006046
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006047 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006049 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6050 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6051 hdd_ctx->last_acs_channel_list = NULL;
6052 hdd_ctx->num_of_channels = 0;
6053 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006054
6055 if (!hdd_ctx->hHal)
6056 return;
6057 sme_scan_flush_result(hdd_ctx->hHal);
6058}
6059#endif
6060
6061#ifdef QCA_HT_2040_COEX
6062/**
6063 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
6064 * @adapter: pointer to adapter
6065 * @staId: station id
6066 * @macAddrSTA: station MAC address
6067 * @channel_type: channel type
6068 *
6069 * This function notifies FW with HT20/HT40 mode
6070 *
6071 * Return: 0 if successful, error number otherwise
6072 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006073int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05306074 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075{
6076 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306077 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006078 struct hdd_context *hdd_ctx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079
6080 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6081
6082 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306083 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006084 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 if (!hdd_ctx->hHal)
6087 return -EINVAL;
6088
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306089 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306091 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006092 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006093 return -EINVAL;
6094 }
6095
6096 return 0;
6097}
6098#endif
6099
6100/**
6101 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6102 * @state: state
6103 *
6104 * This function notifies FW with modem power status
6105 *
6106 * Return: 0 if successful, error number otherwise
6107 */
6108int hdd_wlan_notify_modem_power_state(int state)
6109{
6110 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306111 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006112 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113
Anurag Chouhan6d760662016-02-20 16:05:43 +05306114 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306116 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119 if (!hdd_ctx->hHal)
6120 return -EINVAL;
6121
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306122 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6123 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006124 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006125 state);
6126 return -EINVAL;
6127 }
6128 return 0;
6129}
6130
6131/**
6132 *
6133 * hdd_post_cds_enable_config() - HDD post cds start config helper
6134 * @adapter - Pointer to the HDD
6135 *
6136 * Return: None
6137 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006138QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306140 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141
6142 /*
6143 * Send ready indication to the HDD. This will kick off the MAC
6144 * into a 'running' state and should kick off an initial scan.
6145 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306146 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6147 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006148 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6149 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306150 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151 }
6152
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306153 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006154}
6155
6156/* wake lock APIs for HDD */
6157void hdd_prevent_suspend(uint32_t reason)
6158{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306159 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006160}
6161
6162void hdd_allow_suspend(uint32_t reason)
6163{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306164 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165}
6166
6167void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6168{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306169 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6170 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171}
6172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006174QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006176
Amar Singhal6f8592b2017-04-26 14:31:58 -07006177 return sme_init_chan_list(hdd_ctx->hHal,
6178 hdd_ctx->reg.alpha2,
6179 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180}
6181
6182/**
6183 * hdd_is_5g_supported() - check if hardware supports 5GHz
6184 * @hdd_ctx: Pointer to the hdd context
6185 *
6186 * HDD function to know if hardware supports 5GHz
6187 *
6188 * Return: true if hardware supports 5GHz
6189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006190bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006191{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006192 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006193 return true;
6194
Amar Singhal58b45ef2017-08-01 13:43:54 -07006195 if (hdd_ctx->curr_band != eCSR_BAND_24)
zdingf54169a2016-10-12 17:08:45 +08006196 return true;
6197 else
6198 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199}
6200
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006201static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202{
6203 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006204 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006205
6206 wiphy = hdd_ctx->wiphy;
6207
6208 /*
6209 * The channel information in
6210 * wiphy needs to be initialized before wiphy registration
6211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006212 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6213 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006214 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006215 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216 }
6217
6218#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6219 wiphy->wowlan = &wowlan_support_reg_init;
6220#else
6221 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6222 WIPHY_WOWLAN_MAGIC_PKT |
6223 WIPHY_WOWLAN_DISCONNECT |
6224 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6225 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6226 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6227 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6228 WIPHY_WOWLAN_RFKILL_RELEASE;
6229
6230 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6231 WOW_MAX_FILTERS_PER_LIST);
6232 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6233 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6234#endif
6235
6236 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006237 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306238 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006239 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306240 return ret_val;
6241 }
6242
Amar Singhal5cccafe2017-02-15 12:42:58 -08006243 if (!hdd_ctx->reg_offload)
6244 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245
Amar Singhale4f28ee2015-10-21 14:36:56 -07006246 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247}
6248
Ravi Joshie2331e82015-07-01 18:18:54 -07006249/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006250 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006251 * @hdd_ctx - handle to hdd context
6252 * @tx_packets - transmit packet count
6253 * @rx_packets - receive packet count
6254 *
6255 * The function controls the bus bandwidth and dynamic control of
6256 * tcp delayed ack configuration
6257 *
6258 * Returns: None
6259 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260#ifdef MSM_PLATFORM
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006261static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006262 const uint64_t tx_packets,
6263 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006264{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006266 uint64_t temp_rx = 0;
6267 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006268 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006269 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006270 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006271 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006272 uint16_t index = 0;
6273 bool vote_level_change = false;
6274 bool rx_level_change = false;
6275 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006278 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006280 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006281 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006282 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006283 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006284 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006286 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006287 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6288 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006290 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006291 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306292 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306293 if (hdd_ctx->hbw_requested) {
6294 pld_remove_pm_qos(hdd_ctx->parent_dev);
6295 hdd_ctx->hbw_requested = false;
6296 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306297 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006298 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306299 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306300 if (!hdd_ctx->hbw_requested) {
6301 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6302 hdd_ctx->hbw_requested = true;
6303 }
6304
Nirav Shah3bbfa512016-05-12 16:43:49 +05306305 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006306 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306307 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006308 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006310
Mohit Khannaf8f96822017-05-17 17:11:59 -07006311 qdf_dp_trace_throttle_live_mode(
6312 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6313
Mohit Khannae71e2262015-11-10 09:37:24 -08006314 /* fine-tuning parameters for RX Flows */
6315 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006317 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006318
Ravi Joshifed83572016-10-07 16:20:37 -07006319 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6320 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6321 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6322 next_rx_level = WLAN_SVC_TP_HIGH;
6323 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006324 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006325 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006326 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006327 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006329 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006330 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331 next_rx_level, temp_rx);
6332 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006333 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006334 /* Send throughput indication only if it is enabled.
6335 * Disabling tcp_del_ack will revert the tcp stack behavior
6336 * to default delayed ack. Note that this will disable the
6337 * dynamic delayed ack mechanism across the system
6338 */
6339 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306340 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6341 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342 &next_rx_level,
6343 sizeof(next_rx_level));
6344 }
6345
Mohit Khannae71e2262015-11-10 09:37:24 -08006346 /* fine-tuning parameters for TX Flows */
6347 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6348 hdd_ctx->prev_tx = tx_packets;
6349 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6350 next_tx_level = WLAN_SVC_TP_HIGH;
6351 else
6352 next_tx_level = WLAN_SVC_TP_LOW;
6353
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006354 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006355 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6356 next_tx_level, temp_tx);
6357 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006358 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306359 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6360 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006361 &next_tx_level,
6362 sizeof(next_tx_level));
6363 }
6364
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006365 index = hdd_ctx->hdd_txrx_hist_idx;
6366
6367 if (vote_level_change || tx_level_change || rx_level_change) {
6368 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6369 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6370 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6371 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6372 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6373 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6374 hdd_ctx->hdd_txrx_hist_idx++;
6375 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6376 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006377}
6378
6379#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306380static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006382 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306383 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006384 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306385 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306386 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6387 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388 uint64_t total_tx = 0, total_rx = 0;
6389 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306390 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306391 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392 bool connected = false;
6393 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6394
Prashanth Bhattaab004382016-10-11 16:08:11 -07006395 if (wlan_hdd_validate_context(hdd_ctx))
6396 return;
6397
Jingxiang Gec64e1932017-08-22 14:38:59 +08006398 if (hdd_ctx->isWiphySuspended)
6399 goto restart_timer;
6400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006401 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306402 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 status =
6404 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6405
6406 if (adapterNode->pAdapter == NULL)
6407 continue;
6408 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306409 /*
6410 * Validate magic so we don't end up accessing
6411 * an invalid adapter.
6412 */
6413 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6414 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006415
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006416 if ((adapter->device_mode == QDF_STA_MODE ||
6417 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6419 != eConnectionState_Associated) {
6420
6421 continue;
6422 }
6423
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006424 if ((adapter->device_mode == QDF_SAP_MODE ||
6425 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6427
6428 continue;
6429 }
6430
6431 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6432 adapter->prev_tx_packets);
6433 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6434 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306435
6436 if (adapter->device_mode == QDF_SAP_MODE ||
6437 adapter->device_mode == QDF_P2P_GO_MODE ||
6438 adapter->device_mode == QDF_IBSS_MODE) {
6439
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006440 ret = cdp_get_intra_bss_fwd_pkts_count(
6441 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306442 adapter->sessionId,
6443 &fwd_tx_packets, &fwd_rx_packets);
6444 if (ret == A_OK) {
6445 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6446 fwd_tx_packets,
6447 adapter->prev_fwd_tx_packets);
6448 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6449 fwd_tx_packets,
6450 adapter->prev_fwd_rx_packets);
6451 }
6452 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006453
6454 total_rx += adapter->stats.rx_packets;
6455 total_tx += adapter->stats.tx_packets;
6456
6457 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6458 adapter->prev_tx_packets = adapter->stats.tx_packets;
6459 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306460 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6461 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6463 connected = true;
6464 }
6465
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306466 /* add intra bss forwarded tx and rx packets */
6467 tx_packets += fwd_tx_packets_diff;
6468 rx_packets += fwd_rx_packets_diff;
6469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6471 tx_packets += (uint64_t)ipa_tx_packets;
6472 rx_packets += (uint64_t)ipa_rx_packets;
6473
6474 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006475 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476 return;
6477 }
6478
Yuanyuan Liu13738502016-04-06 17:41:37 -07006479 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480
6481 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6482 hdd_ipa_uc_stat_request(adapter, 2);
6483
Jingxiang Gec64e1932017-08-22 14:38:59 +08006484restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006485 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006486 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006487 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306488 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006489 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006490 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006492
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306493/**
6494 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6495 * @arg: Argument of timer function
6496 *
6497 * Schedule a workqueue in this function where all the processing is done.
6498 *
6499 * Return: None.
6500 */
6501static void __hdd_bus_bw_cbk(void *arg)
6502{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006503 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306504
6505 if (wlan_hdd_validate_context(hdd_ctx))
6506 return;
6507
6508 schedule_work(&hdd_ctx->bus_bw_work);
6509}
6510
6511/**
6512 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6513 * @arg: Argument of timer function
6514 *
6515 * Return: None.
6516 */
6517static void hdd_bus_bw_cbk(void *arg)
6518{
6519 cds_ssr_protect(__func__);
6520 __hdd_bus_bw_cbk(arg);
6521 cds_ssr_unprotect(__func__);
6522}
6523
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006524int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006525{
6526 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306527 INIT_WORK(&hdd_ctx->bus_bw_work,
6528 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006529 hdd_ctx->bus_bw_timer_running = false;
6530 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306531 qdf_timer_init(NULL,
6532 &hdd_ctx->bus_bw_timer,
6533 hdd_bus_bw_cbk, (void *)hdd_ctx,
6534 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006535
6536 return 0;
6537}
6538
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006539void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006540{
Dustin Brownfce08d12017-01-17 16:29:38 -08006541 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006542 hdd_reset_tcp_delack(hdd_ctx);
6543
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006544 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306545 cancel_work_sync(&hdd_ctx->bus_bw_work);
6546 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006547 hdd_ctx->bus_bw_timer_running = false;
6548 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006549}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006550#endif
6551
6552/**
Nirav Shahed34b212016-04-25 10:59:16 +05306553 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6554 * @hdd_ctx: hdd context
6555 *
6556 * Return: 0 for success or error code
6557 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006558static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306559{
6560 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6561 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6562 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006563 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306564 return -ENOMEM;
6565 }
6566 return 0;
6567}
6568
6569/**
6570 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6571 * @hdd_ctx: hdd context
6572 *
6573 * Return: none
6574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006575void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306576{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306577 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6578 return;
6579
6580 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6581 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306582}
6583
Nirav Shahda008342016-05-17 18:50:40 +05306584static uint8_t *convert_level_to_string(uint32_t level)
6585{
6586 switch (level) {
6587 /* initialize the wlan sub system */
6588 case WLAN_SVC_TP_NONE:
6589 return "NONE";
6590 case WLAN_SVC_TP_LOW:
6591 return "LOW";
6592 case WLAN_SVC_TP_MEDIUM:
6593 return "MED";
6594 case WLAN_SVC_TP_HIGH:
6595 return "HIGH";
6596 default:
6597 return "INVAL";
6598 }
6599}
6600
Nirav Shahed34b212016-04-25 10:59:16 +05306601
6602/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006603 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6604 * @hdd_ctx: hdd context
6605 *
6606 * Return: none
6607 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006608void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006609{
6610 int i;
6611
6612#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006613 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306614 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006615 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006616 hdd_ctx->config->busBandwidthHighThreshold,
6617 hdd_ctx->config->busBandwidthMediumThreshold,
6618 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006619 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306620 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006621 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622 hdd_ctx->config->tcpDelackThresholdHigh,
6623 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006624 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306625 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626#endif
6627
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006628 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306629 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6630
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006631 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632
6633 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006634 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006635 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006636 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006637 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6638 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006639 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006640 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6641 convert_level_to_string(
6642 hdd_ctx->hdd_txrx_hist[i].
6643 next_vote_level),
6644 convert_level_to_string(
6645 hdd_ctx->hdd_txrx_hist[i].
6646 next_rx_level),
6647 convert_level_to_string(
6648 hdd_ctx->hdd_txrx_hist[i].
6649 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006651
6652 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653}
6654
6655/**
6656 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6657 * @hdd_ctx: hdd context
6658 *
6659 * Return: none
6660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006661void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006662{
6663 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306664 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6665 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666}
6667
6668/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006669 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07006670 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671 *
6672 * Return: none
6673 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006674void wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675{
6676
Jeff Johnson9d295242017-08-29 14:39:48 -07006677 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306679 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006680 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306681 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682
6683 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306684 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006685 adapter = adapter_node->pAdapter;
6686
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006687 hdd_debug("Netif queue operation statistics:");
6688 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306689 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006690 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306691 curr_time = qdf_system_ticks();
6692 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306693 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306694 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306695 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306696 unpause = adapter->total_unpause_time;
6697 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306698 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306699 pause = adapter->total_pause_time;
6700 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006701 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306702 qdf_system_ticks_to_msecs(total),
6703 qdf_system_ticks_to_msecs(pause),
6704 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006705 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706
Nirav Shahda008342016-05-17 18:50:40 +05306707 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6708 qdf_time_t pause_delta = 0;
6709
6710 if (adapter->pause_map & (1 << i))
6711 pause_delta = delta;
6712
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006713 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07006714 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006715 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716 hdd_reason_type_to_string(i),
6717 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306718 adapter->queue_oper_stats[i].unpause_count,
6719 qdf_system_ticks_to_msecs(
6720 adapter->queue_oper_stats[i].total_pause_time +
6721 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 }
6723
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006724 hdd_debug("Netif queue operation history:");
6725 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306726 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6727
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006728 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006729
6730 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006731 /* using hdd_log to avoid printing function name */
6732 if (adapter->queue_oper_history[i].time == 0)
6733 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07006734 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006735 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306736 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006737 adapter->queue_oper_history[i].time),
6738 hdd_action_type_to_string(
6739 adapter->queue_oper_history[i].netif_action),
6740 hdd_reason_type_to_string(
6741 adapter->queue_oper_history[i].netif_reason),
6742 adapter->queue_oper_history[i].pause_map);
6743 }
6744
6745 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6746 adapter_node = next;
6747 }
6748
6749
6750}
6751
6752/**
6753 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6754 * @hdd_ctx: hdd context
6755 *
6756 * Return: none
6757 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006758void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006759{
Jeff Johnson9d295242017-08-29 14:39:48 -07006760 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306762 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006763
6764 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306765 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766 adapter = adapter_node->pAdapter;
6767
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306768 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306770 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006771 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306772 adapter->history_index = 0;
6773 adapter->start_time = adapter->last_time = qdf_system_ticks();
6774 adapter->total_pause_time = 0;
6775 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6777 adapter_node = next;
6778 }
6779}
6780
6781/**
6782 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6783 * @halHandle: Hal handle
6784 * @pContext: Pointer to the context
6785 * @sessionId: Session ID
6786 * @scanId: Scan ID
6787 * @status: Status
6788 *
6789 * This is the callback to be executed when 11d scan is completed to flush out
6790 * the scan results
6791 *
6792 * 11d scan is done during driver load and is a passive scan on all
6793 * channels supported by the device, 11d scans may find some APs on
6794 * frequencies which are forbidden to be used in the regulatory domain
6795 * the device is operating in. If these APs are notified to the supplicant
6796 * it may try to connect to these APs, thus flush out all the scan results
6797 * which are present in SME after 11d scan is done.
6798 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306799 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306801static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006802 uint8_t sessionId, uint32_t scanId,
6803 eCsrScanStatus status)
6804{
6805 ENTER();
6806
6807 sme_scan_flush_result(halHandle);
6808
6809 EXIT();
6810
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306811 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006812}
6813
6814#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6815/**
6816 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6817 * @hdd_ctx: hdd global context
6818 *
6819 * Return: none
6820 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006821static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006822{
6823 uint8_t i;
6824
6825 mutex_init(&hdd_ctx->op_ctx.op_lock);
6826 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6827 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6828 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6829 }
6830}
6831#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006832static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006833{
6834}
6835#endif
6836
Yingying Tang95409972016-10-20 15:16:15 +08006837#ifdef WLAN_FEATURE_WOW_PULSE
6838/**
6839 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006840 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08006841 * @enable: enable or disable this behaviour
6842 *
6843 * Return: int
6844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006845static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006846{
6847 struct hdd_config *pcfg_ini = phddctx->config;
6848 struct wow_pulse_mode wow_pulse_set_info;
6849 QDF_STATUS status;
6850
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006851 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006852
6853 if (false == phddctx->config->wow_pulse_support)
6854 return 0;
6855
6856 /* prepare the request to send to SME */
6857 if (enable == true) {
6858 wow_pulse_set_info.wow_pulse_enable = true;
6859 wow_pulse_set_info.wow_pulse_pin =
6860 pcfg_ini->wow_pulse_pin;
6861 wow_pulse_set_info.wow_pulse_interval_low =
6862 pcfg_ini->wow_pulse_interval_low;
6863 wow_pulse_set_info.wow_pulse_interval_high =
6864 pcfg_ini->wow_pulse_interval_high;
6865 } else {
6866 wow_pulse_set_info.wow_pulse_enable = false;
6867 wow_pulse_set_info.wow_pulse_pin = 0;
6868 wow_pulse_set_info.wow_pulse_interval_low = 0;
6869 wow_pulse_set_info.wow_pulse_interval_high = 0;
6870 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006871 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006872 wow_pulse_set_info.wow_pulse_enable,
6873 wow_pulse_set_info.wow_pulse_pin,
6874 wow_pulse_set_info.wow_pulse_interval_low,
6875 wow_pulse_set_info.wow_pulse_interval_high);
6876
6877 status = sme_set_wow_pulse(&wow_pulse_set_info);
6878 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006879 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006880 return -EIO;
6881 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006882 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006883 return 0;
6884}
6885#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006886static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08006887{
6888 return 0;
6889}
6890#endif
6891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892#ifdef WLAN_FEATURE_FASTPATH
6893/**
6894 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6895 * @hdd_cfg: hdd config
6896 * @context: lower layer context
6897 *
6898 * Return: none
6899 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306900void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901 void *context)
6902{
6903 if (hdd_cfg->fastpath_enable)
6904 hif_enable_fastpath(context);
6905}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906#endif
6907
Yuanyuan Liu13738502016-04-06 17:41:37 -07006908#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909/**
6910 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006911 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912 * @level: thermal level
6913 *
6914 * Change IPA data path to SW path when the thermal throttle level greater
6915 * than 0, and restore the original data path when throttle level is 0
6916 *
6917 * Return: none
6918 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006919static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006921 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923 /* Change IPA to SW path when throttle level greater than 0 */
6924 if (level > THROTTLE_LEVEL_0)
6925 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6926 else
6927 /* restore original concurrency mode */
6928 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6929}
6930
6931/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306932 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6933 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306934 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006935 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306936 * Get a safe channel to restart SAP. PCL already takes into account the
6937 * unsafe channels. So, the PCL is validated with the ACS range to provide
6938 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006939 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306940 * Return: Channel number to restart SAP in case of success. In case of any
6941 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306943static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07006944 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306946 struct sir_pcl_list pcl;
6947 QDF_STATUS status;
6948 uint32_t i, j;
6949 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006950 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306951 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306953 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6954 if (!hdd_ctx) {
6955 hdd_err("invalid HDD context");
6956 return INVALID_CHANNEL_ID;
6957 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306959 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6960 if (!hal_handle) {
6961 hdd_err("invalid HAL handle");
6962 return INVALID_CHANNEL_ID;
6963 }
6964
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006965 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6966 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08006967 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
6968 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306969 if (QDF_IS_STATUS_ERROR(status)) {
6970 hdd_err("Get PCL failed");
6971 return INVALID_CHANNEL_ID;
6972 }
6973
Frank Liudc2cefb2017-06-21 15:38:18 +08006974 /*
6975 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
6976 * channel is unsafe channel, the pcl may be empty, instead of return,
6977 * try to choose a safe channel from acs range.
6978 */
6979 if (!pcl.pcl_len)
6980 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306981
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006982 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306983 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6984 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6985
6986 /* PCL already takes unsafe channel into account */
6987 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006988 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306989 if ((pcl.pcl_list[i] >=
6990 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6991 (pcl.pcl_list[i] <=
6992 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006993 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306994 return pcl.pcl_list[i];
6995 }
6996 }
6997
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006998 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306999
7000 /* Try for safe channel from all valid channel */
7001 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007002 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307003 &pcl.pcl_len);
7004 if (QDF_IS_STATUS_ERROR(status)) {
7005 hdd_err("error in getting valid channel list");
7006 return INVALID_CHANNEL_ID;
7007 }
7008
7009 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007010 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307011 found = false;
7012 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007013 if (pcl.pcl_list[i] ==
7014 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007015 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307016 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017 break;
7018 }
7019 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307020
7021 if (found)
7022 continue;
7023
7024 if ((pcl.pcl_list[i] >=
7025 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
7026 (pcl.pcl_list[i] <=
7027 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007028 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307029 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 }
7031 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307032
7033 return INVALID_CHANNEL_ID;
7034}
7035
7036/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007037 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307038 * @adapter: AP adapter
7039 * @channel: Channel
7040 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007041 * Moves the SAP interface by invoking the function which
7042 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307043 *
7044 * Return: None
7045 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007046void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307047{
Jeff Johnson87251032017-08-29 13:31:11 -07007048 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307049 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007050 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307051
7052 if (!adapter) {
7053 hdd_err("invalid adapter");
7054 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307056
7057 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7058
7059 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7060 if (!hal_handle) {
7061 hdd_err("invalid HAL handle");
7062 return;
7063 }
7064
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007065 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7066
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307067 hdd_ap_ctx->sapConfig.channel = channel;
7068 hdd_ap_ctx->sapConfig.ch_params.ch_width =
7069 hdd_ap_ctx->sapConfig.ch_width_orig;
7070
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007071 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307072 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
7073
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007074 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
7075 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307076 hdd_ap_ctx->sapConfig.sec_ch,
7077 &hdd_ap_ctx->sapConfig.ch_params);
7078
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007079 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
7080 adapter->sessionId, channel,
7081 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007082}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307083
Jeff Johnson9d295242017-08-29 14:39:48 -07007084int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307085{
7086 struct hdd_external_acs_timer_context *timer_context;
7087
7088 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7089
7090 if (QDF_TIMER_STATE_RUNNING ==
7091 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
7092 ap.vendor_acs_timer)) {
7093 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
7094 }
7095 timer_context = (struct hdd_external_acs_timer_context *)
7096 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
7097 timer_context->reason = reason;
Nachiket Kukadea4855692017-08-21 21:19:09 +05307098 /* Update config to application and start the timer */
Kapil Gupta8878ad92017-02-13 11:56:04 +05307099 hdd_cfg80211_update_acs_config(adapter, reason);
Nachiket Kukadea4855692017-08-21 21:19:09 +05307100 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
7101 WLAN_VENDOR_ACS_WAIT_TIME);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307102 hdd_notice("Updated ACS config to nl with reason %d", reason);
7103
7104 return 0;
7105}
7106
Agrawal Ashish467dde42016-09-08 18:44:22 +05307107/**
7108 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7109 * @hdd_ctx: hdd context pointer
7110 *
7111 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7112 * and if ACS is enabled, driver will ask userspace to restart the
7113 * sap. User space on LTE coex indication restart driver.
7114 *
7115 * Return - none
7116 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007117void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307118{
7119 QDF_STATUS status;
7120 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007121 struct hdd_adapter *adapter_temp;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307122 uint32_t i;
7123 bool found = false;
7124 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125
Agrawal Ashish467dde42016-09-08 18:44:22 +05307126 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
7127 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
7128 adapter_temp = adapter_node->pAdapter;
7129
7130 if (!adapter_temp) {
7131 hdd_err("adapter is NULL, moving to next one");
7132 goto next_adapater;
7133 }
7134
7135 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7136 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007137 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307138 adapter_temp->device_mode,
7139 adapter_temp->sessionCtx.ap.sapConfig.
7140 acs_cfg.acs_mode);
7141 goto next_adapater;
7142 }
7143
7144 found = false;
7145 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007146 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307147 hdd_ctxt->unsafe_channel_list[i]) {
7148 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007149 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307150 adapter_temp->sessionCtx.ap.operatingChannel);
7151 break;
7152 }
7153 }
7154
7155 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007156 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307157 adapter_temp->sessionCtx.ap.operatingChannel);
7158 goto next_adapater;
7159 }
7160
Kapil Gupta8878ad92017-02-13 11:56:04 +05307161 if (hdd_ctxt->config->vendor_acs_support &&
7162 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7163 hdd_update_acs_timer_reason(adapter_temp,
7164 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7165 goto next_adapater;
7166 } else
7167 restart_chan =
7168 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307169 adapter_temp);
7170 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007171 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307172 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007173 /*
7174 * SAP restart due to unsafe channel. While
7175 * restarting the SAP, make sure to clear
7176 * acs_channel, channel to reset to
7177 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307178 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007179 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307180 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7181 adapter_temp->sessionCtx.ap.sapConfig.channel =
7182 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007183 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307184 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7185 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007186 hdd_debug("driver to start sap: %d",
7187 hdd_ctxt->config->sap_internal_restart);
7188 if (hdd_ctxt->config->sap_internal_restart)
7189 hdd_switch_sap_channel(adapter_temp, restart_chan);
7190 else
7191 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307192 }
7193
7194next_adapater:
7195 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7196 adapter_node = next;
7197 }
7198}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307199
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007201 * hdd_init_channel_avoidance() - Initialize channel avoidance
7202 * @hdd_ctx: HDD global context
7203 *
7204 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007205 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007206 * down to the lower layers. Then subscribe to subsequent channel
7207 * avoidance events.
7208 *
7209 * Return: None
7210 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007211static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007212{
7213 uint16_t unsafe_channel_count;
7214 int index;
7215
Yuanyuan Liu13738502016-04-06 17:41:37 -07007216 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7217 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007218 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007219 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007221 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007222 hdd_ctx->unsafe_channel_count);
7223
Anurag Chouhan6d760662016-02-20 16:05:43 +05307224 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007225 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007226
7227 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007228 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229 hdd_ctx->unsafe_channel_list[index]);
7230
7231 }
7232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007233}
Dustin Brown676a2322017-08-15 13:16:13 -07007234
Jeff Johnson9d295242017-08-29 14:39:48 -07007235static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007236 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007237{
7238 uint8_t restart_chan;
7239
7240 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7241 if (!restart_chan) {
7242 hdd_alert("fail to restart SAP");
7243 return;
7244 }
7245
7246 /* SAP restart due to unsafe channel. While restarting
7247 * the SAP, make sure to clear acs_channel, channel to
7248 * reset to 0. Otherwise these settings will override
7249 * the ACS while restart.
7250 */
7251 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7252 adapter->sessionCtx.ap.sapConfig.channel = AUTO_CHANNEL_SELECT;
7253
7254 hdd_debug("sending coex indication");
7255
7256 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7257 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7258 hdd_switch_sap_channel(adapter, restart_chan);
7259}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007260
7261int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7262 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7263{
7264 uint32_t size;
7265 uint16_t *unsafe_list;
7266 uint16_t chan_count;
7267
7268 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7269 return -EINVAL;
7270
7271 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7272 NUM_CHANNELS);
7273 if (chan_count) {
7274 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7275 unsafe_list = qdf_mem_malloc(size);
7276 if (!unsafe_list) {
7277 hdd_err("No memory for unsafe chan list size%d",
7278 size);
7279 return -ENOMEM;
7280 }
7281 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7282 } else {
7283 unsafe_list = NULL;
7284 }
7285
7286 *local_unsafe_list = unsafe_list;
7287 *local_unsafe_list_count = chan_count;
7288
7289 return 0;
7290}
7291
7292bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7293 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7294{
7295 int i, j;
7296
7297 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7298 return true;
7299 if (local_unsafe_list_count == 0)
7300 return false;
7301 for (i = 0; i < local_unsafe_list_count; i++) {
7302 for (j = 0; j < local_unsafe_list_count; j++)
7303 if (local_unsafe_list[i] ==
7304 hdd_ctx->unsafe_channel_list[j])
7305 break;
7306 if (j >= local_unsafe_list_count)
7307 break;
7308 }
7309 if (i >= local_unsafe_list_count) {
7310 hdd_info("unsafe chan list same");
7311 return false;
7312 }
7313
7314 return true;
7315}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007316#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007317static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007318{
7319}
Dustin Brown676a2322017-08-15 13:16:13 -07007320
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007321static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007322{
7323}
Dustin Brown676a2322017-08-15 13:16:13 -07007324
Jeff Johnson9d295242017-08-29 14:39:48 -07007325static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007326 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007327{
7328 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7329}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007330#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331
7332/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007333 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7334 * user space
7335 * @frame_ind: Management frame data to be informed.
7336 *
7337 * This function is used to indicate management frame to
7338 * user space
7339 *
7340 * Return: None
7341 *
7342 */
7343void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7344{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007345 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007346 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007347 int i;
7348
Rajeev Kumard004abc2016-02-17 12:09:56 -08007349 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007350 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007351
7352 if (0 != wlan_hdd_validate_context(hdd_ctx))
7353 return;
7354
7355 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7356 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7357 adapter =
7358 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7359 if (adapter)
7360 break;
7361 }
7362 } else {
7363 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7364 frame_ind->sessionId);
7365 }
7366
7367 if ((NULL != adapter) &&
7368 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7369 __hdd_indicate_mgmt_frame(adapter,
7370 frame_ind->frame_len,
7371 frame_ind->frameBuf,
7372 frame_ind->frameType,
7373 frame_ind->rxChan,
7374 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007375}
7376
Kapil Gupta8878ad92017-02-13 11:56:04 +05307377void hdd_acs_response_timeout_handler(void *context)
7378{
7379 struct hdd_external_acs_timer_context *timer_context =
7380 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007381 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007382 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307383 uint8_t reason;
7384
7385 ENTER();
7386 if (!timer_context) {
7387 hdd_err("invlaid timer context");
7388 return;
7389 }
7390 adapter = timer_context->adapter;
7391 reason = timer_context->reason;
7392
7393
7394 if ((!adapter) ||
7395 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7396 hdd_err("invalid adapter or adapter has invalid magic");
7397 return;
7398 }
7399 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7400 if (wlan_hdd_validate_context(hdd_ctx))
7401 return;
7402
7403 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7404 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7405 else
7406 return;
7407
7408 hdd_err("ACS timeout happened for %s reason %d",
7409 adapter->dev->name, reason);
7410 switch (reason) {
7411 /* SAP init case */
7412 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7413 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7414 false);
7415 wlan_hdd_cfg80211_start_acs(adapter);
7416 break;
7417 /* DFS detected on current channel */
7418 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7419 wlan_sap_update_next_channel(
7420 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7421 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7422 adapter->sessionId);
7423 break;
7424 /* LTE coex event on current channel */
7425 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7426 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7427 break;
7428 default:
7429 hdd_info("invalid reason for timer invoke");
7430
7431 }
7432}
7433
Rajeev Kumard004abc2016-02-17 12:09:56 -08007434/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7436 * @hdd_ctx: HDD context
7437 *
7438 * Disables all the dual mac features like DBS, Agile DFS etc.
7439 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307440 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007442static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007444 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307445 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007446
7447 if (!hdd_ctx) {
7448 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307449 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007450 }
7451
7452 cfg.scan_config = 0;
7453 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007454 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007455
7456 hdd_debug("Disabling all dual mac features...");
7457
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007458 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307459 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7461 return status;
7462 }
7463
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307464 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007465}
7466
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007467static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007468wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007469{
7470 struct policy_mgr_dual_mac_config cfg = {0};
7471 QDF_STATUS status;
7472
7473 if (!hdd_ctx) {
7474 hdd_err("HDD context is NULL");
7475 return QDF_STATUS_E_FAILURE;
7476 }
7477
7478 cfg.scan_config = 0;
7479 cfg.fw_mode_config = 0;
7480 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7481 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7482 hdd_ctx->hdd_psoc, &cfg.scan_config,
7483 &cfg.fw_mode_config,
7484 hdd_ctx->config->dual_mac_feature_disable);
7485
7486 if (status != QDF_STATUS_SUCCESS) {
7487 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7488 status);
7489 return status;
7490 }
7491
7492 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7493 cfg.scan_config, cfg.fw_mode_config);
7494
7495 status = sme_soc_set_dual_mac_config(cfg);
7496 if (status != QDF_STATUS_SUCCESS) {
7497 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7498 return status;
7499 }
7500
7501 return QDF_STATUS_SUCCESS;
7502}
7503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007504/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007505 * hdd_override_ini_config - Override INI config
7506 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007507 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007508 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007509 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007510 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007512static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007513{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007514
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007515 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7516 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007517 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007518 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007519 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007520 if (0 == enable_11d || 1 == enable_11d) {
7521 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007522 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007523 }
Leo Chang11545d62016-10-17 14:53:50 -07007524
7525 if (!hdd_ipa_is_present(hdd_ctx))
7526 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007527}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007528
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007529/**
7530 * hdd_set_trace_level_for_each - Set trace level for each INI config
7531 * @hdd_ctx - HDD context
7532 *
7533 * Set trace level for each module based on INI config.
7534 *
7535 * Return: None
7536 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007537static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007538{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307539 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7540 hdd_ctx->config->qdf_trace_enable_wdi);
7541 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7542 hdd_ctx->config->qdf_trace_enable_hdd);
7543 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7544 hdd_ctx->config->qdf_trace_enable_sme);
7545 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7546 hdd_ctx->config->qdf_trace_enable_pe);
7547 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7548 hdd_ctx->config->qdf_trace_enable_wma);
7549 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7550 hdd_ctx->config->qdf_trace_enable_sys);
7551 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7552 hdd_ctx->config->qdf_trace_enable_qdf);
7553 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7554 hdd_ctx->config->qdf_trace_enable_sap);
7555 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7556 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7557 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7558 hdd_ctx->config->qdf_trace_enable_bmi);
7559 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7560 hdd_ctx->config->qdf_trace_enable_cfg);
7561 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7562 hdd_ctx->config->qdf_trace_enable_epping);
7563 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7564 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7565 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007566 hdd_ctx->config->qdf_trace_enable_txrx);
7567 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7568 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307569 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7570 hdd_ctx->config->qdf_trace_enable_htc);
7571 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7572 hdd_ctx->config->qdf_trace_enable_hif);
7573 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7574 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7575 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7576 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007577 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7578 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007579 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7580 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007581 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7582 hdd_ctx->config->qdf_trace_enable_regulatory);
7583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007584 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007585}
7586
7587/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007588 * hdd_context_init() - Initialize HDD context
7589 * @hdd_ctx: HDD context.
7590 *
7591 * Initialize HDD context along with all the feature specific contexts.
7592 *
7593 * return: 0 on success and errno on failure.
7594 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007595static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007596{
7597 int ret;
7598
7599 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7600 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7601
7602 hdd_init_ll_stats_ctx();
7603
7604 init_completion(&hdd_ctx->mc_sus_event_var);
7605 init_completion(&hdd_ctx->ready_to_suspend);
7606
7607 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307608 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007609 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307610
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007611 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7612
7613 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7614
7615 ret = hdd_scan_context_init(hdd_ctx);
7616 if (ret)
7617 goto list_destroy;
7618
Nitesh Shahd1266d72017-01-25 22:07:07 +05307619 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007620
7621 hdd_rx_wake_lock_create(hdd_ctx);
7622
7623 ret = hdd_sap_context_init(hdd_ctx);
7624 if (ret)
7625 goto scan_destroy;
7626
7627 ret = hdd_roc_context_init(hdd_ctx);
7628 if (ret)
7629 goto sap_destroy;
7630
7631 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7632
7633 hdd_init_offloaded_packets_ctx(hdd_ctx);
7634
7635 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7636 hdd_ctx->config);
7637 if (ret)
7638 goto roc_destroy;
7639
7640 return 0;
7641
7642roc_destroy:
7643 hdd_roc_context_destroy(hdd_ctx);
7644
7645sap_destroy:
7646 hdd_sap_context_destroy(hdd_ctx);
7647
7648scan_destroy:
7649 hdd_scan_context_destroy(hdd_ctx);
7650 hdd_rx_wake_lock_destroy(hdd_ctx);
7651 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007652list_destroy:
7653 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007654
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007655 return ret;
7656}
7657
7658/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307659 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
7660 * @hdd_ctx: pointer to hdd context
7661 *
7662 * Return: status of initialization
7663 * 0 - success
7664 * negative value - failure
7665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007666static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307667{
7668 int ret;
7669
7670 if (!hdd_ctx->config->probe_req_ie_whitelist)
7671 return 0;
7672
7673 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
7674 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
7675 hdd_ctx->config->probe_req_ie_whitelist = false;
7676 return -EINVAL;
7677 }
7678
7679 /* parse ini string probe req oui */
7680 ret = hdd_parse_probe_req_ouis(hdd_ctx);
7681 if (ret) {
7682 hdd_err("parsing error: disable ie whitelisting");
7683 hdd_ctx->config->probe_req_ie_whitelist = false;
7684 }
7685
7686 return ret;
7687}
7688
7689/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007690 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307691 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007692 *
7693 * Allocate and initialize HDD context. HDD context is allocated as part of
7694 * wiphy allocation and then context is initialized.
7695 *
7696 * Return: HDD context on success and ERR_PTR on failure
7697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007698static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007699{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307700 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007701 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007702 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007703 v_CONTEXT_t p_cds_context;
7704
7705 ENTER();
7706
7707 p_cds_context = cds_get_global_context();
7708 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007709 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007710 ret = -EINVAL;
7711 goto err_out;
7712 }
7713
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007714 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007715
7716 if (hdd_ctx == NULL) {
7717 ret = -ENOMEM;
7718 goto err_out;
7719 }
7720
7721 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007722 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307723 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007724
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307725 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007726 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007727 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007728 ret = -ENOMEM;
7729 goto err_free_hdd_context;
7730 }
7731
7732 /* Read and parse the qcom_cfg.ini file */
7733 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307734 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307735 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007736 WLAN_INI_FILE);
7737 ret = -EINVAL;
7738 goto err_free_config;
7739 }
7740
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05307741 ie_whitelist_attrs_init(hdd_ctx);
7742
Dustin Brown7f939932017-05-18 15:02:17 -07007743 hdd_debug("setting timer multiplier: %u",
7744 hdd_ctx->config->timer_multiplier);
7745 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7746
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007747
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307748 if (hdd_ctx->config->fhostNSOffload)
7749 hdd_ctx->ns_offload_enable = true;
7750
Abhishek Singh5ea86532016-04-27 14:10:53 +05307751 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7752
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007753 hdd_override_ini_config(hdd_ctx);
7754
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007755 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007756
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007757 ret = hdd_context_init(hdd_ctx);
7758
7759 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007760 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007761
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007762 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307763 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007764
Anurag Chouhan6d760662016-02-20 16:05:43 +05307765 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007766 goto skip_multicast_logging;
7767
7768 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7769
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007770 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7771 if (ret)
7772 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307773
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007774 ret = hdd_init_netlink_services(hdd_ctx);
7775 if (ret)
7776 goto err_deinit_txrx_histogram;
7777
Dustin Brown7b3dea22017-07-10 13:02:47 -07007778 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
7779 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05307780
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007781skip_multicast_logging:
7782 hdd_set_trace_level_for_each(hdd_ctx);
7783
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07007784 EXIT();
7785
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007786 return hdd_ctx;
7787
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07007788err_deinit_txrx_histogram:
7789 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7790
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007791err_deinit_hdd_context:
7792 hdd_context_deinit(hdd_ctx);
7793
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007794err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307795 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007796
7797err_free_hdd_context:
7798 wiphy_free(hdd_ctx->wiphy);
7799
7800err_out:
7801 return ERR_PTR(ret);
7802}
7803
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007804#ifdef WLAN_OPEN_P2P_INTERFACE
7805/**
7806 * hdd_open_p2p_interface - Open P2P interface
7807 * @hdd_ctx: HDD context
7808 * @rtnl_held: True if RTNL lock held
7809 *
7810 * Open P2P interface during probe. This function called to open the P2P
7811 * interface at probe along with STA interface.
7812 *
7813 * Return: 0 on success and errno on failure
7814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007815static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007816{
Jeff Johnson9d295242017-08-29 14:39:48 -07007817 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007818 uint8_t *p2p_dev_addr;
7819
7820 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7821 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307822 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007823 hdd_ctx->config->intfMacAddr[0].bytes,
7824 sizeof(tSirMacAddr));
7825
7826 /*
7827 * Generate the P2P Device Address. This consists of
7828 * the device's primary MAC address with the locally
7829 * administered bit set.
7830 */
7831 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7832 } else {
7833 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7834 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007835 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007836 return -ENOSPC;
7837 }
7838
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307839 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307840 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007841 }
7842
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007843 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007844 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007845 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007846
7847 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007848 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007849 return -ENOSPC;
7850 }
7851
7852 return 0;
7853}
7854#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007855static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007856 bool rtnl_held)
7857{
7858 return 0;
7859}
7860#endif
7861
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007862static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08007863{
Jeff Johnson9d295242017-08-29 14:39:48 -07007864 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08007865 int ret = 0;
7866
7867 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7868 wlan_hdd_get_intf_addr(hdd_ctx),
7869 NET_NAME_UNKNOWN, rtnl_held);
7870 if (adapter == NULL) {
7871 hdd_err("Failed to open 802.11p interface");
7872 ret = -ENOSPC;
7873 }
7874
7875 return ret;
7876}
7877
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007878/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307879 * hdd_start_station_adapter()- Start the Station Adapter
7880 * @adapter: HDD adapter
7881 *
7882 * This function initializes the adapter for the station mode.
7883 *
7884 * Return: 0 on success or errno on failure.
7885 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007886int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307887{
7888 QDF_STATUS status;
7889
7890 ENTER_DEV(adapter->dev);
7891
7892 status = hdd_init_station_mode(adapter);
7893
7894 if (QDF_STATUS_SUCCESS != status) {
7895 hdd_err("Error Initializing station mode: %d", status);
7896 return qdf_status_to_os_return(status);
7897 }
7898
Arun Khandavallifae92942016-08-01 13:31:08 +05307899 hdd_register_tx_flow_control(adapter,
7900 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007901 hdd_tx_resume_cb,
7902 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307903
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307904 EXIT();
7905 return 0;
7906}
7907
7908/**
7909 * hdd_start_ap_adapter()- Start AP Adapter
7910 * @adapter: HDD adapter
7911 *
7912 * This function initializes the adapter for the AP mode.
7913 *
7914 * Return: 0 on success errno on failure.
7915 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007916int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307917{
7918 QDF_STATUS status;
7919
7920 ENTER();
7921
Arun Khandavallicc544b32017-01-30 19:52:16 +05307922 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307923
7924 if (QDF_STATUS_SUCCESS != status) {
7925 hdd_err("Error Initializing the AP mode: %d", status);
7926 return qdf_status_to_os_return(status);
7927 }
7928
Arun Khandavallifae92942016-08-01 13:31:08 +05307929 hdd_register_tx_flow_control(adapter,
7930 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08007931 hdd_softap_tx_resume_cb,
7932 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05307933
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307934 EXIT();
7935 return 0;
7936}
7937
7938/**
7939 * hdd_start_ftm_adapter()- Start FTM adapter
7940 * @adapter: HDD adapter
7941 *
7942 * This function initializes the adapter for the FTM mode.
7943 *
7944 * Return: 0 on success or errno on failure.
7945 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007946int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307947{
7948 QDF_STATUS qdf_status;
7949
7950 ENTER_DEV(adapter->dev);
7951
7952 qdf_status = hdd_init_tx_rx(adapter);
7953
7954 if (QDF_STATUS_SUCCESS != qdf_status) {
7955 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7956 return qdf_status_to_os_return(qdf_status);
7957 }
7958
7959 return 0;
7960 EXIT();
7961}
7962
7963/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007964 * hdd_open_interfaces - Open all required interfaces
7965 * hdd_ctx: HDD context
7966 * rtnl_held: True if RTNL lock is held
7967 *
7968 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7969 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007970 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007971 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007972static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007973{
Jeff Johnson9d295242017-08-29 14:39:48 -07007974 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007975 int ret;
7976
Jeff Johnson957bc272017-02-02 08:54:48 -08007977 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307978 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007979 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007980
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007981 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007982 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007983 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007984
7985 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007986 return -ENOSPC;
7987
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007988 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7989 adapter->fast_roaming_allowed = true;
7990
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007991 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7992 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007993 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007994
7995 /* Open 802.11p Interface */
7996 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007997 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7998 if (ret)
7999 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008000 }
8001
Jeff Johnson957bc272017-02-02 08:54:48 -08008002 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008003
Jeff Johnson957bc272017-02-02 08:54:48 -08008004err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008005 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008006 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008007}
8008
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008009/**
8010 * hdd_update_country_code - Update country code
8011 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008012 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008013 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008014 *
8015 * Return: 0 on success and errno on failure
8016 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008017static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008018{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008019 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008020 return 0;
8021
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008022 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008023}
8024
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308025#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8026/**
8027 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8028 * @cds_cfg: CDS Configuration
8029 * @hdd_ctx: Pointer to hdd context
8030 *
8031 * Return: none
8032 */
8033static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8034 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008035 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308036{
8037 cds_cfg->tx_flow_stop_queue_th =
8038 hdd_ctx->config->TxFlowStopQueueThreshold;
8039 cds_cfg->tx_flow_start_queue_offset =
8040 hdd_ctx->config->TxFlowStartQueueOffset;
8041}
8042#else
8043static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8044 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008045 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308046{
8047}
8048#endif
8049
8050#ifdef FEATURE_WLAN_RA_FILTERING
8051/**
8052 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8053 * @cds_cfg: CDS Configuration
8054 * @hdd_ctx: Pointer to hdd context
8055 *
8056 * Return: none
8057 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308058static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008059 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308060{
8061 cds_cfg->ra_ratelimit_interval =
8062 hdd_ctx->config->RArateLimitInterval;
8063 cds_cfg->is_ra_ratelimit_enabled =
8064 hdd_ctx->config->IsRArateLimitEnabled;
8065}
8066#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308067static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008068 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308069{
8070}
8071#endif
8072
8073/**
8074 * hdd_update_cds_config() - API to update cds configuration parameters
8075 * @hdd_ctx: HDD Context
8076 *
8077 * Return: 0 for Success, errno on failure
8078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008079static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308080{
8081 struct cds_config_info *cds_cfg;
8082
8083 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8084 if (!cds_cfg) {
8085 hdd_err("failed to allocate cds config");
8086 return -ENOMEM;
8087 }
8088
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008089 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008090 if (!hdd_ctx->config->nMaxPsPoll ||
8091 !hdd_ctx->config->enablePowersaveOffload) {
8092 cds_cfg->powersave_offload_enabled =
8093 hdd_ctx->config->enablePowersaveOffload;
8094 } else {
8095 if ((hdd_ctx->config->enablePowersaveOffload ==
8096 PS_QPOWER_NODEEPSLEEP) ||
8097 (hdd_ctx->config->enablePowersaveOffload ==
8098 PS_LEGACY_NODEEPSLEEP))
8099 cds_cfg->powersave_offload_enabled =
8100 PS_LEGACY_NODEEPSLEEP;
8101 else
8102 cds_cfg->powersave_offload_enabled =
8103 PS_LEGACY_DEEPSLEEP;
8104 hdd_info("Qpower disabled in cds config, %d",
8105 cds_cfg->powersave_offload_enabled);
8106 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308107 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8108 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8109 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8110 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8111 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8112
8113 /* Here ol_ini_info is used to store ini status of arp offload
8114 * ns offload and others. Currently 1st bit is used for arp
8115 * off load and 2nd bit for ns offload currently, rest bits are unused
8116 */
8117 if (hdd_ctx->config->fhostArpOffload)
8118 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8119 if (hdd_ctx->config->fhostNSOffload)
8120 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8121
8122 /*
8123 * Copy the DFS Phyerr Filtering Offload status.
8124 * This parameter reflects the value of the
8125 * dfs_phyerr_filter_offload flag as set in the ini.
8126 */
8127 cds_cfg->dfs_phyerr_filter_offload =
8128 hdd_ctx->config->fDfsPhyerrFilterOffload;
8129 if (hdd_ctx->config->ssdp)
8130 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8131
8132 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8133 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8134
8135 cds_cfg->ap_maxoffload_reorderbuffs =
8136 hdd_ctx->config->apMaxOffloadReorderBuffs;
8137
8138 cds_cfg->ap_disable_intrabss_fwd =
8139 hdd_ctx->config->apDisableIntraBssFwd;
8140
8141 cds_cfg->dfs_pri_multiplier =
8142 hdd_ctx->config->dfsRadarPriMultiplier;
8143 cds_cfg->reorder_offload =
8144 hdd_ctx->config->reorderOffloadSupport;
8145
8146 /* IPA micro controller data path offload resource config item */
8147 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008148 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8149 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008150 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008151 hdd_ctx->config->IpaUcTxBufCount);
8152 hdd_ctx->config->IpaUcTxBufCount =
8153 rounddown_pow_of_two(
8154 hdd_ctx->config->IpaUcTxBufCount);
8155 if (!hdd_ctx->config->IpaUcTxBufCount) {
8156 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308157 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008158 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008159 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008160 hdd_ctx->config->IpaUcTxBufCount);
8161 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308162 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8163 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008164 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8165 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008166 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008167 hdd_ctx->config->IpaUcRxIndRingCount);
8168 hdd_ctx->config->IpaUcRxIndRingCount =
8169 rounddown_pow_of_two(
8170 hdd_ctx->config->IpaUcRxIndRingCount);
8171 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8172 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308173 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008174 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008175 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008176 hdd_ctx->config->IpaUcRxIndRingCount);
8177 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308178 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008179 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308180 cds_cfg->uc_tx_partition_base =
8181 hdd_ctx->config->IpaUcTxPartitionBase;
8182 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8183
8184 cds_cfg->ip_tcp_udp_checksum_offload =
8185 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308186 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308187 cds_cfg->ce_classify_enabled =
8188 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008189 cds_cfg->bpf_packet_filter_enable =
8190 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308191 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8192 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8193 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008194 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008195 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008196 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008197 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308198 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8199 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308200 cds_cfg->auto_power_save_fail_mode =
8201 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308202
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308203 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8204
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308205 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8206 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8207 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008208 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308209 cds_init_ini_config(cds_cfg);
8210 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308211
8212exit:
8213 qdf_mem_free(cds_cfg);
8214 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308215}
8216
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008217/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008218 * hdd_update_user_config() - API to update user configuration
8219 * parameters to obj mgr which are used by multiple components
8220 * @hdd_ctx: HDD Context
8221 *
8222 * Return: 0 for Success, errno on failure
8223 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008224static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008225{
8226 struct wlan_objmgr_psoc_user_config *user_config;
8227
8228 user_config = qdf_mem_malloc(sizeof(*user_config));
8229 if (user_config == NULL) {
8230 hdd_alert("Failed to alloc memory for user_config!");
8231 return -ENOMEM;
8232 }
8233
8234 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8235 user_config->dual_mac_feature_disable =
8236 hdd_ctx->config->dual_mac_feature_disable;
8237 user_config->indoor_channel_support =
8238 hdd_ctx->config->indoor_channel_support;
8239 user_config->is_11d_support_enabled =
8240 hdd_ctx->config->Is11dSupportEnabled;
8241 user_config->is_11h_support_enabled =
8242 hdd_ctx->config->Is11hSupportEnabled;
8243 user_config->optimize_chan_avoid_event =
8244 hdd_ctx->config->goptimize_chan_avoid_event;
8245 user_config->skip_dfs_chnl_in_p2p_search =
8246 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008247 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008248 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8249
8250 qdf_mem_free(user_config);
8251 return 0;
8252}
8253
8254/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008255 * hdd_init_thermal_info - Initialize thermal level
8256 * @hdd_ctx: HDD context
8257 *
8258 * Initialize thermal level at SME layer and set the thermal level callback
8259 * which would be called when a configured thermal threshold is hit.
8260 *
8261 * Return: 0 on success and errno on failure
8262 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008263static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008264{
8265 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308266 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008267
8268 thermal_param.smeThermalMgmtEnabled =
8269 hdd_ctx->config->thermalMitigationEnable;
8270 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8271
Poddar, Siddarth83905022016-04-16 17:56:08 -07008272 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8273 hdd_ctx->config->throttle_dutycycle_level0;
8274 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8275 hdd_ctx->config->throttle_dutycycle_level1;
8276 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8277 hdd_ctx->config->throttle_dutycycle_level2;
8278 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8279 hdd_ctx->config->throttle_dutycycle_level3;
8280
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008281 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8282 hdd_ctx->config->thermalTempMinLevel0;
8283 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8284 hdd_ctx->config->thermalTempMaxLevel0;
8285 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8286 hdd_ctx->config->thermalTempMinLevel1;
8287 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8288 hdd_ctx->config->thermalTempMaxLevel1;
8289 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8290 hdd_ctx->config->thermalTempMinLevel2;
8291 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8292 hdd_ctx->config->thermalTempMaxLevel2;
8293 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8294 hdd_ctx->config->thermalTempMinLevel3;
8295 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8296 hdd_ctx->config->thermalTempMaxLevel3;
8297
8298 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8299
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308300 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308301 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008302
8303 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8304 hdd_set_thermal_level_cb);
8305
8306 return 0;
8307
8308}
8309
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008310#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8311/**
8312 * hdd_hold_rtnl_lock - Hold RTNL lock
8313 *
8314 * Hold RTNL lock
8315 *
8316 * Return: True if held and false otherwise
8317 */
8318static inline bool hdd_hold_rtnl_lock(void)
8319{
8320 rtnl_lock();
8321 return true;
8322}
8323
8324/**
8325 * hdd_release_rtnl_lock - Release RTNL lock
8326 *
8327 * Release RTNL lock
8328 *
8329 * Return: None
8330 */
8331static inline void hdd_release_rtnl_lock(void)
8332{
8333 rtnl_unlock();
8334}
8335#else
8336static inline bool hdd_hold_rtnl_lock(void) { return false; }
8337static inline void hdd_release_rtnl_lock(void) { }
8338#endif
8339
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008340#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008341
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308342/* MAX iwpriv command support */
8343#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308344#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308345#define MAX_PKTLOG_SIZE 16
8346
8347/**
8348 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8349 * @hdd_ctx: hdd context
8350 * @set_value2: pktlog buffer size value
8351 *
8352 *
8353 * Return: 0 for success or error.
8354 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008355static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308356{
8357 struct sir_wifi_start_log start_log = { 0 };
8358 QDF_STATUS status;
8359
8360 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8361 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8362 start_log.ini_triggered = cds_is_packet_log_enabled();
8363 start_log.user_triggered = 1;
8364 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308365 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308366
8367 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8368 if (!QDF_IS_STATUS_SUCCESS(status)) {
8369 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8370 EXIT();
8371 return -EINVAL;
8372 }
8373
8374 return 0;
8375}
8376
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008377/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308378 * hdd_pktlog_clear_buff() - clear pktlog buffer
8379 * @hdd_ctx: hdd context
8380 *
8381 * Return: 0 for success or error.
8382 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008383static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308384{
8385 struct sir_wifi_start_log start_log;
8386 QDF_STATUS status;
8387
8388 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8389 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8390 start_log.ini_triggered = cds_is_packet_log_enabled();
8391 start_log.user_triggered = 1;
8392 start_log.size = 0;
8393 start_log.is_pktlog_buff_clear = true;
8394
8395 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8396 if (!QDF_IS_STATUS_SUCCESS(status)) {
8397 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8398 EXIT();
8399 return -EINVAL;
8400 }
8401
8402 return 0;
8403}
8404
8405
8406/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008407 * hdd_process_pktlog_command() - process pktlog command
8408 * @hdd_ctx: hdd context
8409 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308410 * @set_value2: pktlog buffer size value
8411 *
8412 * This function process pktlog command.
8413 * set_value2 only matters when set_value is 3 (set buff size)
8414 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008415 *
8416 * Return: 0 for success or error.
8417 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008418int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308419 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008420{
8421 int ret;
8422 bool enable;
8423 uint8_t user_triggered = 0;
8424
8425 ret = wlan_hdd_validate_context(hdd_ctx);
8426 if (0 != ret)
8427 return ret;
8428
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008429 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008430
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308431 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008432 hdd_err("invalid pktlog value %d", set_value);
8433 return -EINVAL;
8434 }
8435
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308436 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8437 if (set_value2 <= 0) {
8438 hdd_err("invalid pktlog size %d", set_value2);
8439 return -EINVAL;
8440 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8441 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8442 return -EINVAL;
8443 }
8444 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308445 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8446 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308447 }
8448
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008449 /*
8450 * set_value = 0 then disable packetlog
8451 * set_value = 1 enable packetlog forcefully
8452 * set_vlaue = 2 then disable packetlog if disabled through ini or
8453 * enable packetlog with AUTO type.
8454 */
8455 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8456 true : false;
8457
8458 if (1 == set_value) {
8459 enable = true;
8460 user_triggered = 1;
8461 }
8462
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308463 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008464}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008465/**
8466 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8467 * @hdd_ctx: HDD context
8468 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308469 * @user_triggered: triggered through iwpriv
8470 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008471 *
8472 * Return: 0 on success; error number otherwise
8473 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008474int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308475 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008476{
8477 struct sir_wifi_start_log start_log;
8478 QDF_STATUS status;
8479
8480 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8481 start_log.verbose_level =
8482 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008483 start_log.ini_triggered = cds_is_packet_log_enabled();
8484 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308485 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308486 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308487 /*
8488 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8489 * commands. Host uses this flag to decide whether to send pktlog
8490 * disable command to fw without sending pktlog enable command
8491 * previously. For eg, If vendor sends pktlog disable command without
8492 * sending pktlog enable command, then host discards the packet
8493 * but for iwpriv command, host will send it to fw.
8494 */
8495 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008496 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8497 if (!QDF_IS_STATUS_SUCCESS(status)) {
8498 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8499 EXIT();
8500 return -EINVAL;
8501 }
8502
8503 return 0;
8504}
8505#endif /* REMOVE_PKT_LOG */
8506
Komal Seelam92fff912016-03-24 11:51:41 +05308507/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008508 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8509 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308510 * @dev: Device Pointer
8511 * @num: Number of Valid Mac address
8512 *
8513 * Return: Pointer to MAC address buffer
8514 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008515static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8516 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308517{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008518 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308519}
Komal Seelam92fff912016-03-24 11:51:41 +05308520
8521/**
8522 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8523 * @hdd_ctx: HDD Context
8524 * @num: Number of random mac addresses needed
8525 *
8526 * Generate random addresses using bit manipulation on the base mac address
8527 *
8528 * Return: None
8529 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008530void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308531{
8532 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8533 uint32_t iter;
8534 struct hdd_config *ini = hdd_ctx->config;
8535 uint8_t *buf = NULL;
8536 uint8_t macaddr_b3, tmp_br3;
8537 uint8_t *src = ini->intfMacAddr[0].bytes;
8538
8539 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8540 buf = ini->intfMacAddr[iter].bytes;
8541 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8542 macaddr_b3 = buf[3];
8543 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8544 INTF_MACADDR_MASK;
8545 macaddr_b3 += tmp_br3;
8546 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8547 buf[0] |= 0x02;
8548 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008549 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308550 }
8551}
8552
8553/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008554 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308555 * @hdd_ctx: HDD Context
8556 *
8557 * API to get mac addresses from platform driver and update the driver
8558 * structures and configure FW with the base mac address.
8559 * Return: int
8560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008561static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308562{
8563 uint32_t no_of_mac_addr, iter;
8564 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8565 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8566 uint8_t *addr, *buf;
8567 struct device *dev = hdd_ctx->parent_dev;
8568 struct hdd_config *ini = hdd_ctx->config;
8569 tSirMacAddr mac_addr;
8570 QDF_STATUS status;
8571
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008572 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308573
8574 if (no_of_mac_addr == 0 || !addr) {
8575 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8576 return -EINVAL;
8577 }
8578
8579 if (no_of_mac_addr > max_mac_addr)
8580 no_of_mac_addr = max_mac_addr;
8581
8582 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8583
8584 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8585 buf = ini->intfMacAddr[iter].bytes;
8586 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008587 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308588 }
8589
8590 status = sme_set_custom_mac_addr(mac_addr);
8591
8592 if (!QDF_IS_STATUS_SUCCESS(status))
8593 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008594
Komal Seelam92fff912016-03-24 11:51:41 +05308595 if (no_of_mac_addr < max_mac_addr)
8596 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8597 no_of_mac_addr);
8598 return 0;
8599}
8600
8601/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008602 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8603 * @hdd_ctx: HDD Context
8604 *
8605 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8606 * will generate its own MAC and update it to FW.
8607 *
8608 * Return: 0 for success
8609 * Non-zero error code for failure
8610 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008611static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008612{
8613 tSirMacAddr customMacAddr;
8614 QDF_STATUS status;
8615
8616 qdf_mem_copy(&customMacAddr,
8617 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8618 sizeof(tSirMacAddr));
8619 status = sme_set_custom_mac_addr(customMacAddr);
8620 if (!QDF_IS_STATUS_SUCCESS(status))
8621 return -EAGAIN;
8622 return 0;
8623}
8624
8625/**
Komal Seelam92fff912016-03-24 11:51:41 +05308626 * hdd_initialize_mac_address() - API to get wlan mac addresses
8627 * @hdd_ctx: HDD Context
8628 *
8629 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8630 * is provisioned with mac addresses, driver uses it, else it will use
8631 * wlan_mac.bin to update HW MAC addresses.
8632 *
8633 * Return: None
8634 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008635static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308636{
8637 QDF_STATUS status;
8638 int ret;
8639
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008640 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308641 if (ret == 0)
8642 return;
8643
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008644 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8645 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308646
8647 status = hdd_update_mac_config(hdd_ctx);
8648
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008649 if (QDF_IS_STATUS_SUCCESS(status))
8650 return;
8651
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008652 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8653 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008654
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008655 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008656 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008657 if (ret != 0) {
8658 hdd_err("MAC address out-of-sync, ret:%d", ret);
8659 QDF_ASSERT(ret);
8660 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008661 }
Komal Seelam92fff912016-03-24 11:51:41 +05308662}
8663
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008664static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008665{
8666 int vdev_id = 0;
8667 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8668 int value = hdd_ctx->config->smart_chainmask_enabled;
8669 int vpdev = PDEV_CMD;
8670 int ret;
8671
Naveen Rawat247a8682017-06-05 15:00:31 -07008672 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008673 if (ret)
8674 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8675
8676 return ret;
8677}
8678
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008679static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008680{
8681 int vdev_id = 0;
8682 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8683 int value = hdd_ctx->config->alternative_chainmask_enabled;
8684 int vpdev = PDEV_CMD;
8685 int ret;
8686
Naveen Rawat247a8682017-06-05 15:00:31 -07008687 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008688 if (ret)
8689 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8690 ret);
8691
8692 return ret;
8693}
8694
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008695static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07008696{
8697 int vdev_id = 0;
8698 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8699 int value = hdd_ctx->config->ani_enabled;
8700 int vpdev = PDEV_CMD;
8701 int ret;
8702
Naveen Rawat247a8682017-06-05 15:00:31 -07008703 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008704 if (ret)
8705 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8706
8707 return ret;
8708}
8709
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008710/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008711 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8712 * @hdd_ctx: HDD context
8713 *
8714 * Pre configurations to be done at lower layer before calling cds enable.
8715 *
8716 * Return: 0 on success and errno on failure.
8717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008718static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07008719{
8720 int ret;
8721 QDF_STATUS status;
8722 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008723 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008724
Leo Changfdb45c32016-10-28 11:09:23 -07008725 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008726 /*
8727 * Set 802.11p config
8728 * TODO-OCB: This has been temporarily added here to ensure this
8729 * parameter is set in CSR when we init the channel list. This should
8730 * be removed once the 5.9 GHz channels are added to the regulatory
8731 * domain.
8732 */
8733 hdd_set_dot11p_config(hdd_ctx);
8734
8735 /*
8736 * Note that the cds_pre_enable() sequence triggers the cfg download.
8737 * The cfg download must occur before we update the SME config
8738 * since the SME config operation must access the cfg database
8739 */
8740 status = hdd_set_sme_config(hdd_ctx);
8741
8742 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008743 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008744 ret = qdf_status_to_os_return(status);
8745 goto out;
8746 }
8747
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008748 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8749 if (QDF_STATUS_SUCCESS != status) {
8750 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8751 ret = qdf_status_to_os_return(status);
8752 goto out;
8753 }
8754
Naveen Rawat247a8682017-06-05 15:00:31 -07008755 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008756 hdd_ctx->config->tx_chain_mask_1ss,
8757 PDEV_CMD);
8758 if (0 != ret) {
8759 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8760 goto out;
8761 }
8762
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008763 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8764 if (ret)
8765 goto out;
8766
8767 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8768 if (ret)
8769 goto out;
8770
Jeff Johnson12a744b2017-04-04 08:19:37 -07008771 ret = hdd_set_ani_enabled(hdd_ctx);
8772 if (ret)
8773 goto out;
8774
Naveen Rawat247a8682017-06-05 15:00:31 -07008775 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008776 hdd_ctx->config->arp_ac_category,
8777 PDEV_CMD);
8778 if (0 != ret) {
8779 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8780 hdd_ctx->config->arp_ac_category, ret);
8781 goto out;
8782 }
8783
8784
Prashanth Bhatta07998752016-04-28 12:35:33 -07008785 status = hdd_set_sme_chan_list(hdd_ctx);
8786 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008787 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008788 ret = qdf_status_to_os_return(status);
8789 goto out;
8790 }
8791
8792 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008793 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008794 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008795 ret = -EINVAL;
8796 goto out;
8797 }
8798
Prashanth Bhatta07998752016-04-28 12:35:33 -07008799 /*
8800 * Set the MAC Address Currently this is used by HAL to add self sta.
8801 * Remove this once self sta is added as part of session open.
8802 */
8803 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8804 hdd_ctx->config->intfMacAddr[0].bytes,
8805 sizeof(hdd_ctx->config->intfMacAddr[0]));
8806
8807 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8808 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8809 hal_status, hal_status);
8810 ret = -EINVAL;
8811 goto out;
8812 }
8813
8814 hdd_init_channel_avoidance(hdd_ctx);
8815
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05308816 /* update enable sap mandatory chan list */
8817 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
8818 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008819out:
8820 return ret;
8821}
8822
8823/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008824 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8825 * @context_ptr - hdd context pointer
8826 * @event_ptr - event structure pointer
8827 *
8828 * This is the p2p listen offload stop event handler, it sends vendor
8829 * event back to supplicant to notify the stop reason.
8830 *
8831 * Return: None
8832 */
8833static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8834 void *event_ptr)
8835{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008836 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07008837 struct sir_p2p_lo_event *evt = event_ptr;
8838 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07008839 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07008840
8841 ENTER();
8842
8843 if (hdd_ctx == NULL) {
8844 hdd_err("Invalid HDD context pointer");
8845 return;
8846 }
8847
Peng Xu5c682812017-08-06 07:39:13 -07008848 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
8849 if (!adapter) {
8850 hdd_err("Cannot find adapter by vdev_id = %d",
8851 evt->vdev_id);
8852 return;
8853 }
8854
Peng Xu8fdaa492016-06-22 10:20:47 -07008855 vendor_event =
8856 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07008857 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07008858 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8859 GFP_KERNEL);
8860
8861 if (!vendor_event) {
8862 hdd_err("cfg80211_vendor_event_alloc failed");
8863 return;
8864 }
8865
8866 if (nla_put_u32(vendor_event,
8867 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8868 evt->reason_code)) {
8869 hdd_err("nla put failed");
8870 kfree_skb(vendor_event);
8871 return;
8872 }
8873
8874 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07008875 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
8876 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07008877}
8878
8879/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308880 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8881 * @hdd_ctx: HDD context
8882 *
8883 * This function sends the adaptive dwell time config configuration to the
8884 * firmware via WMA
8885 *
8886 * Return: 0 - success, < 0 - failure
8887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008888static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308889{
8890 QDF_STATUS status;
8891 struct adaptive_dwelltime_params dwelltime_params;
8892
8893 dwelltime_params.is_enabled =
8894 hdd_ctx->config->adaptive_dwell_mode_enabled;
8895 dwelltime_params.dwelltime_mode =
8896 hdd_ctx->config->global_adapt_dwelltime_mode;
8897 dwelltime_params.lpf_weight =
8898 hdd_ctx->config->adapt_dwell_lpf_weight;
8899 dwelltime_params.passive_mon_intval =
8900 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8901 dwelltime_params.wifi_act_threshold =
8902 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8903
8904 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8905 &dwelltime_params);
8906
8907 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8908 if (!QDF_IS_STATUS_SUCCESS(status)) {
8909 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8910 return -EAGAIN;
8911 }
8912 return 0;
8913}
8914
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008915int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308916{
8917 QDF_STATUS status;
8918 struct wmi_dbs_scan_sel_params dbs_scan_params;
8919 uint32_t i = 0;
8920 uint8_t count = 0, numentries = 0;
8921 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8922 * CDS_DBS_SCAN_CLIENTS_MAX];
8923
8924 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07008925 if (hdd_ctx->config->dual_mac_feature_disable ==
8926 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308927 return -EINVAL;
8928
8929 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8930 dbs_scan_config, &numentries,
8931 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8932 * CDS_DBS_SCAN_CLIENTS_MAX));
8933
8934 hdd_info("numentries %hu", numentries);
8935 if (!numentries) {
8936 hdd_info("Donot send scan_selection_config");
8937 return 0;
8938 }
8939
8940 /* hdd_set_fw_log_params */
8941 dbs_scan_params.num_clients = 0;
8942 while (count < (numentries - 2)) {
8943 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8944 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8945 dbs_scan_params.num_non_dbs_scans[i] =
8946 dbs_scan_config[count + 2];
8947 dbs_scan_params.num_clients++;
8948 hdd_debug("module:%d NDS:%d NNDS:%d",
8949 dbs_scan_params.module_id[i],
8950 dbs_scan_params.num_dbs_scans[i],
8951 dbs_scan_params.num_non_dbs_scans[i]);
8952 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8953 i++;
8954 }
8955
8956 dbs_scan_params.pdev_id = 0;
8957
8958 hdd_debug("clients:%d pdev:%d",
8959 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
8960
8961 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
8962 &dbs_scan_params);
8963 hdd_debug("Sending DBS Scan Selection Configuration to fw");
8964 if (!QDF_IS_STATUS_SUCCESS(status)) {
8965 hdd_err("Failed to send DBS Scan selection configuration!");
8966 return -EAGAIN;
8967 }
8968 return 0;
8969}
8970
Arun Khandavallid4349a92016-07-25 11:10:43 +05308971#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8972/**
8973 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8974 * @hdd_ctx: HDD context
8975 *
8976 * Set auto shutdown callback to get indications from firmware to indicate
8977 * userspace to shutdown WLAN after a configured amount of inactivity.
8978 *
8979 * Return: 0 on success and errno on failure.
8980 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008981static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05308982{
8983 QDF_STATUS status;
8984
8985 if (!hdd_ctx->config->WlanAutoShutdown)
8986 return 0;
8987
8988 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8989 wlan_hdd_auto_shutdown_cb);
8990 if (status != QDF_STATUS_SUCCESS)
8991 hdd_err("Auto shutdown feature could not be enabled: %d",
8992 status);
8993
8994 return qdf_status_to_os_return(status);
8995}
8996#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008997static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05308998{
8999 return 0;
9000}
9001#endif
9002
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009003static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009004{
9005 QDF_STATUS status = QDF_STATUS_SUCCESS;
9006
9007 switch (hdd_ctx->config->dual_mac_feature_disable) {
9008 case DISABLE_DBS_CXN_AND_SCAN:
9009 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9010 if (status != QDF_STATUS_SUCCESS)
9011 hdd_err("Failed to disable dual mac features");
9012 break;
9013 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9014 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9015 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9016 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9017 if (status != QDF_STATUS_SUCCESS)
9018 hdd_err("Failed to set dbs scan and fw mode config");
9019 break;
9020 default:
9021 break;
9022 }
9023
9024 return status;
9025}
9026
Arun Khandavallid4349a92016-07-25 11:10:43 +05309027/**
9028 * hdd_features_init() - Init features
9029 * @hdd_ctx: HDD context
9030 * @adapter: Primary adapter context
9031 *
9032 * Initialize features and their feature context after WLAN firmware is up.
9033 *
9034 * Return: 0 on success and errno on failure.
9035 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009036static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309037{
9038 tSirTxPowerLimit hddtxlimit;
9039 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309040 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309041 int ret;
9042
9043 ENTER();
9044
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009045 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309046 if (ret) {
9047 hdd_err("Failed to update country code: %d", ret);
9048 goto out;
9049 }
9050
9051 /* FW capabilities received, Set the Dot11 mode */
9052 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009053 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9054 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309055
Arun Khandavallid4349a92016-07-25 11:10:43 +05309056
9057 if (hdd_ctx->config->fIsImpsEnabled)
9058 hdd_set_idle_ps_config(hdd_ctx, true);
9059 else
9060 hdd_set_idle_ps_config(hdd_ctx, false);
9061
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309062 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009063 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309064
Arun Khandavallid4349a92016-07-25 11:10:43 +05309065 if (hdd_lro_init(hdd_ctx))
9066 hdd_err("Unable to initialize LRO in fw");
9067
9068 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9069 hdd_err("Unable to send adaptive dwelltime setting to FW");
9070
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309071 if (hdd_dbs_scan_selection_init(hdd_ctx))
9072 hdd_err("Unable to send DBS scan selection setting to FW");
9073
Arun Khandavallid4349a92016-07-25 11:10:43 +05309074 ret = hdd_init_thermal_info(hdd_ctx);
9075 if (ret) {
9076 hdd_err("Error while initializing thermal information");
9077 goto deregister_frames;
9078 }
9079
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309080 if (cds_is_packet_log_enabled())
9081 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9082
Arun Khandavallid4349a92016-07-25 11:10:43 +05309083 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9084 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9085 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9086 if (!QDF_IS_STATUS_SUCCESS(status))
9087 hdd_err("Error setting txlimit in sme: %d", status);
9088
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009089 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309090
Arun Khandavallid4349a92016-07-25 11:10:43 +05309091 ret = hdd_register_cb(hdd_ctx);
9092 if (ret) {
9093 hdd_err("Failed to register HDD callbacks!");
9094 goto deregister_frames;
9095 }
9096
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009097 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9098 if (!QDF_IS_STATUS_SUCCESS(status)) {
9099 hdd_err("Failed to set dbs scan and fw mode cfg");
9100 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309101 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009102
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309103 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9104 status = sme_enable_disable_chanavoidind_event(
9105 hdd_ctx->hHal, 0);
9106 if (!QDF_IS_STATUS_SUCCESS(status)) {
9107 hdd_err("Failed to disable Chan Avoidance Indication");
9108 goto deregister_cb;
9109 }
9110 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309111
Manjeet Singha9cae432017-02-28 11:58:22 +05309112 if (hdd_ctx->config->enable_5g_band_pref) {
9113 band_pref_params.rssi_boost_threshold_5g =
9114 hdd_ctx->config->rssi_boost_threshold_5g;
9115 band_pref_params.rssi_boost_factor_5g =
9116 hdd_ctx->config->rssi_boost_factor_5g;
9117 band_pref_params.max_rssi_boost_5g =
9118 hdd_ctx->config->max_rssi_boost_5g;
9119 band_pref_params.rssi_penalize_threshold_5g =
9120 hdd_ctx->config->rssi_penalize_threshold_5g;
9121 band_pref_params.rssi_penalize_factor_5g =
9122 hdd_ctx->config->rssi_penalize_factor_5g;
9123 band_pref_params.max_rssi_penalize_5g =
9124 hdd_ctx->config->max_rssi_penalize_5g;
9125 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9126 }
9127
Arun Khandavallid4349a92016-07-25 11:10:43 +05309128 /* register P2P Listen Offload event callback */
9129 if (wma_is_p2p_lo_capable())
9130 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9131 wlan_hdd_p2p_lo_event_callback);
9132
9133 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9134
9135 if (ret)
9136 goto deregister_cb;
9137
9138 EXIT();
9139 return 0;
9140
9141deregister_cb:
9142 hdd_deregister_cb(hdd_ctx);
9143deregister_frames:
9144 wlan_hdd_cfg80211_deregister_frames(adapter);
9145out:
9146 return -EINVAL;
9147
9148}
9149
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009150/**
9151 * hdd_features_deinit() - Deinit features
9152 * @hdd_ctx: HDD context
9153 *
9154 * De-Initialize features and their feature context.
9155 *
9156 * Return: none.
9157 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009158static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009159{
9160 wlan_hdd_tsf_deinit(hdd_ctx);
9161}
9162
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309163/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009164 * hdd_register_bcn_cb() - register scan beacon callback
9165 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309166 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009167 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309168 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009169static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309170{
9171 QDF_STATUS status;
9172
9173 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9174 wlan_cfg80211_inform_bss_frame,
9175 SCAN_CB_TYPE_INFORM_BCN);
9176 if (!QDF_IS_STATUS_SUCCESS(status)) {
9177 hdd_err("failed with status code %08d [x%08x]",
9178 status, status);
9179 return status;
9180 }
9181
9182 return QDF_STATUS_SUCCESS;
9183}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309184
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309185/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309186 * hdd_configure_cds() - Configure cds modules
9187 * @hdd_ctx: HDD context
9188 * @adapter: Primary adapter context
9189 *
9190 * Enable Cds modules after WLAN firmware is up.
9191 *
9192 * Return: 0 on success and errno on failure.
9193 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009194int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309195{
9196 int ret;
9197 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309198
9199 ret = hdd_pre_enable_configure(hdd_ctx);
9200 if (ret) {
9201 hdd_err("Failed to pre-configure cds");
9202 goto out;
9203 }
9204
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009205 /* Always get latest IPA resources allocated from cds_open and configure
9206 * IPA module before configuring them to FW. Sequence required as crash
9207 * observed otherwise.
9208 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009209 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9210 hdd_err("Failed to setup pipes");
9211 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009212 }
9213
Arun Khandavallifae92942016-08-01 13:31:08 +05309214 /*
9215 * Start CDS which starts up the SME/MAC/HAL modules and everything
9216 * else
9217 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009218 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309219
9220 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009221 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309222 goto out;
9223 }
9224
9225 status = hdd_post_cds_enable_config(hdd_ctx);
9226 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009227 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009228 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309229 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309230 status = hdd_register_bcn_cb(hdd_ctx);
9231 if (!QDF_IS_STATUS_SUCCESS(status)) {
9232 hdd_alert("hdd_post_cds_enable_config failed");
9233 goto cds_disable;
9234 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309235
9236 ret = hdd_features_init(hdd_ctx, adapter);
9237 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009238 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309239
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309240 if (hdd_enable_egap(hdd_ctx))
9241 hdd_debug("enhance green ap is not enabled");
9242
Nachiket Kukadedd302662017-07-13 17:31:44 +05309243 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9244 hdd_debug("Failed to set wow pulse");
9245
Arun Khandavallifae92942016-08-01 13:31:08 +05309246 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009247
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009248cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009249 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009250
Arun Khandavallifae92942016-08-01 13:31:08 +05309251out:
9252 return -EINVAL;
9253}
9254
9255/**
9256 * hdd_deconfigure_cds() -De-Configure cds
9257 * @hdd_ctx: HDD context
9258 *
9259 * Deconfigure Cds modules before WLAN firmware is down.
9260 *
9261 * Return: 0 on success and errno on failure.
9262 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009263static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309264{
9265 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009266 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309267
9268 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009269
9270 /* De-init features */
9271 hdd_features_deinit(hdd_ctx);
9272
Arun Khandavallifae92942016-08-01 13:31:08 +05309273 /* De-register the SME callbacks */
9274 hdd_deregister_cb(hdd_ctx);
9275
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009276 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309277 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9278 hdd_err("Failed to Disable the CDS Modules! :%d",
9279 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009280 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309281 }
9282
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309283 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9284 hdd_err("Failed to disconnect pipes");
9285 ret = -EINVAL;
9286 }
9287
Arun Khandavallifae92942016-08-01 13:31:08 +05309288 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009289 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309290}
9291
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009292#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9293static void hdd_deregister_policy_manager_callback(
9294 struct wlan_objmgr_psoc *psoc)
9295{
9296 if (QDF_STATUS_SUCCESS !=
9297 policy_mgr_deregister_hdd_cb(psoc)) {
9298 hdd_err("HDD callback deregister with policy manager failed");
9299 }
9300}
9301#else
9302static void hdd_deregister_policy_manager_callback(
9303 struct wlan_objmgr_psoc *psoc)
9304{
9305}
9306#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309307
9308/**
9309 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9310 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009311 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309312 *
9313 * This function maintains the driver state machine it will be invoked from
9314 * exit, shutdown and con_mode change handler. Depending on the driver state
9315 * shall perform the stopping/closing of the modules.
9316 *
9317 * Return: 0 for success; non-zero for failure
9318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009319int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309320{
9321 void *hif_ctx;
9322 qdf_device_t qdf_ctx;
9323 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309324 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009325 bool is_idle_stop = !cds_is_driver_unloading() &&
9326 !cds_is_driver_recovering();
9327 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309328
9329 ENTER();
9330
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009331 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9332
Arun Khandavallifae92942016-08-01 13:31:08 +05309333 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9334 if (!qdf_ctx) {
9335 hdd_err("QDF device context NULL");
9336 return -EINVAL;
9337 }
9338
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309339 mutex_lock(&hdd_ctx->iface_change_lock);
9340 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309341
Dustin Brown70111822017-03-30 15:31:40 -07009342 active_threads = cds_return_external_threads_count();
9343 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009344 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009345 active_threads, hdd_ctx->isWiphySuspended);
9346
9347 cds_print_external_threads();
9348
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009349 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009350 mutex_unlock(&hdd_ctx->iface_change_lock);
9351 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009352 hdd_ctx->config->iface_change_wait_time);
9353 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009354 return 0;
9355 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009356 }
9357
Arun Khandavallifae92942016-08-01 13:31:08 +05309358 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9359
9360 switch (hdd_ctx->driver_status) {
9361 case DRIVER_MODULES_UNINITIALIZED:
9362 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309363 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309364 case DRIVER_MODULES_CLOSED:
9365 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309366 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309367 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309368 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309369 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009370 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309371 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309372 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309373 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009374 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309375 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9376 break;
9377 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009378 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309379 break;
9380 default:
9381 hdd_err("Trying to stop wlan in a wrong state: %d",
9382 hdd_ctx->driver_status);
9383 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309384 ret = -EINVAL;
9385 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309386 }
9387
Rajeev Kumarbe021242017-02-16 16:12:23 -08009388 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309389 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9390 hdd_err("Failed to process post CDS disable Modules! :%d",
9391 qdf_status);
9392 ret = -EINVAL;
9393 QDF_ASSERT(0);
9394 }
Jeff Johnsone4b14592017-09-13 14:23:33 -07009395 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309396 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009397 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309398 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309399 QDF_ASSERT(0);
9400 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009401
Arun Khandavallifae92942016-08-01 13:31:08 +05309402 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9403 if (!hif_ctx) {
9404 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309405 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309406 }
9407
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309408 hdd_runtime_suspend_context_deinit(hdd_ctx);
9409
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309410 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309411
9412 ol_cds_free();
9413
Dustin Brown70111822017-03-30 15:31:40 -07009414 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309415 ret = pld_power_off(qdf_ctx->dev);
9416 if (ret)
9417 hdd_err("CNSS power down failed put device into Low power mode:%d",
9418 ret);
9419 }
9420 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009421 /*
9422 * Reset total mac phy during module stop such that during
9423 * next module start same psoc is used to populate new service
9424 * ready data
9425 */
9426 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309427
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309428done:
9429 hdd_ctx->stop_modules_in_progress = false;
9430 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309431 EXIT();
9432
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309433 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309434
9435}
9436
9437/**
9438 * hdd_iface_change_callback() - Function invoked when stop modules expires
9439 * @priv: pointer to hdd context
9440 *
9441 * This function is invoked when the timer waiting for the interface change
9442 * expires, it shall cut-down the power to wlan and stop all the modules.
9443 *
9444 * Return: void
9445 */
9446static void hdd_iface_change_callback(void *priv)
9447{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009448 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
Arun Khandavallifae92942016-08-01 13:31:08 +05309449 int ret;
9450 int status = wlan_hdd_validate_context(hdd_ctx);
9451
9452 if (status)
9453 return;
9454
9455 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009456 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009457 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309458 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009459 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309460 EXIT();
9461}
9462
9463/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309464 * hdd_state_info_dump() - prints state information of hdd layer
9465 * @buf: buffer pointer
9466 * @size: size of buffer to be filled
9467 *
9468 * This function is used to dump state information of hdd layer
9469 *
9470 * Return: None
9471 */
9472static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9473{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009474 struct hdd_context *hdd_ctx;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309475 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9476 QDF_STATUS status;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07009477 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -07009478 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309479 uint16_t len = 0;
9480 char *buf = *buf_ptr;
9481
9482 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9483 if (!hdd_ctx) {
9484 hdd_err("Failed to get hdd context ");
9485 return;
9486 }
9487
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009488 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309489
9490 len += scnprintf(buf + len, *size - len,
9491 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9492 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009493 "\n is_scheduler_suspended %d",
9494 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309495
9496 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9497
9498 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9499 adapter = adapter_node->pAdapter;
9500 if (adapter->dev)
9501 len += scnprintf(buf + len, *size - len,
9502 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009503 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309504 "\n device_mode: %d", adapter->device_mode);
9505 switch (adapter->device_mode) {
9506 case QDF_STA_MODE:
9507 case QDF_P2P_CLIENT_MODE:
9508 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9509 len += scnprintf(buf + len, *size - len,
9510 "\n connState: %d",
9511 hdd_sta_ctx->conn_info.connState);
9512 break;
9513
9514 default:
9515 break;
9516 }
9517 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9518 adapter_node = next;
9519 }
9520
9521 *size -= len;
9522 *buf_ptr += len;
9523}
9524
9525/**
9526 * hdd_register_debug_callback() - registration function for hdd layer
9527 * to print hdd state information
9528 *
9529 * Return: None
9530 */
9531static void hdd_register_debug_callback(void)
9532{
9533 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9534}
9535
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309536/*
9537 * wlan_init_bug_report_lock() - Initialize bug report lock
9538 *
9539 * This function is used to create bug report lock
9540 *
9541 * Return: None
9542 */
9543static void wlan_init_bug_report_lock(void)
9544{
9545 p_cds_contextType p_cds_context;
9546
9547 p_cds_context = cds_get_global_context();
9548 if (!p_cds_context) {
9549 hdd_err("cds context is NULL");
9550 return;
9551 }
9552
9553 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9554}
9555
Mohit Khannaf8f96822017-05-17 17:11:59 -07009556void hdd_dp_trace_init(struct hdd_config *config)
9557{
9558
9559 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
9560 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
9561 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
9562 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
9563 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
9564 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
9565 uint8_t num_entries = 0;
9566
9567 hdd_string_to_u8_array(config->dp_trace_config, config_params,
9568 &num_entries, sizeof(config_params));
9569
9570 /* calculating, num bw timer intervals in a second (1000ms) */
9571 if (config->busBandwidthComputeInterval)
9572 thresh_time_limit =
9573 (1000 / config->busBandwidthComputeInterval);
9574 else
9575 hdd_err("busBandwidthComputeInterval is 0, using defaults");
9576
9577 switch (num_entries) {
9578 case 4:
9579 proto_bitmap = config_params[3];
9580 case 3:
9581 verbosity = config_params[2];
9582 case 2:
9583 thresh = config_params[1];
9584 case 1:
9585 live_mode = config_params[0];
9586 default:
9587 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
9588 live_mode, thresh, thresh_time_limit,
9589 verbosity, proto_bitmap);
9590 };
9591
9592 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
9593 verbosity, proto_bitmap);
9594
9595}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309596/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009597 * hdd_wlan_startup() - HDD init function
9598 * @dev: Pointer to the underlying device
9599 *
9600 * This is the driver startup code executed once a WLAN device has been detected
9601 *
9602 * Return: 0 for success, < 0 for failure
9603 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309604int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009605{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309606 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009607 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009608 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009609 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309610 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009611 uint32_t num_abg_tx_chains = 0;
9612 uint32_t num_11b_tx_chains = 0;
9613 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009614
9615 ENTER();
9616
Arun Khandavallifae92942016-08-01 13:31:08 +05309617 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009618
9619 if (IS_ERR(hdd_ctx))
9620 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009621
Abhishek Singhe9068f12017-03-31 14:14:52 +05309622 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9623 DEFAULT_PSOC_ID);
9624 if (ret) {
9625 hdd_err("Psoc creation fails!");
9626 QDF_BUG(0);
9627 goto err_hdd_free_context;
9628 }
9629
Arun Khandavallifae92942016-08-01 13:31:08 +05309630 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9631 hdd_iface_change_callback, (void *)hdd_ctx);
9632
9633 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309634#ifdef FEATURE_WLAN_CH_AVOID
9635 mutex_init(&hdd_ctx->avoid_freq_lock);
9636#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309637
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009638 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009639 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309640
Jeff Johnson957bc272017-02-02 08:54:48 -08009641 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309642 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009643 hdd_err("Failed to start modules: %d", ret);
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009644 goto err_hdd_free_psoc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009645 }
9646
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309647 wlan_init_bug_report_lock();
9648
Yingying Tang80e15f32016-09-27 18:23:01 +08009649 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009650
Anurag Chouhan6d760662016-02-20 16:05:43 +05309651 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009652
9653 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009654 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309655 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009656 }
9657
Prashanth Bhatta07998752016-04-28 12:35:33 -07009658 ret = hdd_wiphy_init(hdd_ctx);
9659 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009660 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309661 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009662 }
9663
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309664 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -07009665 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309666
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309667 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009668 goto err_wiphy_unregister;
9669
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309670 wlan_hdd_init_chan_info(hdd_ctx);
9671
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009672 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009673
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009674 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009675
Jeff Johnson957bc272017-02-02 08:54:48 -08009676 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9677 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009678 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009679 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009680 }
9681
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009682 hdd_release_rtnl_lock();
9683 rtnl_held = false;
9684
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009685 wlan_hdd_update_11n_mode(hdd_ctx->config);
9686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009687#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309688 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309689 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009690 hdd_skip_acs_scan_timer_handler,
9691 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309692 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009693 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009694 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009695#endif
9696
Nitesh Shah61c10d92016-10-19 19:29:15 +05309697 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9698 QDF_TIMER_TYPE_SW,
9699 wlan_hdd_change_tdls_mode,
9700 hdd_ctx);
9701
Prashanth Bhattaab004382016-10-11 16:08:11 -07009702 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009703
Jeff Johnson9afc5012016-09-23 13:56:27 -07009704 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009705
Nirav Shahbd36b062016-07-18 11:12:59 +05309706 if (hdd_ctx->rps)
9707 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009708
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009709 ret = hdd_register_notifiers(hdd_ctx);
9710 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009711 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309712
9713 status = wlansap_global_init();
9714 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009715 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009716
Komal Seelam8634b772016-09-29 12:12:24 +05309717 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009718 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309719 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009720
Arun Khandavallifae92942016-08-01 13:31:08 +05309721 if (hdd_ctx->config->fIsImpsEnabled)
9722 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309723
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309724 if (hdd_ctx->config->sifs_burst_duration) {
9725 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9726 hdd_ctx->config->sifs_burst_duration;
9727
9728 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009729 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309730 set_value, PDEV_CMD);
9731 }
9732
Paul Zhang42dade02017-05-12 19:20:37 +08009733 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009734 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009735 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309736 /* set chip power save failure detected callback */
9737 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9738 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009739
lifeng959a04c2017-05-10 14:21:28 +08009740 if (hdd_ctx->config->max_mpdus_inampdu) {
9741 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009742 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009743 set_value, PDEV_CMD);
9744 }
9745
9746 if (hdd_ctx->config->enable_rts_sifsbursting) {
9747 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009748 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009749 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9750 set_value, PDEV_CMD);
9751 }
9752
Will Huang496b36c2017-07-11 16:38:50 +08009753 if (hdd_ctx->config->sap_get_peer_info) {
9754 set_value = hdd_ctx->config->sap_get_peer_info;
9755 sme_cli_set_command(0,
9756 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9757 set_value, PDEV_CMD);
9758 }
9759
Naveen Rawat247a8682017-06-05 15:00:31 -07009760 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9761 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9762 if (!hdd_ctx->config->enable2x2) {
9763 if (num_11b_tx_chains > 1)
9764 num_11b_tx_chains = 1;
9765 if (num_11ag_tx_chains > 1)
9766 num_11ag_tx_chains = 1;
9767 }
9768 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9769 num_11b_tx_chains);
9770 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9771 num_11ag_tx_chains);
9772 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9773 num_abg_tx_chains, PDEV_CMD);
9774
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309775 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9776 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309777 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309778
Sachin Ahujadddd2632017-03-07 19:07:24 +05309779 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009780 goto success;
9781
Jeff Johnson957bc272017-02-02 08:54:48 -08009782err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009783 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009784
Jeff Johnson46bde382017-02-01 15:31:16 -08009785err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309786 if (rtnl_held)
9787 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009788
Anurag Chouhance6a4052016-09-14 18:20:42 +05309789 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009791err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009792 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009793
Arun Khandavallifae92942016-08-01 13:31:08 +05309794err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009795 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309796
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009797err_hdd_free_psoc:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309798 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
Jeff Johnson7d562272017-09-13 15:12:54 -07009799 status = cds_sched_close();
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309800 if (!QDF_IS_STATUS_SUCCESS(status)) {
9801 hdd_err("Failed to close CDS Scheduler");
9802 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9803 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009804 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009805
Houston Hoffman47a4a052016-11-14 23:22:44 -08009806 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009807 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009808 hdd_exit_netlink_services(hdd_ctx);
9809
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309810 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009811
Dustin Brown20912462017-06-07 13:48:25 -07009812 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9813
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009814err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309815 if (cds_is_fw_down())
9816 hdd_err("Not setting the complete event as fw is down");
9817 else
9818 hdd_start_complete(ret);
9819
Arun Khandavallifae92942016-08-01 13:31:08 +05309820 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9821 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009822 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009823 return -EIO;
9824
9825success:
9826 EXIT();
9827 return 0;
9828}
9829
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009830/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309831 * hdd_wlan_update_target_info() - update target type info
9832 * @hdd_ctx: HDD context
9833 * @context: hif context
9834 *
9835 * Update target info received from firmware in hdd context
9836 * Return:None
9837 */
9838
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009839void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +05309840{
9841 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9842
9843 if (!tgt_info) {
9844 hdd_err("Target info is Null");
9845 return;
9846 }
9847
9848 hdd_ctx->target_type = tgt_info->target_type;
9849}
9850
9851/**
9852 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309853 * @hdd_ctx: HDD context
9854 *
9855 * Register the HDD callbacks to CDS/SME.
9856 *
9857 * Return: 0 for success or Error code for failure
9858 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009859int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309860{
9861 QDF_STATUS status;
9862 int ret = 0;
9863
9864 ENTER();
9865
9866 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9867
9868 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9869 hdd_send_oem_data_rsp_msg);
9870
9871 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9872 wlan_hdd_cfg80211_fw_mem_dump_cb);
9873 if (!QDF_IS_STATUS_SUCCESS(status)) {
9874 hdd_err("Failed to register memdump callback");
9875 ret = -EINVAL;
9876 return ret;
9877 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309878 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9879 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309880 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9881 sme_nan_register_callback(hdd_ctx->hHal,
9882 wlan_hdd_cfg80211_nan_callback);
9883 sme_stats_ext_register_callback(hdd_ctx->hHal,
9884 wlan_hdd_cfg80211_stats_ext_callback);
9885
9886 sme_ext_scan_register_callback(hdd_ctx->hHal,
9887 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009888 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9889 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309890
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309891 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9892 hdd_rssi_threshold_breached);
9893
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309894 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9895 wlan_hdd_cfg80211_link_layer_stats_callback);
9896
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309897 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9898
Zhang Qianca38fb12016-12-23 11:10:48 +08009899 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9900 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9901
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309902 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9903 hdd_lost_link_info_cb);
9904 /* print error and not block the startup process */
9905 if (!QDF_IS_STATUS_SUCCESS(status))
9906 hdd_err("set lost link info callback failed");
9907
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309908 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9909
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009910 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009911 hdd_set_connection_in_progress,
9912 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309913
9914 status = sme_congestion_register_callback(hdd_ctx->hHal,
9915 hdd_update_cca_info_cb);
9916 if (!QDF_IS_STATUS_SUCCESS(status))
9917 hdd_err("set congestion callback failed");
9918
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +05309919 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
9920 hdd_bt_activity_cb);
9921 if (!QDF_IS_STATUS_SUCCESS(status))
9922 hdd_err("set bt activity info callback failed");
9923
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309924 EXIT();
9925
9926 return ret;
9927}
9928
9929/**
9930 * hdd_deregister_cb() - De-Register HDD callbacks.
9931 * @hdd_ctx: HDD context
9932 *
9933 * De-Register the HDD callbacks to CDS/SME.
9934 *
9935 * Return: void
9936 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009937void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309938{
9939 QDF_STATUS status;
9940
9941 ENTER();
9942
9943 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9944 if (!QDF_IS_STATUS_SUCCESS(status))
9945 hdd_err("De-register of dcc stats callback failed: %d",
9946 status);
9947
9948 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309949 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9950
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309951 sme_stats_ext_register_callback(hdd_ctx->hHal,
9952 wlan_hdd_cfg80211_stats_ext_callback);
9953
9954 sme_nan_deregister_callback(hdd_ctx->hHal);
9955 status = sme_reset_tsfcb(hdd_ctx->hHal);
9956 if (!QDF_IS_STATUS_SUCCESS(status))
9957 hdd_err("Failed to de-register tsfcb the callback:%d",
9958 status);
9959 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9960 if (!QDF_IS_STATUS_SUCCESS(status))
9961 hdd_err("Failed to de-register the fw mem dump callback: %d",
9962 status);
9963
9964 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9965 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9966
9967 EXIT();
9968}
9969
9970/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009971 * hdd_softap_sta_deauth() - handle deauth req from HDD
9972 * @adapter: Pointer to the HDD
9973 * @enable: bool value
9974 *
9975 * This to take counter measure to handle deauth req from HDD
9976 *
9977 * Return: None
9978 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009979QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009980 struct tagCsrDelStaParams *pDelStaParams)
9981{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309982 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009983
9984 ENTER();
9985
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009986 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009987 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9988
9989 /* Ignore request to deauth bcmc station */
9990 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309991 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009992
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309993 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009994 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9995 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009996
9997 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309998 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009999}
10000
10001/**
10002 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10003 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010004 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010005 *
10006 * This to take counter measure to handle deauth req from HDD
10007 *
10008 * Return: None
10009 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010010void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010011 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010012{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010013 ENTER();
10014
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010015 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010016 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10017
10018 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010019 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010020 return;
10021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010022 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010023 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010024}
10025
Jeff Johnson9d295242017-08-29 14:39:48 -070010026void hdd_softap_tkip_mic_fail_counter_measure(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010027 bool enable)
10028{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010029 ENTER();
10030
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010031 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010032 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
10033
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010034 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10035 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010036}
10037
10038/**
10039 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10040 * @hdd_ctx: HDD Context
10041 *
10042 * API to find if there is any STA or P2P-Client is connected
10043 *
10044 * Return: true if connected; false otherwise
10045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010046QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010047{
10048 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10049}
10050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010051/**
10052 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10053 * @adapter: HDD adapter pointer
10054 *
10055 * This function loop through each adapter and disable roaming on each STA
10056 * device mode except the input adapter.
10057 *
10058 * Note: On the input adapter roaming is not enabled yet hence no need to
10059 * disable.
10060 *
10061 * Return: None
10062 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010063void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010064{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010065 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010066 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010067 hdd_adapter_list_node_t *adapterNode = NULL;
10068 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010069 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010070
10071 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010072 hdd_ctx->config->isRoamOffloadScanEnabled &&
10073 QDF_STA_MODE == adapter->device_mode &&
10074 policy_mgr_is_sta_active_connection_exists(
10075 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010076 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010077 adapter->sessionId);
10078 /*
10079 * Loop through adapter and disable roaming for each STA device
10080 * mode except the input adapter.
10081 */
10082 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10083
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010084 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010085 adapterIdx = adapterNode->pAdapter;
10086
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010087 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010088 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010089 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010090 adapterIdx->sessionId);
10091 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10092 (adapterIdx),
10093 adapterIdx->sessionId, 0);
10094 }
10095
10096 status = hdd_get_next_adapter(hdd_ctx,
10097 adapterNode,
10098 &pNext);
10099 adapterNode = pNext;
10100 }
10101 }
10102}
10103
10104/**
10105 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10106 * @adapter: HDD adapter pointer
10107 *
10108 * This function loop through each adapter and enable roaming on each STA
10109 * device mode except the input adapter.
10110 * Note: On the input adapter no need to enable roaming because link got
10111 * disconnected on this.
10112 *
10113 * Return: None
10114 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010115void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010116{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010117 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010118 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010119 hdd_adapter_list_node_t *adapterNode = NULL;
10120 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010121 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010122
10123 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010124 hdd_ctx->config->isRoamOffloadScanEnabled &&
10125 QDF_STA_MODE == adapter->device_mode &&
10126 policy_mgr_is_sta_active_connection_exists(
10127 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010128 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010129 adapter->sessionId);
10130 /*
10131 * Loop through adapter and enable roaming for each STA device
10132 * mode except the input adapter.
10133 */
10134 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10135
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010136 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010137 adapterIdx = adapterNode->pAdapter;
10138
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010139 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010140 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010141 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010142 adapterIdx->sessionId);
10143 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10144 (adapterIdx),
10145 adapterIdx->sessionId,
10146 REASON_CONNECT);
10147 }
10148
10149 status = hdd_get_next_adapter(hdd_ctx,
10150 adapterNode,
10151 &pNext);
10152 adapterNode = pNext;
10153 }
10154 }
10155}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010156
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010157/**
10158 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10159 * @skb: sk buffer pointer
10160 *
10161 * Sends the bcast message to SVC multicast group with generic nl socket
10162 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10163 *
10164 * Return: None
10165 */
10166static void nl_srv_bcast_svc(struct sk_buff *skb)
10167{
10168#ifdef CNSS_GENL
10169 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10170#else
10171 nl_srv_bcast(skb);
10172#endif
10173}
10174
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010175void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176{
10177 struct sk_buff *skb;
10178 struct nlmsghdr *nlh;
10179 tAniMsgHdr *ani_hdr;
10180 void *nl_data = NULL;
10181 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010182 struct radio_index_tlv *radio_info;
10183 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010184
10185 if (in_interrupt() || irqs_disabled() || in_atomic())
10186 flags = GFP_ATOMIC;
10187
10188 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10189
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010190 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010191 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010192
10193 nlh = (struct nlmsghdr *)skb->data;
10194 nlh->nlmsg_pid = 0; /* from kernel */
10195 nlh->nlmsg_flags = 0;
10196 nlh->nlmsg_seq = 0;
10197 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10198
10199 ani_hdr = NLMSG_DATA(nlh);
10200 ani_hdr->type = type;
10201
10202 switch (type) {
10203 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010204 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010205 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010206 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010207 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010208 ani_hdr->length = 0;
10209 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010210 break;
10211 case WLAN_SVC_WLAN_STATUS_IND:
10212 case WLAN_SVC_WLAN_VERSION_IND:
10213 case WLAN_SVC_DFS_CAC_START_IND:
10214 case WLAN_SVC_DFS_CAC_END_IND:
10215 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10216 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10217 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010218 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010219 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010220 ani_hdr->length = len;
10221 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10222 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10223 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010224 break;
10225
10226 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010227 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010228 type);
10229 kfree_skb(skb);
10230 return;
10231 }
10232
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010233 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010234 * Add radio index at the end of the svc event in TLV format
10235 * to maintain the backward compatibility with userspace
10236 * applications.
10237 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010238
10239 tlv_len = 0;
10240
10241 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10242 < WLAN_NL_MAX_PAYLOAD) {
10243 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10244 sizeof(*ani_hdr) + len);
10245 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10246 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10247 radio_info->radio = radio;
10248 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010249 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010250 "Added radio index tlv - radio index %d",
10251 radio_info->radio);
10252 }
10253
10254 nlh->nlmsg_len += tlv_len;
10255 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10256
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010257 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010258}
10259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010260#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10261void wlan_hdd_auto_shutdown_cb(void)
10262{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010263 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010264
10265 if (!hdd_ctx)
10266 return;
10267
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010268 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010269 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10270 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010271}
10272
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010273void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010274{
10275 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010276 QDF_STATUS status;
Jeff Johnson9d295242017-08-29 14:39:48 -070010277 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278 bool ap_connected = false, sta_connected = false;
10279 tHalHandle hal_handle;
10280
10281 hal_handle = hdd_ctx->hHal;
10282 if (hal_handle == NULL)
10283 return;
10284
10285 if (hdd_ctx->config->WlanAutoShutdown == 0)
10286 return;
10287
10288 if (enable == false) {
10289 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010290 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010291 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010292 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010293 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010294 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010295 return;
10296 }
10297
10298 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010299 if (policy_mgr_concurrent_open_sessions_running(
10300 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010301 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10302
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010303 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010304 adapter = adapterNode->pAdapter;
10305 if (adapter
10306 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010307 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010308 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10309 conn_info.connState ==
10310 eConnectionState_Associated) {
10311 sta_connected = true;
10312 break;
10313 }
10314 }
10315 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010316 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010317 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10318 bApActive == true) {
10319 ap_connected = true;
10320 break;
10321 }
10322 }
10323 status = hdd_get_next_adapter(hdd_ctx,
10324 adapterNode,
10325 &pNext);
10326 adapterNode = pNext;
10327 }
10328 }
10329
10330 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010331 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010332 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010333 }
Jeff Johnson68755312017-02-10 11:46:55 -080010334
10335 if (sme_set_auto_shutdown_timer(hal_handle,
10336 hdd_ctx->config->WlanAutoShutdown)
10337 != QDF_STATUS_SUCCESS)
10338 hdd_err("Failed to start wlan auto shutdown timer");
10339 else
10340 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10341 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010342}
10343#endif
10344
Jeff Johnson9d295242017-08-29 14:39:48 -070010345struct hdd_adapter *hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010346 bool check_start_bss)
10347{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010348 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010349 struct hdd_adapter *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010350 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010351 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10352
10353 con_sap_adapter = NULL;
10354
10355 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010356 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010357 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010358 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10359 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010360 adapter != this_sap_adapter) {
10361 if (check_start_bss) {
10362 if (test_bit(SOFTAP_BSS_STARTED,
10363 &adapter->event_flags)) {
10364 con_sap_adapter = adapter;
10365 break;
10366 }
10367 } else {
10368 con_sap_adapter = adapter;
10369 break;
10370 }
10371 }
10372 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10373 adapterNode = pNext;
10374 }
10375
10376 return con_sap_adapter;
10377}
10378
10379#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010380static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010381{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010382 return adapter->device_mode == QDF_STA_MODE ||
10383 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010384}
10385
Jeff Johnson9d295242017-08-29 14:39:48 -070010386static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010387{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010388 return adapter->device_mode == QDF_SAP_MODE ||
10389 adapter->device_mode == QDF_P2P_GO_MODE;
10390}
10391
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010392static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010393{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010394 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010395 hdd_adapter_list_node_t *node;
10396
10397 status = hdd_get_front_adapter(hdd_ctx, &node);
10398 while (QDF_IS_STATUS_SUCCESS(status) && node) {
Jeff Johnson9d295242017-08-29 14:39:48 -070010399 struct hdd_adapter *adapter = node->pAdapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010400
10401 if (adapter &&
10402 hdd_adapter_is_sta(adapter) &&
10403 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10404 conn_info.connState == eConnectionState_Associated) {
10405 return true;
10406 }
10407
10408 if (adapter &&
10409 hdd_adapter_is_ap(adapter) &&
10410 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10411 return true;
10412 }
10413
10414 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10415 }
10416
10417 return false;
10418}
10419
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010420static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010421{
10422 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010423
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010424 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010425 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010426 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010427
Dustin Brown5ec6b552017-03-31 12:11:40 -070010428 return is_running;
10429}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010430
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010431static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010432{
10433 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10434 hdd_ctx->bus_bw_timer_running = true;
10435 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10436 hdd_ctx->config->busBandwidthComputeInterval);
10437 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10438}
10439
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010440void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010441{
10442 ENTER();
10443
10444 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10445 hdd_debug("Bandwidth compute timer already started");
10446 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010447 }
10448
Dustin Brown5ec6b552017-03-31 12:11:40 -070010449 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10450
10451 EXIT();
10452}
10453
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010454void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010455{
10456 ENTER();
10457
10458 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10459 hdd_debug("Bandwidth compute timer already started");
10460 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010461 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010462
10463 if (hdd_any_adapter_is_assoc(hdd_ctx))
10464 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10465
10466 EXIT();
10467}
10468
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010469static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010470{
10471 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10472
10473 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10474 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10475 hdd_ctx->bus_bw_timer_running = false;
10476 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10477
10478 hdd_reset_tcp_delack(hdd_ctx);
10479}
10480
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010481void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010482{
10483 ENTER();
10484
10485 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10486 hdd_debug("Bandwidth compute timer already stopped");
10487 return;
10488 }
10489
10490 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10491
10492 EXIT();
10493}
10494
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010495void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010496{
10497 ENTER();
10498
10499 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10500 hdd_debug("Bandwidth compute timer already stopped");
10501 return;
10502 }
10503
10504 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10505 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10506
10507 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010508}
10509#endif
10510
10511/**
10512 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10513 * and sta's operating channel.
10514 * @sta_adapter: Describe the first argument to foobar.
10515 * @ap_adapter: Describe the second argument to foobar.
10516 * @roam_profile: Roam profile of AP to which STA wants to connect.
10517 * @concurrent_chnl_same: If both SAP and STA channels are same then
10518 * set this flag to true else false.
10519 *
10520 * This function checks the sap's operating channel and sta's operating channel.
10521 * if both are same then it will return false else it will restart the sap in
10522 * sta's channel and return true.
10523 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010524 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010525 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010526QDF_STATUS wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
10527 struct hdd_adapter *ap_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010528 tCsrRoamProfile *roam_profile,
10529 tScanResultHandle *scan_cache,
10530 bool *concurrent_chnl_same)
10531{
Jeff Johnson87251032017-08-29 13:31:11 -070010532 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010533 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010534 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010535 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010536 *concurrent_chnl_same = true;
10537
10538 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10539 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010540 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010541 scan_cache,
10542 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010543 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010544 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010545 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10546 if (hdd_ap_ctx->operatingChannel != channel_id) {
10547 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010548 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010549 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010550 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10552 if (hdd_ap_ctx->operatingChannel != channel_id) {
10553 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010554 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010555 }
10556 }
10557 } else {
10558 /*
10559 * Lets handle worst case scenario here, Scan cache lookup is
10560 * failed so we have to stop the SAP to avoid any channel
10561 * discrepancy between SAP's channel and STA's channel.
10562 * Return the status as failure so caller function could know
10563 * that scan look up is failed.
10564 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010565 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010566 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010567 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010568 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010569}
10570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571/**
10572 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10573 * @ap_adapter: SAP adapter
10574 *
10575 * This function will process the stopping of sap adapter.
10576 *
10577 * Return: None
10578 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010579void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010580{
Jeff Johnson87251032017-08-29 13:31:11 -070010581 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010582 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010583 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010584 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010585
10586 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010587 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010588 return;
10589 }
10590
10591 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10592 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010593 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010594 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010595
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010596 mutex_lock(&hdd_ctx->sap_lock);
10597 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010598 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010599 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10600 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010601 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010602 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010603 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010604 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010605 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010606 qdf_stop_bss_event,
10607 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010608 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010609 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010610 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010611 return;
10612 }
10613 }
10614 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010615 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10616 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010617 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010618 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010619 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010620 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010621 }
10622 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010623}
10624
10625/**
10626 * wlan_hdd_start_sap() - this function starts bss of SAP.
10627 * @ap_adapter: SAP adapter
10628 *
10629 * This function will process the starting of sap adapter.
10630 *
10631 * Return: None
10632 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010633void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010634{
Jeff Johnson87251032017-08-29 13:31:11 -070010635 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010636 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010637 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010638 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 tsap_Config_t *sap_config;
10640
10641 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010642 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010643 return;
10644 }
10645
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010646 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010647 hdd_err("SoftAp role has not been enabled");
10648 return;
10649 }
10650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010651 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10652 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10653 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10654 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010656 mutex_lock(&hdd_ctx->sap_lock);
10657 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10658 goto end;
10659
10660 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010661 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010662 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10663 goto end;
10664 }
10665
Wei Song2f76f642016-11-18 16:32:53 +080010666 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010667 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10668 &hdd_ap_ctx->sapConfig,
10669 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010670 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010671 goto end;
10672
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010673 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010674 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010675 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010676 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010677 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010678 goto end;
10679 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010680 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010681 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010682 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010683 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10684 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010685 ap_adapter->sessionId);
10686 hostapd_state->bCommit = true;
10687
10688end:
10689 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010690 /* SAP context and beacon cleanup will happen during driver unload
10691 * in hdd_stop_adapter
10692 */
10693 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010695}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010696
10697/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010698 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10699 * mac scan config
10700 * @status: Status of set antenna mode
10701 *
10702 * Callback on setting the dual mac configuration
10703 *
10704 * Return: None
10705 */
10706void wlan_hdd_soc_set_antenna_mode_cb(
10707 enum set_antenna_mode_status status)
10708{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010709 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010710
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010711 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010712
10713 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10714 if (0 != wlan_hdd_validate_context(hdd_ctx))
10715 return;
10716
10717 /* Signal the completion of set dual mac config */
10718 complete(&hdd_ctx->set_antenna_mode_cmpl);
10719}
10720
10721/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722 * hdd_get_fw_version() - Get FW version
10723 * @hdd_ctx: pointer to HDD context.
10724 * @major_spid: FW version - major spid.
10725 * @minor_spid: FW version - minor spid
10726 * @ssid: FW version - ssid
10727 * @crmid: FW version - crmid
10728 *
10729 * This function is called to get the firmware build version stored
10730 * as part of the HDD context
10731 *
10732 * Return: None
10733 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010734void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010735 uint32_t *major_spid, uint32_t *minor_spid,
10736 uint32_t *siid, uint32_t *crmid)
10737{
10738 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10739 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10740 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10741 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10742}
10743
10744#ifdef QCA_CONFIG_SMP
10745/**
10746 * wlan_hdd_get_cpu() - get cpu_index
10747 *
10748 * Return: cpu_index
10749 */
10750int wlan_hdd_get_cpu(void)
10751{
10752 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754 put_cpu();
10755 return cpu_index;
10756}
10757#endif
10758
10759/**
10760 * hdd_get_fwpath() - get framework path
10761 *
10762 * This function is used to get the string written by
10763 * userspace to start the wlan driver
10764 *
10765 * Return: string
10766 */
10767const char *hdd_get_fwpath(void)
10768{
10769 return fwpath.string;
10770}
10771
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010772static int hdd_qdf_print_init(void)
10773{
10774 int qdf_print_idx;
10775 QDF_STATUS status;
10776
10777 status = qdf_print_setup();
10778 if (status != QDF_STATUS_SUCCESS) {
10779 pr_err("qdf_print_setup failed\n");
10780 return -EINVAL;
10781 }
10782
10783 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
10784
10785 if (qdf_print_idx < 0) {
10786 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
10787 qdf_print_idx);
10788 return -EINVAL;
10789 }
10790
10791 qdf_set_pidx(qdf_print_idx);
10792
10793 return 0;
10794}
10795
10796static void hdd_qdf_print_deinit(void)
10797{
10798 int qdf_print_idx;
10799
10800 qdf_print_idx = qdf_get_pidx();
10801 qdf_print_ctrl_cleanup(qdf_print_idx);
10802}
10803
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010804/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010805 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010806 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010807 * This function initilizes CDS global context with the help of cds_init. This
10808 * has to be the first function called after probe to get a valid global
10809 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010810 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010811 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010812 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010813int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010814{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010815 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010816 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010817
Houston Hoffman9e06e542016-12-12 12:06:26 -080010818 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010819#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10820 wlan_logging_sock_init_svc();
10821#endif
10822
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010823 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010824 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010825 ret = -ENOMEM;
10826 goto err_out;
10827 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010828
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010829 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010830 hdd_qdf_print_init();
10831
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010832 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010833
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010834err_out:
10835 return ret;
10836}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010837
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010838/**
10839 * hdd_deinit() - Deinitialize Driver
10840 *
10841 * This function frees CDS global context with the help of cds_deinit. This
10842 * has to be the last function call in remove callback to free the global
10843 * context.
10844 */
10845void hdd_deinit(void)
10846{
Dustin Brownedce4a52017-05-10 11:59:15 -070010847 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010848 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010849
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070010850 hdd_qdf_print_deinit();
10851
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010852#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10853 wlan_logging_sock_deinit_svc();
10854#endif
10855}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010856
Yue Ma6e7b1a02017-04-03 14:17:46 -070010857#ifdef QCA_WIFI_NAPIER_EMULATION
10858#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10859#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010860#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010861#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010862
Sachin Ahujadddd2632017-03-07 19:07:24 +053010863static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10864 struct file *file)
10865{
10866 return 0;
10867}
10868
10869static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10870 const char __user *user_buf,
10871 size_t count,
10872 loff_t *f_pos)
10873{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010874 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010875 static const char wlan_off_str[] = "OFF";
10876 static const char wlan_on_str[] = "ON";
10877 int ret;
10878 unsigned long rc;
10879
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010880 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010881 pr_err("Failed to read buffer\n");
10882 return -EINVAL;
10883 }
10884
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010885 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010886 pr_debug("Wifi turning off from UI\n");
10887 goto exit;
10888 }
10889
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010890 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010891 pr_err("Invalid value received from framework");
10892 goto exit;
10893 }
10894
10895 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010896 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010897 rc = wait_for_completion_timeout(&wlan_start_comp,
10898 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10899 if (!rc) {
10900 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10901 ret = -EINVAL;
10902 hdd_start_complete(ret);
10903 return ret;
10904 }
10905
10906 hdd_start_complete(0);
10907 }
10908
10909exit:
10910 return count;
10911}
10912
10913
10914const struct file_operations wlan_hdd_state_fops = {
10915 .owner = THIS_MODULE,
10916 .open = wlan_hdd_state_ctrl_param_open,
10917 .write = wlan_hdd_state_ctrl_param_write,
10918};
10919
10920static int wlan_hdd_state_ctrl_param_create(void)
10921{
10922 unsigned int wlan_hdd_state_major = 0;
10923 int ret;
10924 struct device *dev;
10925
10926 device = MKDEV(wlan_hdd_state_major, 0);
10927
10928 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10929 if (ret) {
10930 pr_err("Failed to register qcwlanstate");
10931 goto dev_alloc_err;
10932 }
10933 wlan_hdd_state_major = MAJOR(device);
10934
10935 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10936 if (IS_ERR(class)) {
10937 pr_err("wlan_hdd_state class_create error");
10938 goto class_err;
10939 }
10940
10941 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10942 if (IS_ERR(dev)) {
10943 pr_err("wlan_hdd_statedevice_create error");
10944 goto err_class_destroy;
10945 }
10946
10947 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10948 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10949 if (ret) {
10950 pr_err("Failed to add cdev error");
10951 goto cdev_add_err;
10952 }
10953
10954 pr_info("wlan_hdd_state %s major(%d) initialized",
10955 WLAN_MODULE_NAME, wlan_hdd_state_major);
10956
10957 return 0;
10958
10959cdev_add_err:
10960 device_destroy(class, device);
10961err_class_destroy:
10962 class_destroy(class);
10963class_err:
10964 unregister_chrdev_region(device, dev_num);
10965dev_alloc_err:
10966 return -ENODEV;
10967}
10968
10969static void wlan_hdd_state_ctrl_param_destroy(void)
10970{
10971 cdev_del(&wlan_hdd_state_cdev);
10972 device_destroy(class, device);
10973 class_destroy(class);
10974 unregister_chrdev_region(device, dev_num);
10975
10976 pr_info("Device node unregistered");
10977}
10978
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010979/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053010980 * component_init - API to init cld component's
10981 *
10982 * Return: None
10983 */
10984static void component_init(void)
10985{
10986 pmo_init();
10987}
10988
10989/**
10990 * component_deinit - API to deinit cld component's
10991 *
10992 * Return: None
10993 */
10994static void component_deinit(void)
10995{
10996 pmo_deinit();
10997}
10998
10999/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011000 * __hdd_module_init - Module init helper
11001 *
11002 * Module init helper function used by both module and static driver.
11003 *
11004 * Return: 0 for success, errno on failure
11005 */
11006static int __hdd_module_init(void)
11007{
11008 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011009
Dustin Brownab482ac2017-06-09 17:00:44 -070011010 pr_err("%s: Loading driver v%s (%s)%s\n",
11011 WLAN_MODULE_NAME,
11012 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070011013 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070011014 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011015
Sachin Ahujadddd2632017-03-07 19:07:24 +053011016 ret = wlan_hdd_state_ctrl_param_create();
11017 if (ret) {
11018 pr_err("wlan_hdd_state_create:%x\n", ret);
11019 goto err_dev_state;
11020 }
11021
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011022 pld_init();
11023
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011024 ret = hdd_init();
11025 if (ret) {
11026 pr_err("hdd_init failed %x\n", ret);
11027 goto err_hdd_init;
11028 }
11029
Rajeev Kumar97767a02016-11-30 11:20:40 -080011030 dispatcher_init();
11031
Mukul Sharmad75a6672017-06-22 15:40:53 +053011032 /* Ensure to call post objmgr init */
11033 component_init();
11034
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011035 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011036
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011037 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011038
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011039 ret = wlan_hdd_register_driver();
11040 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011041 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11042 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011043 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011044 }
11045
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011046 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011047
11048 return 0;
11049out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011050 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080011051 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011052 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011053
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011054err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011055 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011056 wlan_hdd_state_ctrl_param_destroy();
11057err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011058 return ret;
11059}
11060
11061/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011062 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
11063 *
11064 * Block the unloading of the driver until the cds recovery is completed
11065 *
11066 * Return: None
11067 */
11068static void hdd_wait_for_recovery_completion(void)
11069{
11070 int retry = 0;
11071
11072 /* Wait for recovery to complete */
11073 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011074 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011075 msleep(1000);
11076 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011077 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011078 QDF_BUG(0);
11079 }
11080 }
11081}
11082
11083/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011084 * __hdd_module_exit - Module exit helper
11085 *
11086 * Module exit helper function used by both module and static driver.
11087 */
11088static void __hdd_module_exit(void)
11089{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011090
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011091 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11092 QWLAN_VERSIONSTR);
11093
bings6028ee82017-03-29 07:51:40 +080011094 cds_set_unload_in_progress(true);
11095
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011096 hdd_wait_for_recovery_completion();
11097
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011098 wlan_hdd_unregister_driver();
11099
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011100 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011101
Mukul Sharmad75a6672017-06-22 15:40:53 +053011102 /* Ensure to call prior to objmgr deinit */
11103 component_deinit();
11104
Rajeev Kumar97767a02016-11-30 11:20:40 -080011105 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011106 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011107 pld_deinit();
11108
Sachin Ahujadddd2632017-03-07 19:07:24 +053011109 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011110}
11111
Arun Khandavallifae92942016-08-01 13:31:08 +053011112#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011113/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011114 * wlan_boot_cb() - Wlan boot callback
11115 * @kobj: object whose directory we're creating the link in.
11116 * @attr: attribute the user is interacting with
11117 * @buff: the buffer containing the user data
11118 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011119 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011120 * This callback is invoked when the fs is ready to start the
11121 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011122 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011123 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011124 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011125static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011126 struct kobj_attribute *attr,
11127 const char *buf,
11128 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011129{
Arun Khandavallifae92942016-08-01 13:31:08 +053011130
Arun Khandavallifae92942016-08-01 13:31:08 +053011131 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011132 pr_err("%s: wlan driver already initialized\n", __func__);
11133 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011134 }
11135
Arun Khandavallifae92942016-08-01 13:31:08 +053011136 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011137 pr_err("%s: wlan driver initialization failed\n", __func__);
11138 return -EIO;
11139 }
11140
11141 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011142
11143 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011144}
Arun Khandavallifae92942016-08-01 13:31:08 +053011145
11146/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011147 * hdd_sysfs_cleanup() - cleanup sysfs
11148 *
11149 * Return: None
11150 *
11151 */
11152static void hdd_sysfs_cleanup(void)
11153{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011154 /* remove from group */
11155 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11156 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11157 wlan_loader->attr_group);
11158
11159 /* unlink the object from parent */
11160 kobject_del(wlan_loader->boot_wlan_obj);
11161
11162 /* free the object */
11163 kobject_put(wlan_loader->boot_wlan_obj);
11164
11165 kfree(wlan_loader->attr_group);
11166 kfree(wlan_loader);
11167
11168 wlan_loader = NULL;
11169}
11170
11171/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011172 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11173 * ready
11174 *
11175 * This is creates the syfs entry boot_wlan. Which shall be invoked
11176 * when the filesystem is ready.
11177 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011178 * QDF API cannot be used here since this function is called even before
11179 * initializing WLAN driver.
11180 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011181 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011182 */
11183static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011184{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011185 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011186
11187 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011188 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011189 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011190
11191 wlan_loader->boot_wlan_obj = NULL;
11192 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11193 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011194 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011195 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011196
11197 wlan_loader->loaded_state = 0;
11198 wlan_loader->attr_group->attrs = attrs;
11199
11200 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11201 kernel_kobj);
11202 if (!wlan_loader->boot_wlan_obj) {
11203 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011204 goto error_return;
11205 }
11206
11207 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11208 wlan_loader->attr_group);
11209 if (ret) {
11210 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11211 goto error_return;
11212 }
11213
11214 return 0;
11215
11216error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011217 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011218
11219 return ret;
11220}
11221
11222/**
11223 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11224 *
11225 * Return: 0 on success or errno on failure
11226 */
11227static int wlan_deinit_sysfs(void)
11228{
Arun Khandavallifae92942016-08-01 13:31:08 +053011229 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011230 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011231 return -EINVAL;
11232 }
11233
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011234 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011235 return 0;
11236}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011237
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011238#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011239
11240#ifdef MODULE
11241/**
11242 * __hdd_module_init - Module init helper
11243 *
11244 * Module init helper function used by both module and static driver.
11245 *
11246 * Return: 0 for success, errno on failure
11247 */
11248static int hdd_module_init(void)
11249{
Arun Khandavallifae92942016-08-01 13:31:08 +053011250 if (__hdd_module_init()) {
11251 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011252 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011253 }
11254
Dustin Brownab482ac2017-06-09 17:00:44 -070011255 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011256}
11257#else
11258static int __init hdd_module_init(void)
11259{
11260 int ret = -EINVAL;
11261
11262 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011263 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011264 pr_err("Failed to create sysfs entry for loading wlan");
11265
11266 return ret;
11267}
11268#endif
11269
11270
11271#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011272/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011273 * hdd_module_exit() - Exit function
11274 *
11275 * This is the driver exit point (invoked when module is unloaded using rmmod)
11276 *
11277 * Return: None
11278 */
11279static void __exit hdd_module_exit(void)
11280{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011281 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011282}
Arun Khandavallifae92942016-08-01 13:31:08 +053011283#else
11284static void __exit hdd_module_exit(void)
11285{
11286 __hdd_module_exit();
11287 wlan_deinit_sysfs();
11288}
11289#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011290
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011291static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11292{
11293 return param_set_copystring(kmessage, kp);
11294}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011295
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011296/**
11297 * is_con_mode_valid() check con mode is valid or not
11298 * @mode: global con mode
11299 *
11300 * Return: TRUE on success FALSE on failure
11301 */
11302static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11303{
11304 switch (mode) {
11305 case QDF_GLOBAL_MONITOR_MODE:
11306 case QDF_GLOBAL_FTM_MODE:
11307 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011308 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011309 return true;
11310 default:
11311 return false;
11312 }
11313}
11314
11315/**
11316 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11317 * @mode: global con mode
11318 *
11319 * Return: adapter mode
11320 */
11321static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11322 enum tQDF_GLOBAL_CON_MODE mode)
11323{
11324
11325 switch (mode) {
11326 case QDF_GLOBAL_MISSION_MODE:
11327 return QDF_STA_MODE;
11328 case QDF_GLOBAL_MONITOR_MODE:
11329 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011330 case QDF_GLOBAL_EPPING_MODE:
11331 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011332 case QDF_GLOBAL_FTM_MODE:
11333 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011334 case QDF_GLOBAL_QVIT_MODE:
11335 return QDF_QVIT_MODE;
11336 default:
11337 return QDF_MAX_NO_OF_MODE;
11338 }
11339}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011340
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011341static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011342 enum tQDF_GLOBAL_CON_MODE curr_mode)
11343{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011344 int driver_status;
11345
11346 driver_status = hdd_ctx->driver_status;
11347
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011348 switch (curr_mode) {
11349 case QDF_GLOBAL_MISSION_MODE:
11350 case QDF_GLOBAL_MONITOR_MODE:
11351 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011352 if (driver_status != DRIVER_MODULES_CLOSED) {
11353 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11354 hdd_stop_all_adapters(hdd_ctx);
11355 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011356 hdd_deinit_all_adapters(hdd_ctx, false);
11357 hdd_close_all_adapters(hdd_ctx, false);
11358 break;
11359 case QDF_GLOBAL_EPPING_MODE:
11360 epping_disable();
11361 epping_close();
11362 break;
11363 default:
11364 return;
11365 }
11366}
11367
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011368static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011369 enum tQDF_GLOBAL_CON_MODE mode)
11370{
Jeff Johnson9d295242017-08-29 14:39:48 -070011371 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011372 int ret = 0;
11373 bool rtnl_held;
11374 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11375 QDF_STATUS status;
11376
11377 if (!qdf_dev) {
11378 hdd_err("qdf device context is Null return!");
11379 return -EINVAL;
11380 }
11381
11382 rtnl_held = hdd_hold_rtnl_lock();
11383 switch (mode) {
11384 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011385 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11386 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011387 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011388 break;
11389 case QDF_GLOBAL_FTM_MODE:
11390 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11391 wlan_hdd_get_intf_addr(hdd_ctx),
11392 NET_NAME_UNKNOWN, rtnl_held);
11393 if (adapter == NULL)
11394 ret = -EINVAL;
11395 break;
11396 case QDF_GLOBAL_MONITOR_MODE:
11397 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11398 wlan_hdd_get_intf_addr(hdd_ctx),
11399 NET_NAME_UNKNOWN, rtnl_held);
11400 if (adapter == NULL)
11401 ret = -EINVAL;
11402 break;
11403 case QDF_GLOBAL_EPPING_MODE:
11404 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011405 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011406 hdd_err("Failed to open in eeping mode: %d", status);
11407 ret = -EINVAL;
11408 break;
11409 }
11410 ret = epping_enable(qdf_dev->dev);
11411 if (ret) {
11412 hdd_err("Failed to enable in epping mode : %d", ret);
11413 epping_close();
11414 }
11415 break;
11416 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011417 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011418 ret = -ENOTSUPP;
11419 break;
11420 }
11421 hdd_release_rtnl_lock();
11422 rtnl_held = false;
11423 return ret;
11424}
11425
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011426/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011427 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011428 * @kmessage: con mode name on which driver to be bring up
11429 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011430 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011431 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011432 * This function is invoked when user updates con mode using sys entry,
11433 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011434 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011435 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011436 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011437static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011438 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011439{
11440 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011441 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011442 enum tQDF_GLOBAL_CON_MODE curr_mode;
11443 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011444
Dustin Brownab6029b2017-05-24 13:04:19 -070011445 hdd_info("con_mode handler: %s", kmessage);
11446
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011447 ret = wlan_hdd_validate_context(hdd_ctx);
11448 if (ret)
11449 return ret;
11450
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011451 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011452
11453 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011454
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011455 if (!(is_con_mode_valid(con_mode))) {
11456 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011457 ret = -EINVAL;
11458 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011459 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011460
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011461 curr_mode = hdd_get_conparam();
11462 if (curr_mode == con_mode) {
11463 hdd_err("curr mode: %d is same as user triggered mode %d",
11464 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011465 ret = 0;
11466 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011467 }
11468
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011469 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011470 if (ret) {
11471 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011472 goto reset_flags;
11473 }
11474
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053011475 /* Cleanup present mode before switching to new mode */
11476 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
11477
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011478 hdd_set_conparam(con_mode);
11479
11480 /* Register for new con_mode & then kick_start modules again */
11481 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11482 if (ret) {
11483 hdd_err("Failed to register for new mode");
11484 goto reset_flags;
11485 }
11486
11487 adapter_mode = hdd_get_adpter_mode(con_mode);
11488 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11489 hdd_err("invalid adapter");
11490 ret = -EINVAL;
11491 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011492 }
11493
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011494 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011495 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011496 hdd_err("Failed to get adapter:%d", adapter_mode);
11497 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011498 }
11499
11500 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11501 if (ret) {
11502 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011503 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011504 }
11505
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011506 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11507 con_mode == QDF_GLOBAL_FTM_MODE) {
11508 if (hdd_start_adapter(adapter)) {
11509 hdd_err("Failed to start %s adapter", kmessage);
11510 ret = -EINVAL;
11511 goto reset_flags;
11512 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011513 }
11514
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011515 hdd_info("Mode successfully changed to %s", kmessage);
11516 ret = 0;
11517
11518reset_flags:
11519 cds_set_load_in_progress(false);
11520 return ret;
11521}
11522
11523
11524static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11525{
11526 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011527 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011528
11529 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11530 ret = wlan_hdd_validate_context(hdd_ctx);
11531 if (ret)
11532 return ret;
11533
11534 cds_ssr_protect(__func__);
11535 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11536 cds_ssr_unprotect(__func__);
11537
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011538 return ret;
11539}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011540
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011541static int con_mode_handler_ftm(const char *kmessage,
11542 struct kernel_param *kp)
11543{
11544 int ret;
11545
11546 ret = param_set_int(kmessage, kp);
11547
11548 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11549 pr_err("Only FTM mode supported!");
11550 return -ENOTSUPP;
11551 }
11552
11553 hdd_set_conparam(con_mode_ftm);
11554 con_mode = con_mode_ftm;
11555
11556 return ret;
11557}
11558
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011559/**
11560 * hdd_get_conparam() - driver exit point
11561 *
11562 * This is the driver exit point (invoked when module is unloaded using rmmod)
11563 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011564 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011565 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011566enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011567{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011568 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011569}
11570
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011571void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011572{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011573 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011574}
11575
Komal Seelamc11bb222016-01-27 18:57:10 +053011576/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011577 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11578 * @hdd_ctx: HDD context
11579 *
11580 * Cleans up the pre cac interface, if it exists
11581 *
11582 * Return: None
11583 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011584void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011585{
11586 uint8_t session_id;
11587 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070011588 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011589
11590 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11591 if (QDF_IS_STATUS_ERROR(status)) {
11592 hdd_err("failed to get pre cac vdev id");
11593 return;
11594 }
11595
11596 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11597 if (!precac_adapter) {
11598 hdd_err("invalid pre cac adapater");
11599 return;
11600 }
11601
11602 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11603 wlan_hdd_sap_pre_cac_failure,
11604 (void *)precac_adapter);
11605 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11606
11607}
11608
11609/**
Komal Seelamec702b02016-02-24 18:42:16 +053011610 * hdd_update_ol_config - API to update ol configuration parameters
11611 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011612 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011613 * Return: void
11614 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011615static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011616{
Komal Seelamec702b02016-02-24 18:42:16 +053011617 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011618 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011619
Komal Seelamec702b02016-02-24 18:42:16 +053011620 if (!ol_ctx)
11621 return;
11622
11623 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11624 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11625 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11626 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011627 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011628
11629 ol_init_ini_config(ol_ctx, &cfg);
11630}
11631
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011632#ifdef FEATURE_RUNTIME_PM
11633/**
11634 * hdd_populate_runtime_cfg() - populate runtime configuration
11635 * @hdd_ctx: hdd context
11636 * @cfg: pointer to the configuration memory being populated
11637 *
11638 * Return: void
11639 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011640static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011641 struct hif_config_info *cfg)
11642{
11643 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11644 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11645}
11646#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011647static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011648 struct hif_config_info *cfg)
11649{
11650}
11651#endif
11652
Komal Seelamec702b02016-02-24 18:42:16 +053011653/**
11654 * hdd_update_hif_config - API to update HIF configuration parameters
11655 * @hdd_ctx: HDD Context
11656 *
11657 * Return: void
11658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011659static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011660{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011661 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011662 struct hif_config_info cfg;
11663
11664 if (!scn)
11665 return;
11666
11667 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011668 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011669 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070011670
11671 if (hdd_ctx->config->prevent_link_down)
11672 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053011673}
11674
11675/**
11676 * hdd_update_config() - Initialize driver per module ini parameters
11677 * @hdd_ctx: HDD Context
11678 *
11679 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011680 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011682int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011683{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011684 int ret;
11685
Komal Seelamec702b02016-02-24 18:42:16 +053011686 hdd_update_ol_config(hdd_ctx);
11687 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011688 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11689 ret = hdd_update_cds_config_ftm(hdd_ctx);
11690 else
11691 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011692 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011693
11694 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011695}
11696
Mukul Sharma9d797a02017-01-05 20:26:03 +053011697#ifdef FEATURE_WLAN_RA_FILTERING
11698/**
11699 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11700 * @psoc_cfg: pmo psoc Configuration
11701 * @hdd_ctx: Pointer to hdd context
11702 *
11703 * Return: none
11704 */
11705static inline void hdd_ra_populate_pmo_config(
11706 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011707 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011708{
11709 psoc_cfg->ra_ratelimit_interval =
11710 hdd_ctx->config->RArateLimitInterval;
11711 psoc_cfg->ra_ratelimit_enable =
11712 hdd_ctx->config->IsRArateLimitEnabled;
11713}
11714#else
11715static inline void hdd_ra_populate_pmo_config(
11716 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011717 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011718{
11719}
11720#endif
11721/**
11722 * hdd_update_pmo_config - API to update pmo configuration parameters
11723 * @hdd_ctx: HDD context
11724 *
11725 * Return: void
11726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011727static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011728{
11729 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11730 struct pmo_psoc_cfg psoc_cfg;
11731 QDF_STATUS status;
11732
11733 /*
11734 * Value of hdd_ctx->wowEnable can be,
11735 * 0 - Disable both magic pattern match and pattern byte match.
11736 * 1 - Enable magic pattern match on all interfaces.
11737 * 2 - Enable pattern byte match on all interfaces.
11738 * 3 - Enable both magic patter and pattern byte match on
11739 * all interfaces.
11740 */
11741 psoc_cfg.magic_ptrn_enable =
11742 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11743 psoc_cfg.ptrn_match_enable_all_vdev =
11744 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11745 psoc_cfg.bpf_enable =
11746 hdd_ctx->config->bpf_packet_filter_enable;
11747 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011748 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011749 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11750 if (hdd_ctx->config->fhostNSOffload)
11751 psoc_cfg.ns_offload_enable_dynamic = true;
11752 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11753 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11754 psoc_cfg.active_mode_offload =
11755 hdd_ctx->config->active_mode_offload;
11756 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11757 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011758 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11759 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11760 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11761 psoc_cfg.power_save_mode =
11762 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011763 psoc_cfg.auto_power_save_fail_mode =
11764 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011765
11766 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011767 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11768 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011769 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11770 if (status != QDF_STATUS_SUCCESS) {
11771 hdd_err("failed pmo psoc configuration");
11772 return -EINVAL;
11773 }
11774
11775 return 0;
11776}
11777
Abhishek Singhb20db962017-03-03 21:28:46 +053011778#ifdef FEATURE_WLAN_SCAN_PNO
11779static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11780 struct hdd_config *cfg)
11781{
11782 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11783 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11784 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11785 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11786 pno_cfg->channel_prediction_full_scan =
11787 cfg->channel_prediction_full_scan;
11788}
11789#else
11790static inline void
11791hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11792 struct hdd_config *cfg)
11793{
11794 return;
11795}
11796#endif
11797
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011798void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
11799 struct hdd_config *cfg)
11800{
11801 uint8_t i = 0;
11802
11803 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
11804 if (!ie_whitelist->white_list)
11805 return;
11806
11807 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
11808 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
11809 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
11810 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
11811 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
11812 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
11813 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
11814 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
11815
11816 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
11817 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
11818 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
11819}
11820
Abhishek Singh257a9482017-03-06 16:52:39 +053011821/**
11822 * hdd_update_scan_config - API to update scan configuration parameters
11823 * @hdd_ctx: HDD context
11824 *
11825 * Return: 0 if success else err
11826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011827static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053011828{
11829 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11830 struct scan_user_cfg scan_cfg;
11831 struct hdd_config *cfg = hdd_ctx->config;
11832 QDF_STATUS status;
11833
11834 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11835 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11836 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11837 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11838 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11839 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11840 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011841 /* convert to ms */
11842 scan_cfg.scan_cache_aging_time =
11843 cfg->scanAgingTimeout * 1000;
11844 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11845 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11846 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11847 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011848 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011849 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011850
Abhishek Singhb20db962017-03-03 21:28:46 +053011851 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053011852 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053011853
Abhishek Singh257a9482017-03-06 16:52:39 +053011854 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11855 if (status != QDF_STATUS_SUCCESS) {
11856 hdd_err("failed pmo psoc configuration");
11857 return -EINVAL;
11858 }
11859
11860 return 0;
11861}
Abhishek Singh257a9482017-03-06 16:52:39 +053011862
Frank Liud4b2fa02017-03-29 11:46:48 +080011863#ifdef CONVERGED_TDLS_ENABLE
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011864static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080011865{
11866 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11867 struct tdls_start_params tdls_cfg;
11868 struct tdls_user_config *config = &tdls_cfg.config;
11869 struct hdd_config *cfg = hdd_ctx->config;
11870 QDF_STATUS status;
11871
11872 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11873 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11874 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11875 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11876 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11877 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11878 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11879 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11880 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11881 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11882 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11883 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11884 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11885 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11886 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11887 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11888 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11889 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11890 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11891 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11892 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11893 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11894 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11895 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11896 (cfg->fEnableTDLSImplicitTrigger ?
11897 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11898 (cfg->fTDLSExternalControl ?
11899 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11900
11901 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11902 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11903 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11904 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011905 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011906 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011907 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11908 tdls_cfg.tdls_evt_cb_data = psoc;
11909 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11910 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11911 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011912 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11913 tdls_cfg.tdls_wmm_cb_data = psoc;
11914 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11915 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011916 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011917
11918 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11919 if (status != QDF_STATUS_SUCCESS) {
11920 hdd_err("failed pmo psoc configuration");
11921 return -EINVAL;
11922 }
11923
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011924 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011925 /* disable napier specific tdls data path */
11926 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011927
Frank Liud4b2fa02017-03-29 11:46:48 +080011928 return 0;
11929}
11930#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011931static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
Frank Liud4b2fa02017-03-29 11:46:48 +080011932{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011933 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011934 /* disable napier specific tdls data path */
11935 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080011936 return 0;
11937}
11938#endif
11939
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011940int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053011941{
11942 int ret;
11943
11944 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053011945 if (ret)
11946 return ret;
11947 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080011948 if (ret)
11949 return ret;
11950 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011951
11952 return ret;
11953}
11954
Agrawal Ashish65634612016-08-18 13:24:32 +053011955/**
11956 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
11957 * @mode : cfg80211 DFS mode
11958 *
11959 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
11960 */
11961enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
11962{
11963 switch (mode) {
11964 case DFS_MODE_ENABLE:
11965 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011966 case DFS_MODE_DISABLE:
11967 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011968 case DFS_MODE_DEPRIORITIZE:
11969 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011970 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011971 hdd_debug("ACS dfs mode is NONE");
11972 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011973 }
11974}
11975
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011976/**
11977 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
11978 * @hddctx: pointer to hdd context
11979 * @set_value: enable/disable
11980 *
11981 * When Host sends vendor command enable, FW will send *ONE* CA ind to
11982 * Host(even though it is duplicate). When Host send vendor command
11983 * disable,FW doesn't perform any action. Whenever any change in
11984 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
11985 *
11986 * return - 0 on success, appropriate error values on failure.
11987 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011988int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011989{
11990 QDF_STATUS status;
11991
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011992 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011993 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011994
11995 if (!hddctx->config->goptimize_chan_avoid_event) {
11996 hdd_warn("goptimize_chan_avoid_event ini param disabled");
11997 return -EINVAL;
11998 }
11999
12000 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12001 if (!QDF_IS_STATUS_SUCCESS(status)) {
12002 hdd_err("Failed to send chan avoid command to SME");
12003 return -EINVAL;
12004 }
12005 return 0;
12006}
Agrawal Ashish65634612016-08-18 13:24:32 +053012007
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012008/**
12009 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12010 * @value: value to set
12011 *
12012 * This function will set the passed value to roaming in progress flag.
12013 *
12014 * Return: None
12015 */
12016void hdd_set_roaming_in_progress(bool value)
12017{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012018 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012019
12020 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12021 if (!hdd_ctx) {
12022 hdd_err("HDD context is NULL");
12023 return;
12024 }
12025
12026 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012027 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012028}
12029
12030/**
12031 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012032 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012033 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012034 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012035 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012036bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012037{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012038 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012039 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012040
12041 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12042 if (!hdd_ctx) {
12043 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012044 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012045 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012046 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12047 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012048 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12049 hdd_ctx->roaming_in_progress);
12050
12051 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012052}
12053
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012054/**
12055 * hdd_is_connection_in_progress() - check if connection is in
12056 * progress
12057 * @session_id: session id
12058 * @reason: scan reject reason
12059 *
12060 * Go through each adapter and check if Connection is in progress
12061 *
12062 * Return: true if connection is in progress else false
12063 */
12064bool hdd_is_connection_in_progress(uint8_t *session_id,
12065 enum scan_reject_states *reason)
12066{
12067 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012068 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012069 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012070 QDF_STATUS status = 0;
12071 uint8_t sta_id = 0;
12072 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012073 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012074
12075 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12076 if (!hdd_ctx) {
12077 hdd_err("HDD context is NULL");
12078 return false;
12079 }
12080
12081 if (true == hdd_ctx->btCoexModeSet) {
12082 hdd_info("BTCoex Mode operation in progress");
12083 return true;
12084 }
12085 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
12086 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
12087 adapter = adapter_node->pAdapter;
12088 if (!adapter)
12089 goto end;
12090
12091 hdd_info("Adapter with device mode %s(%d) exists",
12092 hdd_device_mode_to_string(adapter->device_mode),
12093 adapter->device_mode);
12094 if (((QDF_STA_MODE == adapter->device_mode)
12095 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12096 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12097 && (eConnectionState_Connecting ==
12098 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12099 conn_info.connState)) {
12100 hdd_err("%p(%d) Connection is in progress",
12101 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12102 adapter->sessionId);
12103 if (session_id && reason) {
12104 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012105 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012106 }
12107 return true;
12108 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012109 /*
12110 * sme_neighbor_middle_of_roaming is for LFR2
12111 * hdd_is_roaming_in_progress is for LFR3
12112 */
12113 if (((QDF_STA_MODE == adapter->device_mode) &&
12114 sme_neighbor_middle_of_roaming(
12115 WLAN_HDD_GET_HAL_CTX(adapter),
12116 adapter->sessionId)) ||
12117 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012118 hdd_err("%p(%d) Reassociation in progress",
12119 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
12120 adapter->sessionId);
12121 if (session_id && reason) {
12122 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012123 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012124 }
12125 return true;
12126 }
12127 if ((QDF_STA_MODE == adapter->device_mode) ||
12128 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12129 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12130 hdd_sta_ctx =
12131 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12132 if ((eConnectionState_Associated ==
12133 hdd_sta_ctx->conn_info.connState)
12134 && (false ==
12135 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12136 sta_mac = (uint8_t *)
12137 &(adapter->macAddressCurrent.bytes[0]);
12138 hdd_err("client " MAC_ADDRESS_STR
12139 " is in middle of WPS/EAPOL exchange.",
12140 MAC_ADDR_ARRAY(sta_mac));
12141 if (session_id && reason) {
12142 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012143 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012144 }
12145 return true;
12146 }
12147 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12148 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12149 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12150 sta_id++) {
12151 if (!((adapter->aStaInfo[sta_id].isUsed)
12152 && (OL_TXRX_PEER_STATE_CONN ==
12153 adapter->aStaInfo[sta_id].tlSTAState)))
12154 continue;
12155
12156 sta_mac = (uint8_t *)
12157 &(adapter->aStaInfo[sta_id].
12158 macAddrSTA.bytes[0]);
12159 hdd_err("client " MAC_ADDRESS_STR
12160 " of SAP/GO is in middle of WPS/EAPOL exchange",
12161 MAC_ADDR_ARRAY(sta_mac));
12162 if (session_id && reason) {
12163 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012164 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012165 }
12166 return true;
12167 }
12168 if (hdd_ctx->connection_in_progress) {
12169 hdd_err("AP/GO: connection is in progress");
12170 return true;
12171 }
12172 }
12173end:
12174 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12175 adapter_node = next;
12176 }
12177 return false;
12178}
12179
12180/**
12181 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012182 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012183 *
12184 * Return: None
12185 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012186void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012187{
Jeff Johnson87251032017-08-29 13:31:11 -070012188 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012189 hdd_hostapd_state_t *hostapd_state;
12190 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012191 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012192 tsap_Config_t *sap_config;
12193 void *sap_ctx;
12194
12195 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12196 sap_config = &hdd_ap_ctx->sapConfig;
12197 sap_ctx = hdd_ap_ctx->sapContext;
12198
12199 mutex_lock(&hdd_ctx->sap_lock);
12200 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12201 wlan_hdd_del_station(ap_adapter);
12202 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12203 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12204 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12205 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12206 qdf_status =
12207 qdf_wait_single_event(&hostapd_state->
12208 qdf_stop_bss_event,
12209 SME_CMD_TIMEOUT_VALUE);
12210
12211 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12212 cds_err("SAP Stop Failed");
12213 goto end;
12214 }
12215 }
12216 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012217 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012218 ap_adapter->device_mode, ap_adapter->sessionId);
12219 cds_err("SAP Stop Success");
12220
12221 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12222 cds_err("SAP Not able to set AP IEs");
12223 wlansap_reset_sap_config_add_ie(sap_config,
12224 eUPDATE_IE_ALL);
12225 goto end;
12226 }
12227
12228 qdf_event_reset(&hostapd_state->qdf_event);
12229 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12230 sap_config,
12231 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12232 cds_err("SAP Start Bss fail");
12233 wlansap_reset_sap_config_add_ie(sap_config,
12234 eUPDATE_IE_ALL);
12235 goto end;
12236 }
12237
12238 cds_info("Waiting for SAP to start");
12239 qdf_status =
12240 qdf_wait_single_event(&hostapd_state->qdf_event,
12241 SME_CMD_TIMEOUT_VALUE);
12242 wlansap_reset_sap_config_add_ie(sap_config,
12243 eUPDATE_IE_ALL);
12244 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12245 cds_err("SAP Start failed");
12246 goto end;
12247 }
12248 cds_err("SAP Start Success");
12249 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12250 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012251 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12252 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012253 ap_adapter->sessionId);
12254 hostapd_state->bCommit = true;
12255 }
12256end:
12257 mutex_unlock(&hdd_ctx->sap_lock);
12258 return;
12259}
12260
12261/**
12262 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12263 * with non dfs acs
12264 *
12265 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12266 *
12267 * Return: None
12268 */
12269void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12270{
Jeff Johnson9d295242017-08-29 14:39:48 -070012271 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012272 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012273 cds_context_type *cds_ctx;
12274
12275 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12276 if (!hdd_ctx) {
12277 cds_err("HDD context is NULL");
12278 return;
12279 }
12280
12281 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12282 if (!cds_ctx) {
12283 cds_err("Invalid CDS Context");
12284 return;
12285 }
12286
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012287 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12288 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012289 cds_info("Concurrency mode is not SAP");
12290 return;
12291 }
12292
12293 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012294 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12295 &ap_adapter->event_flags) &&
12296 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12297 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012298
12299 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12300 ap_adapter->sessionCtx.ap.sapConfig.channel =
12301 AUTO_CHANNEL_SELECT;
12302 ap_adapter->sessionCtx.ap.sapConfig.
12303 acs_cfg.acs_mode = true;
12304
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012305 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012306 }
12307}
12308
12309/**
12310 * hdd_set_connection_in_progress() - to set the connection in
12311 * progress flag
12312 * @value: value to set
12313 *
12314 * This function will set the passed value to connection in progress flag.
12315 * If value is previously being set to true then no need to set it again.
12316 *
12317 * Return: true if value is being set correctly and false otherwise.
12318 */
12319bool hdd_set_connection_in_progress(bool value)
12320{
12321 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012322 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012323
12324 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12325 if (!hdd_ctx) {
12326 cds_err("HDD context is NULL");
12327 return false;
12328 }
12329
12330 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12331 /*
12332 * if the value is set to true previously and if someone is
12333 * trying to make it true again then it could be some race
12334 * condition being triggered. Avoid this situation by returning
12335 * false
12336 */
12337 if (hdd_ctx->connection_in_progress && value)
12338 status = false;
12339 else
12340 hdd_ctx->connection_in_progress = value;
12341 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12342 return status;
12343}
12344
Jeff Johnson9d295242017-08-29 14:39:48 -070012345int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012346{
12347 if (!adapter) {
12348 hdd_err("Invalid adapter");
12349 return -EINVAL;
12350 }
12351 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012352 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012353 WMA_VDEV_MCC_SET_TIME_QUOTA,
12354 set_value, VDEV_CMD);
12355 return 0;
12356
12357}
12358
Jeff Johnson9d295242017-08-29 14:39:48 -070012359int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012360{
12361 if (!adapter) {
12362 hdd_err("Invalid adapter");
12363 return -EINVAL;
12364 }
12365
12366 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012367 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012368 WMA_VDEV_MCC_SET_TIME_LATENCY,
12369 set_value, VDEV_CMD);
12370 return 0;
12371}
12372
Jeff Johnson9d295242017-08-29 14:39:48 -070012373struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012374 *psoc, uint8_t vdev_id)
12375{
Jeff Johnson9d295242017-08-29 14:39:48 -070012376 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012377 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012378
12379 /*
12380 * Currently PSOC is not being used. But this logic will
12381 * change once we have the converged implementation of
12382 * HDD context per PSOC in place. This would break if
12383 * multiple vdev objects reuse the vdev id.
12384 */
12385 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12386 if (!adapter)
12387 hdd_err("Get adapter by vdev id failed");
12388
12389 return adapter;
12390}
12391
Jeff Johnson9d295242017-08-29 14:39:48 -070012392int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012393 int8_t *rssi, int8_t *snr)
12394{
12395 QDF_STATUS status;
12396 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12397 tCsrRoamProfile *profile = &wext_state->roamProfile;
12398
12399 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12400 profile, bssid, rssi, snr);
12401 if (QDF_STATUS_SUCCESS != status) {
12402 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12403 return -EINVAL;
12404 }
12405
12406 return 0;
12407}
12408
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012409/* Register the module init/exit functions */
12410module_init(hdd_module_init);
12411module_exit(hdd_module_exit);
12412
12413MODULE_LICENSE("Dual BSD/GPL");
12414MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12415MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012417module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12418 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012419
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012420module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12421 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012423module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12424 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12425
12426module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12427
12428module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12429
12430module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);