blob: 53219c8b576d6777422e532a3c3ac25734a5e028 [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"
Dustin Brown4bc0a622017-12-06 15:56:50 -080060#include "qdf_debug_domain.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070061#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080062#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070063#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064
65#include <net/addrconf.h>
66#include <linux/wireless.h>
67#include <net/cfg80211.h>
68#include <linux/inetdevice.h>
69#include <net/addrconf.h>
70#include "wlan_hdd_cfg80211.h"
71#include "wlan_hdd_ext_scan.h"
72#include "wlan_hdd_p2p.h"
73#include <linux/rtnetlink.h>
74#include "sap_api.h"
75#include <linux/semaphore.h>
76#include <linux/ctype.h>
77#include <linux/compat.h>
78#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <soc/qcom/subsystem_restart.h>
80#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include <wlan_hdd_hostapd.h>
82#include <wlan_hdd_softap_tx_rx.h>
83#include "cfg_api.h"
84#include "qwlan_version.h"
85#include "wma_types.h"
86#include "wlan_hdd_tdls.h"
87#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053088#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070090#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070091#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080092#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#include "wlan_hdd_nan.h"
94#include "wlan_hdd_debugfs.h"
95#include "wlan_hdd_driver_ops.h"
96#include "epping_main.h"
97#include "wlan_hdd_memdump.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053098#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099
100#include <wlan_hdd_ipa.h>
101#include "hif.h"
102#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800103#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700104#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530106#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700107#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700108#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530109#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700110#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530111#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800112#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800113#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530114#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800115#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800116#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530117#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530118#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800119#include "os_if_wifi_pos.h"
120#include "wifi_pos_api.h"
121#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800122#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700123#include "os_if_nan.h"
124#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700125#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700126#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530127#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530128#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700129#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800130#include "wlan_hdd_sysfs.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800131
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530132#ifdef CNSS_GENL
133#include <net/cnss_nl.h>
134#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800135#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800137#ifdef MODULE
138#define WLAN_MODULE_NAME module_name(THIS_MODULE)
139#else
140#define WLAN_MODULE_NAME "wlan"
141#endif
142
143#ifdef TIMER_MANAGER
144#define TIMER_MANAGER_STR " +TIMER_MANAGER"
145#else
146#define TIMER_MANAGER_STR ""
147#endif
148
149#ifdef MEMORY_DEBUG
150#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
151#else
152#define MEMORY_DEBUG_STR ""
153#endif
154
Sachin Ahujadddd2632017-03-07 19:07:24 +0530155int wlan_start_ret_val;
156static DECLARE_COMPLETION(wlan_start_comp);
157static unsigned int dev_num = 1;
158static struct cdev wlan_hdd_state_cdev;
159static struct class *class;
160static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530161#ifndef MODULE
162static struct gwlan_loader *wlan_loader;
163static ssize_t wlan_boot_cb(struct kobject *kobj,
164 struct kobj_attribute *attr,
165 const char *buf, size_t count);
166struct gwlan_loader {
167 bool loaded_state;
168 struct kobject *boot_wlan_obj;
169 struct attribute_group *attr_group;
170};
171
172static struct kobj_attribute wlan_boot_attribute =
173 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
174
175static struct attribute *attrs[] = {
176 &wlan_boot_attribute.attr,
177 NULL,
178};
179
180#define MODULE_INITIALIZED 1
181#endif
182
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530183#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
184#define MAX_OPS_NAME_STRING_SIZE 20
185
186static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800187static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530188static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800190/* the Android framework expects this param even though we don't use it */
191#define BUF_LEN 20
192static char fwpath_buffer[BUF_LEN];
193static struct kparam_string fwpath = {
194 .string = fwpath_buffer,
195 .maxlen = BUF_LEN,
196};
197
198static char *country_code;
199static int enable_11d = -1;
200static int enable_dfs_chan_scan = -1;
201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800202/*
203 * spinlock for synchronizing asynchronous request/response
204 * (full description of use in wlan_hdd_main.h)
205 */
206DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530207DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800209#define WLAN_NLINK_CESIUM 30
210
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530211static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212
213#define WOW_MAX_FILTER_LISTS 1
214#define WOW_MAX_FILTERS_PER_LIST 4
215#define WOW_MIN_PATTERN_SIZE 6
216#define WOW_MAX_PATTERN_SIZE 64
217
218#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
219static const struct wiphy_wowlan_support wowlan_support_reg_init = {
220 .flags = WIPHY_WOWLAN_ANY |
221 WIPHY_WOWLAN_MAGIC_PKT |
222 WIPHY_WOWLAN_DISCONNECT |
223 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
224 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
225 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
226 WIPHY_WOWLAN_4WAY_HANDSHAKE |
227 WIPHY_WOWLAN_RFKILL_RELEASE,
228 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
229 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
230 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
231};
232#endif
233
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700234static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
235 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
236 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
237 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
238 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
239 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
240 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
241 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
242 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
243 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
244 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
245 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
247 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
248 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
249 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
250 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
251 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700269 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700270 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700271 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700272};
273
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530274int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
275 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
276 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
277 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
278 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
279};
280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530282struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283
284struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800285#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700286static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800287#endif
288
Sachin Ahujadddd2632017-03-07 19:07:24 +0530289void hdd_start_complete(int ret)
290{
291 wlan_start_ret_val = ret;
292
293 complete(&wlan_start_comp);
294}
295
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530297 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700298 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530299 *
300 * Return: none
301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700302static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530303{
Jeff Johnson9d295242017-08-29 14:39:48 -0700304 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530305
Dustin Brown920397d2017-12-13 16:27:50 -0800306 hdd_for_each_adapter(hdd_ctx, adapter)
307 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530308}
309
310/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
312 * @vdev_id: vdev_id
313 * @action: action type
314 * @reason: reason type
315 *
316 * Return: none
317 */
318void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
319 enum netif_action_type action, enum netif_reason_type reason)
320{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700321 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700322 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323
324 if (!hdd_ctx) {
325 hdd_err("hdd ctx is NULL");
326 return;
327 }
328 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
329
330 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331}
332
333/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700334 * Store WLAN driver version and timestamp info in global variables such that
335 * crash debugger can extract them from driver debug symbol and crashdump for
336 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800337 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800338#ifdef BUILD_TAG
339uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
340#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800341uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700342#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800343
344/**
345 * hdd_device_mode_to_string() - return string conversion of device mode
346 * @device_mode: device mode
347 *
348 * This utility function helps log string conversion of device mode.
349 *
350 * Return: string conversion of device mode, if match found;
351 * "Unknown" otherwise.
352 */
353const char *hdd_device_mode_to_string(uint8_t device_mode)
354{
355 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800356 CASE_RETURN_STRING(QDF_STA_MODE);
357 CASE_RETURN_STRING(QDF_SAP_MODE);
358 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
359 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
360 CASE_RETURN_STRING(QDF_FTM_MODE);
361 CASE_RETURN_STRING(QDF_IBSS_MODE);
362 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
363 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700364 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365 default:
366 return "Unknown";
367 }
368}
369
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530370/**
371 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
372 * @adapter: HDD adapter
373 * @chan_number: Channel number
374 * @chan_bw: Bandwidth
375 *
376 * Checks if the given bandwidth is valid for the given channel number.
377 *
378 * Return: 0 for success, non-zero for failure
379 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700380int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530381 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800382 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530383{
384 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
385 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
386 bool found = false;
387 tHalHandle hal;
388
389 hal = WLAN_HDD_GET_HAL_CTX(adapter);
390 if (!hal) {
391 hdd_err("Invalid HAL context");
392 return -EINVAL;
393 }
394
395 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
396 hdd_err("No valid channel list");
397 return -EOPNOTSUPP;
398 }
399
400 for (i = 0; i < len; i++) {
401 if (chan[i] == chan_number) {
402 found = true;
403 break;
404 }
405 }
406
407 if (found == false) {
408 hdd_err("Channel not in driver's valid channel list");
409 return -EOPNOTSUPP;
410 }
411
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700412 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
413 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530414 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
415 return -EINVAL;
416 }
417
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700418 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530419 if (chan_bw == CH_WIDTH_80MHZ) {
420 hdd_err("BW80 not possible in 2.4GHz band");
421 return -EINVAL;
422 }
423 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
424 (chan_bw != CH_WIDTH_MAX)) {
425 hdd_err("Only BW20 possible on channel 14");
426 return -EINVAL;
427 }
428 }
429
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700430 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530431 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
432 (chan_bw != CH_WIDTH_MAX)) {
433 hdd_err("Only BW20 possible on channel 165");
434 return -EINVAL;
435 }
436 }
437
438 return 0;
439}
440
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530441/**
442 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
443 *
444 * Block the unloading of the driver (or) interface up until the
445 * cds recovery is completed
446 *
447 * Return: true for recovery completion else false
448 */
449static bool hdd_wait_for_recovery_completion(void)
450{
451 int retry = 0;
452
453 /* Wait for recovery to complete */
454 while (cds_is_driver_recovering()) {
455 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
456 hdd_err("Recovery in progress; wait here!!!");
457 msleep(1000);
458 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
459 hdd_err("SSR never completed, error");
460 /*
461 * Trigger the bug_on in the internal builds, in the
462 * customer builds self-recovery will be enabled
463 * in those cases just return error.
464 */
465 if (cds_is_self_recovery_enabled())
466 return false;
467 QDF_BUG(0);
468 }
469 }
470
471 hdd_info("Recovery completed successfully!");
472 return true;
473}
474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475static int __hdd_netdev_notifier_call(struct notifier_block *nb,
476 unsigned long state, void *data)
477{
478#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
479 struct netdev_notifier_info *dev_notif_info = data;
480 struct net_device *dev = dev_notif_info->dev;
481#else
482 struct net_device *dev = data;
483#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700484 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700485 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800486
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800487 ENTER_DEV(dev);
488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489 /* Make sure that this callback corresponds to our device. */
490 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
491 return NOTIFY_DONE;
492
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530493 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700495 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496 return NOTIFY_DONE;
497 }
498
499 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700500 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 return NOTIFY_DONE;
502 }
503
504 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
505 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800506 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530507 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800508 return NOTIFY_DONE;
509 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800510
511 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
512 hdd_err("%s: Driver module is closed", __func__);
513 return NOTIFY_DONE;
514 }
515
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530516 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 return NOTIFY_DONE;
518
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800519 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520 dev->name, state);
521
522 switch (state) {
523 case NETDEV_REGISTER:
524 break;
525
526 case NETDEV_UNREGISTER:
527 break;
528
529 case NETDEV_UP:
530 sme_ch_avoid_update_req(hdd_ctx->hHal);
531 break;
532
533 case NETDEV_DOWN:
534 break;
535
536 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700537 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800538 complete(&adapter->linkup_event_var);
539 break;
540
541 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700542 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
543 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530544 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700545 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546 } else {
hqueaa33ee2017-05-04 17:56:35 +0800547 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800548 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530550 /*
551 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
552 * of return status of hdd_stop call, kernel resets the IFF_UP
553 * flag after which driver does not send the cfg80211_scan_done.
554 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
555 */
556 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557 break;
558
559 default:
560 break;
561 }
562
563 return NOTIFY_DONE;
564}
565
566/**
567 * hdd_netdev_notifier_call() - netdev notifier callback function
568 * @nb: pointer to notifier block
569 * @state: state
570 * @ndev: ndev pointer
571 *
572 * Return: 0 on success, error number otherwise.
573 */
574static int hdd_netdev_notifier_call(struct notifier_block *nb,
575 unsigned long state,
576 void *ndev)
577{
578 int ret;
579
580 cds_ssr_protect(__func__);
581 ret = __hdd_netdev_notifier_call(nb, state, ndev);
582 cds_ssr_unprotect(__func__);
583
584 return ret;
585}
586
587struct notifier_block hdd_netdev_notifier = {
588 .notifier_call = hdd_netdev_notifier_call,
589};
590
591/* variable to hold the insmod parameters */
592static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800593
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530594static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700595int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530596
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800597/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800598static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800599
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530600/**
601 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
602 * @ch_width: NL channel width
603 *
604 * Converts the NL channel width to the driver's internal representation
605 *
606 * Return: Converted channel width. In case of non matching NL channel width,
607 * CH_WIDTH_MAX will be returned.
608 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800609enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530610{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800611 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700612
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800613 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530614 switch (ch_width) {
615 case NL80211_CHAN_WIDTH_20_NOHT:
616 case NL80211_CHAN_WIDTH_20:
617 return CH_WIDTH_20MHZ;
618 case NL80211_CHAN_WIDTH_40:
619 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530620 case NL80211_CHAN_WIDTH_80:
621 return CH_WIDTH_80MHZ;
622 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800623 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
624 return CH_WIDTH_80P80MHZ;
625 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
626 return CH_WIDTH_160MHZ;
627 else
628 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530629 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800630 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
631 return CH_WIDTH_160MHZ;
632 else
633 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530634 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800635 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530636 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800637 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530638 default:
639 hdd_err("Invalid channel width %d, setting to default",
640 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800641 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530642 }
643}
644
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530645/* wlan_hdd_find_opclass() - Find operating class for a channel
646 * @hal: handler to HAL
647 * @channel: channel id
648 * @bw_offset: bandwidth offset
649 *
650 * Function invokes sme api to find the operating class
651 *
652 * Return: operating class
653 */
654uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
655 uint8_t bw_offset)
656{
657 uint8_t opclass = 0;
658
659 sme_get_opclass(hal, channel, bw_offset, &opclass);
660 return opclass;
661}
662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530664 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530665 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666 * @bitmask: Bitmask of log levels to be enabled
667 *
668 * Called immediately after the cfg.ini is read in order to configure
669 * the desired trace levels.
670 *
671 * Return: None
672 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530673int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530675 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530676 int qdf_print_idx = -1;
677 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678 /*
679 * if the bitmask is the default value, then a bitmask was not
680 * specified in cfg.ini, so leave the logging level alone (it
681 * will remain at the "compiled in" default value)
682 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700683 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530684 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800685
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530686 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800687
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530688 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530689 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530690 QDF_TRACE_LEVEL_NONE, 0);
691
692 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530693 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530695 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696 while (0 != bitmask) {
697 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530698 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530699 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530700 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530701 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800702 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800704 level++;
705 bitmask >>= 1;
706 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530707 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708}
709
710/**
Chris Guo1751acf2017-07-03 14:09:01 +0800711 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
712 * @hdd_ctx: HDD context pointer
713 *
714 * Return: 0 if the context is valid. Error code otherwise
715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700716int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800717{
718 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
719 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
720 return -ENODEV;
721 }
722
723 if (cds_is_driver_recovering()) {
724 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
725 (void *)_RET_IP_, cds_get_driver_state());
726 return -EAGAIN;
727 }
728
729 if (hdd_ctx->start_modules_in_progress ||
730 hdd_ctx->stop_modules_in_progress) {
731 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
732 (void *)_RET_IP_);
733 return -EAGAIN;
734 }
735
736 return 0;
737}
738
739
740/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 * wlan_hdd_validate_context() - check the HDD context
742 * @hdd_ctx: HDD context pointer
743 *
744 * Return: 0 if the context is valid. Error code otherwise
745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700746int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800748 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530749 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750 return -ENODEV;
751 }
752
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800753 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800754 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530755 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 return -EAGAIN;
757 }
758
Yue Ma9f275d92017-09-14 16:58:41 -0700759 if (cds_is_load_or_unload_in_progress()) {
760 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
761 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700763 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530764
765 if (hdd_ctx->start_modules_in_progress ||
766 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800767 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530768 (void *)_RET_IP_);
769 return -EAGAIN;
770 }
771
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530772 if (cds_is_driver_in_bad_state()) {
773 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
774 (void *)_RET_IP_, cds_get_driver_state());
775 return -ENODEV;
776 }
777
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778 return 0;
779}
780
Jeff Johnson9d295242017-08-29 14:39:48 -0700781int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700782{
783 if (!adapter) {
784 hdd_err("adapter is null");
785 return -EINVAL;
786 }
787
788 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
789 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
790 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
791 return -EINVAL;
792 }
793
794 if (!adapter->dev) {
795 hdd_err("adapter net_device is null");
796 return -EINVAL;
797 }
798
799 if (!(adapter->dev->flags & IFF_UP)) {
800 hdd_info("adapter net_device is not up");
801 return -EAGAIN;
802 }
803
Jeff Johnson1b780e42017-10-31 14:11:45 -0700804 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700805 hdd_info("adapter session is not open");
806 return -EAGAIN;
807 }
808
Jeff Johnson1b780e42017-10-31 14:11:45 -0700809 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
810 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700811 return -EINVAL;
812 }
813
814 return 0;
815}
816
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530818 * wlan_hdd_validate_modules_state() - Check modules status
819 * @hdd_ctx: HDD context pointer
820 *
821 * Check's the driver module's state and returns true if the
822 * modules are enabled returns false if modules are closed.
823 *
824 * Return: True if modules are enabled or false.
825 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700826bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530827{
828 mutex_lock(&hdd_ctx->iface_change_lock);
829 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
830 mutex_unlock(&hdd_ctx->iface_change_lock);
831 hdd_notice("Modules not enabled, Present status: %d",
832 hdd_ctx->driver_status);
833 return false;
834 }
835 mutex_unlock(&hdd_ctx->iface_change_lock);
836 return true;
837}
838
839/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700841 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 *
843 * This function sets the IBSS power save config parameters to WMA
844 * which will send it to firmware if FW supports IBSS power save
845 * before vdev start.
846 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530847 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848 * on failure.
849 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700850QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851{
852 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700853 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854
855 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700856 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530857 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 }
859
Jeff Johnson1b780e42017-10-31 14:11:45 -0700860 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
862 hdd_ctx->config->ibssATIMWinSize,
863 VDEV_CMD);
864 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700865 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530866 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 }
868
Jeff Johnson1b780e42017-10-31 14:11:45 -0700869 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
871 hdd_ctx->config->isIbssPowerSaveAllowed,
872 VDEV_CMD);
873 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700874 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
875 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530876 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 }
878
Jeff Johnson1b780e42017-10-31 14:11:45 -0700879 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
881 hdd_ctx->config->
882 isIbssPowerCollapseAllowed, VDEV_CMD);
883 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700884 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
885 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530886 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887 }
888
Jeff Johnson1b780e42017-10-31 14:11:45 -0700889 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
891 hdd_ctx->config->isIbssAwakeOnTxRx,
892 VDEV_CMD);
893 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700894 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530895 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 }
897
Jeff Johnson1b780e42017-10-31 14:11:45 -0700898 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
900 hdd_ctx->config->ibssInactivityCount,
901 VDEV_CMD);
902 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700903 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530904 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 }
906
Jeff Johnson1b780e42017-10-31 14:11:45 -0700907 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
909 hdd_ctx->config->ibssTxSpEndInactivityTime,
910 VDEV_CMD);
911 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700912 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
913 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530914 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 }
916
Jeff Johnson1b780e42017-10-31 14:11:45 -0700917 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
919 hdd_ctx->config->ibssPsWarmupTime,
920 VDEV_CMD);
921 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700922 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
923 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530924 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 }
926
Jeff Johnson1b780e42017-10-31 14:11:45 -0700927 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
929 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
930 VDEV_CMD);
931 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700932 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
933 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530934 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935 }
936
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530937 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938}
939
Yue Macd359b72017-10-03 15:21:00 -0700940#ifdef FEATURE_RUNTIME_PM
941/**
942 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
943 * @hdd_ctx: HDD context
944 *
945 * Return: None
946 */
947static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
948{
949 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
950
Yue Macd359b72017-10-03 15:21:00 -0700951 qdf_runtime_lock_init(&ctx->dfs);
952
953 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
954}
955
956/**
957 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
958 * @hdd_ctx: HDD Context
959 *
960 * Return: None
961 */
962static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
963{
964 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
965
Yue Macd359b72017-10-03 15:21:00 -0700966 qdf_runtime_lock_deinit(&ctx->dfs);
967
968 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
969}
970
971static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter)
972{
973 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
974
975 qdf_runtime_lock_init(&ctx->connect);
976}
977
Yue Ma9e89e832017-11-14 11:40:23 -0800978static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter)
Yue Macd359b72017-10-03 15:21:00 -0700979{
980 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
981
982 qdf_runtime_lock_deinit(&ctx->connect);
983}
984#else /* FEATURE_RUNTIME_PM */
985static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
986static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
987static void hdd_adapter_runtime_suspend_init(struct hdd_adapter *adapter) {}
Yue Ma9e89e832017-11-14 11:40:23 -0800988static void hdd_adapter_runtime_suspend_deinit(struct hdd_adapter *adapter) {}
Yue Macd359b72017-10-03 15:21:00 -0700989#endif /* FEATURE_RUNTIME_PM */
990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991#define INTF_MACADDR_MASK 0x7
992
993/**
994 * hdd_update_macaddr() - update mac address
995 * @config: hdd configuration
996 * @hw_macaddr: mac address
997 *
998 * Mac address for multiple virtual interface is found as following
999 * i) The mac address of the first interface is just the actual hw mac address.
1000 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1001 * define the mac address for the remaining interfaces and locally
1002 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1003 * supported virtual interfaces, right now this is 0x07 (meaning 8
1004 * interface).
1005 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1006 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1007 *
1008 * Return: None
1009 */
1010void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301011 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012{
1013 int8_t i;
1014 uint8_t macaddr_b3, tmp_br3;
1015
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301016 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301017 QDF_MAC_ADDR_SIZE);
1018 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301019 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301020 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1022 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1023 INTF_MACADDR_MASK;
1024 macaddr_b3 += tmp_br3;
1025
1026 /* XOR-ing bit-24 of the mac address. This will give enough
1027 * mac address range before collision
1028 */
1029 macaddr_b3 ^= (1 << 7);
1030
1031 /* Set locally administered bit */
1032 config->intfMacAddr[i].bytes[0] |= 0x02;
1033 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001034 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035 MAC_ADDRESS_STR, i,
1036 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1037 }
1038}
1039
Kabilan Kannan44a58372017-12-06 18:16:11 -08001040static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1041{
1042 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1043 struct tdls_start_params tdls_cfg;
1044 struct tdls_user_config *config = &tdls_cfg.config;
1045 struct hdd_config *cfg = hdd_ctx->config;
1046 QDF_STATUS status;
1047
1048 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1049 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1050 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1051 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1052 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1053 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1054 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1055 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1056 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1057 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1058 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1059 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1060 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1061 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1062 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1063 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1064 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1065 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1066 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1067 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1068 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1069 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1070 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1071 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1072 (cfg->fEnableTDLSImplicitTrigger ?
1073 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1074 (cfg->fTDLSExternalControl ?
1075 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1076 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1077 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1078
1079 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1080 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1081 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1082 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1083 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1084 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1085 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1086 tdls_cfg.tdls_evt_cb_data = psoc;
1087 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
1088 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
1089 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
1090 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1091 tdls_cfg.tdls_wmm_cb_data = psoc;
1092 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1093 tdls_cfg.tdls_rx_cb_data = psoc;
1094 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1095
1096 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1097 if (status != QDF_STATUS_SUCCESS) {
1098 hdd_err("failed pmo psoc configuration");
1099 return -EINVAL;
1100 }
1101
1102 hdd_ctx->tdls_umac_comp_active = true;
1103 /* enable napier specific tdls data path */
1104 hdd_ctx->tdls_nap_active = true;
1105
1106 return 0;
1107}
1108
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001109static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110 struct wma_tgt_services *cfg)
1111{
1112 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113
1114 /* Set up UAPSD */
1115 config->apUapsdEnabled &= cfg->uapsd;
1116
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001117 /* 11AX mode support */
1118 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1119 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1120 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 /* 11AC mode support */
1123 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1124 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1125 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126
1127 /* ARP offload: override user setting if invalid */
1128 config->fhostArpOffload &= cfg->arp_offload;
1129
1130#ifdef FEATURE_WLAN_SCAN_PNO
1131 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001132 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001133 if (cfg->pno_offload)
1134 config->PnoOffload = true;
1135#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136#ifdef FEATURE_WLAN_TDLS
1137 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301138 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1139 cfg->en_tdls_offchan;
1140 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1141 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001142 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001143 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001144 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1148 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1149#endif
Will Huang496b36c2017-07-11 16:38:50 +08001150 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001151 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001152 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001153 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154
1155}
1156
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001157/**
1158 * hdd_update_vdev_nss() - sets the vdev nss
1159 * @hdd_ctx: HDD context
1160 *
1161 * Sets the Nss per vdev type based on INI
1162 *
1163 * Return: None
1164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001165static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001166{
1167 struct hdd_config *cfg_ini = hdd_ctx->config;
1168 uint8_t max_supp_nss = 1;
1169
Naveen Rawat10b1c152017-01-18 11:16:06 -08001170 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001171 max_supp_nss = 2;
1172
1173 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001174 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001175
1176 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001177 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001178}
1179
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301180/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301181 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1182 * @hdd_ctx: HDD context
1183 *
1184 * Updates wiphy vhtcap fields
1185 *
1186 * Return: None
1187 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001188static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301189{
1190 struct ieee80211_supported_band *band_5g =
1191 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1192 uint32_t val;
1193
1194 if (!band_5g) {
1195 hdd_debug("5GHz band disabled, skipping capability population");
1196 return;
1197 }
1198
1199 val = hdd_ctx->config->txBFCsnValue;
1200 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1201
1202 val = NUM_OF_SOUNDING_DIMENSIONS;
1203 band_5g->vht_cap.cap |=
1204 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1205
1206 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1207 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1208}
1209
1210/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301211 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1212 * @hdd_ctx: HDD context
1213 *
1214 * Sets the DBS capability as per INI and firmware capability
1215 *
1216 * Return: None
1217 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001218static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301219{
1220 struct hdd_config *cfg_ini = hdd_ctx->config;
1221 uint8_t hw_dbs_capable = 0;
1222
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001223 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1224 ((cfg_ini->dual_mac_feature_disable ==
1225 ENABLE_DBS_CXN_AND_SCAN) ||
1226 (cfg_ini->dual_mac_feature_disable ==
1227 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301228 hw_dbs_capable = 1;
1229
1230 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1231}
1232
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001233static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 struct wma_tgt_ht_cap *cfg)
1235{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301236 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 uint32_t value, val32;
1238 uint16_t val16;
1239 struct hdd_config *pconfig = hdd_ctx->config;
1240 tSirMacHTCapabilityInfo *phtCapInfo;
1241 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1242 uint8_t enable_tx_stbc;
1243
1244 /* check and update RX STBC */
1245 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1246 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1247
1248 /* get the MPDU density */
1249 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1250
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301251 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001252 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001253 value = 0;
1254 }
1255
1256 /*
1257 * MPDU density:
1258 * override user's setting if value is larger
1259 * than the one supported by target
1260 */
1261 if (value > cfg->mpdu_density) {
1262 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1263 cfg->mpdu_density);
1264
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301265 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001266 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001267 }
1268
1269 /* get the HT capability info */
1270 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301271 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001272 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273 return;
1274 }
1275 val16 = (uint16_t) val32;
1276 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1277
1278 /* Set the LDPC capability */
1279 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1280
1281 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1282 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1283
1284 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1285 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1286
1287 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1288 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1289
1290 enable_tx_stbc = pconfig->enableTxSTBC;
1291
1292 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1293 pconfig->enable2x2 = 1;
1294 } else {
1295 pconfig->enable2x2 = 0;
1296 enable_tx_stbc = 0;
1297
1298 /* 1x1 */
1299 /* Update Rx Highest Long GI data Rate */
1300 if (sme_cfg_set_int(hdd_ctx->hHal,
1301 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001302 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301303 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001304 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 }
1306
1307 /* Update Tx Highest Long GI data Rate */
1308 if (sme_cfg_set_int
1309 (hdd_ctx->hHal,
1310 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001311 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301312 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001313 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 }
1315 }
1316 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1317 enable_tx_stbc = 0;
1318 phtCapInfo->txSTBC = enable_tx_stbc;
1319
1320 val32 = val16;
1321 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301322 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001323 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1325 value = SIZE_OF_SUPPORTED_MCS_SET;
1326 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001328 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329
1330 if (pconfig->enable2x2) {
1331 for (value = 0; value < cfg->num_rf_chains; value++)
1332 mcs_set[value] =
1333 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1334
1335 status =
1336 sme_cfg_set_str(hdd_ctx->hHal,
1337 WNI_CFG_SUPPORTED_MCS_SET,
1338 mcs_set,
1339 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301340 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001341 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342 }
1343 }
1344#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1345}
1346
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001347static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 struct wma_tgt_vht_cap *cfg)
1349{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301350 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 uint32_t value = 0;
1352 struct hdd_config *pconfig = hdd_ctx->config;
1353 struct wiphy *wiphy = hdd_ctx->wiphy;
1354 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001355 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001356 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001357 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001358 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359
Dustin Brown5e06bd32016-10-04 12:49:10 -07001360 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001361 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001362 return;
1363 }
1364
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 /* Get the current MPDU length */
1366 status =
1367 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1368 &value);
1369
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301370 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001371 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 value = 0;
1373 }
1374
1375 /*
1376 * VHT max MPDU length:
1377 * override if user configured value is too high
1378 * that the target cannot support
1379 */
1380 if (value > cfg->vht_max_mpdu) {
1381 status = sme_cfg_set_int(hdd_ctx->hHal,
1382 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1383 cfg->vht_max_mpdu);
1384
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001385 if (status == QDF_STATUS_E_FAILURE)
1386 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 }
1388
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001389 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1390 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1391
1392 if (pconfig->enable2x2)
1393 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1394
1395 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1396 QDF_STATUS_E_FAILURE) {
1397 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1398 }
1399
1400 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1401 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1402 if (pconfig->enable2x2)
1403 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1404
1405 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1406 QDF_STATUS_E_FAILURE) {
1407 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1408 }
1409
1410 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1411 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1412 if (pconfig->enable2x2)
1413 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1414
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001415 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001416 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1417
1418 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1419 QDF_STATUS_E_FAILURE) {
1420 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1421 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001423 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 &value);
1425
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001427 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 value = 0;
1429 }
1430
jiad4a7a33c2017-08-08 15:32:24 +08001431 /* Set HW RX LDPC capability */
1432 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1433 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 status = sme_cfg_set_int(hdd_ctx->hHal,
1435 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001436 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001438 if (status == QDF_STATUS_E_FAILURE)
1439 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 }
1441
1442 /* Get current GI 80 value */
1443 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1444 &value);
1445
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301446 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001447 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 value = 0;
1449 }
1450
1451 /* set the Guard interval 80MHz */
1452 if (value && !cfg->vht_short_gi_80) {
1453 status = sme_cfg_set_int(hdd_ctx->hHal,
1454 WNI_CFG_VHT_SHORT_GI_80MHZ,
1455 cfg->vht_short_gi_80);
1456
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001457 if (status == QDF_STATUS_E_FAILURE)
1458 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 }
1460
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 /* Get VHT TX STBC cap */
1462 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1463
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301464 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001465 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 value = 0;
1467 }
1468
1469 /* VHT TX STBC cap */
1470 if (value && !cfg->vht_tx_stbc) {
1471 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1472 cfg->vht_tx_stbc);
1473
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001474 if (status == QDF_STATUS_E_FAILURE)
1475 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 }
1477
1478 /* Get VHT RX STBC cap */
1479 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1480
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301481 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001482 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 value = 0;
1484 }
1485
1486 /* VHT RX STBC cap */
1487 if (value && !cfg->vht_rx_stbc) {
1488 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1489 cfg->vht_rx_stbc);
1490
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001491 if (status == QDF_STATUS_E_FAILURE)
1492 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 }
1494
1495 /* Get VHT SU Beamformer cap */
1496 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1497 &value);
1498
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301499 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001500 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 value = 0;
1502 }
1503
1504 /* set VHT SU Beamformer cap */
1505 if (value && !cfg->vht_su_bformer) {
1506 status = sme_cfg_set_int(hdd_ctx->hHal,
1507 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1508 cfg->vht_su_bformer);
1509
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001510 if (status == QDF_STATUS_E_FAILURE)
1511 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512 }
1513
1514 /* check and update SU BEAMFORMEE capabality */
1515 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1516 pconfig->enableTxBF = cfg->vht_su_bformee;
1517
1518 status = sme_cfg_set_int(hdd_ctx->hHal,
1519 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1520 pconfig->enableTxBF);
1521
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001522 if (status == QDF_STATUS_E_FAILURE)
1523 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524
1525 /* Get VHT MU Beamformer cap */
1526 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1527 &value);
1528
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301529 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001530 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 value = 0;
1532 }
1533
1534 /* set VHT MU Beamformer cap */
1535 if (value && !cfg->vht_mu_bformer) {
1536 status = sme_cfg_set_int(hdd_ctx->hHal,
1537 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1538 cfg->vht_mu_bformer);
1539
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001540 if (status == QDF_STATUS_E_FAILURE)
1541 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 }
1543
1544 /* Get VHT MU Beamformee cap */
1545 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1546 &value);
1547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301548 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001549 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 value = 0;
1551 }
1552
1553 /* set VHT MU Beamformee cap */
1554 if (value && !cfg->vht_mu_bformee) {
1555 status = sme_cfg_set_int(hdd_ctx->hHal,
1556 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1557 cfg->vht_mu_bformee);
1558
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001559 if (status == QDF_STATUS_E_FAILURE)
1560 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 }
1562
1563 /* Get VHT MAX AMPDU Len exp */
1564 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1565 &value);
1566
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301567 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001568 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 value = 0;
1570 }
1571
1572 /*
1573 * VHT max AMPDU len exp:
1574 * override if user configured value is too high
1575 * that the target cannot support.
1576 * Even though Rome publish ampdu_len=7, it can
1577 * only support 4 because of some h/w bug.
1578 */
1579
1580 if (value > cfg->vht_max_ampdu_len_exp) {
1581 status = sme_cfg_set_int(hdd_ctx->hHal,
1582 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1583 cfg->vht_max_ampdu_len_exp);
1584
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001585 if (status == QDF_STATUS_E_FAILURE)
1586 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 }
1588
1589 /* Get VHT TXOP PS CAP */
1590 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1591
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301592 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001593 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 value = 0;
1595 }
1596
1597 /* set VHT TXOP PS cap */
1598 if (value && !cfg->vht_txop_ps) {
1599 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1600 cfg->vht_txop_ps);
1601
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001602 if (status == QDF_STATUS_E_FAILURE)
1603 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 }
1605
1606 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1607 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1608 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1609 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1610 else
1611 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1612
1613
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001614 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1615 status = sme_cfg_set_int(hdd_ctx->hHal,
1616 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1617 VHT_CAP_160_AND_80P80_SUPP);
1618 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001619 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 band_5g->vht_cap.cap |=
1621 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001622 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1623 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1624 status = sme_cfg_set_int(hdd_ctx->hHal,
1625 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1626 VHT_CAP_160_SUPP);
1627 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001628 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 band_5g->vht_cap.cap |=
1630 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001631 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1632 }
1633 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1634 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301635 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001636 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301637 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001638 &value);
1639 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301640 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001641 value = 0;
1642 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301643 /* set the Guard interval 160MHz */
1644 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001645 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301646 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1647 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001648
1649 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301650 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001651 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652
1653 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1654 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1655
1656 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1657 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1658 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1660
1661 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1662 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1663
1664 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1665 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1666 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1668 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1669 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1670
1671 band_5g->vht_cap.cap |=
1672 (cfg->vht_max_ampdu_len_exp <<
1673 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1674
1675 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1676 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1677 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1678 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1679 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1680 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1681 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1682 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1683
1684 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1685 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1686
1687}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001689/**
1690 * hdd_generate_macaddr_auto() - Auto-generate mac address
1691 * @hdd_ctx: Pointer to the HDD context
1692 *
1693 * Auto-generate mac address using device serial number.
1694 * Keep the first 3 bytes of OUI as before and replace
1695 * the last 3 bytes with the lower 3 bytes of serial number.
1696 *
1697 * Return: 0 for success
1698 * Non zero failure code for errors
1699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001700static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001701{
1702 unsigned int serialno = 0;
1703 struct qdf_mac_addr mac_addr = {
1704 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1705 };
1706
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001707 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001708 if (serialno == 0)
1709 return -EINVAL;
1710
1711 serialno &= 0x00ffffff;
1712
1713 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1714 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1715 mac_addr.bytes[5] = serialno & 0xff;
1716
1717 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1718 return 0;
1719}
1720
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301721/**
1722 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1723 * configuration to cfg_ini in HDD
1724 * @hdd_ctx: Pointer to hdd_ctx
1725 * @cfg: target configuration
1726 *
1727 * Return: None
1728 */
1729#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001730static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301731 struct wma_tgt_cfg *cfg)
1732{
1733 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1734}
1735#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001736static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301737 struct wma_tgt_cfg *cfg)
1738{
1739}
1740#endif
1741
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001742void hdd_update_tgt_cfg(void *context, void *param)
1743{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001744 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001745 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746 struct wma_tgt_cfg *cfg = param;
1747 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001748 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301749 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301750
Dustin Brownbd68fe12017-11-21 15:28:52 -08001751 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1752 if (ret) {
1753 hdd_err("Failed to create pdev; errno:%d", ret);
1754 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001755 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001756 hdd_debug("New pdev has been created with pdev_id = %u",
1757 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301758 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001759
Naveen Rawat64e477e2016-05-20 10:34:56 -07001760 if (cds_cfg) {
1761 if (hdd_ctx->config->enable_sub_20_channel_width !=
1762 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1763 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1764 cds_cfg->sub_20_channel_width =
1765 WLAN_SUB_20_CH_WIDTH_NONE;
1766 } else {
1767 cds_cfg->sub_20_channel_width =
1768 hdd_ctx->config->enable_sub_20_channel_width;
1769 }
1770 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
1772 /* first store the INI band capability */
1773 temp_band_cap = hdd_ctx->config->nBandCapability;
1774
1775 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301776 hdd_ctx->is_fils_roaming_supported =
1777 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001778
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001779 /*
1780 * now overwrite the target band capability with INI
1781 * setting if INI setting is a subset
1782 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001783
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001784 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1785 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001787 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1788 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001789 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001790 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791 }
1792
Amar Singhal58b45ef2017-08-01 13:43:54 -07001793 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1794
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301795 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001796 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1797 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1798 }
1799
1800 /* This can be extended to other configurations like ht, vht cap... */
1801
Anurag Chouhanc5548422016-02-24 18:33:27 +05301802 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001804 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001806 static struct qdf_mac_addr default_mac_addr = {
1807 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1808 };
1809 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1810 &default_mac_addr)) {
1811 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1812 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1813 MAC_ADDRESS_STR,
1814 MAC_ADDR_ARRAY(hdd_ctx->config->
1815 intfMacAddr[0].bytes));
1816 } else {
1817 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1818 MAC_ADDRESS_STR,
1819 MAC_ADDR_ARRAY(hdd_ctx->config->
1820 intfMacAddr[0].bytes));
1821 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001822 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 }
1824
1825 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001826 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001827
1828 hdd_ctx->max_intf_count = cfg->max_intf_count;
1829
Jeff Johnsonc875e242016-09-23 18:12:34 -07001830 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001831 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001833 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1834 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1835
1836 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1837
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001838 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001839 if (cfg->services.en_11ax) {
1840 hdd_info("11AX: 11ax is enabled - update HDD config");
1841 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1842 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001843
1844 hdd_update_vdev_nss(hdd_ctx);
1845
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301846 hdd_update_hw_dbs_capable(hdd_ctx);
1847
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001848 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001849 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001850 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001851 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001852
Nitesh Shahe50711f2017-04-26 16:30:45 +05301853 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1854 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1855 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001856 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001857 hdd_ctx->current_antenna_mode);
1858
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001859 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1860 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301861 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301862 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301863
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301864 if ((hdd_ctx->config->txBFCsnValue >
1865 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1866 !cfg->tx_bfee_8ss_enabled)
1867 hdd_ctx->config->txBFCsnValue =
1868 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1869
1870 if (sme_cfg_set_int(hdd_ctx->hHal,
1871 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1872 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1873 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1874
1875
1876 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1877 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1878 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301879
1880 /*
1881 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1882 */
1883 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301884
1885 hdd_ctx->fw_mem_dump_enabled = cfg->fw_mem_dump_enabled;
1886
Arun Khandavallid454d422016-08-17 12:47:05 +05301887 /*
1888 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1889 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1890 * configure the STA mode wow pattern.
1891 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301892 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301893 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301894
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301895 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1896
Yue Macd359b72017-10-03 15:21:00 -07001897 /*
1898 * This needs to be done after HDD pdev is created and stored since
1899 * it will access the HDD pdev object lock.
1900 */
1901 hdd_runtime_suspend_context_init(hdd_ctx);
1902
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001903 /* Configure NAN datapath features */
1904 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001905 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001906 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907}
1908
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001909bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910{
Jeff Johnson9d295242017-08-29 14:39:48 -07001911 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07001912 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913
Arif Hussaincd151632017-02-11 16:57:19 -08001914 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001915 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001916 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301917 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919
Dustin Brown920397d2017-12-13 16:27:50 -08001920 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08001921 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1922
1923 if ((QDF_SAP_MODE == adapter->device_mode ||
1924 QDF_P2P_GO_MODE == adapter->device_mode) &&
1925 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07001926 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08001927 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1928 true;
1929 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07001930 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301931 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001932 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301933
1934 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936
1937/**
1938 * hdd_is_valid_mac_address() - validate MAC address
1939 * @pMacAddr: Pointer to the input MAC address
1940 *
1941 * This function validates whether the given MAC address is valid or not
1942 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1943 * where X is the hexa decimal digit character and separated by ':'
1944 * This algorithm works even if MAC address is not separated by ':'
1945 *
1946 * This code checks given input string mac contains exactly 12 hexadecimal
1947 * digits and a separator colon : appears in the input string only after
1948 * an even number of hex digits.
1949 *
1950 * Return: 1 for valid and 0 for invalid
1951 */
1952bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1953{
1954 int xdigit = 0;
1955 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 while (*pMacAddr) {
1958 if (isxdigit(*pMacAddr)) {
1959 xdigit++;
1960 } else if (':' == *pMacAddr) {
1961 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1962 break;
1963
1964 ++separator;
1965 } else {
1966 /* Invalid MAC found */
1967 return 0;
1968 }
1969 ++pMacAddr;
1970 }
1971 return xdigit == 12 && (separator == 5 || separator == 0);
1972}
1973
1974/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301975 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1976 * @dev: Handle to struct net_device to be updated.
1977 *
1978 * Return: None
1979 */
1980static void hdd_mon_mode_ether_setup(struct net_device *dev)
1981{
1982 dev->header_ops = NULL;
1983 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1984 dev->hard_header_len = ETH_HLEN;
1985 dev->mtu = ETH_DATA_LEN;
1986 dev->addr_len = ETH_ALEN;
1987 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1988 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1989 dev->priv_flags |= IFF_TX_SKB_SHARING;
1990
1991 memset(dev->broadcast, 0xFF, ETH_ALEN);
1992}
1993
1994/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001995 * __hdd__mon_open() - HDD Open function
1996 * @dev: Pointer to net_device structure
1997 *
1998 * This is called in response to ifconfig up
1999 *
2000 * Return: 0 for success; non-zero for failure
2001 */
2002static int __hdd_mon_open(struct net_device *dev)
2003{
2004 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002005 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2006 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002007
2008 ENTER_DEV(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002009
2010 ret = wlan_hdd_validate_context(hdd_ctx);
2011 if (ret)
2012 return ret;
2013
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302014 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002015
2016 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2017 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2018 if (ret) {
2019 hdd_err("Failed to start WLAN modules return");
2020 return ret;
2021 }
2022 hdd_err("hdd_wlan_start_modules() successful !");
2023
2024 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2025 ret = hdd_start_adapter(adapter);
2026 if (ret) {
2027 hdd_err("Failed to start adapter :%d",
2028 adapter->device_mode);
2029 return ret;
2030 }
2031 hdd_err("hdd_start_adapters() successful !");
2032 }
2033 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2034 }
2035
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002036 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002037
2038 if (!ret)
2039 ret = hdd_enable_monitor_mode(dev);
2040
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002041 return ret;
2042}
2043
2044/**
2045 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2046 * @dev: Pointer to net_device structure
2047 *
2048 * This is called in response to ifconfig up
2049 *
2050 * Return: 0 for success; non-zero for failure
2051 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002052static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002053{
2054 int ret;
2055
2056 cds_ssr_protect(__func__);
2057 ret = __hdd_mon_open(dev);
2058 cds_ssr_unprotect(__func__);
2059
2060 return ret;
2061}
2062
2063/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302064 * hdd_start_adapter() - Wrapper function for device specific adapter
2065 * @adapter: pointer to HDD adapter
2066 *
2067 * This function is called to start the device specific adapter for
2068 * the mode passed in the adapter's device_mode.
2069 *
2070 * Return: 0 for success; non-zero for failure
2071 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002072int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302073{
2074
2075 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002076 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302077
2078 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002079 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302080
2081 switch (device_mode) {
2082 case QDF_P2P_CLIENT_MODE:
2083 case QDF_P2P_DEVICE_MODE:
2084 case QDF_OCB_MODE:
2085 case QDF_STA_MODE:
2086 case QDF_MONITOR_MODE:
2087 ret = hdd_start_station_adapter(adapter);
2088 if (ret)
2089 goto err_start_adapter;
2090 break;
2091 case QDF_P2P_GO_MODE:
2092 case QDF_SAP_MODE:
2093 ret = hdd_start_ap_adapter(adapter);
2094 if (ret)
2095 goto err_start_adapter;
2096 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302097 case QDF_IBSS_MODE:
2098 /*
2099 * For IBSS interface is initialized as part of
2100 * hdd_init_station_mode()
2101 */
2102 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302103 case QDF_FTM_MODE:
2104 ret = hdd_start_ftm_adapter(adapter);
2105 if (ret)
2106 goto err_start_adapter;
Lin Bai1c678482017-12-18 18:29:11 +08002107 else
2108 goto ftm_complete;
Arun Khandavallifae92942016-08-01 13:31:08 +05302109 break;
2110 default:
2111 hdd_err("Invalid session type %d", device_mode);
2112 QDF_ASSERT(0);
2113 goto err_start_adapter;
2114 }
2115 if (hdd_set_fw_params(adapter))
2116 hdd_err("Failed to set the FW params for the adapter!");
2117
2118 /*
2119 * Action frame registered in one adapter which will
2120 * applicable to all interfaces
2121 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302122 ret = wlan_hdd_cfg80211_register_frames(adapter);
2123 if (ret < 0) {
2124 hdd_err("Failed to register frames - ret %d", ret);
2125 goto err_start_adapter;
2126 }
2127
Lin Bai1c678482017-12-18 18:29:11 +08002128ftm_complete:
Arun Khandavallifae92942016-08-01 13:31:08 +05302129 EXIT();
2130 return 0;
2131err_start_adapter:
2132 return -EINVAL;
2133}
2134
2135/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302136 * hdd_enable_power_management() - API to Enable Power Management
2137 *
2138 * API invokes Bus Interface Layer power management functionality
2139 *
2140 * Return: None
2141 */
2142static void hdd_enable_power_management(void)
2143{
2144 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2145
2146 if (!hif_ctx) {
2147 hdd_err("Bus Interface Context is Invalid");
2148 return;
2149 }
2150
2151 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2152}
2153
2154/**
2155 * hdd_disable_power_management() - API to disable Power Management
2156 *
2157 * API disable Bus Interface Layer Power management functionality
2158 *
2159 * Return: None
2160 */
2161static void hdd_disable_power_management(void)
2162{
2163 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2164
2165 if (!hif_ctx) {
2166 hdd_err("Bus Interface Context is Invalid");
2167 return;
2168 }
2169
2170 hif_disable_power_management(hif_ctx);
2171}
2172
2173/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302174 * hdd_update_hw_sw_info() - API to update the HW/SW information
2175 *
2176 * API to update the HW and SW information in the driver
2177 *
2178 * Return: None
2179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002180static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302181{
2182 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002183 size_t target_hw_name_len;
2184 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302185
2186 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2187 if (!hif_sc) {
2188 hdd_err("HIF context is NULL");
2189 return;
2190 }
2191
2192 /*
2193 * target hw version/revision would only be retrieved after firmware
2194 * download
2195 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002196 hif_get_hw_info(hif_sc,
2197 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302198 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002199 &target_hw_name);
2200
2201 if (hdd_ctx->target_hw_name)
2202 qdf_mem_free(hdd_ctx->target_hw_name);
2203
2204 target_hw_name_len = strlen(target_hw_name) + 1;
2205 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2206 if (hdd_ctx->target_hw_name)
2207 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2208 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302209
2210 /* Get the wlan hw/fw version */
2211 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302212}
2213
2214/**
gbian62edd7e2017-03-07 13:12:13 +08002215 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2216 * @hdd_ctx: Pointer to hdd context
2217 *
2218 * Return: none
2219 */
2220static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002221hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002222{
2223 uint8_t num_entries = 0;
2224 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2225 uint8_t *tx_sched_wrr_ac;
2226 int i;
2227 cds_context_type *cds_ctx;
2228
2229 if (NULL == hdd_ctx)
2230 return;
2231
2232 if (NULL == hdd_ctx->config) {
2233 /* Do nothing if hdd_ctx is invalid */
2234 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2235 return;
2236 }
2237
2238 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2239
2240 if (!cds_ctx) {
2241 hdd_err("Invalid CDS Context");
2242 return;
2243 }
2244
2245 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2246 switch (i) {
2247 case OL_TX_WMM_AC_BE:
2248 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2249 break;
2250 case OL_TX_WMM_AC_BK:
2251 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2252 break;
2253 case OL_TX_WMM_AC_VI:
2254 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2255 break;
2256 case OL_TX_WMM_AC_VO:
2257 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2258 break;
2259 default:
2260 tx_sched_wrr_ac = NULL;
2261 break;
2262 }
2263
2264 hdd_string_to_u8_array(tx_sched_wrr_ac,
2265 tx_sched_wrr_param,
2266 &num_entries,
2267 sizeof(tx_sched_wrr_param));
2268
2269 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2270 cds_ctx->ac_specs[i].wrr_skip_weight =
2271 tx_sched_wrr_param[0];
2272 cds_ctx->ac_specs[i].credit_threshold =
2273 tx_sched_wrr_param[1];
2274 cds_ctx->ac_specs[i].send_limit =
2275 tx_sched_wrr_param[2];
2276 cds_ctx->ac_specs[i].credit_reserve =
2277 tx_sched_wrr_param[3];
2278 cds_ctx->ac_specs[i].discard_weight =
2279 tx_sched_wrr_param[4];
2280 }
2281
2282 num_entries = 0;
2283 }
2284}
2285
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002286#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002287static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2288 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2289{
Jeff Johnson9d295242017-08-29 14:39:48 -07002290 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002291 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002292
2293 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2294 if (!adapter) {
2295 hdd_err("Adapter is NULL");
2296 return PM_MAX_NUM_OF_MODE;
2297 }
2298
2299 return policy_mgr_convert_device_mode_to_qdf_type(
2300 adapter->device_mode);
2301}
2302
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002303static void hdd_register_policy_manager_callback(
2304 struct wlan_objmgr_psoc *psoc)
2305{
2306 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002307
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002308 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002309 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002310 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2311 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002312 hdd_cbacks.get_mode_for_non_connected_vdev =
2313 wlan_hdd_get_mode_for_non_connected_vdev;
2314
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002315 if (QDF_STATUS_SUCCESS !=
2316 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2317 hdd_err("HDD callback registration with policy manager failed");
2318 }
2319}
2320#else
2321static void hdd_register_policy_manager_callback(
2322 struct wlan_objmgr_psoc *psoc)
2323{
2324}
2325#endif
2326
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002327#ifdef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002328static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002329{
2330 struct nan_callbacks cb_obj = {0};
2331
2332 cb_obj.ndi_open = hdd_ndi_open;
2333 cb_obj.ndi_close = hdd_ndi_close;
2334 cb_obj.ndi_start = hdd_ndi_start;
2335 cb_obj.ndi_delete = hdd_ndi_delete;
2336 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2337 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2338
Naveen Rawat37f62c82017-03-26 22:24:43 -07002339 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2340 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002341 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002342
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002343 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2344}
2345#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002346static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002347{
2348}
2349#endif
2350
Dustin Brown4bc0a622017-12-06 15:56:50 -08002351static void hdd_check_for_leaks(void)
2352{
Dustin Brown677e0862017-10-10 16:30:09 -07002353 qdf_mc_timer_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002354}
2355
gbian62edd7e2017-03-07 13:12:13 +08002356/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302357 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2358 * @hdd_ctx: HDD context
2359 * @adapter: HDD adapter
2360 * @reinit: flag to indicate from SSR or normal path
2361 *
2362 * This function maintains the driver state machine it will be invoked from
2363 * startup, reinit and change interface. Depending on the driver state shall
2364 * perform the opening of the modules.
2365 *
2366 * Return: 0 for success; non-zero for failure
2367 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002368int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2369 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302370 bool reinit)
2371{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002372 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302373 qdf_device_t qdf_dev;
2374 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302375 bool unint = false;
2376 void *hif_ctx;
2377
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002378 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302379
2380 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2381 if (!qdf_dev) {
2382 hdd_err("QDF Device Context is Invalid return");
2383 return -EINVAL;
2384 }
2385
Dustin Brown6f427922017-09-19 12:19:00 -07002386 hdd_set_idle_ps_config(hdd_ctx, false);
2387 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302388
Dustin Brown1fe30a82017-10-03 16:13:36 -07002389 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302390 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2391 mutex_unlock(&hdd_ctx->iface_change_lock);
2392 hdd_info("Driver modules already Enabled");
2393 EXIT();
2394 return 0;
2395 }
2396
Dustin Brown1fe30a82017-10-03 16:13:36 -07002397 hdd_ctx->start_modules_in_progress = true;
2398
Arun Khandavallifae92942016-08-01 13:31:08 +05302399 switch (hdd_ctx->driver_status) {
2400 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002401 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302402 unint = true;
2403 /* Fall through dont add break here */
2404 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002405 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2406
Dustin Brown4bc0a622017-12-06 15:56:50 -08002407 qdf_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
2408
Arun Khandavallifae92942016-08-01 13:31:08 +05302409 if (!reinit && !unint) {
2410 ret = pld_power_on(qdf_dev->dev);
2411 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002412 hdd_err("Failed to Powerup the device; errno: %d",
2413 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302414 goto release_lock;
2415 }
2416 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002417
2418 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2419 hdd_ctx->config->enable_fw_log);
2420
Arun Khandavallifae92942016-08-01 13:31:08 +05302421 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2422 qdf_dev->bus_type,
2423 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2424 HIF_ENABLE_TYPE_PROBE);
2425 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002426 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302427 goto power_down;
2428 }
2429
2430 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302431 if (!hif_ctx) {
2432 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002433 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302434 goto power_down;
2435 }
2436
Arun Khandavallifae92942016-08-01 13:31:08 +05302437 status = ol_cds_init(qdf_dev, hif_ctx);
2438 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002439 hdd_err("No Memory to Create BMI Context; status: %d",
2440 status);
2441 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302442 goto hif_close;
2443 }
2444
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002445 ret = hdd_update_config(hdd_ctx);
2446 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002447 hdd_err("Failed to update configuration; errno: %d",
2448 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002449 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002450 }
2451
gbian62edd7e2017-03-07 13:12:13 +08002452 hdd_update_cds_ac_specs_params(hdd_ctx);
2453
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302454 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002455 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002456 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002457 ret = qdf_status_to_os_return(status);
2458 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302459 }
2460
Mukul Sharma9d797a02017-01-05 20:26:03 +05302461 /* initalize components configurations after psoc open */
2462 ret = hdd_update_components_config(hdd_ctx);
2463 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002464 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302465 ret);
2466 goto close;
2467 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002468 status = cds_dp_open(hdd_ctx->hdd_psoc);
2469 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002470 hdd_err("Failed to Open cds post open; status: %d",
2471 status);
2472 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002473 goto close;
2474 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302475
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002476 /*
2477 * NAN compoenet requires certian operations like, open adapter,
2478 * close adapter, etc. to be initiated by HDD, for those
2479 * register HDD callbacks with UMAC's NAN componenet.
2480 */
2481 hdd_nan_register_callbacks(hdd_ctx);
2482
Arun Khandavallifae92942016-08-01 13:31:08 +05302483 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2484
Jeff Johnson3a280122017-09-13 07:42:00 -07002485 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302486 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002487 hdd_err("Failed to pre-enable CDS; status: %d", status);
2488 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002489 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302490 }
2491
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002492 hdd_register_policy_manager_callback(
2493 hdd_ctx->hdd_psoc);
2494
Amar Singhal0928b192017-12-01 10:50:54 -08002495 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2496
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302497 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302498 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002499 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302500
Arun Khandavallifae92942016-08-01 13:31:08 +05302501 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2502 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2503 hdd_ftm_mc_process_msg);
2504 break;
2505 }
2506 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002507 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302508 break;
2509 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302510
2511 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002512 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2513 if (ret) {
2514 hdd_err("HDD IPA UC reinit failed; errno: %d",
2515 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002516 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002517 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302518 }
2519
Arun Khandavallifae92942016-08-01 13:31:08 +05302520 /* Fall through dont add break here */
2521 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002522 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2523
Arun Khandavallifae92942016-08-01 13:31:08 +05302524 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002525 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002526 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002527 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302528 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302529 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2530 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002531 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302532 break;
2533 }
Dustin Browndca39692017-11-09 15:30:25 -08002534
2535 ret = hdd_configure_cds(hdd_ctx, adapter);
2536 if (ret) {
2537 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002538 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302539 }
Dustin Browndca39692017-11-09 15:30:25 -08002540
Komal Seelamf2136bb2016-09-28 18:30:44 +05302541 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002542
Arun Khandavallifae92942016-08-01 13:31:08 +05302543 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002544 hdd_info("Wlan transitioned (now ENABLED)");
2545
Arun Khandavallifae92942016-08-01 13:31:08 +05302546 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002547
Arun Khandavallifae92942016-08-01 13:31:08 +05302548 default:
2549 hdd_err("WLAN start invoked in wrong state! :%d\n",
2550 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002551 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302552 goto release_lock;
2553 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002554
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302555 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302556 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002557
Arun Khandavallifae92942016-08-01 13:31:08 +05302558 EXIT();
Dustin Brown550f6d22017-12-14 15:44:01 -08002559
Arun Khandavallifae92942016-08-01 13:31:08 +05302560 return 0;
2561
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002562post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002563 cds_post_disable();
Dustin Brownbd68fe12017-11-21 15:28:52 -08002564 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002565
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002566cds_txrx_free:
2567 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002568
Arun Khandavallifae92942016-08-01 13:31:08 +05302569close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002570 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002571 hdd_info("Wlan transition aborted (now CLOSED)");
2572
Jeff Johnsone4b14592017-09-13 14:23:33 -07002573 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302574
Dustin Brown28b17892017-10-10 13:29:38 -07002575deinit_config:
2576 cds_deinit_ini_config();
2577
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002578cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302579 ol_cds_free();
2580
2581hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002582 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2583 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302584power_down:
2585 if (!reinit && !unint)
2586 pld_power_off(qdf_dev->dev);
2587release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302588 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302589 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002590
2591 /* many adapter resources are not freed by design in SSR case */
2592 if (!reinit)
2593 hdd_check_for_leaks();
2594 qdf_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
2595
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302596 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002597
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002598 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302599}
2600
Naveen Rawat910726a2017-03-06 11:42:51 -08002601#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002602static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002603{
2604 int ret = os_if_wifi_pos_register_nl();
2605
2606 if (ret)
2607 hdd_err("os_if_wifi_pos_register_nl failed");
2608
2609 return ret;
2610}
2611
2612static int hdd_deactivate_wifi_pos(void)
2613{
2614 int ret = os_if_wifi_pos_deregister_nl();
2615
2616 if (ret)
2617 hdd_err("os_if_wifi_pos_deregister_nl failed");
2618
2619 return ret;
2620}
2621
2622/**
2623 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2624 * @hdd_ctx: hdd context
2625 *
2626 * Return: status of operation
2627 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002628static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002629{
2630 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2631 struct hdd_config *cfg = hdd_ctx->config;
2632
2633 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2634 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2635 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2636 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2637 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2638 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2639 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2640 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2641}
2642#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002643static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002644{
2645 return oem_activate_service(hdd_ctx);
2646}
2647
2648static int hdd_deactivate_wifi_pos(void)
2649{
2650 return 0;
2651}
2652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002653static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002654{
2655}
2656#endif
2657
Arun Khandavallifae92942016-08-01 13:31:08 +05302658/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002659 * __hdd_open() - HDD Open function
2660 * @dev: Pointer to net_device structure
2661 *
2662 * This is called in response to ifconfig up
2663 *
2664 * Return: 0 for success; non-zero for failure
2665 */
2666static int __hdd_open(struct net_device *dev)
2667{
Jeff Johnson9d295242017-08-29 14:39:48 -07002668 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002669 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 int ret;
2671
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002672 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302673 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002674 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302676 /* Nothing to be done if device is unloading */
2677 if (cds_is_driver_unloading()) {
2678 hdd_err("Driver is unloading can not open the hdd");
2679 return -EBUSY;
2680 }
2681
Dustin Brown01847752017-10-25 13:56:27 -07002682 if (cds_is_driver_recovering()) {
2683 hdd_err("WLAN is currently recovering; Please try again.");
2684 return -EBUSY;
2685 }
2686
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302687 mutex_lock(&hdd_init_deinit_lock);
2688
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302689 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2690
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302691 /*
2692 * This scenario can be hit in cases where in the wlan driver after
2693 * registering the netdevices and there is a failure in driver
2694 * initialization. So return error gracefully because the netdevices
2695 * will be de-registered as part of the load failure.
2696 */
2697
2698 if (!cds_is_driver_loaded()) {
2699 hdd_err("Failed to start the wlan driver!!");
2700 ret = -EIO;
2701 goto err_hdd_hdd_init_deinit_lock;
2702 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704
Arun Khandavallifae92942016-08-01 13:31:08 +05302705 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2706 if (ret) {
2707 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302708 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302709 }
2710
2711
2712 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2713 ret = hdd_start_adapter(adapter);
2714 if (ret) {
2715 hdd_err("Failed to start adapter :%d",
2716 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302717 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302718 }
2719 }
2720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002721 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2722 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002723 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002724 /* Enable TX queues only when we are connected */
2725 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302726 WLAN_START_ALL_NETIF_QUEUE,
2727 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728 }
2729
Naveen Rawat286def52016-09-23 15:38:02 -07002730 /* Enable carrier and transmit queues for NDI */
2731 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002732 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002733 wlan_hdd_netif_queue_control(adapter,
2734 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2735 WLAN_CONTROL_PATH);
2736 }
2737
Naveen Rawat910726a2017-03-06 11:42:51 -08002738 hdd_populate_wifi_pos_cfg(hdd_ctx);
2739
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302740err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302741 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302742 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 return ret;
2744}
2745
Arun Khandavallifae92942016-08-01 13:31:08 +05302746
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747/**
2748 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2749 * @dev: Pointer to net_device structure
2750 *
2751 * This is called in response to ifconfig up
2752 *
2753 * Return: 0 for success; non-zero for failure
2754 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002755static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756{
2757 int ret;
2758
2759 cds_ssr_protect(__func__);
2760 ret = __hdd_open(dev);
2761 cds_ssr_unprotect(__func__);
2762
2763 return ret;
2764}
2765
2766/**
2767 * __hdd_stop() - HDD stop function
2768 * @dev: Pointer to net_device structure
2769 *
2770 * This is called in response to ifconfig down
2771 *
2772 * Return: 0 for success; non-zero for failure
2773 */
2774static int __hdd_stop(struct net_device *dev)
2775{
Jeff Johnson9d295242017-08-29 14:39:48 -07002776 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002777 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 int ret;
2779
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002780 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302782 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002783 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784
2785 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302786 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788
2789 /* Nothing to be done if the interface is not opened */
2790 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002791 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792 return -ENODEV;
2793 }
2794
2795 /* Make sure the interface is marked as closed */
2796 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302797
2798 hdd_debug("Disabling Auto Power save timer");
2799 sme_ps_disable_auto_ps_timer(
2800 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002801 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05302802
2803 /*
2804 * Disable TX on the interface, after this hard_start_xmit() will not
2805 * be called on that interface
2806 */
Kabilan Kannan8dac3502017-10-30 12:40:27 -07002807 hdd_notice("Disabling queues, adapter device mode: %s(%d)",
2808 hdd_device_mode_to_string(adapter->device_mode),
2809 adapter->device_mode);
2810
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302811 wlan_hdd_netif_queue_control(adapter,
2812 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2813 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814
2815 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002816 * NAN data interface is different in some sense. The traffic on NDI is
2817 * bursty in nature and depends on the need to transfer. The service
2818 * layer may down the interface after the usage and up again when
2819 * required. In some sense, the NDI is expected to be available
2820 * (like SAP) iface until NDI delete request is issued by the service
2821 * layer. Skip BSS termination and adapter deletion for NAN Data
2822 * interface (NDI).
2823 */
2824 if (WLAN_HDD_IS_NDI(adapter))
2825 return 0;
2826
Tushnim Bhattacharyya86294892017-10-25 16:29:11 -07002827 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->hdd_psoc);
2828
Naveen Rawat286def52016-09-23 15:38:02 -07002829 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830 * The interface is marked as down for outside world (aka kernel)
2831 * But the driver is pretty much alive inside. The driver needs to
2832 * tear down the existing connection on the netdev (session)
2833 * cleanup the data pipes and wait until the control plane is stabilized
2834 * for this interface. The call also needs to wait until the above
2835 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002836 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837 * That is intentional to be able to scan if it is a STA/P2P interface
2838 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302839 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002840
2841 /* DeInit the adapter. This ensures datapath cleanup as well */
2842 hdd_deinit_adapter(hdd_ctx, adapter, true);
2843
Arun Khandavallifae92942016-08-01 13:31:08 +05302844
2845 /*
2846 * Find if any iface is up. If any iface is up then can't put device to
2847 * sleep/power save mode
2848 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302849 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002850 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07002851 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
2852 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05302853 hdd_prevent_suspend_timeout(
2854 hdd_ctx->config->iface_change_wait_time,
2855 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05302856 }
2857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858 EXIT();
2859 return 0;
2860}
2861
2862/**
2863 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2864 * @dev: pointer to net_device structure
2865 *
2866 * This is called in response to ifconfig down
2867 *
2868 * Return: 0 for success and error number for failure
2869 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002870static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002871{
2872 int ret;
2873
2874 cds_ssr_protect(__func__);
2875 ret = __hdd_stop(dev);
2876 cds_ssr_unprotect(__func__);
2877
2878 return ret;
2879}
2880
2881/**
2882 * __hdd_uninit() - HDD uninit function
2883 * @dev: Pointer to net_device structure
2884 *
2885 * This is called during the netdev unregister to uninitialize all data
2886 * associated with the device
2887 *
2888 * Return: None
2889 */
2890static void __hdd_uninit(struct net_device *dev)
2891{
Jeff Johnson9d295242017-08-29 14:39:48 -07002892 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07002893 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002895 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002896
2897 do {
2898 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002899 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 break;
2901 }
2902
Jeff Johnson399c6272017-08-30 10:51:00 -07002903 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2904 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002905 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906 break;
2907 }
2908
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002909 if (dev != adapter->dev)
2910 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911
Jeff Johnson399c6272017-08-30 10:51:00 -07002912 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913
2914 /* after uninit our adapter structure will no longer be valid */
2915 adapter->dev = NULL;
2916 adapter->magic = 0;
2917 } while (0);
2918
2919 EXIT();
2920}
2921
2922/**
2923 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2924 * @dev: pointer to net_device structure
2925 *
2926 * This is called during the netdev unregister to uninitialize all data
2927 * associated with the device
2928 *
2929 * Return: none
2930 */
2931static void hdd_uninit(struct net_device *dev)
2932{
2933 cds_ssr_protect(__func__);
2934 __hdd_uninit(dev);
2935 cds_ssr_unprotect(__func__);
2936}
2937
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002938static int hdd_open_cesium_nl_sock(void)
2939{
2940#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2941 struct netlink_kernel_cfg cfg = {
2942 .groups = WLAN_NLINK_MCAST_GRP_ID,
2943 .input = NULL
2944 };
2945#endif
2946 int ret = 0;
2947
2948#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2949 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2950#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2951 THIS_MODULE,
2952#endif
2953 &cfg);
2954#else
2955 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2956 WLAN_NLINK_MCAST_GRP_ID,
2957 NULL, NULL, THIS_MODULE);
2958#endif
2959
2960 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002961 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002962 ret = -ECONNREFUSED;
2963 }
2964
2965 return ret;
2966}
2967
2968static void hdd_close_cesium_nl_sock(void)
2969{
2970 if (NULL != cesium_nl_srv_sock) {
2971 netlink_kernel_release(cesium_nl_srv_sock);
2972 cesium_nl_srv_sock = NULL;
2973 }
2974}
2975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976/**
2977 * __hdd_set_mac_address() - set the user specified mac address
2978 * @dev: Pointer to the net device.
2979 * @addr: Pointer to the sockaddr.
2980 *
2981 * This function sets the user specified mac address using
2982 * the command ifconfig wlanX hw ether <mac adress>.
2983 *
2984 * Return: 0 for success, non zero for failure
2985 */
2986static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2987{
Jeff Johnson9d295242017-08-29 14:39:48 -07002988 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002989 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002990 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302991 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 int ret;
2993
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002994 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995
2996 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2997 ret = wlan_hdd_validate_context(hdd_ctx);
2998 if (0 != ret)
2999 return ret;
3000
Jeff Johnson1e851a12017-10-28 14:36:12 -07003001 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003002 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3003
3004 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303005 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006}
3007
3008/**
3009 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3010 * function from SSR
3011 * @dev: pointer to net_device structure
3012 * @addr: Pointer to the sockaddr
3013 *
3014 * This function sets the user specified mac address using
3015 * the command ifconfig wlanX hw ether <mac adress>.
3016 *
3017 * Return: 0 for success.
3018 */
3019static int hdd_set_mac_address(struct net_device *dev, void *addr)
3020{
3021 int ret;
3022
3023 cds_ssr_protect(__func__);
3024 ret = __hdd_set_mac_address(dev, addr);
3025 cds_ssr_unprotect(__func__);
3026
3027 return ret;
3028}
3029
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003030uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031{
3032 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003033
Anurag Chouhan6d760662016-02-20 16:05:43 +05303034 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3036 break;
3037 }
3038
Anurag Chouhan6d760662016-02-20 16:05:43 +05303039 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 return NULL;
3041
3042 hdd_ctx->config->intfAddrMask |= (1 << i);
3043 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3044}
3045
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003046void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3047 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048{
3049 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003050
Anurag Chouhan6d760662016-02-20 16:05:43 +05303051 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 if (!memcmp(releaseAddr,
3053 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3054 6)) {
3055 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3056 break;
3057 }
3058 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059}
3060
3061#ifdef WLAN_FEATURE_PACKET_FILTERING
3062/**
3063 * __hdd_set_multicast_list() - set the multicast address list
3064 * @dev: Pointer to the WLAN device.
3065 * @skb: Pointer to OS packet (sk_buff).
3066 *
3067 * This funciton sets the multicast address list.
3068 *
3069 * Return: None
3070 */
3071static void __hdd_set_multicast_list(struct net_device *dev)
3072{
Jeff Johnson9d295242017-08-29 14:39:48 -07003073 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074 int i = 0, status;
3075 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003076 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303077 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3078 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3079 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080
Jeff Johnson3c3994a2016-02-11 08:12:30 -08003081 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303082 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303083 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303086 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303087 goto out;
3088
Dustin Brownc788acb2017-08-01 17:43:51 -07003089 status = hdd_validate_adapter(adapter);
3090 if (status)
3091 goto out;
3092
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303093 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3094 hdd_err("%s: Driver module is closed", __func__);
3095 return;
3096 }
3097
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303098 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3099 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003100 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303101 goto out;
3102 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303104 /* Delete already configured multicast address list */
3105 if (adapter->mc_addr_list.mc_cnt > 0) {
3106 hdd_info("clear previously configured MC address list");
3107 hdd_disable_and_flush_mc_addr_list(adapter,
3108 pmo_mc_list_change_notify);
3109 }
3110
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003112 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303113 hdd_disable_and_flush_mc_addr_list(adapter,
3114 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 } else {
3116 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303117 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003118 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303119 pmo_ucfg_max_mc_addr_supported(psoc));
3120 hdd_disable_and_flush_mc_addr_list(adapter,
3121 pmo_mc_list_change_notify);
3122 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003125 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303126 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 if (i == mc_count)
3128 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303129 memset(&(mc_list_request->mc_addr[i].bytes),
3130 0, ETH_ALEN);
3131 memcpy(&(mc_list_request->mc_addr[i].bytes),
3132 ha->addr, ETH_ALEN);
3133 hdd_info("mlist[%d] = %pM", i,
3134 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135 i++;
3136 }
3137 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303138
3139 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003140 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303141 mc_list_request->count = mc_count;
3142 status = hdd_cache_mc_addr_list(mc_list_request);
3143 if (status == 0) {
3144 hdd_enable_mc_addr_filtering(adapter,
3145 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303147 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303149out:
3150 if (mc_list_request)
3151 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303152 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153}
3154
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003156/**
3157 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3158 * @dev: pointer to net_device
3159 *
3160 * Return: none
3161 */
3162static void hdd_set_multicast_list(struct net_device *dev)
3163{
3164 cds_ssr_protect(__func__);
3165 __hdd_set_multicast_list(dev);
3166 cds_ssr_unprotect(__func__);
3167}
3168#endif
3169
3170/**
3171 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3172 * @dev: Pointer to the WLAN device.
3173 * @skb: Pointer to OS packet (sk_buff).
3174 *
3175 * This function is registered with the Linux OS for network
3176 * core to decide which queue to use first.
3177 *
3178 * Return: ac, Queue Index/access category corresponding to UP in IP header
3179 */
3180static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3181#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3182 , void *accel_priv
3183#endif
3184#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3185 , select_queue_fallback_t fallback
3186#endif
3187)
3188{
3189 return hdd_wmm_select_queue(dev, skb);
3190}
3191
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003192static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193 .ndo_open = hdd_open,
3194 .ndo_stop = hdd_stop,
3195 .ndo_uninit = hdd_uninit,
3196 .ndo_start_xmit = hdd_hard_start_xmit,
3197 .ndo_tx_timeout = hdd_tx_timeout,
3198 .ndo_get_stats = hdd_get_stats,
3199 .ndo_do_ioctl = hdd_ioctl,
3200 .ndo_set_mac_address = hdd_set_mac_address,
3201 .ndo_select_queue = hdd_select_queue,
3202#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204#endif
3205};
3206
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003207/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003208static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003209 .ndo_open = hdd_mon_open,
3210 .ndo_stop = hdd_stop,
3211 .ndo_get_stats = hdd_get_stats,
3212};
3213
3214/**
3215 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003216 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003217 * Return: None
3218 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003219void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003221 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003222 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003223 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003224 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003225}
3226
3227/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003228 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3229 * @hdd_ctx: global hdd context
3230 * @macAddr: mac address to assign to the interface
3231 * @name: User-visible name of the interface
3232 *
3233 * hdd adapter pointer would point to the netdev->priv space, this function
3234 * would retrive the pointer, and setup the hdd adapter configuration.
3235 *
3236 * Return: the pointer to hdd adapter, otherwise NULL
3237 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003238static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003240 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 const char *name)
3242{
Jeff Johnson5505db82017-11-02 21:19:23 -07003243 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003244 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003245 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303246 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247 /*
3248 * cfg80211 initialization and registration....
3249 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003250 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003251#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3252 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003254 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3255 hdd_mon_mode_ether_setup : ether_setup),
3256 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257
Jeff Johnson5505db82017-11-02 21:19:23 -07003258 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259
3260 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003261 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262
Jeff Johnson9d295242017-08-29 14:39:48 -07003263 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003264 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303265 qdf_mem_set(sta_ctx->conn_info.staId,
3266 sizeof(sta_ctx->conn_info.staId),
3267 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003268 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003269 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003271 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303273 qdf_status = qdf_event_create(
3274 &adapter->qdf_session_open_event);
3275 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3276 hdd_err("Session open QDF event init failed!");
3277 free_netdev(adapter->dev);
3278 return NULL;
3279 }
3280
3281 qdf_status = qdf_event_create(
3282 &adapter->qdf_session_close_event);
3283 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3284 hdd_err("Session close QDF event init failed!");
3285 free_netdev(adapter->dev);
3286 return NULL;
3287 }
3288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303290 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291 init_completion(&adapter->linkup_event_var);
3292 init_completion(&adapter->cancel_rem_on_chan_var);
3293 init_completion(&adapter->rem_on_chan_ready_event);
3294 init_completion(&adapter->sta_authorized_event);
3295 init_completion(&adapter->offchannel_tx_event);
3296 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003297 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303299 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300
3301 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003302 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003304 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305
Jeff Johnson5505db82017-11-02 21:19:23 -07003306 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003308 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003309 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003310 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311
3312 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003313 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003315 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316
Jeff Johnson5505db82017-11-02 21:19:23 -07003317 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003318
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003319 hdd_set_station_ops(adapter->dev);
3320
Jeff Johnson5505db82017-11-02 21:19:23 -07003321 hdd_dev_setup_destructor(dev);
3322 dev->ieee80211_ptr = &adapter->wdev;
3323 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003325 adapter->wdev.netdev = dev;
3326 /* set dev's parent to underlying device */
3327 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303329 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003330 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303331 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003332 }
3333
3334 return adapter;
3335}
3336
Jeff Johnson9d295242017-08-29 14:39:48 -07003337static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003339 struct net_device *dev = adapter->dev;
3340 int ret;
3341
3342 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003343
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003344 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003345 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3346
3347 ret = dev_alloc_name(dev, dev->name);
3348 if (ret < 0) {
3349 hdd_err(
3350 "unable to get dev name: %s, err = 0x%x",
3351 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303352 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353 }
3354 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003355
3356 ret = register_netdevice(dev);
3357 if (ret) {
3358 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3359 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303360 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 }
3362 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003363 ret = register_netdev(dev);
3364 if (ret) {
3365 hdd_err("register_netdev(%s) failed, err = 0x%x",
3366 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303367 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 }
3369 }
3370 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3371
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003372 EXIT();
3373
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303374 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375}
3376
Krunal Sonib51eec72017-11-20 21:53:01 -08003377QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378{
Krunal Sonib51eec72017-11-20 21:53:01 -08003379 struct hdd_adapter *adapter;
3380 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381
Krunal Sonib51eec72017-11-20 21:53:01 -08003382 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3383 if (!hdd_ctx) {
3384 hdd_err("Invalid HDD_CTX");
3385 return QDF_STATUS_E_FAILURE;
3386 }
3387
3388 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3389 if (NULL == adapter) {
3390 hdd_err("NULL adapter");
3391 return QDF_STATUS_E_INVAL;
3392 }
3393 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303394 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003395 hdd_debug("session %d opened", adapter->session_id);
3396
3397 return QDF_STATUS_SUCCESS;
3398}
3399
3400QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3401{
3402 struct hdd_adapter *adapter;
3403 struct hdd_context *hdd_ctx;
3404
3405 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3406 if (!hdd_ctx) {
3407 hdd_err("Invalid HDD_CTX");
3408 return QDF_STATUS_E_FAILURE;
3409 }
3410
3411 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003413 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303414 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415 }
3416
3417 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003418 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303419 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 }
3421
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003422 /*
3423 * For NAN Data interface, the close session results in the final
3424 * indication to the userspace
3425 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003426 if (adapter->device_mode == QDF_NDI_MODE)
3427 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3430
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 /*
3432 * We can be blocked while waiting for scheduled work to be
3433 * flushed, and the adapter structure can potentially be freed, in
3434 * which case the magic will have been reset. So make sure the
3435 * magic is still good, and hence the adapter structure is still
3436 * valid, before signaling completion
3437 */
3438 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303439 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303441 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442}
3443
Jeff Johnson9d295242017-08-29 14:39:48 -07003444int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445{
Dustin Brownd28772b2017-03-17 14:16:07 -07003446 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447
Dustin Brownd28772b2017-03-17 14:16:07 -07003448 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003449 if (QDF_IS_STATUS_ERROR(status))
3450 return qdf_status_to_os_return(status);
3451
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003452 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003453 if (QDF_IS_STATUS_ERROR(status))
3454 return qdf_status_to_os_return(status);
3455
3456 if (wma_capability_enhanced_mcast_filter())
3457 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3458 else
3459 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003460
3461 return qdf_status_to_os_return(status);
3462}
3463
Jeff Johnson9d295242017-08-29 14:39:48 -07003464int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003465{
3466 QDF_STATUS status;
3467 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003468 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003469 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003470
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003471 vdev_id = adapter->session_id;
3472 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003473
3474 /* vdev created sanity check */
3475 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003476 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003477 return -EINVAL;
3478 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003479 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003480 /*
3481 * In SSR case, there is no need to destroy vdev in firmware since
3482 * it has already asserted. vdev can be released directly.
3483 */
Krunal Sonib51eec72017-11-20 21:53:01 -08003484 if (cds_is_driver_recovering()) {
3485 hdd_debug("SSR: silently release the vdev for session-id: %d",
3486 adapter->session_id);
3487 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Yue Maf9782842017-05-08 12:49:49 -07003488 goto release_vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08003489 }
Yue Maf9782842017-05-08 12:49:49 -07003490
Dustin Brownd28772b2017-03-17 14:16:07 -07003491 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303492 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003493 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003494 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003495 if (QDF_IS_STATUS_ERROR(status)) {
3496 hdd_err("failed to close sme session: %d", status);
3497 return qdf_status_to_os_return(status);
3498 }
3499
3500 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303501 status = qdf_wait_for_event_completion(
3502 &adapter->qdf_session_close_event,
3503 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3504 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003505 if (adapter->device_mode == QDF_NDI_MODE)
3506 hdd_ndp_session_end_handler(adapter);
3507 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303508 adapter->session_id = HDD_SESSION_ID_INVALID;
3509 if (QDF_STATUS_E_TIMEOUT != status) {
3510 hdd_err("timed out waiting for close sme session: %u", status);
3511 return -ETIMEDOUT;
3512 } else if (adapter->qdf_session_close_event.force_set) {
3513 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
3514 return -EINVAL;
3515 } else {
3516 hdd_err("Failed to close sme session (%u)", status);
3517 return -EINVAL;
3518 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003519 }
Yue Maf9782842017-05-08 12:49:49 -07003520release_vdev:
Sandeep Puligillaef415362017-08-30 16:37:13 -07003521 /* do vdev logical destroy via objmgr */
3522 errno = hdd_objmgr_destroy_vdev(adapter);
3523 if (errno) {
3524 hdd_err("failed to destroy objmgr vdev: %d", errno);
3525 return errno;
3526 }
3527
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003528 /* now that sme session is closed, allow physical vdev destroy */
3529 errno = hdd_objmgr_release_vdev(adapter);
3530 if (errno) {
3531 hdd_err("failed to release objmgr vdev: %d", errno);
3532 return errno;
3533 }
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003534 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003535
3536 return 0;
3537}
3538
Krunal Sonib51eec72017-11-20 21:53:01 -08003539static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3540 struct sme_session_params *session_param,
3541 csr_roam_completeCallback callback,
3542 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003543{
Dustin Brownd28772b2017-03-17 14:16:07 -07003544 uint32_t type;
3545 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003546 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003547
3548 /* determine vdev (sub)type */
3549 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303550 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003551 hdd_err("failed to get vdev type: %d", status);
3552 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003554 session_param->sme_session_id = adapter->session_id;
3555 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3556 session_param->type_of_persona = type;
3557 session_param->subtype_of_persona = sub_type;
3558 session_param->session_open_cb = hdd_sme_open_session_callback;
3559 session_param->session_close_cb = hdd_sme_close_session_callback;
3560 session_param->callback = callback;
3561 session_param->callback_ctx = callback_ctx;
3562
3563 return 0;
3564}
3565
3566int hdd_vdev_create(struct hdd_adapter *adapter,
3567 csr_roam_completeCallback callback, void *ctx)
3568{
3569 QDF_STATUS status;
3570 int errno;
3571 struct hdd_context *hdd_ctx;
3572 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003573
3574 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003575
3576 /* do vdev create via objmgr */
3577 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003578 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003579 if (errno) {
3580 hdd_err("failed to create objmgr vdev: %d", errno);
3581 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003583
3584 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303585 status = qdf_event_reset(&adapter->qdf_session_open_event);
3586 if (QDF_STATUS_SUCCESS != status) {
3587 hdd_err("failed to reinit session open event");
3588 return -EINVAL;
3589 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003590 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3591 callback, ctx);
3592 if (errno) {
3593 hdd_err("failed to populating SME params");
3594 goto objmgr_vdev_destroy_procedure;
3595 }
3596
3597 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003598 if (QDF_IS_STATUS_ERROR(status)) {
3599 hdd_err("failed to open sme session: %d", status);
3600 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003601 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003602 }
3603
3604 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303605 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3606 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3607 if (QDF_STATUS_SUCCESS != status) {
3608 if (adapter->qdf_session_open_event.force_set) {
3609 /*
3610 * SSR/PDR has caused shutdown, which has forcefully
3611 * set the event. Return without the closing session.
3612 */
3613 adapter->session_id = HDD_SESSION_ID_INVALID;
3614 hdd_err("Session open event forcefully set");
3615 return -EINVAL;
3616 } else {
3617 if (QDF_STATUS_E_TIMEOUT == status)
3618 hdd_err("Session failed to open within timeout period");
3619 else
3620 hdd_err("Failed to wait for session open event(status-%d)",
3621 status);
3622 errno = -ETIMEDOUT;
3623 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3624 goto hdd_vdev_destroy_procedure;
3625 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003626 }
3627
3628 /* firmware ready for component communication, raise vdev_ready event */
3629 errno = hdd_vdev_ready(adapter);
3630 if (errno) {
3631 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003632 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003633 }
3634
Jeff Johnson1b780e42017-10-31 14:11:45 -07003635 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003636
3637 return 0;
3638
3639 /*
3640 * Due to legacy constraints, we need to destroy in the same order as
3641 * create. So, split error handling into 2 cases to accommodate.
3642 */
3643
Krunal Soni4a020c72017-10-30 20:58:40 -07003644objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003645 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003646
3647 return errno;
3648
Krunal Soni4a020c72017-10-30 20:58:40 -07003649hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003650 QDF_BUG(!hdd_vdev_destroy(adapter));
3651
3652 return errno;
3653}
3654
Jeff Johnson9d295242017-08-29 14:39:48 -07003655QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003656{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003657 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003658 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003659 QDF_STATUS status;
3660 int ret_val;
3661
Dustin Brownd28772b2017-03-17 14:16:07 -07003662 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3663 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3664 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003665 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003668 status = hdd_register_wext(adapter->dev);
3669 if (QDF_IS_STATUS_ERROR(status)) {
3670 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671 goto error_register_wext;
3672 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003673 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674
Jeff Johnsond377dce2017-10-04 10:32:42 -07003675 qdf_mem_set(sta_ctx->conn_info.staId,
3676 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303677
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003678 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003679 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003680 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003682 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 hdd_ctx->config->OperatingChannel;
3684
3685 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003686 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687
3688 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303689 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003690 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691 status, status);
3692 goto error_init_txrx;
3693 }
3694
3695 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3696
3697 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303698 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003699 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 status, status);
3701 goto error_wmm_init;
3702 }
3703
3704 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3705
Jeff Johnson1b780e42017-10-31 14:11:45 -07003706 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 WMI_PDEV_PARAM_BURST_ENABLE,
3708 hdd_ctx->config->enableSifsBurst,
3709 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003710 if (ret_val)
3711 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05303713 /*
3714 * In case of USB tethering, LRO is disabled. If SSR happened
3715 * during that time, then as part of SSR init, do not enable
3716 * the LRO again. Keep the LRO state same as before SSR.
3717 */
3718 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003719 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05303720
3721 /* rcpi info initialization */
3722 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
3723
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303724 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726error_wmm_init:
3727 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3728 hdd_deinit_tx_rx(adapter);
3729error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003730 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003731error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003732 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 return status;
3735}
3736
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303737/**
Krunal Soni4a020c72017-10-30 20:58:40 -07003738 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303739 * @hdd_ctx: global hdd context
3740 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003741 * @rtnl_held: Used to indicate whether or not the caller is holding
3742 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303743 *
3744 * This function De-initializes the STA/P2P/OCB adapter.
3745 *
3746 * Return: None.
3747 */
Krunal Soni4a020c72017-10-30 20:58:40 -07003748static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003749 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003750 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303751{
3752 ENTER_DEV(adapter->dev);
3753
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303754 if (adapter->dev) {
3755 if (rtnl_held)
3756 adapter->dev->wireless_handlers = NULL;
3757 else {
3758 rtnl_lock();
3759 adapter->dev->wireless_handlers = NULL;
3760 rtnl_unlock();
3761 }
3762 }
3763
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303764 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3765 hdd_deinit_tx_rx(adapter);
3766 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3767 }
3768
3769 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3770 hdd_wmm_adapter_close(adapter);
3771 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3772 }
3773
Krunal Sonib51eec72017-11-20 21:53:01 -08003774
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303775 EXIT();
3776}
3777
Krunal Sonib51eec72017-11-20 21:53:01 -08003778void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
3779 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780 bool rtnl_held)
3781{
3782 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303783
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003784 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003785 case QDF_STA_MODE:
3786 case QDF_P2P_CLIENT_MODE:
3787 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08003788 case QDF_IBSS_MODE:
3789 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003790 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003791 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 break;
3793 }
3794
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003795 case QDF_SAP_MODE:
3796 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003797 {
Krunal Soni4a020c72017-10-30 20:58:40 -07003798 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799 break;
3800 }
3801
3802 default:
3803 break;
3804 }
3805
3806 EXIT();
3807}
3808
Jeff Johnson9d295242017-08-29 14:39:48 -07003809static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07003810 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811{
Jeff Johnson5505db82017-11-02 21:19:23 -07003812 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813
3814 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07003815 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003817 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 return;
3819 }
3820
Rajeev Kumardca5f812016-02-04 17:28:06 -08003821 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303822
Yue Ma9e89e832017-11-14 11:40:23 -08003823 hdd_adapter_runtime_suspend_deinit(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05303824
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825 /*
3826 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3827 * the driver is almost closed and cannot handle either control
3828 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003829 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3830 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 * is not right. Setting this flag helps hdd_stop() to recognize that
3832 * the interface is closed and restricts any operations on that
3833 */
3834 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3835
3836 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003837 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07003838 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003839 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003840 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 /*
3842 * Note that the adapter is no longer valid at this point
3843 * since the memory has been reclaimed
3844 */
3845 }
3846}
3847
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003848static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07003849 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850{
Jeff Johnson9d295242017-08-29 14:39:48 -07003851 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003852
Dustin Brown920397d2017-12-13 16:27:50 -08003853 hdd_for_each_adapter(hdd_ctx, adapter) {
3854 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
3855 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303856 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 }
Dustin Brown920397d2017-12-13 16:27:50 -08003859
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303860 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003862
Arun Khandavalli2358d522016-05-16 18:05:37 +05303863#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3864/**
3865 * hdd_set_fw_log_params() - Set log parameters to FW
3866 * @hdd_ctx: HDD Context
3867 * @adapter: HDD Adapter
3868 *
3869 * This function set the FW Debug log level based on the INI.
3870 *
3871 * Return: None
3872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003873static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003874 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303875{
3876 uint8_t count = 0, numentries = 0,
3877 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3878 uint32_t value = 0;
3879 int ret;
3880
Arun Khandavallifae92942016-08-01 13:31:08 +05303881 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3882 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003883 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303884 return;
3885 }
3886
Arun Khandavallifae92942016-08-01 13:31:08 +05303887 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303888 hdd_ctx->fw_log_settings.dl_type =
3889 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003890 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303891 WMI_DBGLOG_TYPE,
3892 hdd_ctx->config->enableFwLogType,
3893 DBG_CMD);
3894 if (ret != 0)
3895 hdd_err("Failed to enable FW log type ret %d",
3896 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303897
3898 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303899 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003900 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303901 WMI_DBGLOG_LOG_LEVEL,
3902 hdd_ctx->config->enableFwLogLevel,
3903 DBG_CMD);
3904 if (ret != 0)
3905 hdd_err("Failed to enable FW log level ret %d",
3906 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303907
3908 hdd_string_to_u8_array(
3909 hdd_ctx->config->enableFwModuleLogLevel,
3910 moduleloglevel,
3911 &numentries,
3912 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3913
3914 while (count < numentries) {
3915 /*
3916 * FW module log level input string looks like
3917 * below:
3918 * gFwDebugModuleLoglevel=<FW Module ID>,
3919 * <Log Level>,...
3920 * For example:
3921 * gFwDebugModuleLoglevel=
3922 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3923 * Above input string means :
3924 * For FW module ID 1 enable log level 0
3925 * For FW module ID 2 enable log level 1
3926 * For FW module ID 3 enable log level 2
3927 * For FW module ID 4 enable log level 3
3928 * For FW module ID 5 enable log level 4
3929 * For FW module ID 6 enable log level 5
3930 * For FW module ID 7 enable log level 6
3931 */
3932
Nishank Aggarwale239d962017-03-03 12:26:02 +05303933 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3934 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3935 hdd_err("Module id %d and dbglog level %d input length is more than max",
3936 moduleloglevel[count],
3937 moduleloglevel[count + 1]);
3938 return;
3939 }
3940
3941 value = moduleloglevel[count] << 16;
3942 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07003943 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05303944 WMI_DBGLOG_MOD_LOG_LEVEL,
3945 value, DBG_CMD);
3946 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303947 hdd_err("Failed to enable FW module log level %d ret %d",
3948 value, ret);
3949
3950 count += 2;
3951 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303952
Arun Khandavalli2358d522016-05-16 18:05:37 +05303953}
3954#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003955static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07003956 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303957{
3958}
3959
3960#endif
3961
3962/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08003963 * hdd_configure_chain_mask() - programs chain mask to firmware
3964 * @adapter: HDD adapter
3965 *
3966 * Return: 0 on success or errno on failure
3967 */
3968static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
3969{
3970 int ret_val;
3971 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3972
3973 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
3974 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
3975 hdd_ctx->config->txchainmask1x1,
3976 hdd_ctx->config->rxchainmask1x1);
3977 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
3978 hdd_ctx->config->dual_mac_feature_disable,
3979 hdd_ctx->config->tx_chain_mask_2g,
3980 hdd_ctx->config->rx_chain_mask_2g);
3981 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
3982 hdd_ctx->config->tx_chain_mask_5g,
3983 hdd_ctx->config->rx_chain_mask_5g);
3984
3985 if (hdd_ctx->config->enable2x2) {
3986 hdd_info("2x2 enabled. skip chain mask programming");
3987 return 0;
3988 }
3989
3990 if (hdd_ctx->config->txchainmask1x1) {
3991 ret_val = sme_cli_set_command(adapter->session_id,
3992 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3993 hdd_ctx->config->txchainmask1x1,
3994 PDEV_CMD);
3995 if (ret_val)
3996 goto error;
3997 }
3998
3999 if (hdd_ctx->config->rxchainmask1x1) {
4000 ret_val = sme_cli_set_command(adapter->session_id,
4001 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4002 hdd_ctx->config->rxchainmask1x1,
4003 PDEV_CMD);
4004 if (ret_val)
4005 goto error;
4006 }
4007
4008 if (hdd_ctx->lte_coex_ant_share) {
4009 hdd_info("lte ant sharing enabled. skip per band chain mask");
4010 return 0;
4011 }
4012
4013 if (hdd_ctx->config->txchainmask1x1 ||
4014 hdd_ctx->config->rxchainmask1x1) {
4015 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4016 return 0;
4017 }
4018
4019 if (!hdd_ctx->config->dual_mac_feature_disable) {
4020 hdd_info("DBS enabled. skip per band chain mask");
4021 return 0;
4022 }
4023
4024 if (hdd_ctx->config->tx_chain_mask_2g) {
4025 ret_val = sme_cli_set_command(adapter->session_id,
4026 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4027 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4028 if (0 != ret_val)
4029 goto error;
4030 }
4031
4032 if (hdd_ctx->config->rx_chain_mask_2g) {
4033 ret_val = sme_cli_set_command(adapter->session_id,
4034 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4035 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4036 if (0 != ret_val)
4037 goto error;
4038 }
4039
4040 if (hdd_ctx->config->tx_chain_mask_5g) {
4041 ret_val = sme_cli_set_command(adapter->session_id,
4042 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4043 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4044 if (0 != ret_val)
4045 goto error;
4046 }
4047
4048 if (hdd_ctx->config->rx_chain_mask_5g) {
4049 ret_val = sme_cli_set_command(adapter->session_id,
4050 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4051 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4052 if (0 != ret_val)
4053 goto error;
4054 }
4055
4056 return 0;
4057
4058error:
4059 hdd_err("WMI PDEV set param failed %d", ret_val);
4060 return -EINVAL;
4061}
4062
4063/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304064 * hdd_set_fw_params() - Set parameters to firmware
4065 * @adapter: HDD adapter
4066 *
4067 * This function Sets various parameters to fw once the
4068 * adapter is started.
4069 *
4070 * Return: 0 on success or errno on failure
4071 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004072int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304073{
4074 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004075 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304076
4077 ENTER_DEV(adapter->dev);
4078
4079 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4080 if (!hdd_ctx)
4081 return -EINVAL;
4082
Dustin Brown732ab9c2017-06-15 13:24:09 -07004083 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4084 hdd_debug("FTM Mode is active; nothing to do");
4085 return 0;
4086 }
4087
Jeff Johnson1b780e42017-10-31 14:11:45 -07004088 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304089 WMI_PDEV_PARAM_DTIM_SYNTH,
4090 hdd_ctx->config->enable_lprx, PDEV_CMD);
4091 if (ret) {
4092 hdd_err("Failed to set LPRx");
4093 goto error;
4094 }
4095
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304096 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004097 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304098 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4099 hdd_ctx->config->upper_brssi_thresh);
4100
Jeff Johnson1b780e42017-10-31 14:11:45 -07004101 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304102 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4103 hdd_ctx->config->lower_brssi_thresh);
4104
Jeff Johnson1b780e42017-10-31 14:11:45 -07004105 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304106 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4107 hdd_ctx->config->enable_dtim_1chrx);
4108 }
4109
Dustin Brown732ab9c2017-06-15 13:24:09 -07004110 if (hdd_ctx->config->enable2x2) {
4111 hdd_debug("configuring 2x2 mode fw params");
4112
Jeff Johnson1b780e42017-10-31 14:11:45 -07004113 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004114 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4115 hdd_ctx->config->enable_cck_tx_fir_override,
4116 PDEV_CMD);
4117 if (ret) {
4118 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4119 ret);
4120 goto error;
4121 }
4122 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304123#define HDD_DTIM_1CHAIN_RX_ID 0x5
4124#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004125 hdd_debug("configuring 1x1 mode fw params");
4126
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004127 /*
4128 * Disable DTIM 1 chain Rx when in 1x1,
4129 * we are passing two value
4130 * as param_id << 29 | param_value.
4131 * Below param_value = 0(disable)
4132 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004133 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004134 WMI_STA_SMPS_PARAM_CMDID,
4135 HDD_DTIM_1CHAIN_RX_ID <<
4136 HDD_SMPS_PARAM_VALUE_S,
4137 VDEV_CMD);
4138 if (ret) {
4139 hdd_err("DTIM 1 chain set failed %d", ret);
4140 goto error;
4141 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304142
Arun Khandavalli2358d522016-05-16 18:05:37 +05304143#undef HDD_DTIM_1CHAIN_RX_ID
4144#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004145
4146 if (hdd_configure_chain_mask(adapter))
4147 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004148 }
4149
Jeff Johnson1b780e42017-10-31 14:11:45 -07004150 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004151 WMI_PDEV_PARAM_HYST_EN,
4152 hdd_ctx->config->enableMemDeepSleep,
4153 PDEV_CMD);
4154 if (ret) {
4155 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4156 goto error;
4157 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304158
Jeff Johnson1b780e42017-10-31 14:11:45 -07004159 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004160 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4161 hdd_ctx->config->rts_profile,
4162 VDEV_CMD);
4163 if (ret) {
4164 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4165 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304166 }
4167
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004168 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4169
Jeff Johnson1b780e42017-10-31 14:11:45 -07004170 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004171 GEN_VDEV_PARAM_AMSDU,
4172 hdd_ctx->config->max_amsdu_num,
4173 GEN_CMD);
4174 if (ret != 0) {
4175 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4176 goto error;
4177 }
4178
Arun Khandavalli2358d522016-05-16 18:05:37 +05304179 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304180 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004181
Arun Khandavalli2358d522016-05-16 18:05:37 +05304182 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304183
Arun Khandavalli2358d522016-05-16 18:05:37 +05304184error:
4185 return -EINVAL;
4186}
4187
Ryan Hsu07495ea2016-01-21 15:25:39 -08004188/**
4189 * hdd_open_adapter() - open and setup the hdd adatper
4190 * @hdd_ctx: global hdd context
4191 * @session_type: type of the interface to be created
4192 * @iface_name: User-visible name of the interface
4193 * @macAddr: MAC address to assign to the interface
4194 * @name_assign_type: the name of assign type of the netdev
4195 * @rtnl_held: the rtnl lock hold flag
4196 *
4197 * This function open and setup the hdd adpater according to the device
4198 * type request, assign the name, the mac address assigned, and then prepared
4199 * the hdd related parameters, queue, lock and ready to start.
4200 *
4201 * Return: the pointer of hdd adapter, otherwise NULL.
4202 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004203struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004205 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004206 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207{
Jeff Johnson9d295242017-08-29 14:39:48 -07004208 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304209 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210
4211 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4212 /*
4213 * Max limit reached on the number of vdevs configured by the
4214 * host. Return error
4215 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304216 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4217 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 return NULL;
4219 }
4220
4221 if (macAddr == NULL) {
4222 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304223 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224 return NULL;
4225 }
4226 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304227 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304228 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4229 " already exists",
4230 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231 return NULL;
4232 }
4233
4234 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004235 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 /* Reset locally administered bit if the device mode is STA */
4237 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304238 hdd_info("locally administered bit reset in sta mode: "
4239 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004241 case QDF_P2P_CLIENT_MODE:
4242 case QDF_P2P_DEVICE_MODE:
4243 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004244 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304245 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004246 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4247 name_assign_type,
4248 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249
4250 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304251 hdd_err("failed to allocate adapter for session %d",
4252 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 return NULL;
4254 }
4255
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004256 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004258 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304260 else if (QDF_MONITOR_MODE == session_type)
4261 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 else
4263 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4264
4265 adapter->device_mode = session_type;
4266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 /*
4269 * Workqueue which gets scheduled in IPv4 notification
4270 * callback
4271 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004272 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274
4275#ifdef WLAN_NS_OFFLOAD
4276 /*
4277 * Workqueue which gets scheduled in IPv6
4278 * notification callback.
4279 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004280 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 hdd_ipv6_notifier_work_queue);
4282#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004284 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004285 goto err_deinit_adapter_runtime_pm;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286
4287 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004288 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004289 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304290 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4291 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304292
Ravi Joshi1a292562017-05-18 16:28:54 -07004293 /* Initialize NAN Data Interface */
4294 if (QDF_NDI_MODE == session_type) {
4295 status = hdd_init_nan_data_mode(adapter);
4296 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004297 goto err_deinit_adapter_runtime_pm;
Ravi Joshi1a292562017-05-18 16:28:54 -07004298 }
4299
4300 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004302 case QDF_P2P_GO_MODE:
4303 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004304 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4305 name_assign_type,
4306 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004308 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304309 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310 return NULL;
4311 }
4312
4313 adapter->wdev.iftype =
4314 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004315 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 NL80211_IFTYPE_P2P_GO;
4317 adapter->device_mode = session_type;
4318
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004319 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004320 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004322
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004323 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304325 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4326 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304327
4328 /*
4329 * Workqueue which gets scheduled in IPv4 notification
4330 * callback
4331 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004332 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304333 hdd_ipv4_notifier_work_queue);
4334
4335#ifdef WLAN_NS_OFFLOAD
4336 /*
4337 * Workqueue which gets scheduled in IPv6
4338 * notification callback.
4339 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004340 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304341 hdd_ipv6_notifier_work_queue);
4342#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304344 case QDF_FTM_MODE:
4345 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4346 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004347 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304348 if (NULL == adapter) {
4349 hdd_err("Failed to allocate adapter for FTM mode");
4350 return NULL;
4351 }
4352 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4353 adapter->device_mode = session_type;
4354 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004355 if (QDF_STATUS_SUCCESS != status)
Yue Ma9e89e832017-11-14 11:40:23 -08004356 goto err_deinit_adapter_runtime_pm;
Krunal Sonib51eec72017-11-20 21:53:01 -08004357
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304358 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004359 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304360 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304361 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4362 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304363 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004365 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304366 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 return NULL;
4368 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369
hqueaa33ee2017-05-04 17:56:35 +08004370 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4371
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304372 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004374 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 }
4376
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304377 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004378 if (NULL != adapter) {
4379 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4380 adapter = NULL;
4381 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004382
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 return NULL;
4384 }
4385
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304386 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004387 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4388 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390 /* Adapter successfully added. Increment the vdev count */
4391 hdd_ctx->current_intf_count++;
4392
Jeff Johnson5880d792016-08-15 13:32:30 -07004393 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394 hdd_ctx->current_intf_count);
4395
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004396 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 }
4398
Rajeev Kumardca5f812016-02-04 17:28:06 -08004399 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004400 hdd_err("Interface %s wow debug_fs init failed",
4401 netdev_name(adapter->dev));
4402
4403 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4404 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405
4406 return adapter;
4407
Yue Ma9e89e832017-11-14 11:40:23 -08004408err_deinit_adapter_runtime_pm:
4409 /*
4410 * For certain error cases that hdd_alloc_station_adapter()
4411 * is used to allocate the adapter.
4412 */
4413 hdd_adapter_runtime_suspend_deinit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004414err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004415 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304416 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
4418 return NULL;
4419}
4420
Jeff Johnson9d295242017-08-29 14:39:48 -07004421QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004422 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004423{
Dustin Brown920397d2017-12-13 16:27:50 -08004424 /*
4425 * Here we are stopping global bus_bw timer & work per adapter.
4426 *
4427 * The reason is to fix one race condition between
4428 * bus bandwidth work and cleaning up an adapter.
4429 * Under some conditions, it is possible for the bus bandwidth
4430 * work to access a particularly destroyed adapter, leading to
4431 * use-after-free.
4432 */
4433 hdd_debug("wait for bus bw work to flush");
4434 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4435 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436
Dustin Brown920397d2017-12-13 16:27:50 -08004437 /* cleanup adapter */
4438 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4439 adapter->device_mode);
4440 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4441 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442
Dustin Brown920397d2017-12-13 16:27:50 -08004443 /* conditionally restart the bw timer */
4444 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004445
Dustin Brown920397d2017-12-13 16:27:50 -08004446 /* Adapter removed. Decrement vdev count */
4447 if (hdd_ctx->current_intf_count != 0)
4448 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004449
Dustin Brown920397d2017-12-13 16:27:50 -08004450 /* Fw will take care incase of concurrency */
4451 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452}
4453
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004454/**
4455 * hdd_close_all_adapters - Close all open adapters
4456 * @hdd_ctx: Hdd context
4457 * rtnl_held: True if RTNL lock held
4458 *
4459 * Close all open adapters.
4460 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304461 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004463QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464{
Dustin Brown920397d2017-12-13 16:27:50 -08004465 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304466 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467
4468 ENTER();
4469
4470 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004471 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4472 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304473 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004474 adapter->mac_addr.bytes);
4475 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4476
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304477 /* Adapter removed. Decrement vdev count */
4478 if (hdd_ctx->current_intf_count != 0)
4479 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004480 }
Dustin Brown920397d2017-12-13 16:27:50 -08004481 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004482
4483 EXIT();
4484
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304485 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486}
4487
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004488void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304490 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004491 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004492
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004493 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004494 case QDF_STA_MODE:
4495 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004496 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004497 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004498 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004499 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 break;
4501 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004502 case QDF_SAP_MODE:
4503 case QDF_P2P_GO_MODE:
4504 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004506 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507 break;
4508 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004509 case QDF_FTM_MODE:
4510 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 default:
4512 /*
4513 * wlan_hdd_reset_prob_rspies should not have been called
4514 * for these kind of devices
4515 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004516 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004517 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 return;
4519 }
4520
Anurag Chouhanc5548422016-02-24 18:33:27 +05304521 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004522 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523 updateIE.ieBufferlength = 0;
4524 updateIE.pAdditionIEBuffer = NULL;
4525 updateIE.append = true;
4526 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004527 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304529 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004530 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004531 }
4532}
4533
Jeff Johnson9d295242017-08-29 14:39:48 -07004534QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 const bool bCloseSession)
4536{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304537 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson2a722002017-09-30 20:02:35 -07004538 struct hdd_wext_state *pWextState =
4539 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540 union iwreq_data wrqu;
4541 tSirUpdateIE updateIE;
4542 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304543 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544
4545 ENTER();
4546
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004547 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304548 wlan_hdd_netif_queue_control(adapter,
4549 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4550 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004552 case QDF_STA_MODE:
4553 case QDF_P2P_CLIENT_MODE:
4554 case QDF_IBSS_MODE:
4555 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004556 case QDF_NDI_MODE:
4557 if ((QDF_NDI_MODE == adapter->device_mode) ||
4558 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4560 hdd_is_connecting(
4561 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004562 INIT_COMPLETION(adapter->disconnect_comp_var);
4563 /*
4564 * For NDI do not use pWextState from sta_ctx, if needed
4565 * extract from ndi_ctx.
4566 */
4567 if (QDF_NDI_MODE == adapter->device_mode)
4568 qdf_ret_status = sme_roam_disconnect(
4569 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004570 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004571 eCSR_DISCONNECT_REASON_NDI_DELETE);
4572 else if (pWextState->roamProfile.BSSType ==
4573 eCSR_BSS_TYPE_START_IBSS)
4574 qdf_ret_status = sme_roam_disconnect(
4575 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004576 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004577 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004578 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004579 qdf_ret_status =
4580 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004581 hdd_debug("Send disconnected event to userspace");
4582 wlan_hdd_cfg80211_indicate_disconnect(
4583 adapter->dev, true,
4584 WLAN_REASON_UNSPECIFIED);
4585 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004586 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004587 qdf_ret_status = sme_roam_disconnect(
4588 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004589 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004590 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004591 /* success implies disconnect command got
4592 * queued up successfully
4593 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004594 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4595 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596 rc = wait_for_completion_timeout(
4597 &adapter->disconnect_comp_var,
4598 msecs_to_jiffies
4599 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004600 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004601 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004603 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4604 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 memset(&wrqu, '\0', sizeof(wrqu));
4606 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4607 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4608 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4609 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304610 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004611 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004612
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304613 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304614 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615
4616#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004617 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618#endif
4619
4620 hdd_deregister_tx_flow_control(adapter);
4621
4622#ifdef WLAN_NS_OFFLOAD
4623#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004624 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625#endif
4626#endif
4627
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304628 if (adapter->device_mode == QDF_STA_MODE)
4629 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4630 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 /*
4632 * It is possible that the caller of this function does not
4633 * wish to close the session
4634 */
Krunal Soni985b8132017-02-10 18:49:08 -08004635 if (true == bCloseSession) {
4636 if (0 != wlan_hdd_try_disconnect(adapter)) {
4637 hdd_err("Error: Can't disconnect adapter");
4638 return QDF_STATUS_E_FAILURE;
4639 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004640 hdd_debug("Destroying adapter: %d",
4641 adapter->session_id);
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004642 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004643 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 break;
4645
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004646 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08004647 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05304648 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304649 sap_config = &adapter->session.ap.sap_config;
4650 if (sap_config)
4651 wlansap_reset_sap_config_add_ie(sap_config,
4652 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05304653 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004654 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004655
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004656 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07004657 if (QDF_SAP_MODE == adapter->device_mode) {
4658 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
4659 cds_flush_delayed_work(
4660 &adapter->acs_pending_work);
4661 clear_bit(ACS_PENDING, &adapter->event_flags);
4662 }
4663 }
Krunal Soni22208392017-09-29 18:10:34 -07004664 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07004665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004666 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07004667 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004668 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4670
4671 hdd_deregister_tx_flow_control(adapter);
4672
Kapil Guptac1224bf2017-06-22 21:22:40 +05304673 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 mutex_lock(&hdd_ctx->sap_lock);
4675 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304676 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304677 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004678
4679 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680 status = wlansap_stop_bss(
4681 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304683 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07004684 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304686 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304687 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304688 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05304689 qdf_wait_for_event_completion(
4690 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08004691 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692
Anurag Chouhance0dc992016-02-16 18:18:03 +05304693 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004694 hdd_err("failure waiting for wlansap_stop_bss %d",
4695 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004696 }
4697 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004698 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004699 }
4700 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004701 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4702 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004703 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704
Anurag Chouhanc5548422016-02-24 18:33:27 +05304705 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07004706 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004707 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004708 updateIE.ieBufferlength = 0;
4709 updateIE.pAdditionIEBuffer = NULL;
4710 updateIE.append = false;
4711 updateIE.notify = false;
4712 /* Probe bcn reset */
4713 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4714 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304715 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004716 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717 }
4718 /* Assoc resp reset */
4719 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4720 &updateIE,
4721 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304722 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004723 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724 }
4725 /* Reset WNI_CFG_PROBE_RSP Flags */
4726 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07004728 qdf_mem_free(adapter->session.ap.beacon);
4729 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304730 /*
4731 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4732 */
4733 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4734 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4735
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304736#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004737 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304738#endif
4739
4740#ifdef WLAN_NS_OFFLOAD
4741#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004742 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304743#endif
4744#endif
Krunal Sonib51eec72017-11-20 21:53:01 -08004745 if (true == bCloseSession) {
4746 hdd_debug("Destroying adapter: %d",
4747 adapter->session_id);
4748 hdd_vdev_destroy(adapter);
4749 }
4750 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004752 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004753 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004754 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004755 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756 break;
4757 default:
4758 break;
4759 }
4760
Dustin Brown04348372017-12-14 16:13:39 -08004761 if (adapter->scan_info.default_scan_ies) {
4762 qdf_mem_free(adapter->scan_info.default_scan_ies);
4763 adapter->scan_info.default_scan_ies = NULL;
4764 }
4765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 EXIT();
Dustin Brown04348372017-12-14 16:13:39 -08004767
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304768 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769}
4770
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304771/**
4772 * hdd_deinit_all_adapters - deinit all adapters
4773 * @hdd_ctx: HDD context
4774 * @rtnl_held: True if RTNL lock held
4775 *
4776 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004777void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304778{
Jeff Johnson9d295242017-08-29 14:39:48 -07004779 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304780
4781 ENTER();
4782
Dustin Brown920397d2017-12-13 16:27:50 -08004783 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304784 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304785
4786 EXIT();
4787}
4788
Dustin Brown27cd9942017-09-27 16:11:44 -07004789QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx,
4790 bool close_session)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791{
Jeff Johnson9d295242017-08-29 14:39:48 -07004792 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793
4794 ENTER();
4795
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304796 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4797
Dustin Brown920397d2017-12-13 16:27:50 -08004798 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Brown27cd9942017-09-27 16:11:44 -07004799 hdd_stop_adapter(hdd_ctx, adapter, close_session);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800
4801 EXIT();
4802
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304803 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004804}
4805
Paul Zhang84fa9382017-11-10 21:18:21 +08004806static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
4807 struct hdd_adapter *adapter)
4808{
4809 switch (adapter->device_mode) {
4810 case QDF_STA_MODE:
4811 case QDF_P2P_CLIENT_MODE:
4812 case QDF_IBSS_MODE:
4813 case QDF_P2P_DEVICE_MODE:
4814 case QDF_NDI_MODE:
4815 wlan_hdd_scan_abort(adapter);
4816 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4817 if (adapter->device_mode == QDF_STA_MODE)
4818 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4819 adapter->dev);
4820 break;
4821 case QDF_P2P_GO_MODE:
4822 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4823 break;
4824 case QDF_SAP_MODE:
4825 wlan_hdd_undo_acs(adapter);
4826 break;
4827 default:
4828 break;
4829 }
4830}
4831
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004832QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833{
Jeff Johnson9d295242017-08-29 14:39:48 -07004834 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07004835 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004836 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837
4838 ENTER();
4839
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304840 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4841
Dustin Brown920397d2017-12-13 16:27:50 -08004842 hdd_for_each_adapter(hdd_ctx, adapter) {
Yue Mad5b4b9f2017-05-26 16:23:40 -07004843 hdd_notice("Disabling queues for adapter type: %d",
4844 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304845
4846 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004847 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304848 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004849 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304850
Arun Khandavallicc544b32017-01-30 19:52:16 +05304851 if (hdd_ctx->config->sap_internal_restart &&
4852 adapter->device_mode == QDF_SAP_MODE) {
4853 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304854 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304855 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004856 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08004857 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004858 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004859 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4860 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304861 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304862 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004864 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865
Paul Zhang84fa9382017-11-10 21:18:21 +08004866 hdd_reset_scan_operation(hdd_ctx, adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -07004867 adapter->session.station.hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868
4869 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004870 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004871 adapter->device_mode, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4873 hdd_wmm_adapter_close(adapter);
4874 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4875 }
4876
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05304877 if (adapter->device_mode == QDF_STA_MODE)
4878 hdd_clear_fils_connection_info(adapter);
4879
Wu Gao3545e642017-07-14 19:24:41 +08004880 if (adapter->device_mode == QDF_SAP_MODE) {
4881 /*
4882 * If adapter is SAP, set session ID to invalid
4883 * since SAP session will be cleanup during SSR.
4884 */
Wu Gao36717432016-11-21 15:09:48 +08004885 wlansap_set_invalid_session(
4886 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4887
Wu Gao3545e642017-07-14 19:24:41 +08004888 wlansap_cleanup_cac_timer(
4889 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4890 }
4891
Yue Mad5b4b9f2017-05-26 16:23:40 -07004892 /* Delete peers if any for STA and P2P client modes */
4893 if (adapter->device_mode == QDF_STA_MODE ||
4894 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004895 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004896 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07004897 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07004898
4899 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4900 peerMacAddr.bytes);
4901 }
4902
Yue Maf9782842017-05-08 12:49:49 -07004903 /* Destroy vdev which will be recreated during reinit. */
4904 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 }
4906
4907 EXIT();
4908
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304909 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910}
4911
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004912bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304913{
Dustin Brown920397d2017-12-13 16:27:50 -08004914 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304915 bool close_modules = true;
4916
Arun Khandavalliba479c42017-07-26 21:29:40 +05304917 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
4918 hdd_info("FTM mode, don't close the module");
4919 return false;
4920 }
4921
Dustin Brown920397d2017-12-13 16:27:50 -08004922 hdd_for_each_adapter(hdd_ctx, adapter) {
4923 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
4924 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004925 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304926 close_modules = false;
4927 break;
4928 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304929 }
4930
4931 return close_modules;
4932}
4933
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05304934bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05304935{
4936 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4937 return true;
4938 else
4939 return false;
4940}
4941
Anurag Chouhanc4092922016-09-08 15:56:11 +05304942#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004943 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304944struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4945 struct ieee80211_channel *channel,
4946 const u8 *bssid, const u8 *ssid,
4947 size_t ssid_len)
4948{
4949 return cfg80211_get_bss(wiphy, channel, bssid,
4950 ssid, ssid_len,
4951 WLAN_CAPABILITY_ESS,
4952 WLAN_CAPABILITY_ESS);
4953}
4954#else
4955struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4956 struct ieee80211_channel *channel,
4957 const u8 *bssid, const u8 *ssid,
4958 size_t ssid_len)
4959{
4960 return cfg80211_get_bss(wiphy, channel, bssid,
4961 ssid, ssid_len,
4962 IEEE80211_BSS_TYPE_ESS,
4963 IEEE80211_PRIVACY_ANY);
4964}
4965#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304966
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304967#if defined CFG80211_CONNECT_BSS || \
4968 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304969#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05304970 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304971/**
4972 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4973 * @timeout_reason: reason for connect timeout
4974 *
4975 * This function is used to convert host timeout
4976 * reason enum to kernel specific enum.
4977 *
4978 * Return: nl timeout enum
4979 */
4980static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4981 tSirResultCodes timeout_reason)
4982{
4983 switch (timeout_reason) {
4984 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4985 return NL80211_TIMEOUT_SCAN;
4986 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4987 return NL80211_TIMEOUT_AUTH;
4988 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4989 return NL80211_TIMEOUT_ASSOC;
4990 default:
4991 return NL80211_TIMEOUT_UNSPECIFIED;
4992 }
4993}
4994
4995/**
4996 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4997 * @dev: network device
4998 * @bssid: bssid to which we want to associate
4999 * @timeout_reason: reason for connect timeout
5000 *
5001 * This API is used to send connection timeout reason to supplicant
5002 *
5003 * Return: void
5004 */
5005static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5006 const u8 *bssid,
5007 tSirResultCodes timeout_reason)
5008{
5009 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005010
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305011 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5012
5013 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5014 nl_timeout_reason);
5015}
5016
5017/**
5018 * __hdd_connect_bss() - API to send connection status to supplicant
5019 * @dev: network device
5020 * @bssid: bssid to which we want to associate
5021 * @req_ie: Request Information Element
5022 * @req_ie_len: len of the req IE
5023 * @resp_ie: Response IE
5024 * @resp_ie_len: len of ht response IE
5025 * @status: status
5026 * @gfp: Kernel Flag
5027 * @timeout_reason: reason for connect timeout
5028 *
5029 * Return: void
5030 */
5031static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5032 struct cfg80211_bss *bss, const u8 *req_ie,
5033 size_t req_ie_len, const u8 *resp_ie,
5034 size_t resp_ie_len, int status, gfp_t gfp,
5035 tSirResultCodes timeout_reason)
5036{
5037 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005038
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305039 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5040
5041 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5042 resp_ie, resp_ie_len, status, gfp,
5043 nl_timeout_reason);
5044}
5045#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305046#if defined CFG80211_CONNECT_TIMEOUT || \
5047 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305048static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5049 const u8 *bssid,
5050 tSirResultCodes timeout_reason)
5051{
5052 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5053}
5054#endif
5055
5056static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5057 struct cfg80211_bss *bss, const u8 *req_ie,
5058 size_t req_ie_len, const u8 *resp_ie,
5059 size_t resp_ie_len, int status, gfp_t gfp,
5060 tSirResultCodes timeout_reason)
5061{
5062 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5063 resp_ie, resp_ie_len, status, gfp);
5064}
5065#endif
5066
Abhishek Singha84d3952016-09-13 13:45:05 +05305067/**
5068 * hdd_connect_bss() - API to send connection status to supplicant
5069 * @dev: network device
5070 * @bssid: bssid to which we want to associate
5071 * @req_ie: Request Information Element
5072 * @req_ie_len: len of the req IE
5073 * @resp_ie: Response IE
5074 * @resp_ie_len: len of ht response IE
5075 * @status: status
5076 * @gfp: Kernel Flag
5077 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305078 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305079 *
5080 * The API is a wrapper to send connection status to supplicant
5081 *
5082 * Return: Void
5083 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305084#if defined CFG80211_CONNECT_TIMEOUT || \
5085 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305086static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5087 struct cfg80211_bss *bss, const u8 *req_ie,
5088 size_t req_ie_len, const u8 *resp_ie,
5089 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305090 bool connect_timeout,
5091 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305092{
5093 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305094 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305095 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305096 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5097 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305098}
5099#else
5100static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5101 struct cfg80211_bss *bss, const u8 *req_ie,
5102 size_t req_ie_len, const u8 *resp_ie,
5103 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305104 bool connect_timeout,
5105 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305106{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305107 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5108 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305109}
5110#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305111
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305112#if defined(WLAN_FEATURE_FILS_SK)
5113#if defined(CFG80211_CONNECT_DONE) || \
5114 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5115#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5116 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305117/**
5118 * hdd_populate_fils_params() - Populate FILS keys to connect response
5119 * @fils_params: connect response to supplicant
5120 * @fils_kek: FILS kek
5121 * @fils_kek_len: FILS kek length
5122 * @pmk: FILS PMK
5123 * @pmk_len: FILS PMK length
5124 * @pmkid: PMKID
5125 * @fils_seq_num: FILS Seq number
5126 *
5127 * Return: None
5128 */
5129static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5130 *fils_params, const uint8_t *fils_kek,
5131 size_t fils_kek_len, const uint8_t *pmk,
5132 size_t pmk_len, const uint8_t *pmkid,
5133 uint16_t fils_seq_num)
5134{
5135 /* Increament seq number to be used for next FILS */
5136 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5137 fils_params->update_erp_next_seq_num = true;
5138 fils_params->fils_kek = fils_kek;
5139 fils_params->fils_kek_len = fils_kek_len;
5140 fils_params->pmk = pmk;
5141 fils_params->pmk_len = pmk_len;
5142 fils_params->pmkid = pmkid;
5143}
5144#else
5145static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5146 *fils_params, const uint8_t
5147 *fils_kek, size_t fils_kek_len,
5148 const uint8_t *pmk, size_t pmk_len,
5149 const uint8_t *pmkid,
5150 uint16_t fils_seq_num)
5151{ }
5152#endif
5153
Jeff Johnson172237b2017-11-07 15:32:59 -08005154void hdd_update_hlp_info(struct net_device *dev,
5155 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305156{
5157 struct sk_buff *skb;
5158 uint16_t skb_len;
5159 struct llc_snap_hdr_t *llc_hdr;
5160 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305161 uint8_t *hlp_data;
5162 uint16_t hlp_data_len;
5163 struct fils_join_rsp_params *roam_fils_params
5164 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305165 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5166
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305167 if (!roam_fils_params) {
5168 hdd_err("FILS Roam Param NULL");
5169 return;
5170 }
5171
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005172 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305173 hdd_err("FILS HLP Data NULL, len %d",
5174 roam_fils_params->hlp_data_len);
5175 return;
5176 }
5177
5178 hlp_data = roam_fils_params->hlp_data;
5179 hlp_data_len = roam_fils_params->hlp_data_len;
5180
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305181 /* Calculate skb length */
5182 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5183 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5184 if (skb == NULL) {
5185 hdd_err("HLP packet nbuf alloc fails");
5186 return;
5187 }
5188
5189 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5190 QDF_MAC_ADDR_SIZE);
5191 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5192 QDF_MAC_ADDR_SIZE);
5193
5194 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5195 if (IS_SNAP(llc_hdr)) {
5196 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5197 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5198 }
5199
5200 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5201
5202 /*
5203 * This HLP packet is formed from HLP info encapsulated
5204 * in assoc response frame which is AEAD encrypted.
5205 * Hence, this checksum validation can be set unnecessary.
5206 * i.e. network layer need not worry about checksum.
5207 */
5208 skb->ip_summed = CHECKSUM_UNNECESSARY;
5209
5210 status = hdd_rx_packet_cbk(padapter, skb);
5211 if (QDF_IS_STATUS_ERROR(status)) {
5212 hdd_err("Sending HLP packet fails");
5213 return;
5214 }
5215 hdd_debug("send HLP packet to netif successfully");
5216}
5217
5218/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305219 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5220 * @dev: network device
5221 * @bssid: bssid to which we want to associate
5222 * @bss: cfg80211 bss info
5223 * @roam_info: information about connected bss
5224 * @req_ie: Request Information Element
5225 * @req_ie_len: len of the req IE
5226 * @resp_ie: Response IE
5227 * @resp_ie_len: len of ht response IE
5228 * @status: status
5229 * @gfp: allocation flags
5230 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5231 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305232 *
5233 * This API is used as wrapper to send FILS key/sequence number
5234 * params etc. to supplicant in case of FILS connection
5235 *
5236 * Return: None
5237 */
5238static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005239 struct cfg80211_bss *bss,
5240 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305241 const u8 *req_ie, size_t req_ie_len,
5242 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005243 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305244 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305245{
5246 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305247 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5248 struct fils_join_rsp_params *roam_fils_params =
5249 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005250
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305251 qdf_mem_zero(&fils_params, sizeof(fils_params));
5252
5253 if (!roam_fils_params) {
5254 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5255 } else {
5256 fils_params.status = status;
5257 fils_params.bssid = bssid;
5258 fils_params.timeout_reason = timeout_reason;
5259 fils_params.req_ie = req_ie;
5260 fils_params.req_ie_len = req_ie_len;
5261 fils_params.resp_ie = resp_ie;
5262 fils_params.resp_ie_len = resp_ie_len;
5263 fils_params.bss = bss;
5264 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5265 roam_fils_params->kek_len,
5266 roam_fils_params->fils_pmk,
5267 roam_fils_params->fils_pmk_len,
5268 roam_fils_params->fils_pmkid,
5269 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305270 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305271 }
5272 hdd_debug("FILS indicate connect status %d seq no %d",
5273 fils_params.status,
5274 fils_params.fils_erp_next_seq_num);
5275
5276 cfg80211_connect_done(dev, &fils_params, gfp);
5277
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305278 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305279 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305280
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305281 /* Clear all the FILS key info */
5282 if (roam_fils_params && roam_fils_params->fils_pmk)
5283 qdf_mem_free(roam_fils_params->fils_pmk);
5284 if (roam_fils_params)
5285 qdf_mem_free(roam_fils_params);
5286 roam_info->fils_join_rsp = NULL;
5287}
5288#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005289static inline void
5290hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005291 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005292 const u8 *req_ie, size_t req_ie_len,
5293 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5294 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305295 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305296{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305297#endif
5298#endif
5299
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305300#if defined(WLAN_FEATURE_FILS_SK) && \
5301 (defined(CFG80211_CONNECT_DONE) || \
5302 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305303/**
5304 * hdd_fils_update_connect_results() - API to send fils connection status to
5305 * supplicant.
5306 * @dev: network device
5307 * @bssid: bssid to which we want to associate
5308 * @bss: cfg80211 bss info
5309 * @roam_info: information about connected bss
5310 * @req_ie: Request Information Element
5311 * @req_ie_len: len of the req IE
5312 * @resp_ie: Response IE
5313 * @resp_ie_len: len of ht response IE
5314 * @status: status
5315 * @gfp: allocation flags
5316 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5317 * @timeout_reason: reason for connect timeout
5318 *
5319 * The API is a wrapper to send connection status to supplicant
5320 *
5321 * Return: 0 if success else failure
5322 */
5323static int hdd_fils_update_connect_results(struct net_device *dev,
5324 const u8 *bssid,
5325 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005326 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305327 size_t req_ie_len, const u8 *resp_ie,
5328 size_t resp_ie_len, u16 status, gfp_t gfp,
5329 bool connect_timeout,
5330 tSirResultCodes timeout_reason)
5331{
5332 ENTER();
5333 if (!roam_info || !roam_info->is_fils_connection)
5334 return -EINVAL;
5335
5336 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5337 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305338 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305339 return 0;
5340}
5341#else
5342static inline int hdd_fils_update_connect_results(struct net_device *dev,
5343 const u8 *bssid,
5344 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005345 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305346 size_t req_ie_len, const u8 *resp_ie,
5347 size_t resp_ie_len, u16 status, gfp_t gfp,
5348 bool connect_timeout,
5349 tSirResultCodes timeout_reason)
5350{
5351 return -EINVAL;
5352}
5353#endif
5354
Anurag Chouhanc4092922016-09-08 15:56:11 +05305355/**
5356 * hdd_connect_result() - API to send connection status to supplicant
5357 * @dev: network device
5358 * @bssid: bssid to which we want to associate
5359 * @roam_info: information about connected bss
5360 * @req_ie: Request Information Element
5361 * @req_ie_len: len of the req IE
5362 * @resp_ie: Response IE
5363 * @resp_ie_len: len of ht response IE
5364 * @status: status
5365 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305366 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305367 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305368 *
5369 * The API is a wrapper to send connection status to supplicant
5370 * and allow runtime suspend
5371 *
5372 * Return: Void
5373 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305374void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005375 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305376 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305377 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305378 bool connect_timeout,
5379 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305380{
Jeff Johnson9d295242017-08-29 14:39:48 -07005381 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305382 struct cfg80211_bss *bss = NULL;
5383
5384 if (WLAN_STATUS_SUCCESS == status) {
5385 struct ieee80211_channel *chan;
5386 int freq;
5387 int chan_no = roam_info->pBssDesc->channelId;
5388
5389 if (chan_no <= 14)
5390 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005391 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305392 else
5393 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005394 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305395
5396 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5397 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5398 roam_info->u.pConnectedProfile->SSID.ssId,
5399 roam_info->u.pConnectedProfile->SSID.length);
5400 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305401
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305402 if (hdd_fils_update_connect_results(dev, bssid, bss,
5403 roam_info, req_ie, req_ie_len, resp_ie,
5404 resp_ie_len, status, gfp, connect_timeout,
5405 timeout_reason) != 0) {
5406 hdd_connect_bss(dev, bssid, bss, req_ie,
5407 req_ie_len, resp_ie, resp_ie_len,
5408 status, gfp, connect_timeout, timeout_reason);
5409 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305410
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005411 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005412 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305413}
5414#else
5415void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005416 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305417 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305418 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305419 bool connect_timeout,
5420 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305421{
Jeff Johnson9d295242017-08-29 14:39:48 -07005422 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Komal Seelama89be8d2016-09-29 11:09:26 +05305423
Anurag Chouhanc4092922016-09-08 15:56:11 +05305424 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5425 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005426
5427 qdf_runtime_pm_allow_suspend(&padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005428 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305429}
5430#endif
5431
5432
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005433QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005434{
Jeff Johnson9d295242017-08-29 14:39:48 -07005435 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005436#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05305437 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005438#endif
5439 eConnectionState connState;
5440
5441 ENTER();
5442
Dustin Brown920397d2017-12-13 16:27:50 -08005443 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305444 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005445 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305446
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447 hdd_wmm_init(adapter);
5448
5449 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005450 case QDF_STA_MODE:
5451 case QDF_P2P_CLIENT_MODE:
5452 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453
5454 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5455 ->conn_info.connState;
5456
Krunal Sonib51eec72017-11-20 21:53:01 -08005457 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005459 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005461 /* Indicate disconnect event to supplicant
5462 * if associated previously
5463 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005464 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005465 eConnectionState_IbssConnected == connState ||
5466 eConnectionState_NotConnected == connState ||
5467 eConnectionState_IbssDisconnected == connState ||
5468 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005469 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005471 memset(&wrqu, '\0', sizeof(wrqu));
5472 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5473 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5474 wireless_send_event(adapter->dev, SIOCGIWAP,
5475 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005476 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005477 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005478
5479 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305480 wlan_hdd_cfg80211_indicate_disconnect(
5481 adapter->dev, false,
5482 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483 } else if (eConnectionState_Connecting == connState) {
5484 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005485 * Indicate connect failure to supplicant if we
5486 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005487 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305488 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305489 NULL, 0, NULL, 0,
5490 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005491 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005492 }
5493
5494 hdd_register_tx_flow_control(adapter,
5495 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005496 hdd_tx_resume_cb,
5497 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005498
5499 break;
5500
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005501 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005502 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005503 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305504
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505 break;
5506
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005507 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005509 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5511#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005512 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513 /* event supplicant to restart */
5514 cfg80211_del_sta(adapter->dev,
5515 (const u8 *)&bcastMac.bytes[0],
5516 GFP_KERNEL);
5517#endif
5518 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305519 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005520 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305521 hdd_set_mon_rx_cb(adapter->dev);
5522 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5523 adapter->mon_bandwidth);
5524 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005525 default:
5526 break;
5527 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005528 /*
5529 * Action frame registered in one adapter which will
5530 * applicable to all interfaces
5531 */
5532 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533 }
5534
5535 EXIT();
5536
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305537 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005538}
5539
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005540QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005541 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305543 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005544 qdf_list_node_t *node;
5545
5546 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005547
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005548 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005549 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005550 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005551
5552 if (QDF_IS_STATUS_ERROR(status))
5553 return status;
5554
5555 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5556
5557 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558}
5559
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005560QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005561 struct hdd_adapter *current_adapter,
5562 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005563{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305564 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005565 qdf_list_node_t *node;
5566
5567 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005568
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005569 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005570 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005571 &current_adapter->node,
5572 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005573 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005574
5575 if (QDF_IS_STATUS_ERROR(status))
5576 return status;
5577
5578 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5579
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005580 return status;
5581}
5582
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005583QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005584 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005585{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305586 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005587
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005588 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005589 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005590 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005592 return status;
5593}
5594
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005595QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005596 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005597{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305598 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005599 qdf_list_node_t *node;
5600
5601 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005602
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005603 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005604 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005605 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005606
5607 if (QDF_IS_STATUS_ERROR(status))
5608 return status;
5609
5610 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005612 return status;
5613}
5614
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005615QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005616 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005617{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305618 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005619
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005620 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005621 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005622 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005624 return status;
5625}
5626
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005627QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005628 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305630 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005631
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005632 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005633 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005634 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005636 return status;
5637}
5638
Jeff Johnson9d295242017-08-29 14:39:48 -07005639struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640 tSirMacAddr macAddr)
5641{
Jeff Johnson9d295242017-08-29 14:39:48 -07005642 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005643
Dustin Brown920397d2017-12-13 16:27:50 -08005644 hdd_for_each_adapter(hdd_ctx, adapter) {
5645 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
5646 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648 }
5649
5650 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651}
5652
Jeff Johnson9d295242017-08-29 14:39:48 -07005653struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654 uint32_t vdev_id)
5655{
Jeff Johnson9d295242017-08-29 14:39:48 -07005656 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657
Dustin Brown920397d2017-12-13 16:27:50 -08005658 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07005659 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661 }
5662
Jeff Johnson5880d792016-08-15 13:32:30 -07005663 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664
5665 return NULL;
5666}
5667
Abhishek Singh7996eb72015-12-30 17:24:02 +05305668/**
5669 * hdd_get_adapter_by_sme_session_id() - Return adapter with
5670 * the sessionid
5671 * @hdd_ctx: hdd context.
5672 * @sme_session_id: sme session is for the adapter to get.
5673 *
5674 * This function is used to get the adapter with provided session id
5675 *
5676 * Return: adapter pointer if found
5677 *
5678 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07005679struct hdd_adapter *
5680hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
5681 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305682{
Jeff Johnson9d295242017-08-29 14:39:48 -07005683 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305684
Dustin Brown920397d2017-12-13 16:27:50 -08005685 hdd_for_each_adapter(hdd_ctx, adapter) {
5686 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05305687 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05305688 }
Dustin Brown920397d2017-12-13 16:27:50 -08005689
Abhishek Singh7996eb72015-12-30 17:24:02 +05305690 return NULL;
5691}
5692
Jeff Johnson9d295242017-08-29 14:39:48 -07005693struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07005694 const char *iface_name)
5695{
Jeff Johnson9d295242017-08-29 14:39:48 -07005696 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005697
Dustin Brown920397d2017-12-13 16:27:50 -08005698 hdd_for_each_adapter(hdd_ctx, adapter) {
5699 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07005700 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07005701 }
Dustin Brown920397d2017-12-13 16:27:50 -08005702
Naveen Rawat4edb6822017-04-12 10:09:17 -07005703 return NULL;
5704}
5705
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005706/**
5707 * hdd_get_adapter() - to get adapter matching the mode
5708 * @hdd_ctx: hdd context
5709 * @mode: adapter mode
5710 *
5711 * This routine will return the pointer to adapter matching
5712 * with the passed mode.
5713 *
5714 * Return: pointer to adapter or null
5715 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005716struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005717 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005718{
Jeff Johnson9d295242017-08-29 14:39:48 -07005719 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720
Dustin Brown920397d2017-12-13 16:27:50 -08005721 hdd_for_each_adapter(hdd_ctx, adapter) {
5722 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005723 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724 }
5725
5726 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727}
5728
5729/**
5730 * hdd_get_operating_channel() - return operating channel of the device mode
5731 * @hdd_ctx: Pointer to the HDD context.
5732 * @mode: Device mode for which operating channel is required.
5733 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005734 * QDF_STA_MODE,
5735 * QDF_P2P_CLIENT_MODE,
5736 * QDF_SAP_MODE,
5737 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005738 *
5739 * This API returns the operating channel of the requested device mode
5740 *
5741 * Return: channel number. "0" id the requested device is not found OR it is
5742 * not connected.
5743 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005744uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08005745 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746{
Jeff Johnson9d295242017-08-29 14:39:48 -07005747 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748 uint8_t operatingChannel = 0;
5749
Dustin Brown920397d2017-12-13 16:27:50 -08005750 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751 if (mode == adapter->device_mode) {
5752 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005753 case QDF_STA_MODE:
5754 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005755 if (hdd_conn_is_connected
5756 (WLAN_HDD_GET_STATION_CTX_PTR
5757 (adapter))) {
5758 operatingChannel =
5759 (WLAN_HDD_GET_STATION_CTX_PTR
5760 (adapter))->conn_info.
5761 operationChannel;
5762 }
5763 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005764 case QDF_SAP_MODE:
5765 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005766 /* softap connection info */
5767 if (test_bit
5768 (SOFTAP_BSS_STARTED,
5769 &adapter->event_flags))
5770 operatingChannel =
5771 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07005772 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773 break;
5774 default:
5775 break;
5776 }
5777
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005778 /* Found the device of interest. break the loop */
5779 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005781 }
Dustin Brown920397d2017-12-13 16:27:50 -08005782
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005783 return operatingChannel;
5784}
5785
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005786static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005787 hdd_ctx)
5788{
Jeff Johnson9d295242017-08-29 14:39:48 -07005789 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005790
5791 ENTER();
5792
Dustin Brown920397d2017-12-13 16:27:50 -08005793 hdd_for_each_adapter(hdd_ctx, adapter) {
5794 if (adapter->device_mode == QDF_STA_MODE ||
5795 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5796 adapter->device_mode == QDF_IBSS_MODE ||
5797 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5798 adapter->device_mode == QDF_SAP_MODE ||
5799 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 wlan_hdd_cfg80211_deregister_frames(adapter);
5801 hdd_unregister_wext(adapter->dev);
5802 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005803 }
5804
5805 EXIT();
5806
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305807 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005808}
5809
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005810QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811{
Jeff Johnson9d295242017-08-29 14:39:48 -07005812 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813
5814 ENTER();
5815
Dustin Brown920397d2017-12-13 16:27:50 -08005816 hdd_for_each_adapter(hdd_ctx, adapter) {
5817 if (adapter->device_mode == QDF_STA_MODE ||
5818 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5819 adapter->device_mode == QDF_IBSS_MODE ||
5820 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5821 adapter->device_mode == QDF_SAP_MODE ||
5822 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005823 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005824 adapter->session_id, INVALID_SCAN_ID,
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07005825 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005826 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005827 }
5828
5829 EXIT();
5830
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305831 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005832}
5833
Dustin Brownf27bce82016-11-03 12:52:27 -07005834/**
5835 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5836 * adapters
5837 * @hdd_ctx: The HDD context containing the adapters to operate on
5838 *
5839 * return: QDF_STATUS_SUCCESS
5840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005841static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07005842{
Jeff Johnson9d295242017-08-29 14:39:48 -07005843 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07005844 int err;
5845
5846 ENTER();
5847
Dustin Brown920397d2017-12-13 16:27:50 -08005848 hdd_for_each_adapter(hdd_ctx, adapter) {
5849 if (adapter->device_mode == QDF_STA_MODE ||
5850 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
5851 adapter->device_mode == QDF_IBSS_MODE ||
5852 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
5853 adapter->device_mode == QDF_SAP_MODE ||
5854 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07005855 err = wlan_hdd_sched_scan_stop(adapter->dev);
5856 if (err)
5857 hdd_err("Unable to stop scheduled scan");
5858 }
Dustin Brownf27bce82016-11-03 12:52:27 -07005859 }
5860
5861 EXIT();
5862
5863 return QDF_STATUS_SUCCESS;
5864}
5865
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866#ifdef WLAN_NS_OFFLOAD
5867/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005868 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869 * @hdd_ctx: Pointer to hdd context
5870 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005871 * Unregister for IPv6 address change notifications.
5872 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005873 * Return: None
5874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005875static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005876{
5877 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878}
5879
5880/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005881 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005882 * @hdd_ctx: Pointer to hdd context
5883 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005884 * Register for IPv6 address change notifications.
5885 *
5886 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005888static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005889{
5890 int ret;
5891
5892 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5893 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005894 if (ret) {
5895 hdd_err("Failed to register IPv6 notifier: %d", ret);
5896 goto out;
5897 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005899 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005900out:
5901 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005902}
5903#else
5904/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005905 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005906 * @hdd_ctx: Pointer to hdd context
5907 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005908 * Unregister for IPv6 address change notifications.
5909 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005910 * Return: None
5911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005912static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005913{
5914}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005917 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005918 * @hdd_ctx: Pointer to hdd context
5919 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005920 * Register for IPv6 address change notifications.
5921 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005922 * Return: None
5923 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005924static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005926 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005927}
5928#endif
5929
5930/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005931 * hdd_register_notifiers - Register netdev notifiers.
5932 * @hdd_ctx: HDD context
5933 *
5934 * Register netdev notifiers like IPv4 and IPv6.
5935 *
5936 * Return: 0 on success and errno on failure
5937 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005938static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005939{
5940 int ret;
5941
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005942 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5943 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05305944 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005945
5946 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5947 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5948 if (ret) {
5949 hdd_err("Failed to register IPv4 notifier: %d", ret);
5950 goto unregister_ip6_notifier;
5951 }
5952
5953 return 0;
5954
5955unregister_ip6_notifier:
5956 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005957out:
5958 return ret;
5959
5960}
5961
5962/**
5963 * hdd_unregister_notifiers - Unregister netdev notifiers.
5964 * @hdd_ctx: HDD context
5965 *
5966 * Unregister netdev notifiers like IPv4 and IPv6.
5967 *
5968 * Return: None.
5969 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005970void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005971{
5972 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5973
5974 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005975}
5976
5977/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005978 * hdd_exit_netlink_services - Exit netlink services
5979 * @hdd_ctx: HDD context
5980 *
5981 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5982 * nl service.
5983 *
5984 * Return: None.
5985 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005986static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005987{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005988 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005989 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005990 ptt_sock_deactivate_svc();
5991
5992 nl_srv_exit();
5993}
5994
5995/**
5996 * hdd_init_netlink_services- Init netlink services
5997 * @hdd_ctx: HDD context
5998 *
5999 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6000 * nl service.
6001 *
6002 * Return: 0 on success and errno on failure.
6003 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006004static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006005{
6006 int ret;
6007
Ryan Hsuceddceb2016-04-28 10:20:14 -07006008 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006009 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006010 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006011 goto out;
6012 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006013 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006014
Naveen Rawat910726a2017-03-06 11:42:51 -08006015 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006016 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006017 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006018 goto err_nl_srv;
6019 }
6020
6021 ret = ptt_sock_activate_svc();
6022 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006023 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006024 goto err_nl_srv;
6025 }
6026
6027 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006028 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006029 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006030
6031 ret = cnss_diag_activate_service();
6032 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006033 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006034 goto err_close_cesium;
6035 }
6036
6037 return 0;
6038
6039err_close_cesium:
6040 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006041 ptt_sock_deactivate_svc();
6042err_nl_srv:
6043 nl_srv_exit();
6044out:
6045 return ret;
6046}
6047
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006048/**
6049 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6050 * @hdd_ctx: HDD context.
6051 *
6052 * Destroy RX wakelock.
6053 *
6054 * Return: None.
6055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006056static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006057{
6058 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6059}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006060
6061/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006062 * hdd_rx_wake_lock_create() - Create RX wakelock
6063 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006064 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006065 * Create RX wakelock.
6066 *
6067 * Return: None.
6068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006069static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006070{
6071 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6072}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006073
6074/**
Houston Hoffman160db392016-10-10 17:37:51 -07006075 * hdd_context_deinit() - Deinitialize HDD context
6076 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006077 *
Houston Hoffman160db392016-10-10 17:37:51 -07006078 * Deinitialize HDD context along with all the feature specific contexts but
6079 * do not free hdd context itself. Caller of this API is supposed to free
6080 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006081 *
Houston Hoffman160db392016-10-10 17:37:51 -07006082 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006083 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006084static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006085{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306086 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6087
Houston Hoffman160db392016-10-10 17:37:51 -07006088 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006089
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006090 hdd_sap_context_destroy(hdd_ctx);
6091
6092 hdd_rx_wake_lock_destroy(hdd_ctx);
6093
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006094 hdd_scan_context_destroy(hdd_ctx);
6095
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006096 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006097
Houston Hoffman160db392016-10-10 17:37:51 -07006098 return 0;
6099}
6100
6101/**
6102 * hdd_context_destroy() - Destroy HDD context
6103 * @hdd_ctx: HDD context to be destroyed.
6104 *
6105 * Free config and HDD context as well as destroy all the resources.
6106 *
6107 * Return: None
6108 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006109static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006110{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006111 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306112
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306113 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6114
Houston Hoffman160db392016-10-10 17:37:51 -07006115 hdd_context_deinit(hdd_ctx);
6116
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306117 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006118 hdd_ctx->config = NULL;
6119
6120 wiphy_free(hdd_ctx->wiphy);
6121}
6122
6123/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306124 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6125 *
6126 * This function is used to destroy bug report lock
6127 *
6128 * Return: None
6129 */
6130static void wlan_destroy_bug_report_lock(void)
6131{
6132 p_cds_contextType p_cds_context;
6133
6134 p_cds_context = cds_get_global_context();
6135 if (!p_cds_context) {
6136 hdd_err("cds context is NULL");
6137 return;
6138 }
6139
6140 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6141}
6142
6143/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006144 * hdd_wlan_exit() - HDD WLAN exit function
6145 * @hdd_ctx: Pointer to the HDD Context
6146 *
6147 * This is the driver exit point (invoked during rmmod)
6148 *
6149 * Return: None
6150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006151static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306154 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155
6156 ENTER();
6157
Dustin Brown6f427922017-09-19 12:19:00 -07006158 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306159
6160 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161
Prashanth Bhattaab004382016-10-11 16:08:11 -07006162 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006163
6164#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306165 if (QDF_TIMER_STATE_RUNNING ==
6166 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6167 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 }
6169
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306170 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306171 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006172 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006174 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6175 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6176 hdd_ctx->last_acs_channel_list = NULL;
6177 hdd_ctx->num_of_channels = 0;
6178 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006179#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180
Arun Khandavallifae92942016-08-01 13:31:08 +05306181 mutex_lock(&hdd_ctx->iface_change_lock);
6182 driver_status = hdd_ctx->driver_status;
6183 mutex_unlock(&hdd_ctx->iface_change_lock);
6184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 /*
6186 * Powersave Offload Case
6187 * Disable Idle Power Save Mode
6188 */
6189 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006190 /* clear the scan queue in all the scenarios */
6191 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006192
Arun Khandavallifae92942016-08-01 13:31:08 +05306193 if (driver_status != DRIVER_MODULES_CLOSED) {
6194 hdd_unregister_wext_all_adapters(hdd_ctx);
6195 /*
6196 * Cancel any outstanding scan requests. We are about to close
6197 * all of our adapters, but an adapter structure is what SME
6198 * passes back to our callback function. Hence if there
6199 * are any outstanding scan requests then there is a
6200 * race condition between when the adapter is closed and
6201 * when the callback is invoked. We try to resolve that
6202 * race condition here by canceling any outstanding scans
6203 * before we close the adapters.
6204 * Note that the scans may be cancelled in an asynchronous
6205 * manner, so ideally there needs to be some kind of
6206 * synchronization. Rather than introduce a new
6207 * synchronization here, we will utilize the fact that we are
6208 * about to Request Full Power, and since that is synchronized,
6209 * the expectation is that by the time Request Full Power has
6210 * completed, all scans will be cancelled
6211 */
6212 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006213 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -07006214 hdd_stop_all_adapters(hdd_ctx, true);
bings29c99862017-11-01 13:54:13 +08006215 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216 }
6217
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306218 unregister_netdevice_notifier(&hdd_netdev_notifier);
6219
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006220 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306221
Dustin Brown021cecd2017-12-11 13:56:43 -08006222 memdump_deinit();
6223 hdd_driver_memdump_deinit();
6224
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306225 qdf_nbuf_deinit_replenish_timer();
6226
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306227 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6228 hdd_info("Release wakelock for monitor mode!");
6229 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6230 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6231 }
6232
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306233 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6234 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6235 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6236
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237 /*
6238 * Close CDS
6239 * This frees pMac(HAL) context. There should not be any call
6240 * that requires pMac access after this.
6241 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006242
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07006243 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006244 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08006246 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247
6248 hdd_ipa_cleanup(hdd_ctx);
6249
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306250 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05306251 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306252 /*
6253 * If there is re_init failure wiphy would have already de-registered
6254 * check the wiphy status before un-registering again
6255 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306256 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306257 wiphy_unregister(wiphy);
6258 wlan_hdd_cfg80211_deinit(wiphy);
6259 hdd_lpass_notify_stop(hdd_ctx);
6260 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006261
Arun Khandavallifae92942016-08-01 13:31:08 +05306262 hdd_exit_netlink_services(hdd_ctx);
6263 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306264#ifdef FEATURE_WLAN_CH_AVOID
6265 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6266#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306267
Abhishek Singhe9068f12017-03-31 14:14:52 +05306268 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6269 if (driver_status)
6270 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006271
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006272 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273}
6274
6275void __hdd_wlan_exit(void)
6276{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006277 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006278
6279 ENTER();
6280
Anurag Chouhan6d760662016-02-20 16:05:43 +05306281 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006282 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006283 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284 EXIT();
6285 return;
6286 }
6287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288 /* Do all the cleanup before deregistering the driver */
6289 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291 EXIT();
6292}
6293
6294#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006295/**
6296 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006297 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006298 *
6299 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6300 * Then new ACS request will do a fresh scan without reusing the cached
6301 * scan information.
6302 *
6303 * Return: void
6304 */
Tang Yingying523322d2017-01-17 23:28:43 +08006305static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006307 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006309 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006310 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006311 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6312 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6313 hdd_ctx->last_acs_channel_list = NULL;
6314 hdd_ctx->num_of_channels = 0;
6315 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006316
6317 if (!hdd_ctx->hHal)
6318 return;
6319 sme_scan_flush_result(hdd_ctx->hHal);
6320}
6321#endif
6322
6323#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006324int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6325 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326{
6327 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306328 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006329 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330
6331 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6332
6333 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306334 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006335 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 if (!hdd_ctx->hHal)
6338 return -EINVAL;
6339
Jeff Johnsone7672e72017-10-21 15:10:04 -07006340 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006341 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306342 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006343 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006344 return -EINVAL;
6345 }
6346
6347 return 0;
6348}
6349#endif
6350
6351/**
6352 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6353 * @state: state
6354 *
6355 * This function notifies FW with modem power status
6356 *
6357 * Return: 0 if successful, error number otherwise
6358 */
6359int hdd_wlan_notify_modem_power_state(int state)
6360{
6361 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306362 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006363 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364
Anurag Chouhan6d760662016-02-20 16:05:43 +05306365 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306367 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370 if (!hdd_ctx->hHal)
6371 return -EINVAL;
6372
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306373 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6374 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006375 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376 state);
6377 return -EINVAL;
6378 }
6379 return 0;
6380}
6381
6382/**
6383 *
6384 * hdd_post_cds_enable_config() - HDD post cds start config helper
6385 * @adapter - Pointer to the HDD
6386 *
6387 * Return: None
6388 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006389QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306391 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392
6393 /*
6394 * Send ready indication to the HDD. This will kick off the MAC
6395 * into a 'running' state and should kick off an initial scan.
6396 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306397 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6398 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006399 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6400 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306401 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 }
6403
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306404 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405}
6406
6407/* wake lock APIs for HDD */
6408void hdd_prevent_suspend(uint32_t reason)
6409{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306410 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006411}
6412
6413void hdd_allow_suspend(uint32_t reason)
6414{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306415 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416}
6417
6418void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6419{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306420 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6421 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422}
6423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006425QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006427
Amar Singhal6f8592b2017-04-26 14:31:58 -07006428 return sme_init_chan_list(hdd_ctx->hHal,
6429 hdd_ctx->reg.alpha2,
6430 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431}
6432
6433/**
6434 * hdd_is_5g_supported() - check if hardware supports 5GHz
6435 * @hdd_ctx: Pointer to the hdd context
6436 *
6437 * HDD function to know if hardware supports 5GHz
6438 *
6439 * Return: true if hardware supports 5GHz
6440 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006441bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006442{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006443 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006444 return true;
6445
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006446 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006447 return true;
6448 else
6449 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450}
6451
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006452static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006453{
6454 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006455 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006456
6457 wiphy = hdd_ctx->wiphy;
6458
6459 /*
6460 * The channel information in
6461 * wiphy needs to be initialized before wiphy registration
6462 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006463 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6464 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006465 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006466 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006467 }
6468
6469#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6470 wiphy->wowlan = &wowlan_support_reg_init;
6471#else
6472 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6473 WIPHY_WOWLAN_MAGIC_PKT |
6474 WIPHY_WOWLAN_DISCONNECT |
6475 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6476 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6477 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6478 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6479 WIPHY_WOWLAN_RFKILL_RELEASE;
6480
6481 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6482 WOW_MAX_FILTERS_PER_LIST);
6483 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6484 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6485#endif
6486
6487 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006488 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306489 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006490 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306491 return ret_val;
6492 }
6493
Amar Singhal5cccafe2017-02-15 12:42:58 -08006494 if (!hdd_ctx->reg_offload)
6495 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496
Amar Singhale4f28ee2015-10-21 14:36:56 -07006497 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498}
6499
Mohit Khannaca4173b2017-09-12 21:52:19 -07006500#ifdef MSM_PLATFORM
6501/**
6502 * hdd_display_periodic_stats() - Function to display periodic stats
6503 * @hdd_ctx - handle to hdd context
6504 * @bool data_in_interval - true, if data detected in bw time interval
6505 *
6506 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6507 * Stats show up in wlan driver logs.
6508 *
6509 * Returns: None
6510 */
6511static inline
6512void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6513 bool data_in_interval)
6514{
6515 static u32 counter;
6516 static bool data_in_time_period;
6517 ol_txrx_pdev_handle pdev;
6518
6519 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6520 return;
6521
6522 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6523 if (!pdev) {
6524 hdd_err("pdev is NULL");
6525 return;
6526 }
6527
6528 counter++;
6529 if (data_in_interval)
6530 data_in_time_period = data_in_interval;
6531
6532 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6533 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6534 if (data_in_time_period) {
6535 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6536 CDP_TXRX_PATH_STATS,
6537 QDF_STATS_VERBOSITY_LEVEL_LOW);
6538 wlan_hdd_display_netif_queue_history
6539 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6540 qdf_dp_trace_dump_stats();
6541 }
6542 counter = 0;
6543 data_in_time_period = false;
6544 }
6545}
6546
Ravi Joshie2331e82015-07-01 18:18:54 -07006547/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006548 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006549 * @hdd_ctx - handle to hdd context
6550 * @tx_packets - transmit packet count
6551 * @rx_packets - receive packet count
6552 *
6553 * The function controls the bus bandwidth and dynamic control of
6554 * tcp delayed ack configuration
6555 *
6556 * Returns: None
6557 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006558
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006559static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006560 const uint64_t tx_packets,
6561 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006563 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006564 uint64_t temp_rx = 0;
6565 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006566 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006567 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006568 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006569 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006570 uint16_t index = 0;
6571 bool vote_level_change = false;
6572 bool rx_level_change = false;
6573 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574
Mohit Khannaca4173b2017-09-12 21:52:19 -07006575 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006576 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006577 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006578 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006579 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006580 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006581 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006582 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006585 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6586 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006587 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006588 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006589 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306590 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306591 if (hdd_ctx->hbw_requested) {
6592 pld_remove_pm_qos(hdd_ctx->parent_dev);
6593 hdd_ctx->hbw_requested = false;
6594 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306595 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006596 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006597 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306598 if (!hdd_ctx->hbw_requested) {
6599 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6600 hdd_ctx->hbw_requested = true;
6601 }
6602
Nirav Shah3bbfa512016-05-12 16:43:49 +05306603 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006604 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006605 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006606 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006608
Mohit Khannaf8f96822017-05-17 17:11:59 -07006609 qdf_dp_trace_throttle_live_mode(
6610 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
6611
Mohit Khannae71e2262015-11-10 09:37:24 -08006612 /* fine-tuning parameters for RX Flows */
6613 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6614
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006615 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006616
Poddar, Siddarth47c23402017-10-25 12:17:39 +05306617 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
6618 hdd_disable_lro_for_low_tput(hdd_ctx, true);
6619 else
6620 hdd_disable_lro_for_low_tput(hdd_ctx, false);
6621
Ravi Joshifed83572016-10-07 16:20:37 -07006622 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6623 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6624 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6625 next_rx_level = WLAN_SVC_TP_HIGH;
6626 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006627 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006628 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006629 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006630 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006633 struct wlan_rx_tp_data rx_tp_data = {0};
6634
Ravi Joshie2331e82015-07-01 18:18:54 -07006635 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006636 next_rx_level, temp_rx);
6637 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006638 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006639 /* Send throughput indication only if it is enabled.
6640 * Disabling tcp_del_ack will revert the tcp stack behavior
6641 * to default delayed ack. Note that this will disable the
6642 * dynamic delayed ack mechanism across the system
6643 */
6644 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006645 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
6646
Mohit Khanna6272fb682017-04-13 09:34:36 -07006647 if (hdd_ctx->config->enable_tcp_adv_win_scale)
6648 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
6649
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07006650 rx_tp_data.level = next_rx_level;
6651 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6652 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
6653 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006654 }
6655
Mohit Khannae71e2262015-11-10 09:37:24 -08006656 /* fine-tuning parameters for TX Flows */
6657 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6658 hdd_ctx->prev_tx = tx_packets;
6659 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6660 next_tx_level = WLAN_SVC_TP_HIGH;
6661 else
6662 next_tx_level = WLAN_SVC_TP_LOW;
6663
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006664 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006665 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6666 next_tx_level, temp_tx);
6667 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006668 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306669 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6670 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006671 &next_tx_level,
6672 sizeof(next_tx_level));
6673 }
6674
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006675 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006676 if (vote_level_change || tx_level_change || rx_level_change) {
6677 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6678 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6679 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6680 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6681 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6682 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6683 hdd_ctx->hdd_txrx_hist_idx++;
6684 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6685 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07006686
6687 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006688}
6689
6690#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306691static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006693 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306694 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07006695 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306696 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306697 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6698 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306700 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701 bool connected = false;
6702 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6703
Prashanth Bhattaab004382016-10-11 16:08:11 -07006704 if (wlan_hdd_validate_context(hdd_ctx))
6705 return;
6706
Jeff Johnson214671b2017-10-30 19:45:23 -07006707 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08006708 goto restart_timer;
6709
Dustin Brown920397d2017-12-13 16:27:50 -08006710 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05306711 /*
6712 * Validate magic so we don't end up accessing
6713 * an invalid adapter.
6714 */
6715 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6716 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006718 if ((adapter->device_mode == QDF_STA_MODE ||
6719 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006720 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6721 != eConnectionState_Associated) {
6722
6723 continue;
6724 }
6725
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006726 if ((adapter->device_mode == QDF_SAP_MODE ||
6727 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07006728 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006729
6730 continue;
6731 }
6732
6733 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6734 adapter->prev_tx_packets);
6735 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6736 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306737
6738 if (adapter->device_mode == QDF_SAP_MODE ||
6739 adapter->device_mode == QDF_P2P_GO_MODE ||
6740 adapter->device_mode == QDF_IBSS_MODE) {
6741
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006742 ret = cdp_get_intra_bss_fwd_pkts_count(
6743 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07006744 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306745 &fwd_tx_packets, &fwd_rx_packets);
6746 if (ret == A_OK) {
6747 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6748 fwd_tx_packets,
6749 adapter->prev_fwd_tx_packets);
6750 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6751 fwd_tx_packets,
6752 adapter->prev_fwd_rx_packets);
6753 }
6754 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006755
6756 total_rx += adapter->stats.rx_packets;
6757 total_tx += adapter->stats.tx_packets;
6758
6759 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6760 adapter->prev_tx_packets = adapter->stats.tx_packets;
6761 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306762 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6763 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6765 connected = true;
6766 }
6767
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306768 /* add intra bss forwarded tx and rx packets */
6769 tx_packets += fwd_tx_packets_diff;
6770 rx_packets += fwd_rx_packets_diff;
6771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6773 tx_packets += (uint64_t)ipa_tx_packets;
6774 rx_packets += (uint64_t)ipa_rx_packets;
6775
Yun Park2aa880c2017-08-22 10:58:10 -07006776 if (adapter) {
6777 adapter->stats.tx_packets += ipa_tx_packets;
6778 adapter->stats.rx_packets += ipa_rx_packets;
6779 }
6780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006782 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006783 return;
6784 }
6785
Yuanyuan Liu13738502016-04-06 17:41:37 -07006786 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787
6788 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6789 hdd_ipa_uc_stat_request(adapter, 2);
6790
Jingxiang Gec64e1932017-08-22 14:38:59 +08006791restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08006792 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006793 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006794 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306795 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006796 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006797 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006799
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306800/**
6801 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6802 * @arg: Argument of timer function
6803 *
6804 * Schedule a workqueue in this function where all the processing is done.
6805 *
6806 * Return: None.
6807 */
6808static void __hdd_bus_bw_cbk(void *arg)
6809{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006810 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306811
6812 if (wlan_hdd_validate_context(hdd_ctx))
6813 return;
6814
6815 schedule_work(&hdd_ctx->bus_bw_work);
6816}
6817
6818/**
6819 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6820 * @arg: Argument of timer function
6821 *
6822 * Return: None.
6823 */
6824static void hdd_bus_bw_cbk(void *arg)
6825{
6826 cds_ssr_protect(__func__);
6827 __hdd_bus_bw_cbk(arg);
6828 cds_ssr_unprotect(__func__);
6829}
6830
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006831int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006832{
6833 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306834 INIT_WORK(&hdd_ctx->bus_bw_work,
6835 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006836 hdd_ctx->bus_bw_timer_running = false;
6837 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306838 qdf_timer_init(NULL,
6839 &hdd_ctx->bus_bw_timer,
6840 hdd_bus_bw_cbk, (void *)hdd_ctx,
6841 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006842
6843 return 0;
6844}
6845
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006846void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006847{
Dustin Brownfce08d12017-01-17 16:29:38 -08006848 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006849 hdd_reset_tcp_delack(hdd_ctx);
6850
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006851 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306852 cancel_work_sync(&hdd_ctx->bus_bw_work);
6853 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006854 hdd_ctx->bus_bw_timer_running = false;
6855 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006856}
Lin Baic5c06882017-09-21 13:58:43 +08006857
6858void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
6859{
6860 if (hdd_ctx)
6861 cancel_work_sync(&hdd_ctx->bus_bw_work);
6862}
jiadcdaf9bd2017-10-26 12:20:21 +08006863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864#endif
6865
6866/**
Nirav Shahed34b212016-04-25 10:59:16 +05306867 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6868 * @hdd_ctx: hdd context
6869 *
6870 * Return: 0 for success or error code
6871 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006872static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306873{
6874 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6875 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6876 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006877 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306878 return -ENOMEM;
6879 }
6880 return 0;
6881}
6882
6883/**
6884 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6885 * @hdd_ctx: hdd context
6886 *
6887 * Return: none
6888 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006889void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306890{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306891 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6892 return;
6893
6894 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6895 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306896}
6897
Nirav Shahda008342016-05-17 18:50:40 +05306898static uint8_t *convert_level_to_string(uint32_t level)
6899{
6900 switch (level) {
6901 /* initialize the wlan sub system */
6902 case WLAN_SVC_TP_NONE:
6903 return "NONE";
6904 case WLAN_SVC_TP_LOW:
6905 return "LOW";
6906 case WLAN_SVC_TP_MEDIUM:
6907 return "MED";
6908 case WLAN_SVC_TP_HIGH:
6909 return "HIGH";
6910 default:
6911 return "INVAL";
6912 }
6913}
6914
Nirav Shahed34b212016-04-25 10:59:16 +05306915
6916/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6918 * @hdd_ctx: hdd context
6919 *
6920 * Return: none
6921 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006922void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923{
6924 int i;
6925
6926#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006927 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306928 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006929 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006930 hdd_ctx->config->busBandwidthHighThreshold,
6931 hdd_ctx->config->busBandwidthMediumThreshold,
6932 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006933 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306934 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006935 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936 hdd_ctx->config->tcpDelackThresholdHigh,
6937 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006938 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306939 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940#endif
6941
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006942 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306943 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6944
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006945 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006946
6947 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006948 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006949 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Houston Hoffman00227112017-08-14 23:58:18 -07006950 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006951 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6952 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006953 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006954 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6955 convert_level_to_string(
6956 hdd_ctx->hdd_txrx_hist[i].
6957 next_vote_level),
6958 convert_level_to_string(
6959 hdd_ctx->hdd_txrx_hist[i].
6960 next_rx_level),
6961 convert_level_to_string(
6962 hdd_ctx->hdd_txrx_hist[i].
6963 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006964 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965}
6966
6967/**
6968 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6969 * @hdd_ctx: hdd context
6970 *
6971 * Return: none
6972 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006973void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006974{
6975 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306976 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6977 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006978}
6979
Mohit Khannaca4173b2017-09-12 21:52:19 -07006980/* length of the netif queue log needed per adapter */
6981#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
6982
6983/**
6984 *
6985 * hdd_display_netif_queue_history_compact() - display compact netifq history
6986 * @hdd_ctx: hdd context
6987 *
6988 * Return: none
6989 */
6990static void
6991hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
6992{
6993 int adapter_num = 0;
6994 int i;
6995 int bytes_written;
6996 u32 tbytes;
6997 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006998 char temp_str[20 * WLAN_REASON_TYPE_MAX];
6999 char comb_log_str[(ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1];
7000 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007001
7002 bytes_written = 0;
7003 qdf_mem_set(comb_log_str, 0, sizeof(comb_log_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07007004
Dustin Brown920397d2017-12-13 16:27:50 -08007005 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007006 curr_time = qdf_system_ticks();
7007 total = curr_time - adapter->start_time;
7008 delta = curr_time - adapter->last_time;
7009
7010 if (adapter->pause_map) {
7011 pause = adapter->total_pause_time + delta;
7012 unpause = adapter->total_unpause_time;
7013 } else {
7014 unpause = adapter->total_unpause_time + delta;
7015 pause = adapter->total_pause_time;
7016 }
7017
7018 tbytes = 0;
7019 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7020 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7021 if (adapter->queue_oper_stats[i].pause_count == 0)
7022 continue;
7023 tbytes +=
7024 snprintf(
7025 &temp_str[tbytes],
7026 (tbytes >= sizeof(temp_str) ?
7027 0 : sizeof(temp_str) - tbytes),
7028 "%d(%d,%d) ",
7029 i,
7030 adapter->queue_oper_stats[i].
7031 pause_count,
7032 adapter->queue_oper_stats[i].
7033 unpause_count);
7034 }
7035 if (tbytes >= sizeof(temp_str))
7036 hdd_warn("log truncated");
7037
7038 bytes_written += snprintf(&comb_log_str[bytes_written],
7039 bytes_written >= sizeof(comb_log_str) ? 0 :
7040 sizeof(comb_log_str) - bytes_written,
7041 "[%d %d] (%d) %u/%ums %s|",
7042 adapter->session_id, adapter->device_mode,
7043 adapter->pause_map,
7044 qdf_system_ticks_to_msecs(pause),
7045 qdf_system_ticks_to_msecs(total),
7046 temp_str);
7047
Mohit Khannaca4173b2017-09-12 21:52:19 -07007048 adapter_num++;
7049 }
7050
7051 /* using QDF_TRACE to avoid printing function name */
7052 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7053 "STATS |%s", comb_log_str);
7054
7055 if (bytes_written >= sizeof(comb_log_str))
7056 hdd_warn("log string truncated");
7057}
7058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007059/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007060 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007061 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007062 *
7063 * Return: none
7064 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007065void
7066wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7067 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007068{
7069
Jeff Johnson9d295242017-08-29 14:39:48 -07007070 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007071 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307072 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073
Mohit Khannaca4173b2017-09-12 21:52:19 -07007074 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7075 hdd_display_netif_queue_history_compact(hdd_ctx);
7076 return;
7077 }
7078
Dustin Brown920397d2017-12-13 16:27:50 -08007079 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007080 hdd_debug("Netif queue operation statistics:");
7081 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007082 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007083 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307084 curr_time = qdf_system_ticks();
7085 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307086 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307087 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307088 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307089 unpause = adapter->total_unpause_time;
7090 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307091 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307092 pause = adapter->total_pause_time;
7093 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007094 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307095 qdf_system_ticks_to_msecs(total),
7096 qdf_system_ticks_to_msecs(pause),
7097 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007098 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007099
Nirav Shahda008342016-05-17 18:50:40 +05307100 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7101 qdf_time_t pause_delta = 0;
7102
7103 if (adapter->pause_map & (1 << i))
7104 pause_delta = delta;
7105
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007106 /* using hdd_log to avoid printing function name */
Houston Hoffman00227112017-08-14 23:58:18 -07007107 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007108 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 hdd_reason_type_to_string(i),
7110 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05307111 adapter->queue_oper_stats[i].unpause_count,
7112 qdf_system_ticks_to_msecs(
7113 adapter->queue_oper_stats[i].total_pause_time +
7114 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 }
7116
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007117 hdd_debug("Netif queue operation history:");
7118 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307119 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7120
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007121 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122
7123 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007124 /* using hdd_log to avoid printing function name */
7125 if (adapter->queue_oper_history[i].time == 0)
7126 continue;
Houston Hoffman00227112017-08-14 23:58:18 -07007127 hdd_log(QDF_TRACE_LEVEL_DEBUG,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007128 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05307129 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 adapter->queue_oper_history[i].time),
7131 hdd_action_type_to_string(
7132 adapter->queue_oper_history[i].netif_action),
7133 hdd_reason_type_to_string(
7134 adapter->queue_oper_history[i].netif_reason),
7135 adapter->queue_oper_history[i].pause_map);
7136 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007137 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138}
7139
7140/**
7141 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7142 * @hdd_ctx: hdd context
7143 *
7144 * Return: none
7145 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007146void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007147{
Jeff Johnson9d295242017-08-29 14:39:48 -07007148 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149
Dustin Brown920397d2017-12-13 16:27:50 -08007150 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307151 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307153 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307155 adapter->history_index = 0;
7156 adapter->start_time = adapter->last_time = qdf_system_ticks();
7157 adapter->total_pause_time = 0;
7158 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007159 }
7160}
7161
7162/**
7163 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7164 * @halHandle: Hal handle
7165 * @pContext: Pointer to the context
7166 * @sessionId: Session ID
7167 * @scanId: Scan ID
7168 * @status: Status
7169 *
7170 * This is the callback to be executed when 11d scan is completed to flush out
7171 * the scan results
7172 *
7173 * 11d scan is done during driver load and is a passive scan on all
7174 * channels supported by the device, 11d scans may find some APs on
7175 * frequencies which are forbidden to be used in the regulatory domain
7176 * the device is operating in. If these APs are notified to the supplicant
7177 * it may try to connect to these APs, thus flush out all the scan results
7178 * which are present in SME after 11d scan is done.
7179 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307180 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007181 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307182static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183 uint8_t sessionId, uint32_t scanId,
7184 eCsrScanStatus status)
7185{
7186 ENTER();
7187
7188 sme_scan_flush_result(halHandle);
7189
7190 EXIT();
7191
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307192 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007193}
7194
7195#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7196/**
7197 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7198 * @hdd_ctx: hdd global context
7199 *
7200 * Return: none
7201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007202static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007203{
7204 uint8_t i;
7205
7206 mutex_init(&hdd_ctx->op_ctx.op_lock);
7207 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7208 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7209 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7210 }
7211}
7212#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007213static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214{
7215}
7216#endif
7217
Yingying Tang95409972016-10-20 15:16:15 +08007218#ifdef WLAN_FEATURE_WOW_PULSE
7219/**
7220 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007221 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007222 * @enable: enable or disable this behaviour
7223 *
7224 * Return: int
7225 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007226static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007227{
7228 struct hdd_config *pcfg_ini = phddctx->config;
7229 struct wow_pulse_mode wow_pulse_set_info;
7230 QDF_STATUS status;
7231
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007232 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007233
7234 if (false == phddctx->config->wow_pulse_support)
7235 return 0;
7236
7237 /* prepare the request to send to SME */
7238 if (enable == true) {
7239 wow_pulse_set_info.wow_pulse_enable = true;
7240 wow_pulse_set_info.wow_pulse_pin =
7241 pcfg_ini->wow_pulse_pin;
7242 wow_pulse_set_info.wow_pulse_interval_low =
7243 pcfg_ini->wow_pulse_interval_low;
7244 wow_pulse_set_info.wow_pulse_interval_high =
7245 pcfg_ini->wow_pulse_interval_high;
7246 } else {
7247 wow_pulse_set_info.wow_pulse_enable = false;
7248 wow_pulse_set_info.wow_pulse_pin = 0;
7249 wow_pulse_set_info.wow_pulse_interval_low = 0;
7250 wow_pulse_set_info.wow_pulse_interval_high = 0;
7251 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007252 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007253 wow_pulse_set_info.wow_pulse_enable,
7254 wow_pulse_set_info.wow_pulse_pin,
7255 wow_pulse_set_info.wow_pulse_interval_low,
7256 wow_pulse_set_info.wow_pulse_interval_high);
7257
7258 status = sme_set_wow_pulse(&wow_pulse_set_info);
7259 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007260 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007261 return -EIO;
7262 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007263 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007264 return 0;
7265}
7266#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007267static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007268{
7269 return 0;
7270}
7271#endif
7272
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273#ifdef WLAN_FEATURE_FASTPATH
7274/**
7275 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7276 * @hdd_cfg: hdd config
7277 * @context: lower layer context
7278 *
7279 * Return: none
7280 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307281void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007282 void *context)
7283{
7284 if (hdd_cfg->fastpath_enable)
7285 hif_enable_fastpath(context);
7286}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007287#endif
7288
Yuanyuan Liu13738502016-04-06 17:41:37 -07007289#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007290/**
7291 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007292 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007293 * @level: thermal level
7294 *
7295 * Change IPA data path to SW path when the thermal throttle level greater
7296 * than 0, and restore the original data path when throttle level is 0
7297 *
7298 * Return: none
7299 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007300static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007301{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007302 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304 /* Change IPA to SW path when throttle level greater than 0 */
7305 if (level > THROTTLE_LEVEL_0)
7306 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7307 else
7308 /* restore original concurrency mode */
7309 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7310}
7311
7312/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307313 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7314 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307315 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007316 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307317 * Get a safe channel to restart SAP. PCL already takes into account the
7318 * unsafe channels. So, the PCL is validated with the ACS range to provide
7319 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007320 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307321 * Return: Channel number to restart SAP in case of success. In case of any
7322 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007323 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307324static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007325 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007326{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307327 struct sir_pcl_list pcl;
7328 QDF_STATUS status;
7329 uint32_t i, j;
7330 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007331 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307332 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007333
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307334 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7335 if (!hdd_ctx) {
7336 hdd_err("invalid HDD context");
7337 return INVALID_CHANNEL_ID;
7338 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307340 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7341 if (!hal_handle) {
7342 hdd_err("invalid HAL handle");
7343 return INVALID_CHANNEL_ID;
7344 }
7345
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007346 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7347 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007348 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7349 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307350 if (QDF_IS_STATUS_ERROR(status)) {
7351 hdd_err("Get PCL failed");
7352 return INVALID_CHANNEL_ID;
7353 }
7354
Frank Liudc2cefb2017-06-21 15:38:18 +08007355 /*
7356 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7357 * channel is unsafe channel, the pcl may be empty, instead of return,
7358 * try to choose a safe channel from acs range.
7359 */
7360 if (!pcl.pcl_len)
7361 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307362
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007363 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007364 adapter->session.ap.sap_config.acs_cfg.start_ch,
7365 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307366
7367 /* PCL already takes unsafe channel into account */
7368 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007369 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307370 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007371 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307372 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007373 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007374 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307375 return pcl.pcl_list[i];
7376 }
7377 }
7378
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007379 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307380
7381 /* Try for safe channel from all valid channel */
7382 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007383 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307384 &pcl.pcl_len);
7385 if (QDF_IS_STATUS_ERROR(status)) {
7386 hdd_err("error in getting valid channel list");
7387 return INVALID_CHANNEL_ID;
7388 }
7389
7390 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007391 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307392 found = false;
7393 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007394 if (pcl.pcl_list[i] ==
7395 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007396 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307397 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007398 break;
7399 }
7400 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307401
7402 if (found)
7403 continue;
7404
7405 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007406 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307407 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007408 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007409 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307410 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007411 }
7412 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307413
7414 return INVALID_CHANNEL_ID;
7415}
7416
7417/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007418 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307419 * @adapter: AP adapter
7420 * @channel: Channel
7421 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007422 * Moves the SAP interface by invoking the function which
7423 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307424 *
7425 * Return: None
7426 */
Jeff Johnson9d295242017-08-29 14:39:48 -07007427void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307428{
Jeff Johnson87251032017-08-29 13:31:11 -07007429 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307430 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007431 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307432
7433 if (!adapter) {
7434 hdd_err("invalid adapter");
7435 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007436 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307437
7438 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7439
7440 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7441 if (!hal_handle) {
7442 hdd_err("invalid HAL handle");
7443 return;
7444 }
7445
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007446 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7447
Jeff Johnson91df29d2017-10-27 19:29:50 -07007448 hdd_ap_ctx->sap_config.channel = channel;
7449 hdd_ap_ctx->sap_config.ch_params.ch_width =
7450 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307451
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007452 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007453 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307454
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007455 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007456 hdd_ap_ctx->sap_config.channel,
7457 hdd_ap_ctx->sap_config.sec_ch,
7458 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307459
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007460 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007461 adapter->session_id, channel,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007462 hdd_ap_ctx->sap_config.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007463}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307464
Jeff Johnson9d295242017-08-29 14:39:48 -07007465int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307466{
7467 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307468 int status;
7469 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307470
7471 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7472
7473 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007474 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307475 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007476 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307477 }
7478 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007479 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307480 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307481 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007482 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307483 WLAN_VENDOR_ACS_WAIT_TIME);
7484 if (qdf_status != QDF_STATUS_SUCCESS) {
7485 hdd_err("failed to start external acs timer");
7486 return -ENOSPC;
7487 }
7488 /* Update config to application */
7489 status = hdd_cfg80211_update_acs_config(adapter, reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307490 hdd_notice("Updated ACS config to nl with reason %d", reason);
7491
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307492 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307493}
7494
Agrawal Ashish467dde42016-09-08 18:44:22 +05307495/**
7496 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7497 * @hdd_ctx: hdd context pointer
7498 *
7499 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7500 * and if ACS is enabled, driver will ask userspace to restart the
7501 * sap. User space on LTE coex indication restart driver.
7502 *
7503 * Return - none
7504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007505void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307506{
Dustin Brown920397d2017-12-13 16:27:50 -08007507 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307508 uint32_t i;
7509 bool found = false;
7510 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511
Dustin Brown920397d2017-12-13 16:27:50 -08007512 hdd_for_each_adapter(hdd_ctxt, adapter) {
7513 if (!(adapter->device_mode == QDF_SAP_MODE &&
7514 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007515 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007516 adapter->device_mode,
7517 adapter->session.ap.sap_config.
7518 acs_cfg.acs_mode);
7519 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307520 }
7521
7522 found = false;
7523 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007524 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307525 hdd_ctxt->unsafe_channel_list[i]) {
7526 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007527 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007528 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307529 break;
7530 }
7531 }
7532
7533 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007534 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007535 adapter->session.ap.operating_channel);
7536 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307537 }
7538
Kapil Gupta8878ad92017-02-13 11:56:04 +05307539 if (hdd_ctxt->config->vendor_acs_support &&
7540 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007541 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307542 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007543 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307544 } else
7545 restart_chan =
7546 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007547 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307548 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007549 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307550 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007551 /*
7552 * SAP restart due to unsafe channel. While
7553 * restarting the SAP, make sure to clear
7554 * acs_channel, channel to reset to
7555 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307556 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007557 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307558 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007559 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307560 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007561 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307562 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7563 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007564 hdd_debug("driver to start sap: %d",
7565 hdd_ctxt->config->sap_internal_restart);
7566 if (hdd_ctxt->config->sap_internal_restart)
Dustin Brown920397d2017-12-13 16:27:50 -08007567 hdd_switch_sap_channel(adapter, restart_chan);
Liangwei Dong6663d162017-07-10 03:29:36 -04007568 else
7569 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307570 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307571 }
7572}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007575 * hdd_init_channel_avoidance() - Initialize channel avoidance
7576 * @hdd_ctx: HDD global context
7577 *
7578 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007579 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580 * down to the lower layers. Then subscribe to subsequent channel
7581 * avoidance events.
7582 *
7583 * Return: None
7584 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007585static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007586{
7587 uint16_t unsafe_channel_count;
7588 int index;
7589
Yuanyuan Liu13738502016-04-06 17:41:37 -07007590 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7591 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007592 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007593 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007594
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007595 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007596 hdd_ctx->unsafe_channel_count);
7597
Anurag Chouhan6d760662016-02-20 16:05:43 +05307598 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007599 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600
7601 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007602 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007603 hdd_ctx->unsafe_channel_list[index]);
7604
7605 }
7606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007607}
Dustin Brown676a2322017-08-15 13:16:13 -07007608
Jeff Johnson9d295242017-08-29 14:39:48 -07007609static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007610 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007611{
7612 uint8_t restart_chan;
7613
7614 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7615 if (!restart_chan) {
7616 hdd_alert("fail to restart SAP");
7617 return;
7618 }
7619
7620 /* SAP restart due to unsafe channel. While restarting
7621 * the SAP, make sure to clear acs_channel, channel to
7622 * reset to 0. Otherwise these settings will override
7623 * the ACS while restart.
7624 */
7625 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07007626 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07007627
7628 hdd_debug("sending coex indication");
7629
7630 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7631 WLAN_SVC_LTE_COEX_IND, NULL, 0);
7632 hdd_switch_sap_channel(adapter, restart_chan);
7633}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08007634
7635int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
7636 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
7637{
7638 uint32_t size;
7639 uint16_t *unsafe_list;
7640 uint16_t chan_count;
7641
7642 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
7643 return -EINVAL;
7644
7645 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
7646 NUM_CHANNELS);
7647 if (chan_count) {
7648 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
7649 unsafe_list = qdf_mem_malloc(size);
7650 if (!unsafe_list) {
7651 hdd_err("No memory for unsafe chan list size%d",
7652 size);
7653 return -ENOMEM;
7654 }
7655 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
7656 } else {
7657 unsafe_list = NULL;
7658 }
7659
7660 *local_unsafe_list = unsafe_list;
7661 *local_unsafe_list_count = chan_count;
7662
7663 return 0;
7664}
7665
7666bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
7667 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
7668{
7669 int i, j;
7670
7671 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
7672 return true;
7673 if (local_unsafe_list_count == 0)
7674 return false;
7675 for (i = 0; i < local_unsafe_list_count; i++) {
7676 for (j = 0; j < local_unsafe_list_count; j++)
7677 if (local_unsafe_list[i] ==
7678 hdd_ctx->unsafe_channel_list[j])
7679 break;
7680 if (j >= local_unsafe_list_count)
7681 break;
7682 }
7683 if (i >= local_unsafe_list_count) {
7684 hdd_info("unsafe chan list same");
7685 return false;
7686 }
7687
7688 return true;
7689}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007691static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007692{
7693}
Dustin Brown676a2322017-08-15 13:16:13 -07007694
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007695static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007696{
7697}
Dustin Brown676a2322017-08-15 13:16:13 -07007698
Jeff Johnson9d295242017-08-29 14:39:48 -07007699static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007700 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07007701{
7702 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
7703}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007704#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007705
7706/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007707 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7708 * user space
7709 * @frame_ind: Management frame data to be informed.
7710 *
7711 * This function is used to indicate management frame to
7712 * user space
7713 *
7714 * Return: None
7715 *
7716 */
7717void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7718{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007719 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07007720 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08007721 int i;
7722
Rajeev Kumard004abc2016-02-17 12:09:56 -08007723 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007724 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007725
7726 if (0 != wlan_hdd_validate_context(hdd_ctx))
7727 return;
7728
7729 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7730 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7731 adapter =
7732 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7733 if (adapter)
7734 break;
7735 }
7736 } else {
7737 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7738 frame_ind->sessionId);
7739 }
7740
7741 if ((NULL != adapter) &&
7742 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7743 __hdd_indicate_mgmt_frame(adapter,
7744 frame_ind->frame_len,
7745 frame_ind->frameBuf,
7746 frame_ind->frameType,
7747 frame_ind->rxChan,
7748 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007749}
7750
Kapil Gupta8878ad92017-02-13 11:56:04 +05307751void hdd_acs_response_timeout_handler(void *context)
7752{
7753 struct hdd_external_acs_timer_context *timer_context =
7754 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07007755 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007756 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307757 uint8_t reason;
7758
7759 ENTER();
7760 if (!timer_context) {
7761 hdd_err("invlaid timer context");
7762 return;
7763 }
7764 adapter = timer_context->adapter;
7765 reason = timer_context->reason;
7766
7767
7768 if ((!adapter) ||
7769 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7770 hdd_err("invalid adapter or adapter has invalid magic");
7771 return;
7772 }
7773 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7774 if (wlan_hdd_validate_context(hdd_ctx))
7775 return;
7776
7777 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7778 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7779 else
7780 return;
7781
7782 hdd_err("ACS timeout happened for %s reason %d",
7783 adapter->dev->name, reason);
7784 switch (reason) {
7785 /* SAP init case */
7786 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7787 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7788 false);
7789 wlan_hdd_cfg80211_start_acs(adapter);
7790 break;
7791 /* DFS detected on current channel */
7792 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7793 wlan_sap_update_next_channel(
7794 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7795 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007796 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307797 break;
7798 /* LTE coex event on current channel */
7799 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7800 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7801 break;
7802 default:
7803 hdd_info("invalid reason for timer invoke");
7804
7805 }
7806}
7807
Rajeev Kumard004abc2016-02-17 12:09:56 -08007808/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007809 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7810 * @hdd_ctx: HDD context
7811 *
7812 * Disables all the dual mac features like DBS, Agile DFS etc.
7813 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307814 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007816static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007817{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007818 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307819 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007820
7821 if (!hdd_ctx) {
7822 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307823 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007824 }
7825
7826 cfg.scan_config = 0;
7827 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007828 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007829
7830 hdd_debug("Disabling all dual mac features...");
7831
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007832 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307833 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007834 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7835 return status;
7836 }
7837
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307838 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007839}
7840
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007841static QDF_STATUS
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007842wlan_hdd_update_dbs_scan_and_fw_mode_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07007843{
7844 struct policy_mgr_dual_mac_config cfg = {0};
7845 QDF_STATUS status;
7846
7847 if (!hdd_ctx) {
7848 hdd_err("HDD context is NULL");
7849 return QDF_STATUS_E_FAILURE;
7850 }
7851
7852 cfg.scan_config = 0;
7853 cfg.fw_mode_config = 0;
7854 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
7855 status = policy_mgr_get_updated_scan_and_fw_mode_config(
7856 hdd_ctx->hdd_psoc, &cfg.scan_config,
7857 &cfg.fw_mode_config,
7858 hdd_ctx->config->dual_mac_feature_disable);
7859
7860 if (status != QDF_STATUS_SUCCESS) {
7861 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
7862 status);
7863 return status;
7864 }
7865
7866 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
7867 cfg.scan_config, cfg.fw_mode_config);
7868
7869 status = sme_soc_set_dual_mac_config(cfg);
7870 if (status != QDF_STATUS_SUCCESS) {
7871 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7872 return status;
7873 }
7874
7875 return QDF_STATUS_SUCCESS;
7876}
7877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007878/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007879 * hdd_override_ini_config - Override INI config
7880 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007881 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007882 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007883 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007884 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007885 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007886static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007887{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007888
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007889 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7890 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007891 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007892 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007893 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007894 if (0 == enable_11d || 1 == enable_11d) {
7895 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007896 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007897 }
Leo Chang11545d62016-10-17 14:53:50 -07007898
7899 if (!hdd_ipa_is_present(hdd_ctx))
7900 hdd_ctx->config->IpaConfig = 0;
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05307901
7902 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
7903 !hdd_ctx->config->enable_bcast_probe_rsp) {
7904 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
7905 hdd_ctx->config->rssi_assoc_reject_enabled,
7906 hdd_ctx->config->enable_bcast_probe_rsp);
7907 hdd_ctx->config->oce_sta_enabled = 0;
7908 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007909}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007910
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007911/**
7912 * hdd_set_trace_level_for_each - Set trace level for each INI config
7913 * @hdd_ctx - HDD context
7914 *
7915 * Set trace level for each module based on INI config.
7916 *
7917 * Return: None
7918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007919static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007920{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307921 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7922 hdd_ctx->config->qdf_trace_enable_wdi);
7923 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7924 hdd_ctx->config->qdf_trace_enable_hdd);
7925 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7926 hdd_ctx->config->qdf_trace_enable_sme);
7927 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7928 hdd_ctx->config->qdf_trace_enable_pe);
7929 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7930 hdd_ctx->config->qdf_trace_enable_wma);
7931 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7932 hdd_ctx->config->qdf_trace_enable_sys);
7933 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7934 hdd_ctx->config->qdf_trace_enable_qdf);
7935 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7936 hdd_ctx->config->qdf_trace_enable_sap);
7937 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7938 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7939 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7940 hdd_ctx->config->qdf_trace_enable_bmi);
7941 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7942 hdd_ctx->config->qdf_trace_enable_cfg);
7943 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7944 hdd_ctx->config->qdf_trace_enable_epping);
7945 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7946 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7947 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07007948 hdd_ctx->config->qdf_trace_enable_txrx);
7949 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
7950 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307951 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7952 hdd_ctx->config->qdf_trace_enable_htc);
7953 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7954 hdd_ctx->config->qdf_trace_enable_hif);
7955 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7956 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7957 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7958 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007959 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7960 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007961 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7962 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007963 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7964 hdd_ctx->config->qdf_trace_enable_regulatory);
7965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007966 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007967}
7968
7969/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007970 * hdd_context_init() - Initialize HDD context
7971 * @hdd_ctx: HDD context.
7972 *
7973 * Initialize HDD context along with all the feature specific contexts.
7974 *
7975 * return: 0 on success and errno on failure.
7976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007977static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007978{
7979 int ret;
7980
7981 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7982 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7983
7984 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05307985 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007986
7987 init_completion(&hdd_ctx->mc_sus_event_var);
7988 init_completion(&hdd_ctx->ready_to_suspend);
7989
7990 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307991 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007992 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307993
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007994 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007995
7996 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7997
7998 ret = hdd_scan_context_init(hdd_ctx);
7999 if (ret)
8000 goto list_destroy;
8001
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008002 hdd_rx_wake_lock_create(hdd_ctx);
8003
8004 ret = hdd_sap_context_init(hdd_ctx);
8005 if (ret)
8006 goto scan_destroy;
8007
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008008 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8009
8010 hdd_init_offloaded_packets_ctx(hdd_ctx);
8011
8012 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8013 hdd_ctx->config);
8014 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008015 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008016
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308017 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8018 "monitor_mode_wakelock");
8019
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008020 return 0;
8021
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008022sap_destroy:
8023 hdd_sap_context_destroy(hdd_ctx);
8024
8025scan_destroy:
8026 hdd_scan_context_destroy(hdd_ctx);
8027 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008028list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008029 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008030
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008031 return ret;
8032}
8033
8034/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308035 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8036 * @hdd_ctx: pointer to hdd context
8037 *
8038 * Return: status of initialization
8039 * 0 - success
8040 * negative value - failure
8041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008042static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308043{
8044 int ret;
8045
8046 if (!hdd_ctx->config->probe_req_ie_whitelist)
8047 return 0;
8048
8049 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8050 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8051 hdd_ctx->config->probe_req_ie_whitelist = false;
8052 return -EINVAL;
8053 }
8054
8055 /* parse ini string probe req oui */
8056 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8057 if (ret) {
8058 hdd_err("parsing error: disable ie whitelisting");
8059 hdd_ctx->config->probe_req_ie_whitelist = false;
8060 }
8061
8062 return ret;
8063}
8064
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308065
8066/**
8067 * hdd_iface_change_callback() - Function invoked when stop modules expires
8068 * @priv: pointer to hdd context
8069 *
8070 * This function is invoked when the timer waiting for the interface change
8071 * expires, it shall cut-down the power to wlan and stop all the modules.
8072 *
8073 * Return: void
8074 */
8075static void hdd_iface_change_callback(void *priv)
8076{
8077 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8078 int ret;
8079 int status = wlan_hdd_validate_context(hdd_ctx);
8080
8081 if (status)
8082 return;
8083
8084 ENTER();
8085 hdd_debug("Interface change timer expired close the modules!");
8086 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8087 if (ret)
8088 hdd_err("Failed to stop modules");
8089 EXIT();
8090}
8091
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308092/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008093 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308094 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008095 *
8096 * Allocate and initialize HDD context. HDD context is allocated as part of
8097 * wiphy allocation and then context is initialized.
8098 *
8099 * Return: HDD context on success and ERR_PTR on failure
8100 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008101static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008102{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308103 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008104 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008105 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008106
8107 ENTER();
8108
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008109 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008110 if (hdd_ctx == NULL) {
8111 ret = -ENOMEM;
8112 goto err_out;
8113 }
8114
Dustin Brown6f427922017-09-19 12:19:00 -07008115 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8116 hdd_iface_change_callback,
8117 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308118
8119 mutex_init(&hdd_ctx->iface_change_lock);
8120
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008121 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308122 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008123
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308124 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008125 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008126 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008127 ret = -ENOMEM;
8128 goto err_free_hdd_context;
8129 }
8130
8131 /* Read and parse the qcom_cfg.ini file */
8132 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308133 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308134 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008135 WLAN_INI_FILE);
8136 ret = -EINVAL;
8137 goto err_free_config;
8138 }
8139
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308140 ie_whitelist_attrs_init(hdd_ctx);
8141
Dustin Brown7f939932017-05-18 15:02:17 -07008142 hdd_debug("setting timer multiplier: %u",
8143 hdd_ctx->config->timer_multiplier);
8144 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8145
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008146
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308147 if (hdd_ctx->config->fhostNSOffload)
8148 hdd_ctx->ns_offload_enable = true;
8149
Abhishek Singh5ea86532016-04-27 14:10:53 +05308150 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8151
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008152 hdd_override_ini_config(hdd_ctx);
8153
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008154 ret = hdd_context_init(hdd_ctx);
8155
8156 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008157 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008158
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008159 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308160 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008161
Anurag Chouhan6d760662016-02-20 16:05:43 +05308162 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008163 goto skip_multicast_logging;
8164
8165 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8166
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008167 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8168 if (ret)
8169 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308170
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008171 ret = hdd_init_netlink_services(hdd_ctx);
8172 if (ret)
8173 goto err_deinit_txrx_histogram;
8174
Dustin Brown7b3dea22017-07-10 13:02:47 -07008175 wlan_logging_set_log_to_console(hdd_ctx->config->wlanLoggingToConsole);
8176 wlan_logging_set_active(hdd_ctx->config->wlanLoggingEnable);
Nirav Shahed34b212016-04-25 10:59:16 +05308177
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008178skip_multicast_logging:
8179 hdd_set_trace_level_for_each(hdd_ctx);
8180
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008181 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8182
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008183 EXIT();
8184
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008185 return hdd_ctx;
8186
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008187err_deinit_txrx_histogram:
8188 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8189
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008190err_deinit_hdd_context:
8191 hdd_context_deinit(hdd_ctx);
8192
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008193err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308194 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008195
8196err_free_hdd_context:
8197 wiphy_free(hdd_ctx->wiphy);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308198 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008199
8200err_out:
8201 return ERR_PTR(ret);
8202}
8203
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008204#ifdef WLAN_OPEN_P2P_INTERFACE
8205/**
8206 * hdd_open_p2p_interface - Open P2P interface
8207 * @hdd_ctx: HDD context
8208 * @rtnl_held: True if RTNL lock held
8209 *
8210 * Open P2P interface during probe. This function called to open the P2P
8211 * interface at probe along with STA interface.
8212 *
8213 * Return: 0 on success and errno on failure
8214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008215static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008216{
Jeff Johnson9d295242017-08-29 14:39:48 -07008217 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008218 uint8_t *p2p_dev_addr;
8219
8220 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8221 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008222 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008223 hdd_ctx->config->intfMacAddr[0].bytes,
8224 sizeof(tSirMacAddr));
8225
8226 /*
8227 * Generate the P2P Device Address. This consists of
8228 * the device's primary MAC address with the locally
8229 * administered bit set.
8230 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008231 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008232 } else {
8233 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8234 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008235 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008236 return -ENOSPC;
8237 }
8238
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008239 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8240 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008241 }
8242
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008243 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008244 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008245 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008246
8247 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008248 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008249 return -ENOSPC;
8250 }
8251
8252 return 0;
8253}
8254#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008255static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008256 bool rtnl_held)
8257{
8258 return 0;
8259}
8260#endif
8261
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008262static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008263{
Jeff Johnson9d295242017-08-29 14:39:48 -07008264 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008265 int ret = 0;
8266
8267 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8268 wlan_hdd_get_intf_addr(hdd_ctx),
8269 NET_NAME_UNKNOWN, rtnl_held);
8270 if (adapter == NULL) {
8271 hdd_err("Failed to open 802.11p interface");
8272 ret = -ENOSPC;
8273 }
8274
8275 return ret;
8276}
8277
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008278/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308279 * hdd_start_station_adapter()- Start the Station Adapter
8280 * @adapter: HDD adapter
8281 *
8282 * This function initializes the adapter for the station mode.
8283 *
8284 * Return: 0 on success or errno on failure.
8285 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008286int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308287{
8288 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008289 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308290
8291 ENTER_DEV(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008292 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8293 hdd_err("session is already opened, %d",
8294 adapter->session_id);
8295 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8296 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308297
Krunal Sonib51eec72017-11-20 21:53:01 -08008298 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8299 if (ret) {
8300 hdd_err("failed to create vdev: %d", ret);
8301 return ret;
8302 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308303 status = hdd_init_station_mode(adapter);
8304
8305 if (QDF_STATUS_SUCCESS != status) {
8306 hdd_err("Error Initializing station mode: %d", status);
8307 return qdf_status_to_os_return(status);
8308 }
8309
Arun Khandavallifae92942016-08-01 13:31:08 +05308310 hdd_register_tx_flow_control(adapter,
8311 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008312 hdd_tx_resume_cb,
8313 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308314
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308315 EXIT();
8316 return 0;
8317}
8318
8319/**
8320 * hdd_start_ap_adapter()- Start AP Adapter
8321 * @adapter: HDD adapter
8322 *
8323 * This function initializes the adapter for the AP mode.
8324 *
8325 * Return: 0 on success errno on failure.
8326 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008327int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308328{
8329 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008330 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008331 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308332
8333 ENTER();
8334
Krunal Sonib51eec72017-11-20 21:53:01 -08008335 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8336 hdd_err("session is already opened, %d",
8337 adapter->session_id);
8338 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8339 }
8340 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008341 * In SSR case no need to create new sap context.
8342 * Otherwise create sap context first and then create
8343 * vdev as while creating the vdev, driver needs to
8344 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008345 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008346 if (adapter->session.ap.sap_context) {
8347 is_ssr = true;
8348 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008349 hdd_err("sap creation failed");
8350 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8351 }
8352
8353 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8354 adapter->session.ap.sap_context);
8355 if (ret) {
8356 hdd_err("failed to create vdev, status:%d", ret);
8357 hdd_sap_destroy_ctx(adapter);
8358 return ret;
8359 }
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008360 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308361
8362 if (QDF_STATUS_SUCCESS != status) {
8363 hdd_err("Error Initializing the AP mode: %d", status);
8364 return qdf_status_to_os_return(status);
8365 }
8366
Arun Khandavallifae92942016-08-01 13:31:08 +05308367 hdd_register_tx_flow_control(adapter,
8368 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008369 hdd_softap_tx_resume_cb,
8370 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308371
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308372 EXIT();
8373 return 0;
8374}
8375
8376/**
8377 * hdd_start_ftm_adapter()- Start FTM adapter
8378 * @adapter: HDD adapter
8379 *
8380 * This function initializes the adapter for the FTM mode.
8381 *
8382 * Return: 0 on success or errno on failure.
8383 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008384int hdd_start_ftm_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308385{
8386 QDF_STATUS qdf_status;
8387
8388 ENTER_DEV(adapter->dev);
8389
8390 qdf_status = hdd_init_tx_rx(adapter);
8391
8392 if (QDF_STATUS_SUCCESS != qdf_status) {
8393 hdd_err("Failed to start FTM adapter: %d", qdf_status);
8394 return qdf_status_to_os_return(qdf_status);
8395 }
8396
8397 return 0;
8398 EXIT();
8399}
8400
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308401static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8402 bool rtnl_held)
8403{
8404 struct hdd_adapter *adapter;
8405
8406 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8407 hdd_ctx->config->enableConcurrentSTA,
8408 wlan_hdd_get_intf_addr(hdd_ctx),
8409 NET_NAME_UNKNOWN, rtnl_held);
8410
8411 if (!adapter)
8412 return -ENOSPC;
8413
8414 return 0;
8415}
8416
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308417/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008418 * hdd_open_interfaces - Open all required interfaces
8419 * hdd_ctx: HDD context
8420 * rtnl_held: True if RTNL lock is held
8421 *
8422 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8423 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008424 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008425 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008426static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008427{
Jeff Johnson9d295242017-08-29 14:39:48 -07008428 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008429 int ret;
8430
Ravi Joshia307f632017-07-17 23:41:41 -07008431 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008432 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8433 con_mode == QDF_GLOBAL_FTM_MODE) {
8434 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8435 QDF_MONITOR_MODE : QDF_FTM_MODE;
8436
8437 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8438 wlan_hdd_get_intf_addr(hdd_ctx),
8439 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008440 if (!adapter) {
8441 hdd_err("open adapter failed");
8442 return -ENOSPC;
8443 }
Lin Bai1c678482017-12-18 18:29:11 +08008444
Ravi Joshia307f632017-07-17 23:41:41 -07008445 return 0;
8446 }
8447
Jeff Johnson957bc272017-02-02 08:54:48 -08008448 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308449 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008450 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008451
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008452 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008453 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008454 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008455
8456 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008457 return -ENOSPC;
8458
Deepak Dhamdherea2785822016-11-17 01:17:45 -08008459 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
8460 adapter->fast_roaming_allowed = true;
8461
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308462 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8463 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8464 if (ret)
8465 hdd_err("Cannot create concurrent STA interface");
8466 }
8467
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008468 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8469 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008470 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008471
8472 /* Open 802.11p Interface */
8473 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008474 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8475 if (ret)
8476 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008477 }
8478
Jeff Johnson957bc272017-02-02 08:54:48 -08008479 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008480
Jeff Johnson957bc272017-02-02 08:54:48 -08008481err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008482 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008483 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008484}
8485
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008486/**
8487 * hdd_update_country_code - Update country code
8488 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008489 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008490 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008491 *
8492 * Return: 0 on success and errno on failure
8493 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008494static int hdd_update_country_code(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008495{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008496 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008497 return 0;
8498
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008499 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008500}
8501
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308502#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8503/**
8504 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8505 * @cds_cfg: CDS Configuration
8506 * @hdd_ctx: Pointer to hdd context
8507 *
8508 * Return: none
8509 */
8510static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8511 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008512 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308513{
8514 cds_cfg->tx_flow_stop_queue_th =
8515 hdd_ctx->config->TxFlowStopQueueThreshold;
8516 cds_cfg->tx_flow_start_queue_offset =
8517 hdd_ctx->config->TxFlowStartQueueOffset;
8518}
8519#else
8520static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8521 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008522 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308523{
8524}
8525#endif
8526
8527#ifdef FEATURE_WLAN_RA_FILTERING
8528/**
8529 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8530 * @cds_cfg: CDS Configuration
8531 * @hdd_ctx: Pointer to hdd context
8532 *
8533 * Return: none
8534 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308535static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008536 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308537{
8538 cds_cfg->ra_ratelimit_interval =
8539 hdd_ctx->config->RArateLimitInterval;
8540 cds_cfg->is_ra_ratelimit_enabled =
8541 hdd_ctx->config->IsRArateLimitEnabled;
8542}
8543#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308544static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008545 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308546{
8547}
8548#endif
8549
8550/**
8551 * hdd_update_cds_config() - API to update cds configuration parameters
8552 * @hdd_ctx: HDD Context
8553 *
8554 * Return: 0 for Success, errno on failure
8555 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008556static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308557{
8558 struct cds_config_info *cds_cfg;
8559
8560 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8561 if (!cds_cfg) {
8562 hdd_err("failed to allocate cds config");
8563 return -ENOMEM;
8564 }
8565
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008566 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008567 if (!hdd_ctx->config->nMaxPsPoll ||
8568 !hdd_ctx->config->enablePowersaveOffload) {
8569 cds_cfg->powersave_offload_enabled =
8570 hdd_ctx->config->enablePowersaveOffload;
8571 } else {
8572 if ((hdd_ctx->config->enablePowersaveOffload ==
8573 PS_QPOWER_NODEEPSLEEP) ||
8574 (hdd_ctx->config->enablePowersaveOffload ==
8575 PS_LEGACY_NODEEPSLEEP))
8576 cds_cfg->powersave_offload_enabled =
8577 PS_LEGACY_NODEEPSLEEP;
8578 else
8579 cds_cfg->powersave_offload_enabled =
8580 PS_LEGACY_DEEPSLEEP;
8581 hdd_info("Qpower disabled in cds config, %d",
8582 cds_cfg->powersave_offload_enabled);
8583 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308584 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8585 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8586 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8587 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8588 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8589
8590 /* Here ol_ini_info is used to store ini status of arp offload
8591 * ns offload and others. Currently 1st bit is used for arp
8592 * off load and 2nd bit for ns offload currently, rest bits are unused
8593 */
8594 if (hdd_ctx->config->fhostArpOffload)
8595 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8596 if (hdd_ctx->config->fhostNSOffload)
8597 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8598
8599 /*
8600 * Copy the DFS Phyerr Filtering Offload status.
8601 * This parameter reflects the value of the
8602 * dfs_phyerr_filter_offload flag as set in the ini.
8603 */
8604 cds_cfg->dfs_phyerr_filter_offload =
8605 hdd_ctx->config->fDfsPhyerrFilterOffload;
8606 if (hdd_ctx->config->ssdp)
8607 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8608
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308609 cds_cfg->force_target_assert_enabled =
8610 hdd_ctx->config->crash_inject_enabled;
8611
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308612 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8613 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8614
8615 cds_cfg->ap_maxoffload_reorderbuffs =
8616 hdd_ctx->config->apMaxOffloadReorderBuffs;
8617
8618 cds_cfg->ap_disable_intrabss_fwd =
8619 hdd_ctx->config->apDisableIntraBssFwd;
8620
8621 cds_cfg->dfs_pri_multiplier =
8622 hdd_ctx->config->dfsRadarPriMultiplier;
8623 cds_cfg->reorder_offload =
8624 hdd_ctx->config->reorderOffloadSupport;
8625
8626 /* IPA micro controller data path offload resource config item */
8627 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008628 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8629 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008630 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008631 hdd_ctx->config->IpaUcTxBufCount);
8632 hdd_ctx->config->IpaUcTxBufCount =
8633 rounddown_pow_of_two(
8634 hdd_ctx->config->IpaUcTxBufCount);
8635 if (!hdd_ctx->config->IpaUcTxBufCount) {
8636 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308637 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008638 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008639 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008640 hdd_ctx->config->IpaUcTxBufCount);
8641 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308642 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8643 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008644 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8645 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008646 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008647 hdd_ctx->config->IpaUcRxIndRingCount);
8648 hdd_ctx->config->IpaUcRxIndRingCount =
8649 rounddown_pow_of_two(
8650 hdd_ctx->config->IpaUcRxIndRingCount);
8651 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8652 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308653 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008654 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008655 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008656 hdd_ctx->config->IpaUcRxIndRingCount);
8657 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308658 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008659 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308660 cds_cfg->uc_tx_partition_base =
8661 hdd_ctx->config->IpaUcTxPartitionBase;
8662 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8663
8664 cds_cfg->ip_tcp_udp_checksum_offload =
8665 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07008666 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308667 cds_cfg->ce_classify_enabled =
8668 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008669 cds_cfg->bpf_packet_filter_enable =
8670 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308671 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8672 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8673 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008674 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008675 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07008676 cds_cfg->max_msdus_per_rxinorderind =
8677 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008678 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008679 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308680 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8681 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308682 cds_cfg->auto_power_save_fail_mode =
8683 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308684
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308685 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07008686 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308687
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308688 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8689 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8690 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008691 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308692 cds_init_ini_config(cds_cfg);
8693 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308694
8695exit:
8696 qdf_mem_free(cds_cfg);
8697 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308698}
8699
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008700/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008701 * hdd_update_user_config() - API to update user configuration
8702 * parameters to obj mgr which are used by multiple components
8703 * @hdd_ctx: HDD Context
8704 *
8705 * Return: 0 for Success, errno on failure
8706 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008707static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008708{
8709 struct wlan_objmgr_psoc_user_config *user_config;
8710
8711 user_config = qdf_mem_malloc(sizeof(*user_config));
8712 if (user_config == NULL) {
8713 hdd_alert("Failed to alloc memory for user_config!");
8714 return -ENOMEM;
8715 }
8716
8717 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8718 user_config->dual_mac_feature_disable =
8719 hdd_ctx->config->dual_mac_feature_disable;
8720 user_config->indoor_channel_support =
8721 hdd_ctx->config->indoor_channel_support;
8722 user_config->is_11d_support_enabled =
8723 hdd_ctx->config->Is11dSupportEnabled;
8724 user_config->is_11h_support_enabled =
8725 hdd_ctx->config->Is11hSupportEnabled;
8726 user_config->optimize_chan_avoid_event =
8727 hdd_ctx->config->goptimize_chan_avoid_event;
8728 user_config->skip_dfs_chnl_in_p2p_search =
8729 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008730 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008731 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8732
8733 qdf_mem_free(user_config);
8734 return 0;
8735}
8736
8737/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008738 * hdd_init_thermal_info - Initialize thermal level
8739 * @hdd_ctx: HDD context
8740 *
8741 * Initialize thermal level at SME layer and set the thermal level callback
8742 * which would be called when a configured thermal threshold is hit.
8743 *
8744 * Return: 0 on success and errno on failure
8745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008746static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008747{
8748 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308749 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008750
8751 thermal_param.smeThermalMgmtEnabled =
8752 hdd_ctx->config->thermalMitigationEnable;
8753 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8754
Poddar, Siddarth83905022016-04-16 17:56:08 -07008755 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8756 hdd_ctx->config->throttle_dutycycle_level0;
8757 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8758 hdd_ctx->config->throttle_dutycycle_level1;
8759 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8760 hdd_ctx->config->throttle_dutycycle_level2;
8761 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8762 hdd_ctx->config->throttle_dutycycle_level3;
8763
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008764 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8765 hdd_ctx->config->thermalTempMinLevel0;
8766 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8767 hdd_ctx->config->thermalTempMaxLevel0;
8768 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8769 hdd_ctx->config->thermalTempMinLevel1;
8770 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8771 hdd_ctx->config->thermalTempMaxLevel1;
8772 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8773 hdd_ctx->config->thermalTempMinLevel2;
8774 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8775 hdd_ctx->config->thermalTempMaxLevel2;
8776 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8777 hdd_ctx->config->thermalTempMinLevel3;
8778 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8779 hdd_ctx->config->thermalTempMaxLevel3;
8780
8781 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8782
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308783 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308784 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008785
8786 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8787 hdd_set_thermal_level_cb);
8788
8789 return 0;
8790
8791}
8792
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008793#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8794/**
8795 * hdd_hold_rtnl_lock - Hold RTNL lock
8796 *
8797 * Hold RTNL lock
8798 *
8799 * Return: True if held and false otherwise
8800 */
8801static inline bool hdd_hold_rtnl_lock(void)
8802{
8803 rtnl_lock();
8804 return true;
8805}
8806
8807/**
8808 * hdd_release_rtnl_lock - Release RTNL lock
8809 *
8810 * Release RTNL lock
8811 *
8812 * Return: None
8813 */
8814static inline void hdd_release_rtnl_lock(void)
8815{
8816 rtnl_unlock();
8817}
8818#else
8819static inline bool hdd_hold_rtnl_lock(void) { return false; }
8820static inline void hdd_release_rtnl_lock(void) { }
8821#endif
8822
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008823#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008824
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308825/* MAX iwpriv command support */
8826#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308827#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308828#define MAX_PKTLOG_SIZE 16
8829
8830/**
8831 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8832 * @hdd_ctx: hdd context
8833 * @set_value2: pktlog buffer size value
8834 *
8835 *
8836 * Return: 0 for success or error.
8837 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008838static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308839{
8840 struct sir_wifi_start_log start_log = { 0 };
8841 QDF_STATUS status;
8842
8843 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8844 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8845 start_log.ini_triggered = cds_is_packet_log_enabled();
8846 start_log.user_triggered = 1;
8847 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308848 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308849
8850 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8851 if (!QDF_IS_STATUS_SUCCESS(status)) {
8852 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8853 EXIT();
8854 return -EINVAL;
8855 }
8856
8857 return 0;
8858}
8859
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008860/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308861 * hdd_pktlog_clear_buff() - clear pktlog buffer
8862 * @hdd_ctx: hdd context
8863 *
8864 * Return: 0 for success or error.
8865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008866static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308867{
8868 struct sir_wifi_start_log start_log;
8869 QDF_STATUS status;
8870
8871 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8872 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8873 start_log.ini_triggered = cds_is_packet_log_enabled();
8874 start_log.user_triggered = 1;
8875 start_log.size = 0;
8876 start_log.is_pktlog_buff_clear = true;
8877
8878 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8879 if (!QDF_IS_STATUS_SUCCESS(status)) {
8880 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8881 EXIT();
8882 return -EINVAL;
8883 }
8884
8885 return 0;
8886}
8887
8888
8889/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008890 * hdd_process_pktlog_command() - process pktlog command
8891 * @hdd_ctx: hdd context
8892 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308893 * @set_value2: pktlog buffer size value
8894 *
8895 * This function process pktlog command.
8896 * set_value2 only matters when set_value is 3 (set buff size)
8897 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008898 *
8899 * Return: 0 for success or error.
8900 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008901int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308902 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008903{
8904 int ret;
8905 bool enable;
8906 uint8_t user_triggered = 0;
8907
8908 ret = wlan_hdd_validate_context(hdd_ctx);
8909 if (0 != ret)
8910 return ret;
8911
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008912 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008913
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308914 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008915 hdd_err("invalid pktlog value %d", set_value);
8916 return -EINVAL;
8917 }
8918
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308919 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8920 if (set_value2 <= 0) {
8921 hdd_err("invalid pktlog size %d", set_value2);
8922 return -EINVAL;
8923 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8924 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8925 return -EINVAL;
8926 }
8927 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308928 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8929 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308930 }
8931
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008932 /*
8933 * set_value = 0 then disable packetlog
8934 * set_value = 1 enable packetlog forcefully
8935 * set_vlaue = 2 then disable packetlog if disabled through ini or
8936 * enable packetlog with AUTO type.
8937 */
8938 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8939 true : false;
8940
8941 if (1 == set_value) {
8942 enable = true;
8943 user_triggered = 1;
8944 }
8945
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308946 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008947}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07008948
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008949/**
8950 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8951 * @hdd_ctx: HDD context
8952 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308953 * @user_triggered: triggered through iwpriv
8954 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008955 *
8956 * Return: 0 on success; error number otherwise
8957 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008958int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308959 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008960{
8961 struct sir_wifi_start_log start_log;
8962 QDF_STATUS status;
8963
8964 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8965 start_log.verbose_level =
8966 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008967 start_log.ini_triggered = cds_is_packet_log_enabled();
8968 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308969 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308970 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308971 /*
8972 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8973 * commands. Host uses this flag to decide whether to send pktlog
8974 * disable command to fw without sending pktlog enable command
8975 * previously. For eg, If vendor sends pktlog disable command without
8976 * sending pktlog enable command, then host discards the packet
8977 * but for iwpriv command, host will send it to fw.
8978 */
8979 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008980 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8981 if (!QDF_IS_STATUS_SUCCESS(status)) {
8982 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8983 EXIT();
8984 return -EINVAL;
8985 }
8986
8987 return 0;
8988}
8989#endif /* REMOVE_PKT_LOG */
8990
Komal Seelam92fff912016-03-24 11:51:41 +05308991/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008992 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8993 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308994 * @dev: Device Pointer
8995 * @num: Number of Valid Mac address
8996 *
8997 * Return: Pointer to MAC address buffer
8998 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008999static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9000 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309001{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009002 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309003}
Komal Seelam92fff912016-03-24 11:51:41 +05309004
9005/**
9006 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9007 * @hdd_ctx: HDD Context
9008 * @num: Number of random mac addresses needed
9009 *
9010 * Generate random addresses using bit manipulation on the base mac address
9011 *
9012 * Return: None
9013 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009014void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309015{
9016 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9017 uint32_t iter;
9018 struct hdd_config *ini = hdd_ctx->config;
9019 uint8_t *buf = NULL;
9020 uint8_t macaddr_b3, tmp_br3;
9021 uint8_t *src = ini->intfMacAddr[0].bytes;
9022
9023 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9024 buf = ini->intfMacAddr[iter].bytes;
9025 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9026 macaddr_b3 = buf[3];
9027 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9028 INTF_MACADDR_MASK;
9029 macaddr_b3 += tmp_br3;
9030 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9031 buf[0] |= 0x02;
9032 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009033 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309034 }
9035}
9036
9037/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009038 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309039 * @hdd_ctx: HDD Context
9040 *
9041 * API to get mac addresses from platform driver and update the driver
9042 * structures and configure FW with the base mac address.
9043 * Return: int
9044 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009045static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309046{
9047 uint32_t no_of_mac_addr, iter;
9048 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9049 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9050 uint8_t *addr, *buf;
9051 struct device *dev = hdd_ctx->parent_dev;
9052 struct hdd_config *ini = hdd_ctx->config;
9053 tSirMacAddr mac_addr;
9054 QDF_STATUS status;
9055
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009056 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309057
9058 if (no_of_mac_addr == 0 || !addr) {
9059 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9060 return -EINVAL;
9061 }
9062
9063 if (no_of_mac_addr > max_mac_addr)
9064 no_of_mac_addr = max_mac_addr;
9065
9066 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9067
9068 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9069 buf = ini->intfMacAddr[iter].bytes;
9070 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009071 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309072 }
9073
9074 status = sme_set_custom_mac_addr(mac_addr);
9075
9076 if (!QDF_IS_STATUS_SUCCESS(status))
9077 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009078
Komal Seelam92fff912016-03-24 11:51:41 +05309079 if (no_of_mac_addr < max_mac_addr)
9080 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9081 no_of_mac_addr);
9082 return 0;
9083}
9084
9085/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009086 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9087 * @hdd_ctx: HDD Context
9088 *
9089 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9090 * will generate its own MAC and update it to FW.
9091 *
9092 * Return: 0 for success
9093 * Non-zero error code for failure
9094 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009095static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009096{
9097 tSirMacAddr customMacAddr;
9098 QDF_STATUS status;
9099
9100 qdf_mem_copy(&customMacAddr,
9101 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9102 sizeof(tSirMacAddr));
9103 status = sme_set_custom_mac_addr(customMacAddr);
9104 if (!QDF_IS_STATUS_SUCCESS(status))
9105 return -EAGAIN;
9106 return 0;
9107}
9108
9109/**
Komal Seelam92fff912016-03-24 11:51:41 +05309110 * hdd_initialize_mac_address() - API to get wlan mac addresses
9111 * @hdd_ctx: HDD Context
9112 *
9113 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9114 * is provisioned with mac addresses, driver uses it, else it will use
9115 * wlan_mac.bin to update HW MAC addresses.
9116 *
9117 * Return: None
9118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009119static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309120{
9121 QDF_STATUS status;
9122 int ret;
9123
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009124 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309125 if (ret == 0)
9126 return;
9127
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009128 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9129 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309130
9131 status = hdd_update_mac_config(hdd_ctx);
9132
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009133 if (QDF_IS_STATUS_SUCCESS(status))
9134 return;
9135
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009136 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9137 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009138
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009139 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009140 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009141 if (ret != 0) {
9142 hdd_err("MAC address out-of-sync, ret:%d", ret);
9143 QDF_ASSERT(ret);
9144 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009145 }
Komal Seelam92fff912016-03-24 11:51:41 +05309146}
9147
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009148static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009149{
9150 int vdev_id = 0;
9151 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9152 int value = hdd_ctx->config->smart_chainmask_enabled;
9153 int vpdev = PDEV_CMD;
9154 int ret;
9155
Naveen Rawat247a8682017-06-05 15:00:31 -07009156 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009157 if (ret)
9158 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9159
9160 return ret;
9161}
9162
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009163static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009164{
9165 int vdev_id = 0;
9166 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9167 int value = hdd_ctx->config->alternative_chainmask_enabled;
9168 int vpdev = PDEV_CMD;
9169 int ret;
9170
Naveen Rawat247a8682017-06-05 15:00:31 -07009171 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009172 if (ret)
9173 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9174 ret);
9175
9176 return ret;
9177}
9178
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009179static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009180{
9181 int vdev_id = 0;
9182 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9183 int value = hdd_ctx->config->ani_enabled;
9184 int vpdev = PDEV_CMD;
9185 int ret;
9186
Naveen Rawat247a8682017-06-05 15:00:31 -07009187 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009188 if (ret)
9189 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9190
9191 return ret;
9192}
9193
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009194/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009195 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9196 * @hdd_ctx: HDD context
9197 *
9198 * Pre configurations to be done at lower layer before calling cds enable.
9199 *
9200 * Return: 0 on success and errno on failure.
9201 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009202static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009203{
9204 int ret;
9205 QDF_STATUS status;
9206 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009207 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009208
Leo Changfdb45c32016-10-28 11:09:23 -07009209 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009210 /*
9211 * Set 802.11p config
9212 * TODO-OCB: This has been temporarily added here to ensure this
9213 * parameter is set in CSR when we init the channel list. This should
9214 * be removed once the 5.9 GHz channels are added to the regulatory
9215 * domain.
9216 */
9217 hdd_set_dot11p_config(hdd_ctx);
9218
9219 /*
9220 * Note that the cds_pre_enable() sequence triggers the cfg download.
9221 * The cfg download must occur before we update the SME config
9222 * since the SME config operation must access the cfg database
9223 */
9224 status = hdd_set_sme_config(hdd_ctx);
9225
9226 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009227 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009228 ret = qdf_status_to_os_return(status);
9229 goto out;
9230 }
9231
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009232 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9233 if (QDF_STATUS_SUCCESS != status) {
9234 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9235 ret = qdf_status_to_os_return(status);
9236 goto out;
9237 }
9238
Naveen Rawat247a8682017-06-05 15:00:31 -07009239 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009240 hdd_ctx->config->tx_chain_mask_1ss,
9241 PDEV_CMD);
9242 if (0 != ret) {
9243 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9244 goto out;
9245 }
9246
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009247 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9248 if (ret)
9249 goto out;
9250
9251 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9252 if (ret)
9253 goto out;
9254
Jeff Johnson12a744b2017-04-04 08:19:37 -07009255 ret = hdd_set_ani_enabled(hdd_ctx);
9256 if (ret)
9257 goto out;
9258
Naveen Rawat247a8682017-06-05 15:00:31 -07009259 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009260 hdd_ctx->config->arp_ac_category,
9261 PDEV_CMD);
9262 if (0 != ret) {
9263 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9264 hdd_ctx->config->arp_ac_category, ret);
9265 goto out;
9266 }
9267
Prashanth Bhatta07998752016-04-28 12:35:33 -07009268 status = hdd_set_sme_chan_list(hdd_ctx);
9269 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009270 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009271 ret = qdf_status_to_os_return(status);
9272 goto out;
9273 }
9274
9275 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009276 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009277 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009278 ret = -EINVAL;
9279 goto out;
9280 }
9281
Prashanth Bhatta07998752016-04-28 12:35:33 -07009282 /*
9283 * Set the MAC Address Currently this is used by HAL to add self sta.
9284 * Remove this once self sta is added as part of session open.
9285 */
9286 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9287 hdd_ctx->config->intfMacAddr[0].bytes,
9288 sizeof(hdd_ctx->config->intfMacAddr[0]));
9289
9290 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9291 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9292 hal_status, hal_status);
9293 ret = -EINVAL;
9294 goto out;
9295 }
9296
9297 hdd_init_channel_avoidance(hdd_ctx);
9298
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309299 /* update enable sap mandatory chan list */
9300 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9301 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009302out:
9303 return ret;
9304}
9305
9306/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009307 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9308 * @context_ptr - hdd context pointer
9309 * @event_ptr - event structure pointer
9310 *
9311 * This is the p2p listen offload stop event handler, it sends vendor
9312 * event back to supplicant to notify the stop reason.
9313 *
9314 * Return: None
9315 */
9316static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9317 void *event_ptr)
9318{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009319 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009320 struct sir_p2p_lo_event *evt = event_ptr;
9321 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009322 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009323
9324 ENTER();
9325
9326 if (hdd_ctx == NULL) {
9327 hdd_err("Invalid HDD context pointer");
9328 return;
9329 }
9330
Peng Xu5c682812017-08-06 07:39:13 -07009331 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9332 if (!adapter) {
9333 hdd_err("Cannot find adapter by vdev_id = %d",
9334 evt->vdev_id);
9335 return;
9336 }
9337
Peng Xu8fdaa492016-06-22 10:20:47 -07009338 vendor_event =
9339 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009340 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009341 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9342 GFP_KERNEL);
9343
9344 if (!vendor_event) {
9345 hdd_err("cfg80211_vendor_event_alloc failed");
9346 return;
9347 }
9348
9349 if (nla_put_u32(vendor_event,
9350 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9351 evt->reason_code)) {
9352 hdd_err("nla put failed");
9353 kfree_skb(vendor_event);
9354 return;
9355 }
9356
9357 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009358 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9359 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009360}
9361
9362/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309363 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9364 * @hdd_ctx: HDD context
9365 *
9366 * This function sends the adaptive dwell time config configuration to the
9367 * firmware via WMA
9368 *
9369 * Return: 0 - success, < 0 - failure
9370 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009371static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309372{
9373 QDF_STATUS status;
9374 struct adaptive_dwelltime_params dwelltime_params;
9375
9376 dwelltime_params.is_enabled =
9377 hdd_ctx->config->adaptive_dwell_mode_enabled;
9378 dwelltime_params.dwelltime_mode =
9379 hdd_ctx->config->global_adapt_dwelltime_mode;
9380 dwelltime_params.lpf_weight =
9381 hdd_ctx->config->adapt_dwell_lpf_weight;
9382 dwelltime_params.passive_mon_intval =
9383 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9384 dwelltime_params.wifi_act_threshold =
9385 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9386
9387 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9388 &dwelltime_params);
9389
9390 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9391 if (!QDF_IS_STATUS_SUCCESS(status)) {
9392 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9393 return -EAGAIN;
9394 }
9395 return 0;
9396}
9397
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009398int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309399{
9400 QDF_STATUS status;
9401 struct wmi_dbs_scan_sel_params dbs_scan_params;
9402 uint32_t i = 0;
9403 uint8_t count = 0, numentries = 0;
9404 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9405 * CDS_DBS_SCAN_CLIENTS_MAX];
9406
9407 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009408 if (hdd_ctx->config->dual_mac_feature_disable ==
9409 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309410 return -EINVAL;
9411
9412 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9413 dbs_scan_config, &numentries,
9414 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9415 * CDS_DBS_SCAN_CLIENTS_MAX));
9416
9417 hdd_info("numentries %hu", numentries);
9418 if (!numentries) {
9419 hdd_info("Donot send scan_selection_config");
9420 return 0;
9421 }
9422
9423 /* hdd_set_fw_log_params */
9424 dbs_scan_params.num_clients = 0;
9425 while (count < (numentries - 2)) {
9426 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9427 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9428 dbs_scan_params.num_non_dbs_scans[i] =
9429 dbs_scan_config[count + 2];
9430 dbs_scan_params.num_clients++;
9431 hdd_debug("module:%d NDS:%d NNDS:%d",
9432 dbs_scan_params.module_id[i],
9433 dbs_scan_params.num_dbs_scans[i],
9434 dbs_scan_params.num_non_dbs_scans[i]);
9435 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9436 i++;
9437 }
9438
9439 dbs_scan_params.pdev_id = 0;
9440
9441 hdd_debug("clients:%d pdev:%d",
9442 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9443
9444 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9445 &dbs_scan_params);
9446 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9447 if (!QDF_IS_STATUS_SUCCESS(status)) {
9448 hdd_err("Failed to send DBS Scan selection configuration!");
9449 return -EAGAIN;
9450 }
9451 return 0;
9452}
9453
Arun Khandavallid4349a92016-07-25 11:10:43 +05309454#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9455/**
9456 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9457 * @hdd_ctx: HDD context
9458 *
9459 * Set auto shutdown callback to get indications from firmware to indicate
9460 * userspace to shutdown WLAN after a configured amount of inactivity.
9461 *
9462 * Return: 0 on success and errno on failure.
9463 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009464static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309465{
9466 QDF_STATUS status;
9467
9468 if (!hdd_ctx->config->WlanAutoShutdown)
9469 return 0;
9470
9471 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9472 wlan_hdd_auto_shutdown_cb);
9473 if (status != QDF_STATUS_SUCCESS)
9474 hdd_err("Auto shutdown feature could not be enabled: %d",
9475 status);
9476
9477 return qdf_status_to_os_return(status);
9478}
9479#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009480static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309481{
9482 return 0;
9483}
9484#endif
9485
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009486static QDF_STATUS hdd_set_dbs_scan_and_fw_mode_cfg(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009487{
9488 QDF_STATUS status = QDF_STATUS_SUCCESS;
9489
9490 switch (hdd_ctx->config->dual_mac_feature_disable) {
9491 case DISABLE_DBS_CXN_AND_SCAN:
9492 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9493 if (status != QDF_STATUS_SUCCESS)
9494 hdd_err("Failed to disable dual mac features");
9495 break;
9496 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN:
9497 case DISABLE_DBS_CXN_AND_ENABLE_DBS_SCAN_WITH_ASYNC_SCAN_OFF:
9498 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
9499 status = wlan_hdd_update_dbs_scan_and_fw_mode_config(hdd_ctx);
9500 if (status != QDF_STATUS_SUCCESS)
9501 hdd_err("Failed to set dbs scan and fw mode config");
9502 break;
9503 default:
9504 break;
9505 }
9506
9507 return status;
9508}
9509
Arun Khandavallid4349a92016-07-25 11:10:43 +05309510/**
9511 * hdd_features_init() - Init features
9512 * @hdd_ctx: HDD context
9513 * @adapter: Primary adapter context
9514 *
9515 * Initialize features and their feature context after WLAN firmware is up.
9516 *
9517 * Return: 0 on success and errno on failure.
9518 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009519static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309520{
9521 tSirTxPowerLimit hddtxlimit;
9522 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309523 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309524 int ret;
9525
9526 ENTER();
9527
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07009528 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309529 if (ret) {
9530 hdd_err("Failed to update country code: %d", ret);
9531 goto out;
9532 }
9533
9534 /* FW capabilities received, Set the Dot11 mode */
9535 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009536 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9537 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309538
Arun Khandavallid4349a92016-07-25 11:10:43 +05309539
9540 if (hdd_ctx->config->fIsImpsEnabled)
9541 hdd_set_idle_ps_config(hdd_ctx, true);
9542 else
9543 hdd_set_idle_ps_config(hdd_ctx, false);
9544
Poddar, Siddarth37033032017-10-11 15:47:40 +05309545 /* Send Enable/Disable data stall detection cmd to FW */
9546 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9547 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9548
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309549 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009550 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309551
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309552 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9553 hdd_warn("Error in setting Voltage Corner mode config to FW");
9554
Arun Khandavallid4349a92016-07-25 11:10:43 +05309555 if (hdd_lro_init(hdd_ctx))
9556 hdd_err("Unable to initialize LRO in fw");
9557
9558 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9559 hdd_err("Unable to send adaptive dwelltime setting to FW");
9560
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309561 if (hdd_dbs_scan_selection_init(hdd_ctx))
9562 hdd_err("Unable to send DBS scan selection setting to FW");
9563
Arun Khandavallid4349a92016-07-25 11:10:43 +05309564 ret = hdd_init_thermal_info(hdd_ctx);
9565 if (ret) {
9566 hdd_err("Error while initializing thermal information");
9567 goto deregister_frames;
9568 }
9569
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309570 if (cds_is_packet_log_enabled())
9571 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
9572
Arun Khandavallid4349a92016-07-25 11:10:43 +05309573 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9574 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9575 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9576 if (!QDF_IS_STATUS_SUCCESS(status))
9577 hdd_err("Error setting txlimit in sme: %d", status);
9578
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009579 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309580
Arun Khandavallid4349a92016-07-25 11:10:43 +05309581 ret = hdd_register_cb(hdd_ctx);
9582 if (ret) {
9583 hdd_err("Failed to register HDD callbacks!");
9584 goto deregister_frames;
9585 }
9586
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009587 status = hdd_set_dbs_scan_and_fw_mode_cfg(hdd_ctx);
9588 if (!QDF_IS_STATUS_SUCCESS(status)) {
9589 hdd_err("Failed to set dbs scan and fw mode cfg");
9590 goto deregister_cb;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309591 }
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009592
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309593 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9594 status = sme_enable_disable_chanavoidind_event(
9595 hdd_ctx->hHal, 0);
9596 if (!QDF_IS_STATUS_SUCCESS(status)) {
9597 hdd_err("Failed to disable Chan Avoidance Indication");
9598 goto deregister_cb;
9599 }
9600 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309601
Manjeet Singha9cae432017-02-28 11:58:22 +05309602 if (hdd_ctx->config->enable_5g_band_pref) {
9603 band_pref_params.rssi_boost_threshold_5g =
9604 hdd_ctx->config->rssi_boost_threshold_5g;
9605 band_pref_params.rssi_boost_factor_5g =
9606 hdd_ctx->config->rssi_boost_factor_5g;
9607 band_pref_params.max_rssi_boost_5g =
9608 hdd_ctx->config->max_rssi_boost_5g;
9609 band_pref_params.rssi_penalize_threshold_5g =
9610 hdd_ctx->config->rssi_penalize_threshold_5g;
9611 band_pref_params.rssi_penalize_factor_5g =
9612 hdd_ctx->config->rssi_penalize_factor_5g;
9613 band_pref_params.max_rssi_penalize_5g =
9614 hdd_ctx->config->max_rssi_penalize_5g;
9615 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9616 }
9617
Arun Khandavallid4349a92016-07-25 11:10:43 +05309618 /* register P2P Listen Offload event callback */
9619 if (wma_is_p2p_lo_capable())
9620 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9621 wlan_hdd_p2p_lo_event_callback);
9622
9623 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9624
9625 if (ret)
9626 goto deregister_cb;
9627
9628 EXIT();
9629 return 0;
9630
9631deregister_cb:
9632 hdd_deregister_cb(hdd_ctx);
9633deregister_frames:
9634 wlan_hdd_cfg80211_deregister_frames(adapter);
9635out:
9636 return -EINVAL;
9637
9638}
9639
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009640/**
9641 * hdd_features_deinit() - Deinit features
9642 * @hdd_ctx: HDD context
9643 *
9644 * De-Initialize features and their feature context.
9645 *
9646 * Return: none.
9647 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009648static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009649{
9650 wlan_hdd_tsf_deinit(hdd_ctx);
9651}
9652
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309653/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009654 * hdd_register_bcn_cb() - register scan beacon callback
9655 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309656 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009657 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309658 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009659static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309660{
9661 QDF_STATUS status;
9662
9663 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9664 wlan_cfg80211_inform_bss_frame,
9665 SCAN_CB_TYPE_INFORM_BCN);
9666 if (!QDF_IS_STATUS_SUCCESS(status)) {
9667 hdd_err("failed with status code %08d [x%08x]",
9668 status, status);
9669 return status;
9670 }
9671
9672 return QDF_STATUS_SUCCESS;
9673}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309674
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309675/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309676 * hdd_configure_cds() - Configure cds modules
9677 * @hdd_ctx: HDD context
9678 * @adapter: Primary adapter context
9679 *
9680 * Enable Cds modules after WLAN firmware is up.
9681 *
9682 * Return: 0 on success and errno on failure.
9683 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009684int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05309685{
9686 int ret;
9687 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309688 int set_value;
9689 uint32_t num_abg_tx_chains = 0;
9690 uint32_t num_11b_tx_chains = 0;
9691 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -07009692 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +05309693
9694 if (hdd_ctx->config->sifs_burst_duration) {
9695 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9696 hdd_ctx->config->sifs_burst_duration;
9697
9698 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9699 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9700 set_value, PDEV_CMD);
9701 }
9702
9703 if (hdd_ctx->config->is_force_1x1)
9704 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
9705 1, PDEV_CMD);
9706 /* set chip power save failure detected callback */
9707 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9708 hdd_chip_pwr_save_fail_detected_cb);
9709
9710 if (hdd_ctx->config->max_mpdus_inampdu) {
9711 set_value = hdd_ctx->config->max_mpdus_inampdu;
9712 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
9713 set_value, PDEV_CMD);
9714 }
9715
9716 if (hdd_ctx->config->enable_rts_sifsbursting) {
9717 set_value = hdd_ctx->config->enable_rts_sifsbursting;
9718 sme_cli_set_command(0,
9719 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9720 set_value, PDEV_CMD);
9721 }
9722
9723 if (hdd_ctx->config->sap_get_peer_info) {
9724 set_value = hdd_ctx->config->sap_get_peer_info;
9725 sme_cli_set_command(0,
9726 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
9727 set_value, PDEV_CMD);
9728 }
9729
9730 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9731 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9732 if (!hdd_ctx->config->enable2x2) {
9733 if (num_11b_tx_chains > 1)
9734 num_11b_tx_chains = 1;
9735 if (num_11ag_tx_chains > 1)
9736 num_11ag_tx_chains = 1;
9737 }
9738 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9739 num_11b_tx_chains);
9740 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9741 num_11ag_tx_chains);
9742 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9743 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +05309744
9745 ret = hdd_pre_enable_configure(hdd_ctx);
9746 if (ret) {
9747 hdd_err("Failed to pre-configure cds");
9748 goto out;
9749 }
9750
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009751 /* Always get latest IPA resources allocated from cds_open and configure
9752 * IPA module before configuring them to FW. Sequence required as crash
9753 * observed otherwise.
9754 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009755 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9756 hdd_err("Failed to setup pipes");
9757 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009758 }
9759
Arun Khandavallifae92942016-08-01 13:31:08 +05309760 /*
9761 * Start CDS which starts up the SME/MAC/HAL modules and everything
9762 * else
9763 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -07009764 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309765
9766 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009767 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309768 goto out;
9769 }
9770
9771 status = hdd_post_cds_enable_config(hdd_ctx);
9772 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009773 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009774 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309775 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309776 status = hdd_register_bcn_cb(hdd_ctx);
9777 if (!QDF_IS_STATUS_SUCCESS(status)) {
9778 hdd_alert("hdd_post_cds_enable_config failed");
9779 goto cds_disable;
9780 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309781
9782 ret = hdd_features_init(hdd_ctx, adapter);
9783 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009784 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309785
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009786 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -07009787 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009788 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
9789 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -07009790 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -07009791 goto cds_disable;
9792 }
9793
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309794 if (hdd_enable_egap(hdd_ctx))
9795 hdd_debug("enhance green ap is not enabled");
9796
Nachiket Kukadedd302662017-07-13 17:31:44 +05309797 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
9798 hdd_debug("Failed to set wow pulse");
9799
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +05309800 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
9801 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
9802
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +05309803
9804 if (hdd_ctx->config->enable_phy_reg_retention)
9805 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
9806 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
9807
Arun Khandavallifae92942016-08-01 13:31:08 +05309808 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009809
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009810cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009811 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009812
Arun Khandavallifae92942016-08-01 13:31:08 +05309813out:
9814 return -EINVAL;
9815}
9816
9817/**
9818 * hdd_deconfigure_cds() -De-Configure cds
9819 * @hdd_ctx: HDD context
9820 *
9821 * Deconfigure Cds modules before WLAN firmware is down.
9822 *
9823 * Return: 0 on success and errno on failure.
9824 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009825static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309826{
9827 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009828 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309829
9830 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009831
9832 /* De-init features */
9833 hdd_features_deinit(hdd_ctx);
9834
Arun Khandavallifae92942016-08-01 13:31:08 +05309835 /* De-register the SME callbacks */
9836 hdd_deregister_cb(hdd_ctx);
9837
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -07009838 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309839 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9840 hdd_err("Failed to Disable the CDS Modules! :%d",
9841 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009842 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309843 }
9844
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309845 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9846 hdd_err("Failed to disconnect pipes");
9847 ret = -EINVAL;
9848 }
9849
Arun Khandavallifae92942016-08-01 13:31:08 +05309850 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009851 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309852}
9853
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009854#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9855static void hdd_deregister_policy_manager_callback(
9856 struct wlan_objmgr_psoc *psoc)
9857{
9858 if (QDF_STATUS_SUCCESS !=
9859 policy_mgr_deregister_hdd_cb(psoc)) {
9860 hdd_err("HDD callback deregister with policy manager failed");
9861 }
9862}
9863#else
9864static void hdd_deregister_policy_manager_callback(
9865 struct wlan_objmgr_psoc *psoc)
9866{
9867}
9868#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309869
9870/**
9871 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9872 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009873 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309874 *
9875 * This function maintains the driver state machine it will be invoked from
9876 * exit, shutdown and con_mode change handler. Depending on the driver state
9877 * shall perform the stopping/closing of the modules.
9878 *
9879 * Return: 0 for success; non-zero for failure
9880 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009881int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309882{
9883 void *hif_ctx;
9884 qdf_device_t qdf_ctx;
9885 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309886 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -08009887 bool is_recovery_stop = cds_is_driver_recovering();
9888 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop;
Dustin Brown70111822017-03-30 15:31:40 -07009889 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309890
9891 ENTER();
Yun Parkfec73dc2017-09-06 10:40:07 -07009892 hdd_alert("stop WLAN module: entering driver status=%d",
9893 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +05309894
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009895 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9896
Arun Khandavallifae92942016-08-01 13:31:08 +05309897 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9898 if (!qdf_ctx) {
9899 hdd_err("QDF device context NULL");
9900 return -EINVAL;
9901 }
9902
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309903 mutex_lock(&hdd_ctx->iface_change_lock);
9904 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009905 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +05309906
Dustin Brown70111822017-03-30 15:31:40 -07009907 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -07009908 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009909 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -07009910 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -07009911
9912 cds_print_external_threads();
9913
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009914 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009915 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -07009916 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
9917 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05309918 hdd_prevent_suspend_timeout(
9919 hdd_ctx->config->iface_change_wait_time,
9920 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009921 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -07009922 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -07009923 return 0;
9924 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009925 }
9926
Arun Khandavallifae92942016-08-01 13:31:08 +05309927 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9928
Kabilan Kannan6edafeb2017-11-16 16:34:34 -08009929 /* free user wowl patterns */
9930 hdd_free_user_wowl_ptrns();
9931
Arun Khandavallifae92942016-08-01 13:31:08 +05309932 switch (hdd_ctx->driver_status) {
9933 case DRIVER_MODULES_UNINITIALIZED:
9934 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309935 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309936 case DRIVER_MODULES_CLOSED:
9937 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309938 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309939 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -08009940 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
9941
Komal Seelamf2136bb2016-09-28 18:30:44 +05309942 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309943 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009944 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309945 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309946 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309947 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009948 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -08009949
Arun Khandavallifae92942016-08-01 13:31:08 +05309950 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08009951 hdd_info("Wlan transitioned (now OPENED)");
9952
9953 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +05309954 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08009955 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05309956 break;
9957 default:
9958 hdd_err("Trying to stop wlan in a wrong state: %d",
9959 hdd_ctx->driver_status);
9960 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309961 ret = -EINVAL;
9962 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309963 }
9964
Dustin Brown550f6d22017-12-14 15:44:01 -08009965 hdd_debug("Closing CDS modules!");
Rajeev Kumarbe021242017-02-16 16:12:23 -08009966 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309967 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9968 hdd_err("Failed to process post CDS disable Modules! :%d",
9969 qdf_status);
9970 ret = -EINVAL;
9971 QDF_ASSERT(0);
9972 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009973
psimhadeea0a12017-12-18 14:50:02 -08009974 hdd_runtime_suspend_context_deinit(hdd_ctx);
9975
Dustin Brownbd68fe12017-11-21 15:28:52 -08009976 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
9977 if (ret) {
9978 hdd_err("Failed to destroy pdev; errno:%d", ret);
9979 QDF_ASSERT(0);
9980 }
9981
9982 /*
9983 * Reset total mac phy during module stop such that during
9984 * next module start same psoc is used to populate new service
9985 * ready data
9986 */
9987 hdd_ctx->hdd_psoc->total_mac_phy = 0;
9988
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07009989 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
9990 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9991 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
9992 ret = -EINVAL;
9993 QDF_ASSERT(0);
9994 }
9995
Jeff Johnsone4b14592017-09-13 14:23:33 -07009996 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05309997 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009998 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309999 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010000 QDF_ASSERT(0);
10001 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010002
Arun Khandavallifae92942016-08-01 13:31:08 +053010003 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10004 if (!hif_ctx) {
10005 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010006 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010007 }
10008
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010009 if (hdd_ctx->target_hw_name) {
10010 qdf_mem_free(hdd_ctx->target_hw_name);
10011 hdd_ctx->target_hw_name = NULL;
10012 }
10013
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010014 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010015
10016 ol_cds_free();
10017
Dustin Brown70111822017-03-30 15:31:40 -070010018 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010019 ret = pld_power_off(qdf_ctx->dev);
10020 if (ret)
10021 hdd_err("CNSS power down failed put device into Low power mode:%d",
10022 ret);
10023 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010024
Dustin Brown4bc0a622017-12-06 15:56:50 -080010025 /* many adapter resources are not freed by design in SSR case */
10026 if (!is_recovery_stop)
10027 hdd_check_for_leaks();
10028 qdf_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
10029
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010030 /* Once the firmware sequence is completed reset this flag */
10031 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010032 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010033 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010034
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010035done:
10036 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010037 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010038 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010039 hdd_alert("stop WLAN module: exit driver status=%d",
10040 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010041
Arun Khandavallifae92942016-08-01 13:31:08 +053010042 EXIT();
10043
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010044 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010045}
10046
Arun Khandavallifae92942016-08-01 13:31:08 +053010047
10048/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010049 * hdd_state_info_dump() - prints state information of hdd layer
10050 * @buf: buffer pointer
10051 * @size: size of buffer to be filled
10052 *
10053 * This function is used to dump state information of hdd layer
10054 *
10055 * Return: None
10056 */
10057static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10058{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010059 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010060 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010061 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010062 uint16_t len = 0;
10063 char *buf = *buf_ptr;
10064
10065 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10066 if (!hdd_ctx) {
10067 hdd_err("Failed to get hdd context ");
10068 return;
10069 }
10070
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010071 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010072
10073 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010074 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010075 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010076 "\n is_scheduler_suspended %d",
10077 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010078
Dustin Brown920397d2017-12-13 16:27:50 -080010079 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010080 if (adapter->dev)
10081 len += scnprintf(buf + len, *size - len,
10082 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010083 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010084 "\n device_mode: %d", adapter->device_mode);
10085 switch (adapter->device_mode) {
10086 case QDF_STA_MODE:
10087 case QDF_P2P_CLIENT_MODE:
10088 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10089 len += scnprintf(buf + len, *size - len,
10090 "\n connState: %d",
10091 hdd_sta_ctx->conn_info.connState);
10092 break;
10093
10094 default:
10095 break;
10096 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010097 }
10098
10099 *size -= len;
10100 *buf_ptr += len;
10101}
10102
10103/**
10104 * hdd_register_debug_callback() - registration function for hdd layer
10105 * to print hdd state information
10106 *
10107 * Return: None
10108 */
10109static void hdd_register_debug_callback(void)
10110{
10111 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10112}
10113
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010114/*
10115 * wlan_init_bug_report_lock() - Initialize bug report lock
10116 *
10117 * This function is used to create bug report lock
10118 *
10119 * Return: None
10120 */
10121static void wlan_init_bug_report_lock(void)
10122{
10123 p_cds_contextType p_cds_context;
10124
10125 p_cds_context = cds_get_global_context();
10126 if (!p_cds_context) {
10127 hdd_err("cds context is NULL");
10128 return;
10129 }
10130
10131 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10132}
10133
Mohit Khannaf8f96822017-05-17 17:11:59 -070010134void hdd_dp_trace_init(struct hdd_config *config)
10135{
10136
10137 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10138 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10139 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10140 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10141 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10142 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10143 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010144 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010145
10146 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10147 &num_entries, sizeof(config_params));
10148
10149 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010150 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010151 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010152 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010153 else if (bw_compute_interval > 1000) {
10154 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10155 thresh_time_limit = 1;
10156 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010157 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10158
10159 switch (num_entries) {
10160 case 4:
10161 proto_bitmap = config_params[3];
10162 case 3:
10163 verbosity = config_params[2];
10164 case 2:
10165 thresh = config_params[1];
10166 case 1:
10167 live_mode = config_params[0];
10168 default:
10169 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
10170 live_mode, thresh, thresh_time_limit,
10171 verbosity, proto_bitmap);
10172 };
10173
10174 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10175 verbosity, proto_bitmap);
10176
10177}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010178/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010179 * hdd_wlan_startup() - HDD init function
10180 * @dev: Pointer to the underlying device
10181 *
10182 * This is the driver startup code executed once a WLAN device has been detected
10183 *
10184 * Return: 0 for success, < 0 for failure
10185 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010186int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010187{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010188 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010189 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010190 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010191 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010192
10193 ENTER();
10194
Arun Khandavallifae92942016-08-01 13:31:08 +053010195 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010196
10197 if (IS_ERR(hdd_ctx))
10198 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010199
Abhishek Singhe9068f12017-03-31 14:14:52 +053010200 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10201 DEFAULT_PSOC_ID);
10202 if (ret) {
10203 hdd_err("Psoc creation fails!");
10204 QDF_BUG(0);
10205 goto err_hdd_free_context;
10206 }
10207
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010208 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010209#ifdef FEATURE_WLAN_CH_AVOID
10210 mutex_init(&hdd_ctx->avoid_freq_lock);
10211#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010212
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010213 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -070010214 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010215
Dustin Brown021cecd2017-12-11 13:56:43 -080010216 memdump_init();
10217 hdd_driver_memdump_init();
10218
Jeff Johnson957bc272017-02-02 08:54:48 -080010219 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010220 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010221 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010222 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010223 }
10224
Yingying Tang80e15f32016-09-27 18:23:01 +080010225 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226
Anurag Chouhan6d760662016-02-20 16:05:43 +053010227 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010228
10229 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010230 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010231 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010232 }
10233
Prashanth Bhatta07998752016-04-28 12:35:33 -070010234 ret = hdd_wiphy_init(hdd_ctx);
10235 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010236 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010237 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010238 }
10239
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010240 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010241 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010242
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010243 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010244 goto err_wiphy_unregister;
10245
Kapil Gupta4f0c0c12017-02-07 15:21:15 +053010246 wlan_hdd_init_chan_info(hdd_ctx);
10247
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010248 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010249
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010250 ret = hdd_register_notifiers(hdd_ctx);
10251 if (ret)
10252 goto err_ipa_cleanup;
10253
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010254 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010255
Jeff Johnson957bc272017-02-02 08:54:48 -080010256 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10257 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010258 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010259 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010260 }
10261
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010262 hdd_release_rtnl_lock();
10263 rtnl_held = false;
10264
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010265 wlan_hdd_update_11n_mode(hdd_ctx->config);
10266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010267#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010268 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010269 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010270 hdd_skip_acs_scan_timer_handler,
10271 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010272 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010273 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010274 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010275#endif
10276
Prashanth Bhattaab004382016-10-11 16:08:11 -070010277 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010278
Jeff Johnson9afc5012016-09-23 13:56:27 -070010279 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010280
Nirav Shahbd36b062016-07-18 11:12:59 +053010281 if (hdd_ctx->rps)
10282 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010283
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +053010284 status = wlansap_global_init();
10285 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -080010286 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010287
Arun Khandavallifae92942016-08-01 13:31:08 +053010288 if (hdd_ctx->config->fIsImpsEnabled)
10289 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010290 else
10291 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010292
Mukul Sharma07bd8752017-10-10 16:58:14 +053010293 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010294 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10295 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010296 hdd_prevent_suspend_timeout(
10297 hdd_ctx->config->iface_change_wait_time,
10298 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10299 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010300
Sachin Ahujadddd2632017-03-07 19:07:24 +053010301 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010302 goto success;
10303
Jeff Johnson957bc272017-02-02 08:54:48 -080010304err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010305 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010306
Jeff Johnson46bde382017-02-01 15:31:16 -080010307err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010308 if (rtnl_held)
10309 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010310
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010311 unregister_netdevice_notifier(&hdd_netdev_notifier);
10312
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010313err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010314 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010316err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010317 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010318
Arun Khandavallifae92942016-08-01 13:31:08 +053010319err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010320 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010321
Dustin Brown021cecd2017-12-11 13:56:43 -080010322err_memdump_deinit:
10323 hdd_driver_memdump_deinit();
10324 memdump_deinit();
10325
Houston Hoffman47a4a052016-11-14 23:22:44 -080010326 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010327 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010328 hdd_exit_netlink_services(hdd_ctx);
10329
Dustin Brown20912462017-06-07 13:48:25 -070010330 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10331
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010332err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010333 if (cds_is_fw_down())
10334 hdd_err("Not setting the complete event as fw is down");
10335 else
10336 hdd_start_complete(ret);
10337
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010338 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010339 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010340 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010341
10342success:
10343 EXIT();
10344 return 0;
10345}
10346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010347/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010348 * hdd_wlan_update_target_info() - update target type info
10349 * @hdd_ctx: HDD context
10350 * @context: hif context
10351 *
10352 * Update target info received from firmware in hdd context
10353 * Return:None
10354 */
10355
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010356void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010357{
10358 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10359
10360 if (!tgt_info) {
10361 hdd_err("Target info is Null");
10362 return;
10363 }
10364
10365 hdd_ctx->target_type = tgt_info->target_type;
10366}
10367
10368/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010369 * hdd_get_nud_stats_cb() - callback api to update the stats
10370 * received from the firmware
10371 * @data: pointer to adapter.
10372 * @rsp: pointer to data received from FW.
10373 *
10374 * This is called when wlan driver received response event for
10375 * get arp stats to firmware.
10376 *
10377 * Return: None
10378 */
10379static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10380{
10381 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10382 struct hdd_nud_stats_context *context;
10383 int status;
10384 struct hdd_adapter *adapter = NULL;
10385
10386 ENTER();
10387
10388 if (!rsp) {
10389 hdd_err("data is null");
10390 return;
10391 }
10392
10393 status = wlan_hdd_validate_context(hdd_ctx);
10394 if (0 != status)
10395 return;
10396
10397 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10398 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10399 hdd_err("Invalid adapter or adapter has invalid magic");
10400 return;
10401 }
10402
10403 hdd_notice("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10404 hdd_notice("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10405 hdd_notice("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10406 hdd_notice("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10407 hdd_notice("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10408 rsp->out_of_order_arp_rsp_drop_cnt);
10409 hdd_notice("rsp->dad_detected :%x", rsp->dad_detected);
10410 hdd_notice("rsp->connect_status :%x", rsp->connect_status);
10411 hdd_notice("rsp->ba_session_establishment_status :%x",
10412 rsp->ba_session_establishment_status);
10413
10414 adapter->hdd_stats.hdd_arp_stats.tx_fw_cnt = rsp->arp_req_enqueue;
10415 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
10416 adapter->hdd_stats.hdd_arp_stats.tx_ack_cnt = rsp->arp_req_tx_success;
10417 adapter->dad |= rsp->dad_detected;
10418 adapter->con_status = rsp->connect_status;
10419
10420 spin_lock(&hdd_context_lock);
10421 context = &hdd_ctx->nud_stats_context;
10422 complete(&context->response_event);
10423 spin_unlock(&hdd_context_lock);
10424
10425 EXIT();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010426}
10427
10428/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010429 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010430 * @hdd_ctx: HDD context
10431 *
10432 * Register the HDD callbacks to CDS/SME.
10433 *
10434 * Return: 0 for success or Error code for failure
10435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010436int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010437{
10438 QDF_STATUS status;
10439 int ret = 0;
10440
10441 ENTER();
10442
10443 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10444
10445 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10446 hdd_send_oem_data_rsp_msg);
10447
10448 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
10449 wlan_hdd_cfg80211_fw_mem_dump_cb);
10450 if (!QDF_IS_STATUS_SUCCESS(status)) {
10451 hdd_err("Failed to register memdump callback");
10452 ret = -EINVAL;
10453 return ret;
10454 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010455 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10456 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010457 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10458 sme_nan_register_callback(hdd_ctx->hHal,
10459 wlan_hdd_cfg80211_nan_callback);
10460 sme_stats_ext_register_callback(hdd_ctx->hHal,
10461 wlan_hdd_cfg80211_stats_ext_callback);
10462
10463 sme_ext_scan_register_callback(hdd_ctx->hHal,
10464 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010465 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10466 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010467
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010468 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10469 hdd_rssi_threshold_breached);
10470
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010471 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10472
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010473 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10474 wlan_hdd_cfg80211_link_layer_stats_callback);
10475
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010476 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10477
Zhang Qianca38fb12016-12-23 11:10:48 +080010478 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10479 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10480
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010481 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10482 hdd_lost_link_info_cb);
10483 /* print error and not block the startup process */
10484 if (!QDF_IS_STATUS_SUCCESS(status))
10485 hdd_err("set lost link info callback failed");
10486
Poddar, Siddarth34872782017-08-10 14:08:51 +053010487 ret = hdd_register_data_stall_detect_cb();
10488 if (ret) {
10489 hdd_err("Register data stall detect detect callback failed.");
10490 return ret;
10491 }
10492
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010493 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10494
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010495 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010496 hdd_set_connection_in_progress,
10497 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010498
10499 status = sme_congestion_register_callback(hdd_ctx->hHal,
10500 hdd_update_cca_info_cb);
10501 if (!QDF_IS_STATUS_SUCCESS(status))
10502 hdd_err("set congestion callback failed");
10503
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010504 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10505 hdd_bt_activity_cb);
10506 if (!QDF_IS_STATUS_SUCCESS(status))
10507 hdd_err("set bt activity info callback failed");
10508
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010509 EXIT();
10510
10511 return ret;
10512}
10513
10514/**
10515 * hdd_deregister_cb() - De-Register HDD callbacks.
10516 * @hdd_ctx: HDD context
10517 *
10518 * De-Register the HDD callbacks to CDS/SME.
10519 *
10520 * Return: void
10521 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010522void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010523{
10524 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010525 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010526
10527 ENTER();
10528
10529 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10530 if (!QDF_IS_STATUS_SUCCESS(status))
10531 hdd_err("De-register of dcc stats callback failed: %d",
10532 status);
10533
10534 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010535 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10536
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010537 sme_stats_ext_register_callback(hdd_ctx->hHal,
10538 wlan_hdd_cfg80211_stats_ext_callback);
10539
10540 sme_nan_deregister_callback(hdd_ctx->hHal);
10541 status = sme_reset_tsfcb(hdd_ctx->hHal);
10542 if (!QDF_IS_STATUS_SUCCESS(status))
10543 hdd_err("Failed to de-register tsfcb the callback:%d",
10544 status);
10545 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
10546 if (!QDF_IS_STATUS_SUCCESS(status))
10547 hdd_err("Failed to de-register the fw mem dump callback: %d",
10548 status);
10549
Poddar, Siddarth34872782017-08-10 14:08:51 +053010550 ret = hdd_deregister_data_stall_detect_cb();
10551 if (ret)
10552 hdd_err("Failed to de-register data stall detect event callback");
10553
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010554 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10555 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10556
10557 EXIT();
10558}
10559
10560/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010561 * hdd_softap_sta_deauth() - handle deauth req from HDD
10562 * @adapter: Pointer to the HDD
10563 * @enable: bool value
10564 *
10565 * This to take counter measure to handle deauth req from HDD
10566 *
10567 * Return: None
10568 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010569QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010570 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010572 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010573
10574 ENTER();
10575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010576 /* Ignore request to deauth bcmc station */
10577 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010578 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010580 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010581 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10582 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010583
10584 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010585 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010586}
10587
10588/**
10589 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10590 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010591 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010592 *
10593 * This to take counter measure to handle deauth req from HDD
10594 *
10595 * Return: None
10596 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010597void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010598 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010599{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010600 ENTER();
10601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010602 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010603 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010604 return;
10605
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010606 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010607 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010608}
10609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010610/**
10611 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10612 * @hdd_ctx: HDD Context
10613 *
10614 * API to find if there is any STA or P2P-Client is connected
10615 *
10616 * Return: true if connected; false otherwise
10617 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010618QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010619{
10620 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10621}
10622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010623/**
10624 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10625 * @adapter: HDD adapter pointer
10626 *
10627 * This function loop through each adapter and disable roaming on each STA
10628 * device mode except the input adapter.
10629 *
10630 * Note: On the input adapter roaming is not enabled yet hence no need to
10631 * disable.
10632 *
10633 * Return: None
10634 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010635void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010636{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010637 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010638 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639
10640 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010641 hdd_ctx->config->isRoamOffloadScanEnabled &&
10642 QDF_STA_MODE == adapter->device_mode &&
10643 policy_mgr_is_sta_active_connection_exists(
10644 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010645 hdd_debug("Connect received on STA session Id(%d)",
10646 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010647 /*
10648 * Loop through adapter and disable roaming for each STA device
10649 * mode except the input adapter.
10650 */
Dustin Brown920397d2017-12-13 16:27:50 -080010651 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010652 if (QDF_STA_MODE == adapterIdx->device_mode &&
10653 adapter->session_id != adapterIdx->session_id) {
10654 hdd_debug("Disable Roaming on session Id(%d)",
10655 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010656 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
10657 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010658 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010659 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010660 }
10661 }
10662}
10663
10664/**
10665 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
10666 * @adapter: HDD adapter pointer
10667 *
10668 * This function loop through each adapter and enable roaming on each STA
10669 * device mode except the input adapter.
10670 * Note: On the input adapter no need to enable roaming because link got
10671 * disconnected on this.
10672 *
10673 * Return: None
10674 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010675void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010676{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010677 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010678 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010679
10680 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010681 hdd_ctx->config->isRoamOffloadScanEnabled &&
10682 QDF_STA_MODE == adapter->device_mode &&
10683 policy_mgr_is_sta_active_connection_exists(
10684 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010685 hdd_debug("Disconnect received on STA session Id(%d)",
10686 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010687 /*
10688 * Loop through adapter and enable roaming for each STA device
10689 * mode except the input adapter.
10690 */
Dustin Brown920397d2017-12-13 16:27:50 -080010691 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070010692 if (QDF_STA_MODE == adapterIdx->device_mode &&
10693 adapter->session_id != adapterIdx->session_id) {
10694 hdd_debug("Enabling Roaming on session Id(%d)",
10695 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010696 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10697 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070010698 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010699 REASON_CONNECT);
10700 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010701 }
10702 }
10703}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010704
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010705/**
10706 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10707 * @skb: sk buffer pointer
10708 *
10709 * Sends the bcast message to SVC multicast group with generic nl socket
10710 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10711 *
10712 * Return: None
10713 */
10714static void nl_srv_bcast_svc(struct sk_buff *skb)
10715{
10716#ifdef CNSS_GENL
10717 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10718#else
10719 nl_srv_bcast(skb);
10720#endif
10721}
10722
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010723void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010724{
10725 struct sk_buff *skb;
10726 struct nlmsghdr *nlh;
10727 tAniMsgHdr *ani_hdr;
10728 void *nl_data = NULL;
10729 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010730 struct radio_index_tlv *radio_info;
10731 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010732
10733 if (in_interrupt() || irqs_disabled() || in_atomic())
10734 flags = GFP_ATOMIC;
10735
10736 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10737
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010738 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010739 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010740
10741 nlh = (struct nlmsghdr *)skb->data;
10742 nlh->nlmsg_pid = 0; /* from kernel */
10743 nlh->nlmsg_flags = 0;
10744 nlh->nlmsg_seq = 0;
10745 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10746
10747 ani_hdr = NLMSG_DATA(nlh);
10748 ani_hdr->type = type;
10749
10750 switch (type) {
10751 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010752 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010753 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010755 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010756 ani_hdr->length = 0;
10757 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758 break;
10759 case WLAN_SVC_WLAN_STATUS_IND:
10760 case WLAN_SVC_WLAN_VERSION_IND:
10761 case WLAN_SVC_DFS_CAC_START_IND:
10762 case WLAN_SVC_DFS_CAC_END_IND:
10763 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10764 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10765 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010766 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010767 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080010768 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769 ani_hdr->length = len;
10770 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10771 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10772 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010773 break;
10774
10775 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010776 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010777 type);
10778 kfree_skb(skb);
10779 return;
10780 }
10781
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010782 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010783 * Add radio index at the end of the svc event in TLV format
10784 * to maintain the backward compatibility with userspace
10785 * applications.
10786 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010787
10788 tlv_len = 0;
10789
10790 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10791 < WLAN_NL_MAX_PAYLOAD) {
10792 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10793 sizeof(*ani_hdr) + len);
10794 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10795 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10796 radio_info->radio = radio;
10797 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010798 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010799 "Added radio index tlv - radio index %d",
10800 radio_info->radio);
10801 }
10802
10803 nlh->nlmsg_len += tlv_len;
10804 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10805
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010806 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010807}
10808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010809#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10810void wlan_hdd_auto_shutdown_cb(void)
10811{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010812 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010813
10814 if (!hdd_ctx)
10815 return;
10816
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010817 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010818 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10819 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010820}
10821
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010822void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010823{
Jeff Johnson9d295242017-08-29 14:39:48 -070010824 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010825 bool ap_connected = false, sta_connected = false;
10826 tHalHandle hal_handle;
10827
10828 hal_handle = hdd_ctx->hHal;
10829 if (hal_handle == NULL)
10830 return;
10831
10832 if (hdd_ctx->config->WlanAutoShutdown == 0)
10833 return;
10834
10835 if (enable == false) {
10836 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010837 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010838 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010839 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010840 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010841 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010842 return;
10843 }
10844
10845 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080010846 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
10847 hdd_for_each_adapter(hdd_ctx, adapter) {
10848 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010849 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10850 conn_info.connState ==
10851 eConnectionState_Associated) {
10852 sta_connected = true;
10853 break;
10854 }
10855 }
Dustin Brown920397d2017-12-13 16:27:50 -080010856
10857 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010858 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070010859 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010860 ap_connected = true;
10861 break;
10862 }
10863 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010864 }
10865 }
10866
10867 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010868 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010869 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010870 }
Jeff Johnson68755312017-02-10 11:46:55 -080010871
10872 if (sme_set_auto_shutdown_timer(hal_handle,
10873 hdd_ctx->config->WlanAutoShutdown)
10874 != QDF_STATUS_SUCCESS)
10875 hdd_err("Failed to start wlan auto shutdown timer");
10876 else
10877 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10878 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010879}
10880#endif
10881
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010882struct hdd_adapter *
10883hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
10884 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010885{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010886 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010887 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010888
10889 con_sap_adapter = NULL;
10890
Dustin Brown920397d2017-12-13 16:27:50 -080010891 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010892 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10893 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010894 adapter != this_sap_adapter) {
10895 if (check_start_bss) {
10896 if (test_bit(SOFTAP_BSS_STARTED,
10897 &adapter->event_flags)) {
10898 con_sap_adapter = adapter;
10899 break;
10900 }
10901 } else {
10902 con_sap_adapter = adapter;
10903 break;
10904 }
10905 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906 }
10907
10908 return con_sap_adapter;
10909}
10910
10911#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070010912static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010913{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010914 return adapter->device_mode == QDF_STA_MODE ||
10915 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010916}
10917
Jeff Johnson9d295242017-08-29 14:39:48 -070010918static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010919{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010920 return adapter->device_mode == QDF_SAP_MODE ||
10921 adapter->device_mode == QDF_P2P_GO_MODE;
10922}
10923
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010924static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010925{
Dustin Brown920397d2017-12-13 16:27:50 -080010926 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010927
Dustin Brown920397d2017-12-13 16:27:50 -080010928 hdd_for_each_adapter(hdd_ctx, adapter) {
10929 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070010930 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10931 conn_info.connState == eConnectionState_Associated) {
10932 return true;
10933 }
10934
Dustin Brown920397d2017-12-13 16:27:50 -080010935 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070010936 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070010937 return true;
10938 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010939 }
10940
10941 return false;
10942}
10943
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010944static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010945{
10946 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010947
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010948 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010949 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010950 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010951
Dustin Brown5ec6b552017-03-31 12:11:40 -070010952 return is_running;
10953}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010954
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010955static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010956{
10957 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10958 hdd_ctx->bus_bw_timer_running = true;
10959 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10960 hdd_ctx->config->busBandwidthComputeInterval);
10961 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10962}
10963
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010964void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010965{
10966 ENTER();
10967
10968 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10969 hdd_debug("Bandwidth compute timer already started");
10970 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010971 }
10972
Dustin Brown5ec6b552017-03-31 12:11:40 -070010973 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10974
10975 EXIT();
10976}
10977
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010978void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010979{
10980 ENTER();
10981
10982 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10983 hdd_debug("Bandwidth compute timer already started");
10984 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010985 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010986
10987 if (hdd_any_adapter_is_assoc(hdd_ctx))
10988 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10989
10990 EXIT();
10991}
10992
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010993static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070010994{
10995 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10996
10997 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10998 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10999 hdd_ctx->bus_bw_timer_running = false;
11000 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11001
11002 hdd_reset_tcp_delack(hdd_ctx);
11003}
11004
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011005void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011006{
11007 ENTER();
11008
11009 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11010 hdd_debug("Bandwidth compute timer already stopped");
11011 return;
11012 }
11013
11014 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11015
11016 EXIT();
11017}
11018
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011019void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011020{
11021 ENTER();
11022
11023 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11024 hdd_debug("Bandwidth compute timer already stopped");
11025 return;
11026 }
11027
11028 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11029 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11030
11031 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011032}
11033#endif
11034
11035/**
11036 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11037 * and sta's operating channel.
11038 * @sta_adapter: Describe the first argument to foobar.
11039 * @ap_adapter: Describe the second argument to foobar.
11040 * @roam_profile: Roam profile of AP to which STA wants to connect.
11041 * @concurrent_chnl_same: If both SAP and STA channels are same then
11042 * set this flag to true else false.
11043 *
11044 * This function checks the sap's operating channel and sta's operating channel.
11045 * if both are same then it will return false else it will restart the sap in
11046 * sta's channel and return true.
11047 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011048 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011049 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011050QDF_STATUS
11051wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11052 struct hdd_adapter *ap_adapter,
11053 tCsrRoamProfile *roam_profile,
11054 tScanResultHandle *scan_cache,
11055 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011056{
Jeff Johnson87251032017-08-29 13:31:11 -070011057 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011058 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011059 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011060 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011061 *concurrent_chnl_same = true;
11062
11063 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11064 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011065 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011066 scan_cache,
11067 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011068 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011069 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011070 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011071 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011072 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011073 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011074 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011075 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011077 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011078 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011079 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011080 }
11081 }
11082 } else {
11083 /*
11084 * Lets handle worst case scenario here, Scan cache lookup is
11085 * failed so we have to stop the SAP to avoid any channel
11086 * discrepancy between SAP's channel and STA's channel.
11087 * Return the status as failure so caller function could know
11088 * that scan look up is failed.
11089 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011090 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011091 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011092 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011093 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011094}
11095
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011096/**
11097 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11098 * @ap_adapter: SAP adapter
11099 *
11100 * This function will process the stopping of sap adapter.
11101 *
11102 * Return: None
11103 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011104void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011105{
Jeff Johnson87251032017-08-29 13:31:11 -070011106 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011107 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011108 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011109 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011110
11111 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011112 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011113 return;
11114 }
11115
11116 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11117 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011118 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011119 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011121 mutex_lock(&hdd_ctx->sap_lock);
11122 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011123 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011124 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011125 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011126 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011127 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011128 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011129 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011130 qdf_stop_bss_event,
11131 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011132 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011133 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011134 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011135 return;
11136 }
11137 }
11138 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011139 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11140 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011141 ap_adapter->session_id);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011142 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011143 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011144 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011145 }
11146 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011147}
11148
11149/**
11150 * wlan_hdd_start_sap() - this function starts bss of SAP.
11151 * @ap_adapter: SAP adapter
11152 *
11153 * This function will process the starting of sap adapter.
11154 *
11155 * Return: None
11156 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011157void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011158{
Jeff Johnson87251032017-08-29 13:31:11 -070011159 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011160 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011161 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011162 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011163 tsap_Config_t *sap_config;
11164
11165 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011166 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011167 return;
11168 }
11169
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011170 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011171 hdd_err("SoftAp role has not been enabled");
11172 return;
11173 }
11174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011175 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11176 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11177 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011178 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011180 mutex_lock(&hdd_ctx->sap_lock);
11181 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11182 goto end;
11183
11184 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011185 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011186 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
11187 goto end;
11188 }
11189
Wei Song2f76f642016-11-18 16:32:53 +080011190 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011191 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011192 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011193 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011194 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011195 goto end;
11196
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011197 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011198 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011199 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011200 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011201 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011202 goto end;
11203 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011204 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011205 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070011206 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011207 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11208 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011209 ap_adapter->session_id);
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011210 mutex_unlock(&hdd_ctx->sap_lock);
11211
11212 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011213end:
11214 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011215 /* SAP context and beacon cleanup will happen during driver unload
11216 * in hdd_stop_adapter
11217 */
11218 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011220}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011221
11222/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011223 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11224 * mac scan config
11225 * @status: Status of set antenna mode
11226 *
11227 * Callback on setting the dual mac configuration
11228 *
11229 * Return: None
11230 */
11231void wlan_hdd_soc_set_antenna_mode_cb(
11232 enum set_antenna_mode_status status)
11233{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011234 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011235
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011236 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011237
11238 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11239 if (0 != wlan_hdd_validate_context(hdd_ctx))
11240 return;
11241
11242 /* Signal the completion of set dual mac config */
11243 complete(&hdd_ctx->set_antenna_mode_cmpl);
11244}
11245
11246/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011247 * hdd_get_fw_version() - Get FW version
11248 * @hdd_ctx: pointer to HDD context.
11249 * @major_spid: FW version - major spid.
11250 * @minor_spid: FW version - minor spid
11251 * @ssid: FW version - ssid
11252 * @crmid: FW version - crmid
11253 *
11254 * This function is called to get the firmware build version stored
11255 * as part of the HDD context
11256 *
11257 * Return: None
11258 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011259void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011260 uint32_t *major_spid, uint32_t *minor_spid,
11261 uint32_t *siid, uint32_t *crmid)
11262{
11263 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11264 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11265 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11266 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11267}
11268
11269#ifdef QCA_CONFIG_SMP
11270/**
11271 * wlan_hdd_get_cpu() - get cpu_index
11272 *
11273 * Return: cpu_index
11274 */
11275int wlan_hdd_get_cpu(void)
11276{
11277 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011279 put_cpu();
11280 return cpu_index;
11281}
11282#endif
11283
11284/**
11285 * hdd_get_fwpath() - get framework path
11286 *
11287 * This function is used to get the string written by
11288 * userspace to start the wlan driver
11289 *
11290 * Return: string
11291 */
11292const char *hdd_get_fwpath(void)
11293{
11294 return fwpath.string;
11295}
11296
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011297static int hdd_qdf_print_init(void)
11298{
11299 int qdf_print_idx;
11300 QDF_STATUS status;
11301
11302 status = qdf_print_setup();
11303 if (status != QDF_STATUS_SUCCESS) {
11304 pr_err("qdf_print_setup failed\n");
11305 return -EINVAL;
11306 }
11307
11308 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11309
11310 if (qdf_print_idx < 0) {
11311 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11312 qdf_print_idx);
11313 return -EINVAL;
11314 }
11315
11316 qdf_set_pidx(qdf_print_idx);
11317
11318 return 0;
11319}
11320
11321static void hdd_qdf_print_deinit(void)
11322{
11323 int qdf_print_idx;
11324
11325 qdf_print_idx = qdf_get_pidx();
11326 qdf_print_ctrl_cleanup(qdf_print_idx);
11327}
11328
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011329/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011330 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011331 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011332 * This function initilizes CDS global context with the help of cds_init. This
11333 * has to be the first function called after probe to get a valid global
11334 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011335 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011336 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011337 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011338int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011339{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011340 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011341 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011342
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011343 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011344 if (QDF_IS_STATUS_ERROR(status)) {
11345 hdd_err("Failed to allocate CDS context");
11346 ret = -ENOMEM;
11347 goto err_out;
11348 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011349
11350 wlan_init_bug_report_lock();
11351
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011352#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11353 wlan_logging_sock_init_svc();
11354#endif
11355
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011356 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11357 (void *)hdd_drv_ops_inactivity_handler, NULL,
11358 QDF_TIMER_TYPE_SW);
11359
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011360 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011361 hdd_qdf_print_init();
11362
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011363 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011364
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011365err_out:
11366 return ret;
11367}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011368
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011369/**
11370 * hdd_deinit() - Deinitialize Driver
11371 *
11372 * This function frees CDS global context with the help of cds_deinit. This
11373 * has to be the last function call in remove callback to free the global
11374 * context.
11375 */
11376void hdd_deinit(void)
11377{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011378 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011379
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011380 wlan_destroy_bug_report_lock();
11381 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011382
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011383 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011384#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11385 wlan_logging_sock_deinit_svc();
11386#endif
11387}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011388
Yue Ma6e7b1a02017-04-03 14:17:46 -070011389#ifdef QCA_WIFI_NAPIER_EMULATION
11390#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11391#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011392#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011393#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011394
Sachin Ahujadddd2632017-03-07 19:07:24 +053011395static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11396 struct file *file)
11397{
11398 return 0;
11399}
11400
11401static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11402 const char __user *user_buf,
11403 size_t count,
11404 loff_t *f_pos)
11405{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011406 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011407 static const char wlan_off_str[] = "OFF";
11408 static const char wlan_on_str[] = "ON";
11409 int ret;
11410 unsigned long rc;
11411
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011412 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011413 pr_err("Failed to read buffer\n");
11414 return -EINVAL;
11415 }
11416
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011417 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011418 pr_debug("Wifi turning off from UI\n");
11419 goto exit;
11420 }
11421
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011422 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011423 pr_err("Invalid value received from framework");
11424 goto exit;
11425 }
11426
11427 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011428 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011429 rc = wait_for_completion_timeout(&wlan_start_comp,
11430 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11431 if (!rc) {
11432 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11433 ret = -EINVAL;
11434 hdd_start_complete(ret);
11435 return ret;
11436 }
11437
11438 hdd_start_complete(0);
11439 }
11440
11441exit:
11442 return count;
11443}
11444
11445
11446const struct file_operations wlan_hdd_state_fops = {
11447 .owner = THIS_MODULE,
11448 .open = wlan_hdd_state_ctrl_param_open,
11449 .write = wlan_hdd_state_ctrl_param_write,
11450};
11451
11452static int wlan_hdd_state_ctrl_param_create(void)
11453{
11454 unsigned int wlan_hdd_state_major = 0;
11455 int ret;
11456 struct device *dev;
11457
11458 device = MKDEV(wlan_hdd_state_major, 0);
11459
11460 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11461 if (ret) {
11462 pr_err("Failed to register qcwlanstate");
11463 goto dev_alloc_err;
11464 }
11465 wlan_hdd_state_major = MAJOR(device);
11466
11467 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11468 if (IS_ERR(class)) {
11469 pr_err("wlan_hdd_state class_create error");
11470 goto class_err;
11471 }
11472
11473 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11474 if (IS_ERR(dev)) {
11475 pr_err("wlan_hdd_statedevice_create error");
11476 goto err_class_destroy;
11477 }
11478
11479 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11480 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11481 if (ret) {
11482 pr_err("Failed to add cdev error");
11483 goto cdev_add_err;
11484 }
11485
11486 pr_info("wlan_hdd_state %s major(%d) initialized",
11487 WLAN_MODULE_NAME, wlan_hdd_state_major);
11488
11489 return 0;
11490
11491cdev_add_err:
11492 device_destroy(class, device);
11493err_class_destroy:
11494 class_destroy(class);
11495class_err:
11496 unregister_chrdev_region(device, dev_num);
11497dev_alloc_err:
11498 return -ENODEV;
11499}
11500
11501static void wlan_hdd_state_ctrl_param_destroy(void)
11502{
11503 cdev_del(&wlan_hdd_state_cdev);
11504 device_destroy(class, device);
11505 class_destroy(class);
11506 unregister_chrdev_region(device, dev_num);
11507
11508 pr_info("Device node unregistered");
11509}
11510
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011511/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011512 * component_init - API to init cld component's
11513 *
11514 * Return: None
11515 */
11516static void component_init(void)
11517{
11518 pmo_init();
11519}
11520
11521/**
11522 * component_deinit - API to deinit cld component's
11523 *
11524 * Return: None
11525 */
11526static void component_deinit(void)
11527{
11528 pmo_deinit();
11529}
11530
11531/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011532 * __hdd_module_init - Module init helper
11533 *
11534 * Module init helper function used by both module and static driver.
11535 *
11536 * Return: 0 for success, errno on failure
11537 */
11538static int __hdd_module_init(void)
11539{
11540 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011541
Dustin Brown96cd9632017-11-13 12:45:04 -080011542 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011543 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011544 g_wlan_driver_version,
Dustin Brownab482ac2017-06-09 17:00:44 -070011545 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011546
Sachin Ahujadddd2632017-03-07 19:07:24 +053011547 ret = wlan_hdd_state_ctrl_param_create();
11548 if (ret) {
11549 pr_err("wlan_hdd_state_create:%x\n", ret);
11550 goto err_dev_state;
11551 }
11552
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011553 pld_init();
11554
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011555 ret = hdd_init();
11556 if (ret) {
11557 pr_err("hdd_init failed %x\n", ret);
11558 goto err_hdd_init;
11559 }
11560
Rajeev Kumar97767a02016-11-30 11:20:40 -080011561 dispatcher_init();
11562
Mukul Sharmad75a6672017-06-22 15:40:53 +053011563 /* Ensure to call post objmgr init */
11564 component_init();
11565
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011566 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011567
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011568 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011569
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011570 ret = wlan_hdd_register_driver();
11571 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011572 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11573 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011574 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011575 }
11576
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011577 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011578
11579 return 0;
11580out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011581 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011582 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011583 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011584 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011585
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011586err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011587 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053011588 wlan_hdd_state_ctrl_param_destroy();
11589err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011590 return ret;
11591}
11592
11593/**
11594 * __hdd_module_exit - Module exit helper
11595 *
11596 * Module exit helper function used by both module and static driver.
11597 */
11598static void __hdd_module_exit(void)
11599{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011600
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011601 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11602 QWLAN_VERSIONSTR);
11603
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011604 hdd_wait_for_recovery_completion();
11605
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011606 wlan_hdd_unregister_driver();
11607
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011608 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011609
Mukul Sharmad75a6672017-06-22 15:40:53 +053011610 /* Ensure to call prior to objmgr deinit */
11611 component_deinit();
11612
Rajeev Kumar97767a02016-11-30 11:20:40 -080011613 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011614
11615 hdd_sysfs_destroy_version_interface();
11616
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011617 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011618 pld_deinit();
11619
Sachin Ahujadddd2632017-03-07 19:07:24 +053011620 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011621}
11622
Arun Khandavallifae92942016-08-01 13:31:08 +053011623#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011624/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011625 * wlan_boot_cb() - Wlan boot callback
11626 * @kobj: object whose directory we're creating the link in.
11627 * @attr: attribute the user is interacting with
11628 * @buff: the buffer containing the user data
11629 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011630 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011631 * This callback is invoked when the fs is ready to start the
11632 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011633 *
Arun Khandavallifae92942016-08-01 13:31:08 +053011634 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011635 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011636static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011637 struct kobj_attribute *attr,
11638 const char *buf,
11639 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011640{
Arun Khandavallifae92942016-08-01 13:31:08 +053011641
Arun Khandavallifae92942016-08-01 13:31:08 +053011642 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011643 pr_err("%s: wlan driver already initialized\n", __func__);
11644 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053011645 }
11646
Arun Khandavallifae92942016-08-01 13:31:08 +053011647 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011648 pr_err("%s: wlan driver initialization failed\n", __func__);
11649 return -EIO;
11650 }
11651
11652 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053011653
11654 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011655}
Arun Khandavallifae92942016-08-01 13:31:08 +053011656
11657/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011658 * hdd_sysfs_cleanup() - cleanup sysfs
11659 *
11660 * Return: None
11661 *
11662 */
11663static void hdd_sysfs_cleanup(void)
11664{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011665 /* remove from group */
11666 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11667 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11668 wlan_loader->attr_group);
11669
11670 /* unlink the object from parent */
11671 kobject_del(wlan_loader->boot_wlan_obj);
11672
11673 /* free the object */
11674 kobject_put(wlan_loader->boot_wlan_obj);
11675
11676 kfree(wlan_loader->attr_group);
11677 kfree(wlan_loader);
11678
11679 wlan_loader = NULL;
11680}
11681
11682/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011683 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11684 * ready
11685 *
11686 * This is creates the syfs entry boot_wlan. Which shall be invoked
11687 * when the filesystem is ready.
11688 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011689 * QDF API cannot be used here since this function is called even before
11690 * initializing WLAN driver.
11691 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011692 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011693 */
11694static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011695{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011696 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011697
11698 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011699 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011700 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011701
11702 wlan_loader->boot_wlan_obj = NULL;
11703 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11704 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011705 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011706 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011707
11708 wlan_loader->loaded_state = 0;
11709 wlan_loader->attr_group->attrs = attrs;
11710
11711 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11712 kernel_kobj);
11713 if (!wlan_loader->boot_wlan_obj) {
11714 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011715 goto error_return;
11716 }
11717
11718 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11719 wlan_loader->attr_group);
11720 if (ret) {
11721 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11722 goto error_return;
11723 }
11724
11725 return 0;
11726
11727error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011728 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011729
11730 return ret;
11731}
11732
11733/**
11734 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11735 *
11736 * Return: 0 on success or errno on failure
11737 */
11738static int wlan_deinit_sysfs(void)
11739{
Arun Khandavallifae92942016-08-01 13:31:08 +053011740 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011741 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011742 return -EINVAL;
11743 }
11744
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011745 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011746 return 0;
11747}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011748
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011749#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011750
11751#ifdef MODULE
11752/**
11753 * __hdd_module_init - Module init helper
11754 *
11755 * Module init helper function used by both module and static driver.
11756 *
11757 * Return: 0 for success, errno on failure
11758 */
11759static int hdd_module_init(void)
11760{
Arun Khandavallifae92942016-08-01 13:31:08 +053011761 if (__hdd_module_init()) {
11762 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011763 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011764 }
11765
Dustin Brownab482ac2017-06-09 17:00:44 -070011766 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011767}
11768#else
11769static int __init hdd_module_init(void)
11770{
11771 int ret = -EINVAL;
11772
11773 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011774 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011775 pr_err("Failed to create sysfs entry for loading wlan");
11776
11777 return ret;
11778}
11779#endif
11780
11781
11782#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011783/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011784 * hdd_module_exit() - Exit function
11785 *
11786 * This is the driver exit point (invoked when module is unloaded using rmmod)
11787 *
11788 * Return: None
11789 */
11790static void __exit hdd_module_exit(void)
11791{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011792 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011793}
Arun Khandavallifae92942016-08-01 13:31:08 +053011794#else
11795static void __exit hdd_module_exit(void)
11796{
11797 __hdd_module_exit();
11798 wlan_deinit_sysfs();
11799}
11800#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011801
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011802static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11803{
11804 return param_set_copystring(kmessage, kp);
11805}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011806
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011807/**
11808 * is_con_mode_valid() check con mode is valid or not
11809 * @mode: global con mode
11810 *
11811 * Return: TRUE on success FALSE on failure
11812 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080011813static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011814{
11815 switch (mode) {
11816 case QDF_GLOBAL_MONITOR_MODE:
11817 case QDF_GLOBAL_FTM_MODE:
11818 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011819 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011820 return true;
11821 default:
11822 return false;
11823 }
11824}
11825
11826/**
11827 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11828 * @mode: global con mode
11829 *
11830 * Return: adapter mode
11831 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011832static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080011833 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011834{
11835
11836 switch (mode) {
11837 case QDF_GLOBAL_MISSION_MODE:
11838 return QDF_STA_MODE;
11839 case QDF_GLOBAL_MONITOR_MODE:
11840 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011841 case QDF_GLOBAL_EPPING_MODE:
11842 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011843 case QDF_GLOBAL_FTM_MODE:
11844 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011845 case QDF_GLOBAL_QVIT_MODE:
11846 return QDF_QVIT_MODE;
11847 default:
11848 return QDF_MAX_NO_OF_MODE;
11849 }
11850}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011851
Dustin Brown27cd9942017-09-27 16:11:44 -070011852static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011853 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070011854{
11855 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
11856 return;
11857
11858 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070011859 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053011860 hdd_info("Release wakelock for monitor mode!");
11861 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
11862 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
11863 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070011864 case QDF_GLOBAL_FTM_MODE:
11865 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11866 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
11867
11868 /* re-use the existing session */
11869 hdd_stop_all_adapters(hdd_ctx, false);
11870 break;
11871 default:
11872 break;
11873 }
11874}
11875
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011876static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011877 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011878{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011879 int driver_status;
11880
11881 driver_status = hdd_ctx->driver_status;
11882
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011883 switch (curr_mode) {
11884 case QDF_GLOBAL_MISSION_MODE:
11885 case QDF_GLOBAL_MONITOR_MODE:
11886 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011887 hdd_deinit_all_adapters(hdd_ctx, false);
11888 hdd_close_all_adapters(hdd_ctx, false);
11889 break;
11890 case QDF_GLOBAL_EPPING_MODE:
11891 epping_disable();
11892 epping_close();
11893 break;
11894 default:
11895 return;
11896 }
11897}
11898
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011899static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080011900 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011901{
Jeff Johnson9d295242017-08-29 14:39:48 -070011902 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011903 int ret = 0;
11904 bool rtnl_held;
11905 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11906 QDF_STATUS status;
11907
11908 if (!qdf_dev) {
11909 hdd_err("qdf device context is Null return!");
11910 return -EINVAL;
11911 }
11912
11913 rtnl_held = hdd_hold_rtnl_lock();
11914 switch (mode) {
11915 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011916 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11917 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011918 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011919 break;
11920 case QDF_GLOBAL_FTM_MODE:
11921 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11922 wlan_hdd_get_intf_addr(hdd_ctx),
11923 NET_NAME_UNKNOWN, rtnl_held);
11924 if (adapter == NULL)
11925 ret = -EINVAL;
11926 break;
11927 case QDF_GLOBAL_MONITOR_MODE:
11928 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11929 wlan_hdd_get_intf_addr(hdd_ctx),
11930 NET_NAME_UNKNOWN, rtnl_held);
11931 if (adapter == NULL)
11932 ret = -EINVAL;
11933 break;
11934 case QDF_GLOBAL_EPPING_MODE:
11935 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011936 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011937 hdd_err("Failed to open in eeping mode: %d", status);
11938 ret = -EINVAL;
11939 break;
11940 }
11941 ret = epping_enable(qdf_dev->dev);
11942 if (ret) {
11943 hdd_err("Failed to enable in epping mode : %d", ret);
11944 epping_close();
11945 }
11946 break;
11947 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011948 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011949 ret = -ENOTSUPP;
11950 break;
11951 }
11952 hdd_release_rtnl_lock();
11953 rtnl_held = false;
11954 return ret;
11955}
11956
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011957/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011958 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011959 * @kmessage: con mode name on which driver to be bring up
11960 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011961 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011962 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011963 * This function is invoked when user updates con mode using sys entry,
11964 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011965 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011966 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011967 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011968static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011969 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011970{
11971 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070011972 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080011973 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011974 enum QDF_OPMODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011975
Dustin Brownab6029b2017-05-24 13:04:19 -070011976 hdd_info("con_mode handler: %s", kmessage);
11977
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011978 ret = wlan_hdd_validate_context(hdd_ctx);
11979 if (ret)
11980 return ret;
11981
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011982 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011983
11984 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011985
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011986 if (!(is_con_mode_valid(con_mode))) {
11987 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011988 ret = -EINVAL;
11989 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011990 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011991
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011992 curr_mode = hdd_get_conparam();
11993 if (curr_mode == con_mode) {
11994 hdd_err("curr mode: %d is same as user triggered mode %d",
11995 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011996 ret = 0;
11997 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011998 }
11999
Sourav Mohapatra3bc5e982017-11-24 15:53:49 +053012000 if (!cds_wait_for_external_threads_completion(__func__))
12001 hdd_warn("Waiting for monitor mode: External threads are active");
12002
Dustin Brown27cd9942017-09-27 16:11:44 -070012003 /* ensure adapters are stopped */
12004 hdd_stop_present_mode(hdd_ctx, curr_mode);
12005
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012006 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012007 if (ret) {
12008 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012009 goto reset_flags;
12010 }
12011
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012012 /* Cleanup present mode before switching to new mode */
12013 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12014
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012015 hdd_set_conparam(con_mode);
12016
12017 /* Register for new con_mode & then kick_start modules again */
12018 ret = hdd_register_req_mode(hdd_ctx, con_mode);
12019 if (ret) {
12020 hdd_err("Failed to register for new mode");
12021 goto reset_flags;
12022 }
12023
12024 adapter_mode = hdd_get_adpter_mode(con_mode);
12025 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12026 hdd_err("invalid adapter");
12027 ret = -EINVAL;
12028 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012029 }
12030
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012031 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012032 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012033 hdd_err("Failed to get adapter:%d", adapter_mode);
12034 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012035 }
12036
12037 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12038 if (ret) {
12039 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012040 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012041 }
12042
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012043 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
Dustin Brown27cd9942017-09-27 16:11:44 -070012044 con_mode == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012045 if (hdd_start_adapter(adapter)) {
12046 hdd_err("Failed to start %s adapter", kmessage);
12047 ret = -EINVAL;
12048 goto reset_flags;
12049 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012050 }
12051
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012052 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
12053 hdd_info("Acquire wakelock for monitor mode!");
12054 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12055 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12056 }
12057
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012058 hdd_info("Mode successfully changed to %s", kmessage);
12059 ret = 0;
12060
12061reset_flags:
12062 cds_set_load_in_progress(false);
12063 return ret;
12064}
12065
12066
12067static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12068{
12069 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012070 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012071
12072 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12073 ret = wlan_hdd_validate_context(hdd_ctx);
12074 if (ret)
12075 return ret;
12076
12077 cds_ssr_protect(__func__);
12078 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12079 cds_ssr_unprotect(__func__);
12080
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012081 return ret;
12082}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012083
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012084static int con_mode_handler_ftm(const char *kmessage,
12085 struct kernel_param *kp)
12086{
12087 int ret;
12088
12089 ret = param_set_int(kmessage, kp);
12090
12091 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12092 pr_err("Only FTM mode supported!");
12093 return -ENOTSUPP;
12094 }
12095
12096 hdd_set_conparam(con_mode_ftm);
12097 con_mode = con_mode_ftm;
12098
12099 return ret;
12100}
12101
Ravi Joshia307f632017-07-17 23:41:41 -070012102static int con_mode_handler_monitor(const char *kmessage,
12103 struct kernel_param *kp)
12104{
12105 int ret;
12106
12107 ret = param_set_int(kmessage, kp);
12108
12109 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12110 pr_err("Only Monitor mode supported!");
12111 return -ENOTSUPP;
12112 }
12113
12114 hdd_set_conparam(con_mode_monitor);
12115 con_mode = con_mode_monitor;
12116
12117 return ret;
12118}
12119
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012120/**
12121 * hdd_get_conparam() - driver exit point
12122 *
12123 * This is the driver exit point (invoked when module is unloaded using rmmod)
12124 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012125 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012126 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012127enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012128{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012129 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012130}
12131
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012132void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012133{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012134 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012135}
12136
Komal Seelamc11bb222016-01-27 18:57:10 +053012137/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012138 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12139 * @hdd_ctx: HDD context
12140 *
12141 * Cleans up the pre cac interface, if it exists
12142 *
12143 * Return: None
12144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012145void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012146{
12147 uint8_t session_id;
12148 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012149 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012150
12151 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12152 if (QDF_IS_STATUS_ERROR(status)) {
12153 hdd_err("failed to get pre cac vdev id");
12154 return;
12155 }
12156
12157 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12158 if (!precac_adapter) {
12159 hdd_err("invalid pre cac adapater");
12160 return;
12161 }
12162
12163 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12164 wlan_hdd_sap_pre_cac_failure,
12165 (void *)precac_adapter);
12166 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12167
12168}
12169
12170/**
Komal Seelamec702b02016-02-24 18:42:16 +053012171 * hdd_update_ol_config - API to update ol configuration parameters
12172 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012173 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012174 * Return: void
12175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012176static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012177{
Komal Seelamec702b02016-02-24 18:42:16 +053012178 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012179 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012180
Komal Seelamec702b02016-02-24 18:42:16 +053012181 if (!ol_ctx)
12182 return;
12183
12184 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12185 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12186 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12187 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012188 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012189
12190 ol_init_ini_config(ol_ctx, &cfg);
12191}
12192
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012193#ifdef FEATURE_RUNTIME_PM
12194/**
12195 * hdd_populate_runtime_cfg() - populate runtime configuration
12196 * @hdd_ctx: hdd context
12197 * @cfg: pointer to the configuration memory being populated
12198 *
12199 * Return: void
12200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012202 struct hif_config_info *cfg)
12203{
12204 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12205 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12206}
12207#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012208static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012209 struct hif_config_info *cfg)
12210{
12211}
12212#endif
12213
Komal Seelamec702b02016-02-24 18:42:16 +053012214/**
12215 * hdd_update_hif_config - API to update HIF configuration parameters
12216 * @hdd_ctx: HDD Context
12217 *
12218 * Return: void
12219 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012220static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012221{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012222 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012223 struct hif_config_info cfg;
12224
12225 if (!scn)
12226 return;
12227
12228 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012229 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012230 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012231
12232 if (hdd_ctx->config->prevent_link_down)
12233 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012234}
12235
12236/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012237 * hdd_update_dp_config() - Propagate config parameters to Lithium
12238 * datapath
12239 * @hdd_ctx: HDD Context
12240 *
12241 * Return: 0 for success/errno for failure
12242 */
12243static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12244{
12245 struct cdp_config_params params;
12246 QDF_STATUS status;
12247
12248 params.tso_enable = hdd_ctx->config->tso_enable;
12249 params.lro_enable = hdd_ctx->config->lro_enable;
12250#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12251 params.tx_flow_stop_queue_threshold =
12252 hdd_ctx->config->TxFlowStopQueueThreshold;
12253 params.tx_flow_start_queue_offset =
12254 hdd_ctx->config->TxFlowStartQueueOffset;
12255#endif
12256 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12257 params.napi_enable = hdd_ctx->napi_enable;
12258 params.tcp_udp_checksumoffload =
12259 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12260
12261 status = cdp_update_config_parameters(
12262 cds_get_context(QDF_MODULE_ID_SOC),
12263 &params);
12264 if (status) {
12265 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
12266 "%s: Failed to attach config parameters", __func__);
12267 return status;
12268 }
12269
12270 return 0;
12271}
12272
12273/**
Komal Seelamec702b02016-02-24 18:42:16 +053012274 * hdd_update_config() - Initialize driver per module ini parameters
12275 * @hdd_ctx: HDD Context
12276 *
12277 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012278 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012280int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012281{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012282 int ret;
12283
Komal Seelamec702b02016-02-24 18:42:16 +053012284 hdd_update_ol_config(hdd_ctx);
12285 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012286 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12287 ret = hdd_update_cds_config_ftm(hdd_ctx);
12288 else
12289 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012290 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012291
12292 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012293}
12294
Mukul Sharma9d797a02017-01-05 20:26:03 +053012295#ifdef FEATURE_WLAN_RA_FILTERING
12296/**
12297 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12298 * @psoc_cfg: pmo psoc Configuration
12299 * @hdd_ctx: Pointer to hdd context
12300 *
12301 * Return: none
12302 */
12303static inline void hdd_ra_populate_pmo_config(
12304 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012305 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012306{
12307 psoc_cfg->ra_ratelimit_interval =
12308 hdd_ctx->config->RArateLimitInterval;
12309 psoc_cfg->ra_ratelimit_enable =
12310 hdd_ctx->config->IsRArateLimitEnabled;
12311}
12312#else
12313static inline void hdd_ra_populate_pmo_config(
12314 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012315 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012316{
12317}
12318#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012319
Mukul Sharma9d797a02017-01-05 20:26:03 +053012320/**
12321 * hdd_update_pmo_config - API to update pmo configuration parameters
12322 * @hdd_ctx: HDD context
12323 *
12324 * Return: void
12325 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012326static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012327{
12328 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12329 struct pmo_psoc_cfg psoc_cfg;
12330 QDF_STATUS status;
12331
12332 /*
12333 * Value of hdd_ctx->wowEnable can be,
12334 * 0 - Disable both magic pattern match and pattern byte match.
12335 * 1 - Enable magic pattern match on all interfaces.
12336 * 2 - Enable pattern byte match on all interfaces.
12337 * 3 - Enable both magic patter and pattern byte match on
12338 * all interfaces.
12339 */
12340 psoc_cfg.magic_ptrn_enable =
12341 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12342 psoc_cfg.ptrn_match_enable_all_vdev =
12343 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Will Huangfe649172017-09-06 16:52:18 +080012344 psoc_cfg.ptrn_id_per_vdev = wma_is_service_enabled(
12345 WMI_SERVICE_UNIFIED_WOW_CAPABILITY);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012346 psoc_cfg.bpf_enable =
12347 hdd_ctx->config->bpf_packet_filter_enable;
12348 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012349 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012350 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
12351 if (hdd_ctx->config->fhostNSOffload)
12352 psoc_cfg.ns_offload_enable_dynamic = true;
12353 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12354 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
12355 psoc_cfg.active_mode_offload =
12356 hdd_ctx->config->active_mode_offload;
12357 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012358 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9d797a02017-01-05 20:26:03 +053012359 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053012360 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12361 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12362 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
12363 psoc_cfg.power_save_mode =
12364 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012365 psoc_cfg.auto_power_save_fail_mode =
12366 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012367
12368 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012369 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12370 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Rajeev Kumard1a7ac42017-11-08 14:54:22 -080012371 status = ucfg_pmo_update_psoc_config(psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012372 if (status != QDF_STATUS_SUCCESS) {
12373 hdd_err("failed pmo psoc configuration");
12374 return -EINVAL;
12375 }
12376
12377 return 0;
12378}
12379
Abhishek Singhb20db962017-03-03 21:28:46 +053012380#ifdef FEATURE_WLAN_SCAN_PNO
12381static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12382 struct hdd_config *cfg)
12383{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012384 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12385
Abhishek Singhb20db962017-03-03 21:28:46 +053012386 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12387 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12388 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12389 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12390 pno_cfg->channel_prediction_full_scan =
12391 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012392 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12393 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12394 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12395 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012396}
12397#else
12398static inline void
12399hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012400 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012401{
Abhishek Singhb20db962017-03-03 21:28:46 +053012402}
12403#endif
12404
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012405void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12406 struct hdd_config *cfg)
12407{
12408 uint8_t i = 0;
12409
12410 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12411 if (!ie_whitelist->white_list)
12412 return;
12413
12414 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12415 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12416 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12417 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12418 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12419 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12420 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12421 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12422
12423 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12424 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12425 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12426}
12427
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012428uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12429{
12430 uint8_t i, score;
12431
12432 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12433 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12434 if (score > MAX_INDEX_SCORE)
12435 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12436 MAX_INDEX_SCORE, i);
12437 }
12438
12439 return per_index_score;
12440}
12441
12442/**
12443 * hdd_update_score_config - API to update candidate scoring related params
12444 * configuration parameters
12445 * @score_config: score config to update
12446 * @cfg: config params
12447 *
12448 * Return: 0 if success else err
12449 */
12450static void hdd_update_score_config(
12451 struct scoring_config *score_config, struct hdd_config *cfg)
12452{
12453 int total_weight;
12454
12455 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12456 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12457 score_config->weight_cfg.vht_caps_weightage =
12458 cfg->vht_caps_weightage;
12459 score_config->weight_cfg.he_caps_weightage =
12460 cfg->he_caps_weightage;
12461 score_config->weight_cfg.chan_width_weightage =
12462 cfg->chan_width_weightage;
12463 score_config->weight_cfg.chan_band_weightage =
12464 cfg->chan_band_weightage;
12465 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12466 score_config->weight_cfg.beamforming_cap_weightage =
12467 cfg->beamforming_cap_weightage;
12468 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12469 score_config->weight_cfg.channel_congestion_weightage =
12470 cfg->channel_congestion_weightage;
12471 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12472
12473 total_weight = score_config->weight_cfg.rssi_weightage +
12474 score_config->weight_cfg.ht_caps_weightage +
12475 score_config->weight_cfg.vht_caps_weightage +
12476 score_config->weight_cfg.he_caps_weightage +
12477 score_config->weight_cfg.chan_width_weightage +
12478 score_config->weight_cfg.chan_band_weightage +
12479 score_config->weight_cfg.nss_weightage +
12480 score_config->weight_cfg.beamforming_cap_weightage +
12481 score_config->weight_cfg.pcl_weightage +
12482 score_config->weight_cfg.channel_congestion_weightage +
12483 score_config->weight_cfg.oce_wan_weightage;
12484
12485 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12486 hdd_err("total weight is greater than %d fallback to default values",
12487 BEST_CANDIDATE_MAX_WEIGHT);
12488
12489 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12490 score_config->weight_cfg.ht_caps_weightage =
12491 HT_CAPABILITY_WEIGHTAGE;
12492 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12493 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12494 score_config->weight_cfg.chan_width_weightage =
12495 CHAN_WIDTH_WEIGHTAGE;
12496 score_config->weight_cfg.chan_band_weightage =
12497 CHAN_BAND_WEIGHTAGE;
12498 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12499 score_config->weight_cfg.beamforming_cap_weightage =
12500 BEAMFORMING_CAP_WEIGHTAGE;
12501 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12502 score_config->weight_cfg.channel_congestion_weightage =
12503 CHANNEL_CONGESTION_WEIGHTAGE;
12504 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12505 }
12506
12507 score_config->bandwidth_weight_per_index =
12508 hdd_limit_max_per_index_score(
12509 cfg->bandwidth_weight_per_index);
12510 score_config->nss_weight_per_index =
12511 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12512 score_config->band_weight_per_index =
12513 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12514
12515 score_config->rssi_score.best_rssi_threshold =
12516 cfg->best_rssi_threshold;
12517 score_config->rssi_score.good_rssi_threshold =
12518 cfg->good_rssi_threshold;
12519 score_config->rssi_score.bad_rssi_threshold =
12520 cfg->bad_rssi_threshold;
12521 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12522 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12523 score_config->rssi_score.good_rssi_bucket_size =
12524 cfg->good_rssi_bucket_size;
12525 score_config->rssi_score.bad_rssi_bucket_size =
12526 cfg->bad_rssi_bucket_size;
12527 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12528 cfg->rssi_pref_5g_rssi_thresh;
12529
12530 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12531 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12532 hdd_limit_max_per_index_score(
12533 cfg->esp_qbss_score_slots3_to_0);
12534 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12535 hdd_limit_max_per_index_score(
12536 cfg->esp_qbss_score_slots7_to_4);
12537 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12538 hdd_limit_max_per_index_score(
12539 cfg->esp_qbss_score_slots11_to_8);
12540 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12541 hdd_limit_max_per_index_score(
12542 cfg->esp_qbss_score_slots15_to_12);
12543
12544 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12545 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12546 hdd_limit_max_per_index_score(
12547 cfg->oce_wan_score_slots3_to_0);
12548 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12549 hdd_limit_max_per_index_score(
12550 cfg->oce_wan_score_slots7_to_4);
12551 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12552 hdd_limit_max_per_index_score(
12553 cfg->oce_wan_score_slots11_to_8);
12554 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12555 hdd_limit_max_per_index_score(
12556 cfg->oce_wan_score_slots15_to_12);
12557
12558
12559 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12560 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12561 score_config->nss = cfg->enable2x2 ? 2 : 1;
12562
12563 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12564 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12565 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12566 score_config->he_cap = 1;
12567
12568 if (score_config->he_cap ||
12569 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12570 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12571 score_config->vht_cap = 1;
12572
12573 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12574 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12575 score_config->ht_cap = 1;
12576
12577 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12578 score_config->vht_24G_cap = 1;
12579
12580 if (cfg->enableTxBF)
12581 score_config->beamformee_cap = 1;
12582
12583}
12584
Abhishek Singh257a9482017-03-06 16:52:39 +053012585/**
12586 * hdd_update_scan_config - API to update scan configuration parameters
12587 * @hdd_ctx: HDD context
12588 *
12589 * Return: 0 if success else err
12590 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012591static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053012592{
12593 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12594 struct scan_user_cfg scan_cfg;
12595 struct hdd_config *cfg = hdd_ctx->config;
12596 QDF_STATUS status;
12597
12598 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
12599 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
12600 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
12601 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
12602 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
12603 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
12604 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053012605 /* convert to ms */
12606 scan_cfg.scan_cache_aging_time =
12607 cfg->scanAgingTimeout * 1000;
12608 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
12609 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
12610 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
12611 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053012612 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053012613 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080012614 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
12615 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053012616 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070012617 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singh257a9482017-03-06 16:52:39 +053012618
Abhishek Singhb20db962017-03-03 21:28:46 +053012619 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012620 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012621 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053012622
Abhishek Singh257a9482017-03-06 16:52:39 +053012623 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
12624 if (status != QDF_STATUS_SUCCESS) {
12625 hdd_err("failed pmo psoc configuration");
12626 return -EINVAL;
12627 }
12628
12629 return 0;
12630}
Abhishek Singh257a9482017-03-06 16:52:39 +053012631
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012632int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012633{
12634 int ret;
12635
12636 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053012637 if (ret)
12638 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012639
Abhishek Singh257a9482017-03-06 16:52:39 +053012640 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080012641 if (ret)
12642 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012643
Frank Liud4b2fa02017-03-29 11:46:48 +080012644 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012645 if (ret)
12646 return ret;
12647
12648 ret = hdd_update_dp_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012649
12650 return ret;
12651}
12652
Agrawal Ashish65634612016-08-18 13:24:32 +053012653/**
12654 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
12655 * @mode : cfg80211 DFS mode
12656 *
12657 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
12658 */
12659enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
12660{
12661 switch (mode) {
12662 case DFS_MODE_ENABLE:
12663 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012664 case DFS_MODE_DISABLE:
12665 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012666 case DFS_MODE_DEPRIORITIZE:
12667 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012668 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012669 hdd_debug("ACS dfs mode is NONE");
12670 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053012671 }
12672}
12673
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012674/**
12675 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
12676 * @hddctx: pointer to hdd context
12677 * @set_value: enable/disable
12678 *
12679 * When Host sends vendor command enable, FW will send *ONE* CA ind to
12680 * Host(even though it is duplicate). When Host send vendor command
12681 * disable,FW doesn't perform any action. Whenever any change in
12682 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
12683 *
12684 * return - 0 on success, appropriate error values on failure.
12685 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012686int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012687{
12688 QDF_STATUS status;
12689
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012690 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012691 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053012692
12693 if (!hddctx->config->goptimize_chan_avoid_event) {
12694 hdd_warn("goptimize_chan_avoid_event ini param disabled");
12695 return -EINVAL;
12696 }
12697
12698 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
12699 if (!QDF_IS_STATUS_SUCCESS(status)) {
12700 hdd_err("Failed to send chan avoid command to SME");
12701 return -EINVAL;
12702 }
12703 return 0;
12704}
Agrawal Ashish65634612016-08-18 13:24:32 +053012705
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012706/**
12707 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
12708 * @value: value to set
12709 *
12710 * This function will set the passed value to roaming in progress flag.
12711 *
12712 * Return: None
12713 */
12714void hdd_set_roaming_in_progress(bool value)
12715{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012716 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012717
12718 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12719 if (!hdd_ctx) {
12720 hdd_err("HDD context is NULL");
12721 return;
12722 }
12723
12724 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012725 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012726}
12727
12728/**
12729 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012730 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012731 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012732 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012733 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012734bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012735{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012736 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012737 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012738
12739 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12740 if (!hdd_ctx) {
12741 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012742 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012743 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012744 hdd_debug("dev mode = %d, roaming_in_progress = %d",
12745 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080012746 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
12747 hdd_ctx->roaming_in_progress);
12748
12749 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080012750}
12751
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012752/**
12753 * hdd_is_connection_in_progress() - check if connection is in
12754 * progress
12755 * @session_id: session id
12756 * @reason: scan reject reason
12757 *
12758 * Go through each adapter and check if Connection is in progress
12759 *
12760 * Return: true if connection is in progress else false
12761 */
12762bool hdd_is_connection_in_progress(uint8_t *session_id,
12763 enum scan_reject_states *reason)
12764{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070012765 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070012766 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012767 uint8_t sta_id = 0;
12768 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012769 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012770
12771 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12772 if (!hdd_ctx) {
12773 hdd_err("HDD context is NULL");
12774 return false;
12775 }
12776
Dustin Brown920397d2017-12-13 16:27:50 -080012777 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012778 hdd_info("Adapter with device mode %s(%d) exists",
12779 hdd_device_mode_to_string(adapter->device_mode),
12780 adapter->device_mode);
12781 if (((QDF_STA_MODE == adapter->device_mode)
12782 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
12783 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
12784 && (eConnectionState_Connecting ==
12785 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
12786 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012787 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012788 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012789 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012790 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012791 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012792 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012793 }
12794 return true;
12795 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012796 /*
12797 * sme_neighbor_middle_of_roaming is for LFR2
12798 * hdd_is_roaming_in_progress is for LFR3
12799 */
12800 if (((QDF_STA_MODE == adapter->device_mode) &&
12801 sme_neighbor_middle_of_roaming(
12802 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012803 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070012804 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012805 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012806 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070012807 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012808 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012809 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012810 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012811 }
12812 return true;
12813 }
12814 if ((QDF_STA_MODE == adapter->device_mode) ||
12815 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
12816 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
12817 hdd_sta_ctx =
12818 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12819 if ((eConnectionState_Associated ==
12820 hdd_sta_ctx->conn_info.connState)
12821 && (false ==
12822 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
12823 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070012824 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012825 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012826 " is in middle of WPS/EAPOL exchange.",
12827 MAC_ADDR_ARRAY(sta_mac));
12828 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012829 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012830 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012831 }
12832 return true;
12833 }
12834 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
12835 (QDF_P2P_GO_MODE == adapter->device_mode)) {
12836 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
12837 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012838 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012839 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012840 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012841 continue;
12842
12843 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070012844 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070012845 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012846 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012847 " of SAP/GO is in middle of WPS/EAPOL exchange",
12848 MAC_ADDR_ARRAY(sta_mac));
12849 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070012850 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012851 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012852 }
12853 return true;
12854 }
12855 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053012856 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012857 return true;
12858 }
12859 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012860 }
Dustin Brown920397d2017-12-13 16:27:50 -080012861
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012862 return false;
12863}
12864
12865/**
12866 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070012867 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012868 *
12869 * Return: None
12870 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012871void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012872{
Jeff Johnson87251032017-08-29 13:31:11 -070012873 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012874 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012875 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012876 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012877 tsap_Config_t *sap_config;
12878 void *sap_ctx;
12879
12880 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070012881 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012882 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012883
12884 mutex_lock(&hdd_ctx->sap_lock);
12885 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12886 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012887 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12888 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12889 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12890 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012891 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012892 qdf_stop_bss_event,
12893 SME_CMD_TIMEOUT_VALUE);
12894
12895 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012896 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012897 goto end;
12898 }
12899 }
12900 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012901 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012902 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnson6867ec32017-09-29 20:30:20 -070012903 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012904
12905 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012906 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012907 wlansap_reset_sap_config_add_ie(sap_config,
12908 eUPDATE_IE_ALL);
12909 goto end;
12910 }
12911
12912 qdf_event_reset(&hostapd_state->qdf_event);
12913 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12914 sap_config,
12915 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012916 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012917 wlansap_reset_sap_config_add_ie(sap_config,
12918 eUPDATE_IE_ALL);
12919 goto end;
12920 }
12921
Jeff Johnson6867ec32017-09-29 20:30:20 -070012922 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012923 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053012924 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012925 SME_CMD_TIMEOUT_VALUE);
12926 wlansap_reset_sap_config_add_ie(sap_config,
12927 eUPDATE_IE_ALL);
12928 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012929 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012930 goto end;
12931 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070012932 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012933 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -070012934 if (hostapd_state->bss_state == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012935 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12936 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012937 ap_adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012938 }
12939end:
12940 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012941}
12942
12943/**
12944 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12945 * with non dfs acs
12946 *
12947 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12948 *
12949 * Return: None
12950 */
12951void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12952{
Jeff Johnson9d295242017-08-29 14:39:48 -070012953 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012954 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012955 cds_context_type *cds_ctx;
12956
12957 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12958 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012959 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012960 return;
12961 }
12962
12963 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12964 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012965 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012966 return;
12967 }
12968
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012969 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12970 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070012971 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012972 return;
12973 }
12974
12975 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012976 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12977 &ap_adapter->event_flags) &&
12978 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070012979 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012980
Jeff Johnson6867ec32017-09-29 20:30:20 -070012981 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070012982 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012983 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070012984 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012985 acs_cfg.acs_mode = true;
12986
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012987 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012988 }
12989}
12990
12991/**
12992 * hdd_set_connection_in_progress() - to set the connection in
12993 * progress flag
12994 * @value: value to set
12995 *
12996 * This function will set the passed value to connection in progress flag.
12997 * If value is previously being set to true then no need to set it again.
12998 *
12999 * Return: true if value is being set correctly and false otherwise.
13000 */
13001bool hdd_set_connection_in_progress(bool value)
13002{
13003 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013004 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013005
13006 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13007 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013008 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013009 return false;
13010 }
13011
13012 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13013 /*
13014 * if the value is set to true previously and if someone is
13015 * trying to make it true again then it could be some race
13016 * condition being triggered. Avoid this situation by returning
13017 * false
13018 */
13019 if (hdd_ctx->connection_in_progress && value)
13020 status = false;
13021 else
13022 hdd_ctx->connection_in_progress = value;
13023 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13024 return status;
13025}
13026
Jeff Johnson9d295242017-08-29 14:39:48 -070013027int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013028{
13029 if (!adapter) {
13030 hdd_err("Invalid adapter");
13031 return -EINVAL;
13032 }
13033 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013034 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013035 WMA_VDEV_MCC_SET_TIME_QUOTA,
13036 set_value, VDEV_CMD);
13037 return 0;
13038
13039}
13040
Jeff Johnson9d295242017-08-29 14:39:48 -070013041int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013042{
13043 if (!adapter) {
13044 hdd_err("Invalid adapter");
13045 return -EINVAL;
13046 }
13047
13048 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013049 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013050 WMA_VDEV_MCC_SET_TIME_LATENCY,
13051 set_value, VDEV_CMD);
13052 return 0;
13053}
13054
Jeff Johnson9d295242017-08-29 14:39:48 -070013055struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013056 *psoc, uint8_t vdev_id)
13057{
Jeff Johnson9d295242017-08-29 14:39:48 -070013058 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013059 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013060
13061 /*
13062 * Currently PSOC is not being used. But this logic will
13063 * change once we have the converged implementation of
13064 * HDD context per PSOC in place. This would break if
13065 * multiple vdev objects reuse the vdev id.
13066 */
13067 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13068 if (!adapter)
13069 hdd_err("Get adapter by vdev id failed");
13070
13071 return adapter;
13072}
13073
Jeff Johnson9d295242017-08-29 14:39:48 -070013074int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013075 int8_t *rssi, int8_t *snr)
13076{
13077 QDF_STATUS status;
Jeff Johnson2a722002017-09-30 20:02:35 -070013078 struct hdd_wext_state *wext_state =
13079 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013080 tCsrRoamProfile *profile = &wext_state->roamProfile;
13081
13082 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
13083 profile, bssid, rssi, snr);
13084 if (QDF_STATUS_SUCCESS != status) {
13085 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13086 return -EINVAL;
13087 }
13088
13089 return 0;
13090}
13091
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013092/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013093 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13094 * @adapter - HDD adapter
13095 * @tos - type of service
13096 * @status - status of the traffic
13097 *
13098 * Return: 0 on success and non zero value on failure
13099 */
13100
13101int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13102 bool is_tos_active)
13103{
13104 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013105 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013106 uint32_t max_off_chan_time = 0;
13107 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013108 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013109 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013110
13111 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13112 ret = wlan_hdd_validate_context(hdd_ctx);
13113
13114 if (ret < 0) {
13115 hdd_err("failed to set limit off chan params");
13116 return ret;
13117 }
13118
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013119 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13120
13121 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013122 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013123 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013124 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013125
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013126 if (adapter->active_ac) {
13127 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013128 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013129 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13130 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13131 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013132 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013133 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013134 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13135 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13136 PM_LATENCY);
13137 } else {
13138 /*ignore this command if only BE/BK is active */
13139 is_tos_active = false;
13140 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13141 hdd_ctx->config->conc_system_pref);
13142 }
13143 } else {
13144 /* No active tos */
13145 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13146 hdd_ctx->config->conc_system_pref);
13147 }
13148
Jeff Johnson1b780e42017-10-31 14:11:45 -070013149 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013150 is_tos_active, max_off_chan_time,
13151 hdd_ctx->config->nRestTimeConc, true);
13152 if (!QDF_IS_STATUS_SUCCESS(status)) {
13153 hdd_err("failed to set limit off chan params");
13154 ret = -EINVAL;
13155 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013156
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013157 return ret;
13158}
13159
13160/**
13161 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13162 * @adapter - HDD adapter
13163 *
13164 * Return: 0 on success and non zero value on failure
13165 */
13166int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13167{
13168 struct hdd_context *hdd_ctx;
13169 int ret;
13170 QDF_STATUS status;
13171 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13172
13173 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13174 ret = wlan_hdd_validate_context(hdd_ctx);
13175 if (ret < 0)
13176 return ret;
13177
13178 /* set the system preferece to default */
13179 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13180 hdd_ctx->config->conc_system_pref);
13181
13182 /* clear the bitmap */
13183 adapter->active_ac = 0;
13184
13185 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013186 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013187
Jeff Johnson1b780e42017-10-31 14:11:45 -070013188 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013189 false, 0, 0, false);
13190 if (!QDF_IS_STATUS_SUCCESS(status)) {
13191 hdd_err("failed to reset limit off chan params");
13192 ret = -EINVAL;
13193 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013194
13195 return ret;
13196}
13197
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013198/**
13199 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13200 * @drv_op: Enum indicating driver op
13201 *
13202 * Return: none
13203 */
13204void hdd_start_driver_ops_timer(int drv_op)
13205{
13206 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13207 switch (drv_op) {
13208 case eHDD_DRV_OP_PROBE:
13209 memcpy(drv_ops_string, "probe", sizeof("probe"));
13210 break;
13211 case eHDD_DRV_OP_REMOVE:
13212 memcpy(drv_ops_string, "remove", sizeof("remove"));
13213 break;
13214 case eHDD_DRV_OP_SHUTDOWN:
13215 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13216 break;
13217 case eHDD_DRV_OP_REINIT:
13218 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13219 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013220 case eHDD_DRV_OP_IFF_UP:
13221 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13222 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013223 }
13224
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013225 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013226 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13227 HDD_OPS_INACTIVITY_TIMEOUT);
13228}
13229
13230/**
13231 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13232 *
13233 * Return: none
13234 */
13235void hdd_stop_driver_ops_timer(void)
13236{
13237 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13238}
13239
13240/**
13241 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13242 * inactivity timer
13243 *
13244 * Return: None
13245 */
13246void hdd_drv_ops_inactivity_handler(void)
13247{
13248 hdd_err("%s: %d Sec timer expired while in .%s",
13249 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13250
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013251 if (hdd_drv_ops_task) {
13252 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13253 qdf_print_thread_trace(hdd_drv_ops_task);
13254 } else {
13255 hdd_err("hdd_drv_ops_task is null");
13256 }
13257
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013258 /* Driver shutdown is stuck, no recovery possible at this point */
13259 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13260 sizeof("shutdown")))
13261 QDF_BUG(0);
13262
13263 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013264 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013265 else
13266 QDF_BUG(0);
13267}
13268
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013269void hdd_pld_ipa_uc_shutdown_pipes(void)
13270{
13271 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13272
13273 if (!hdd_ctx)
13274 return;
13275
13276 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13277}
13278
Yun Parkff6a16a2017-09-26 16:38:18 -070013279/**
13280 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13281 * @struct hdd_context *hdd_ctx
13282 * @struct hdd_adapter *padapter
13283 * @bool enble
13284 *
13285 * Return: none
13286 */
13287void hdd_set_rx_mode_rps(bool enable)
13288{
13289 struct cds_config_info *cds_cfg = cds_get_ini_config();
13290 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13291 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13292
13293 if (adapter && hdd_ctx &&
13294 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13295 if (enable && !cds_cfg->rps_enabled)
13296 hdd_send_rps_ind(adapter);
13297 else if (!enable && cds_cfg->rps_enabled)
13298 hdd_send_rps_disable_ind(adapter);
13299 }
13300}
13301
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013302/* Register the module init/exit functions */
13303module_init(hdd_module_init);
13304module_exit(hdd_module_exit);
13305
13306MODULE_LICENSE("Dual BSD/GPL");
13307MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13308MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013310module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13311 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013312
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013313module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13314 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13315
Ravi Joshia307f632017-07-17 23:41:41 -070013316module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13317 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13318
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013319module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13320 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13321
13322module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13323
13324module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13325
13326module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);