blob: 2b86a5c150f8d8a970ef3df46cc50e9e641791b8 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 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"
Dustin Brown26b3d042017-12-21 11:13:27 -080058#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080059#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080060#endif
Dustin Brownd4241942018-02-26 12:51:37 -080061#include "qdf_str.h"
62#include "qdf_trace.h"
63#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070064#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080065#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070066#include <cdp_txrx_stats.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080067
68#include <net/addrconf.h>
69#include <linux/wireless.h>
70#include <net/cfg80211.h>
71#include <linux/inetdevice.h>
72#include <net/addrconf.h>
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_ext_scan.h"
75#include "wlan_hdd_p2p.h"
76#include <linux/rtnetlink.h>
77#include "sap_api.h"
78#include <linux/semaphore.h>
79#include <linux/ctype.h>
80#include <linux/compat.h>
81#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <soc/qcom/subsystem_restart.h>
83#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include <wlan_hdd_hostapd.h>
85#include <wlan_hdd_softap_tx_rx.h>
86#include "cfg_api.h"
87#include "qwlan_version.h"
88#include "wma_types.h"
89#include "wlan_hdd_tdls.h"
90#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053091#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080092#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070093#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070094#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080095#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080096#include "wlan_hdd_nan.h"
97#include "wlan_hdd_debugfs.h"
98#include "wlan_hdd_driver_ops.h"
99#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530100#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800101
102#include <wlan_hdd_ipa.h>
103#include "hif.h"
104#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800105#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700106#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530107#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700108#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700109#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530110#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700111#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530112#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800113#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800114#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530115#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800116#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800117#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530118#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530119#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800120#include "os_if_wifi_pos.h"
121#include "wifi_pos_api.h"
122#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800123#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700124#include "os_if_nan.h"
125#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700126#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800127#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700128#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530129#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530130#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700131#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800132#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530133#include "wlan_disa_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530134#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530135#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530136#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530137
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530138#ifdef CNSS_GENL
139#include <net/cnss_nl.h>
140#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800141#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800142#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530143
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530144#include <wlan_green_ap_ucfg_api.h>
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800145#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800146#ifdef MODULE
147#define WLAN_MODULE_NAME module_name(THIS_MODULE)
148#else
149#define WLAN_MODULE_NAME "wlan"
150#endif
151
152#ifdef TIMER_MANAGER
153#define TIMER_MANAGER_STR " +TIMER_MANAGER"
154#else
155#define TIMER_MANAGER_STR ""
156#endif
157
158#ifdef MEMORY_DEBUG
159#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
160#else
161#define MEMORY_DEBUG_STR ""
162#endif
163
Dustin Brownc1034df2018-02-07 14:51:32 -0800164#ifdef PANIC_ON_BUG
165#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
166#else
167#define PANIC_ON_BUG_STR ""
168#endif
169
Sachin Ahujadddd2632017-03-07 19:07:24 +0530170int wlan_start_ret_val;
171static DECLARE_COMPLETION(wlan_start_comp);
172static unsigned int dev_num = 1;
173static struct cdev wlan_hdd_state_cdev;
174static struct class *class;
175static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530176#ifndef MODULE
177static struct gwlan_loader *wlan_loader;
178static ssize_t wlan_boot_cb(struct kobject *kobj,
179 struct kobj_attribute *attr,
180 const char *buf, size_t count);
181struct gwlan_loader {
182 bool loaded_state;
183 struct kobject *boot_wlan_obj;
184 struct attribute_group *attr_group;
185};
186
187static struct kobj_attribute wlan_boot_attribute =
188 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
189
190static struct attribute *attrs[] = {
191 &wlan_boot_attribute.attr,
192 NULL,
193};
194
195#define MODULE_INITIALIZED 1
196#endif
197
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530198#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
199#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800200#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530201
202static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800203static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530204static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206/* the Android framework expects this param even though we don't use it */
207#define BUF_LEN 20
208static char fwpath_buffer[BUF_LEN];
209static struct kparam_string fwpath = {
210 .string = fwpath_buffer,
211 .maxlen = BUF_LEN,
212};
213
214static char *country_code;
215static int enable_11d = -1;
216static int enable_dfs_chan_scan = -1;
217
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218/*
219 * spinlock for synchronizing asynchronous request/response
220 * (full description of use in wlan_hdd_main.h)
221 */
222DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530223DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800225#define WLAN_NLINK_CESIUM 30
226
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530227static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800228
229#define WOW_MAX_FILTER_LISTS 1
230#define WOW_MAX_FILTERS_PER_LIST 4
231#define WOW_MIN_PATTERN_SIZE 6
232#define WOW_MAX_PATTERN_SIZE 64
233
234#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
235static const struct wiphy_wowlan_support wowlan_support_reg_init = {
236 .flags = WIPHY_WOWLAN_ANY |
237 WIPHY_WOWLAN_MAGIC_PKT |
238 WIPHY_WOWLAN_DISCONNECT |
239 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
240 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
241 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
242 WIPHY_WOWLAN_4WAY_HANDSHAKE |
243 WIPHY_WOWLAN_RFKILL_RELEASE,
244 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
245 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
246 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
247};
248#endif
249
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700250static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
251 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
264 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
265 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
266 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
267 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700285 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700286 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700287 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530288 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800289 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530290 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700291};
292
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530293int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
294 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
295 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
296 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
297 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
298};
299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530301struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800302
303struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800304#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700305static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800306#endif
307
Sachin Ahujadddd2632017-03-07 19:07:24 +0530308void hdd_start_complete(int ret)
309{
310 wlan_start_ret_val = ret;
311
312 complete(&wlan_start_comp);
313}
314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315/**
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700316 * hdd_green_ap_check_enable() - to check whether to enable green ap or not
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530317 * @hdd_ctx: hdd context
318 * @enable_green_ap: 1 - enable green ap enabled, 0 - disbale green ap
319 *
320 * Return: 0 - success, < 0 - failure
321 */
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700322static int hdd_green_ap_check_enable(struct hdd_context *hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530323 bool *enable_green_ap)
324{
325 uint8_t num_sessions, mode;
326 QDF_STATUS status;
327
328 for (mode = 0;
329 mode < QDF_MAX_NO_OF_MODE;
330 mode++) {
331 if (mode == QDF_SAP_MODE || mode == QDF_P2P_GO_MODE)
332 continue;
333
334 status = policy_mgr_mode_specific_num_active_sessions(
335 hdd_ctx->hdd_psoc, mode, &num_sessions);
336 hdd_debug("No. of active sessions for mode: %d is %d",
337 mode, num_sessions);
338 if (status != QDF_STATUS_SUCCESS) {
339 hdd_err("Failed to get num sessions for mode: %d",
340 mode);
341 return -EINVAL;
342 } else if (num_sessions) {
343 *enable_green_ap = false;
344 return 0;
345 }
346 }
347 *enable_green_ap = true;
348 return 0;
349}
350
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700351int hdd_green_ap_start_state_mc(struct hdd_context *hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530352 enum QDF_OPMODE mode, bool is_session_start)
353{
354 struct hdd_config *cfg;
355 bool enable_green_ap = false;
356 uint8_t num_sap_sessions = 0, num_p2p_go_sessions = 0, ret = 0;
357
358 cfg = hdd_ctx->config;
359 if (!cfg) {
360 hdd_err("NULL hdd config");
361 return -EINVAL;
362 }
363
364 if (!cfg->enable2x2 || !cfg->enableGreenAP) {
365 hdd_info("Green AP support not present: enable2x2: %d, enableGreenAp: %d",
366 cfg->enable2x2, cfg->enableGreenAP);
367 return 0;
368 }
369
370 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->hdd_psoc,
371 QDF_SAP_MODE,
372 &num_sap_sessions);
373 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->hdd_psoc,
374 QDF_P2P_GO_MODE,
375 &num_p2p_go_sessions);
376
377 switch (mode) {
378 case QDF_STA_MODE:
379 case QDF_P2P_CLIENT_MODE:
380 case QDF_IBSS_MODE:
381 if (!num_sap_sessions && !num_p2p_go_sessions)
382 return 0;
383
384 if (is_session_start) {
385 hdd_debug("Disabling Green AP");
386 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
387 false);
388 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
389 } else {
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700390 ret = hdd_green_ap_check_enable(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530391 &enable_green_ap);
392 if (!ret) {
393 if (enable_green_ap) {
394 hdd_debug("Enabling Green AP");
395 ucfg_green_ap_set_ps_config(
396 hdd_ctx->hdd_pdev, true);
397 wlan_green_ap_start(hdd_ctx->hdd_pdev);
398 }
399 } else {
400 hdd_err("Failed to check Green AP enable status");
401 }
402 }
403 break;
404 case QDF_SAP_MODE:
405 case QDF_P2P_GO_MODE:
406 if (is_session_start) {
Jeff Johnsone8846ab2018-03-31 11:54:45 -0700407 ret = hdd_green_ap_check_enable(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530408 &enable_green_ap);
409 if (!ret) {
410 if (enable_green_ap) {
411 hdd_debug("Enabling Green AP");
412 ucfg_green_ap_set_ps_config(
413 hdd_ctx->hdd_pdev, true);
414 wlan_green_ap_start(hdd_ctx->hdd_pdev);
415 }
416 } else {
417 hdd_err("Failed to check Green AP enable status");
418 }
419 } else {
420 if (!num_sap_sessions && !num_p2p_go_sessions) {
421 hdd_debug("Disabling Green AP");
422 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
423 false);
424 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
425 }
426 }
427 break;
428 default:
429 break;
430 }
431 return ret;
432}
433
434/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530435 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700436 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530437 *
438 * Return: none
439 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700440static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530441{
Jeff Johnson9d295242017-08-29 14:39:48 -0700442 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530443
Dustin Brown920397d2017-12-13 16:27:50 -0800444 hdd_for_each_adapter(hdd_ctx, adapter)
445 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530446}
447
448/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
450 * @vdev_id: vdev_id
451 * @action: action type
452 * @reason: reason type
453 *
454 * Return: none
455 */
456void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
457 enum netif_action_type action, enum netif_reason_type reason)
458{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700459 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700460 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800461
462 if (!hdd_ctx) {
463 hdd_err("hdd ctx is NULL");
464 return;
465 }
466 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
467
468 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800469}
470
471/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700472 * Store WLAN driver version and timestamp info in global variables such that
473 * crash debugger can extract them from driver debug symbol and crashdump for
474 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800475 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800476#ifdef BUILD_TAG
477uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
478#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700480#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800481
482/**
483 * hdd_device_mode_to_string() - return string conversion of device mode
484 * @device_mode: device mode
485 *
486 * This utility function helps log string conversion of device mode.
487 *
488 * Return: string conversion of device mode, if match found;
489 * "Unknown" otherwise.
490 */
491const char *hdd_device_mode_to_string(uint8_t device_mode)
492{
493 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800494 CASE_RETURN_STRING(QDF_STA_MODE);
495 CASE_RETURN_STRING(QDF_SAP_MODE);
496 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
497 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
498 CASE_RETURN_STRING(QDF_FTM_MODE);
499 CASE_RETURN_STRING(QDF_IBSS_MODE);
500 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
501 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700502 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503 default:
504 return "Unknown";
505 }
506}
507
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530508/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500509 * hdd_get_valid_chan() - return current chan list from regulatory.
510 * @hdd_ctx: HDD context
511 * @chan_list: buf hold returned chan list
512 * @chan_num: input buf size and output returned chan num
513 *
514 * This function helps get current available chan list from regulatory
515 * module. It excludes the "disabled" and "invalid" channels.
516 *
517 * Return: 0 for success.
518 */
519static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
520 uint8_t *chan_list,
521 uint32_t *chan_num)
522{
523 int i = 0, j = 0;
524 struct regulatory_channel *cur_chan_list;
525 struct wlan_objmgr_pdev *pdev;
526
527 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
528 return -EINVAL;
529
530 pdev = hdd_ctx->hdd_pdev;
531 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
532 sizeof(struct regulatory_channel));
533 if (!cur_chan_list)
534 return -ENOMEM;
535
536 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
537 QDF_STATUS_SUCCESS) {
538 qdf_mem_free(cur_chan_list);
539 return -EINVAL;
540 }
541
542 for (i = 0; i < NUM_CHANNELS; i++) {
543 uint32_t ch = cur_chan_list[i].chan_num;
544 enum channel_state state = wlan_reg_get_channel_state(pdev,
545 ch);
546
547 if (state != CHANNEL_STATE_DISABLE &&
548 state != CHANNEL_STATE_INVALID &&
549 j < *chan_num) {
550 chan_list[j] = (uint8_t)ch;
551 j++;
552 }
553 }
554 *chan_num = j;
555 qdf_mem_free(cur_chan_list);
556 return 0;
557}
558
559/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530560 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
561 * @adapter: HDD adapter
562 * @chan_number: Channel number
563 * @chan_bw: Bandwidth
564 *
565 * Checks if the given bandwidth is valid for the given channel number.
566 *
567 * Return: 0 for success, non-zero for failure
568 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700569int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530570 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800571 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530572{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500573 uint8_t chan[NUM_CHANNELS];
574 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530575 bool found = false;
576 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500577 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530578
579 hal = WLAN_HDD_GET_HAL_CTX(adapter);
580 if (!hal) {
581 hdd_err("Invalid HAL context");
582 return -EINVAL;
583 }
584
Liangwei Dong17bf2662018-01-05 02:02:05 -0500585 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
586 &len);
587 if (ret) {
588 hdd_err("error %d in getting valid channel list", ret);
589 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530590 }
591
592 for (i = 0; i < len; i++) {
593 if (chan[i] == chan_number) {
594 found = true;
595 break;
596 }
597 }
598
599 if (found == false) {
600 hdd_err("Channel not in driver's valid channel list");
601 return -EOPNOTSUPP;
602 }
603
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700604 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
605 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530606 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
607 return -EINVAL;
608 }
609
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700610 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530611 if (chan_bw == CH_WIDTH_80MHZ) {
612 hdd_err("BW80 not possible in 2.4GHz band");
613 return -EINVAL;
614 }
615 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
616 (chan_bw != CH_WIDTH_MAX)) {
617 hdd_err("Only BW20 possible on channel 14");
618 return -EINVAL;
619 }
620 }
621
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700622 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530623 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
624 (chan_bw != CH_WIDTH_MAX)) {
625 hdd_err("Only BW20 possible on channel 165");
626 return -EINVAL;
627 }
628 }
629
630 return 0;
631}
632
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530633/**
634 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
635 *
636 * Block the unloading of the driver (or) interface up until the
637 * cds recovery is completed
638 *
639 * Return: true for recovery completion else false
640 */
641static bool hdd_wait_for_recovery_completion(void)
642{
643 int retry = 0;
644
645 /* Wait for recovery to complete */
646 while (cds_is_driver_recovering()) {
647 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
648 hdd_err("Recovery in progress; wait here!!!");
649 msleep(1000);
650 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
651 hdd_err("SSR never completed, error");
652 /*
653 * Trigger the bug_on in the internal builds, in the
654 * customer builds self-recovery will be enabled
655 * in those cases just return error.
656 */
657 if (cds_is_self_recovery_enabled())
658 return false;
659 QDF_BUG(0);
660 }
661 }
662
663 hdd_info("Recovery completed successfully!");
664 return true;
665}
666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667static int __hdd_netdev_notifier_call(struct notifier_block *nb,
668 unsigned long state, void *data)
669{
670#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
671 struct netdev_notifier_info *dev_notif_info = data;
672 struct net_device *dev = dev_notif_info->dev;
673#else
674 struct net_device *dev = data;
675#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700676 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700677 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800678
Dustin Brownfdf17c12018-03-14 12:55:34 -0700679 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800681 /* Make sure that this callback corresponds to our device. */
682 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
683 return NOTIFY_DONE;
684
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530685 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700687 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800688 return NOTIFY_DONE;
689 }
690
691 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700692 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693 return NOTIFY_DONE;
694 }
695
696 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
697 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800698 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530699 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800700 return NOTIFY_DONE;
701 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800702
703 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
704 hdd_err("%s: Driver module is closed", __func__);
705 return NOTIFY_DONE;
706 }
707
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530708 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800709 return NOTIFY_DONE;
710
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800711 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800712 dev->name, state);
713
714 switch (state) {
715 case NETDEV_REGISTER:
716 break;
717
718 case NETDEV_UNREGISTER:
719 break;
720
721 case NETDEV_UP:
722 sme_ch_avoid_update_req(hdd_ctx->hHal);
723 break;
724
725 case NETDEV_DOWN:
726 break;
727
728 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700729 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730 complete(&adapter->linkup_event_var);
731 break;
732
733 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700734 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
735 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530736 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700737 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 } else {
hqueaa33ee2017-05-04 17:56:35 +0800739 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800740 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530742 /*
743 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
744 * of return status of hdd_stop call, kernel resets the IFF_UP
745 * flag after which driver does not send the cfg80211_scan_done.
746 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
747 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530748 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749 break;
750
751 default:
752 break;
753 }
754
755 return NOTIFY_DONE;
756}
757
758/**
759 * hdd_netdev_notifier_call() - netdev notifier callback function
760 * @nb: pointer to notifier block
761 * @state: state
762 * @ndev: ndev pointer
763 *
764 * Return: 0 on success, error number otherwise.
765 */
766static int hdd_netdev_notifier_call(struct notifier_block *nb,
767 unsigned long state,
768 void *ndev)
769{
770 int ret;
771
772 cds_ssr_protect(__func__);
773 ret = __hdd_netdev_notifier_call(nb, state, ndev);
774 cds_ssr_unprotect(__func__);
775
776 return ret;
777}
778
779struct notifier_block hdd_netdev_notifier = {
780 .notifier_call = hdd_netdev_notifier_call,
781};
782
783/* variable to hold the insmod parameters */
784static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800785
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530786static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700787int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530788
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800789/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800790static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530792/**
793 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
794 * @ch_width: NL channel width
795 *
796 * Converts the NL channel width to the driver's internal representation
797 *
798 * Return: Converted channel width. In case of non matching NL channel width,
799 * CH_WIDTH_MAX will be returned.
800 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800801enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530802{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800803 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700804
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800805 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530806 switch (ch_width) {
807 case NL80211_CHAN_WIDTH_20_NOHT:
808 case NL80211_CHAN_WIDTH_20:
809 return CH_WIDTH_20MHZ;
810 case NL80211_CHAN_WIDTH_40:
811 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530812 case NL80211_CHAN_WIDTH_80:
813 return CH_WIDTH_80MHZ;
814 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800815 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
816 return CH_WIDTH_80P80MHZ;
817 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
818 return CH_WIDTH_160MHZ;
819 else
820 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530821 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800822 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
823 return CH_WIDTH_160MHZ;
824 else
825 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530826 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800827 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530828 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800829 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530830 default:
831 hdd_err("Invalid channel width %d, setting to default",
832 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800833 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530834 }
835}
836
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530837/* wlan_hdd_find_opclass() - Find operating class for a channel
838 * @hal: handler to HAL
839 * @channel: channel id
840 * @bw_offset: bandwidth offset
841 *
842 * Function invokes sme api to find the operating class
843 *
844 * Return: operating class
845 */
846uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
847 uint8_t bw_offset)
848{
849 uint8_t opclass = 0;
850
851 sme_get_opclass(hal, channel, bw_offset, &opclass);
852 return opclass;
853}
854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530856 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530857 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800858 * @bitmask: Bitmask of log levels to be enabled
859 *
860 * Called immediately after the cfg.ini is read in order to configure
861 * the desired trace levels.
862 *
863 * Return: None
864 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530865int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530867 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530868 int qdf_print_idx = -1;
869 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 /*
871 * if the bitmask is the default value, then a bitmask was not
872 * specified in cfg.ini, so leave the logging level alone (it
873 * will remain at the "compiled in" default value)
874 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700875 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530876 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530878 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530880 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530881 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530882 QDF_TRACE_LEVEL_NONE, 0);
883
884 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530885 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530887 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888 while (0 != bitmask) {
889 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530890 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530891 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530892 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530893 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 level++;
897 bitmask >>= 1;
898 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530899 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900}
901
902/**
Chris Guo1751acf2017-07-03 14:09:01 +0800903 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
904 * @hdd_ctx: HDD context pointer
905 *
906 * Return: 0 if the context is valid. Error code otherwise
907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700908int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800909{
910 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
911 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
912 return -ENODEV;
913 }
914
915 if (cds_is_driver_recovering()) {
916 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
917 (void *)_RET_IP_, cds_get_driver_state());
918 return -EAGAIN;
919 }
920
921 if (hdd_ctx->start_modules_in_progress ||
922 hdd_ctx->stop_modules_in_progress) {
923 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
924 (void *)_RET_IP_);
925 return -EAGAIN;
926 }
927
928 return 0;
929}
930
931
932/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 * wlan_hdd_validate_context() - check the HDD context
934 * @hdd_ctx: HDD context pointer
935 *
936 * Return: 0 if the context is valid. Error code otherwise
937 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700938int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530941 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 return -ENODEV;
943 }
944
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800945 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800946 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530947 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 return -EAGAIN;
949 }
950
Yue Ma9f275d92017-09-14 16:58:41 -0700951 if (cds_is_load_or_unload_in_progress()) {
952 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
953 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700955 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530956
957 if (hdd_ctx->start_modules_in_progress ||
958 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800959 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530960 (void *)_RET_IP_);
961 return -EAGAIN;
962 }
963
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530964 if (cds_is_driver_in_bad_state()) {
965 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
966 (void *)_RET_IP_, cds_get_driver_state());
967 return -ENODEV;
968 }
969
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530970 if (cds_is_fw_down()) {
971 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
972 (void *)_RET_IP_, cds_get_driver_state());
973 return -ENODEV;
974 }
975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 return 0;
977}
978
Jeff Johnson9d295242017-08-29 14:39:48 -0700979int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700980{
981 if (!adapter) {
982 hdd_err("adapter is null");
983 return -EINVAL;
984 }
985
986 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
987 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
988 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
989 return -EINVAL;
990 }
991
992 if (!adapter->dev) {
993 hdd_err("adapter net_device is null");
994 return -EINVAL;
995 }
996
997 if (!(adapter->dev->flags & IFF_UP)) {
998 hdd_info("adapter net_device is not up");
999 return -EAGAIN;
1000 }
1001
Jeff Johnson1b780e42017-10-31 14:11:45 -07001002 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -07001003 hdd_info("adapter session is not open");
1004 return -EAGAIN;
1005 }
1006
Jeff Johnson1b780e42017-10-31 14:11:45 -07001007 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
1008 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001009 return -EINVAL;
1010 }
1011
1012 return 0;
1013}
1014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301016 * wlan_hdd_validate_modules_state() - Check modules status
1017 * @hdd_ctx: HDD context pointer
1018 *
1019 * Check's the driver module's state and returns true if the
1020 * modules are enabled returns false if modules are closed.
1021 *
1022 * Return: True if modules are enabled or false.
1023 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001024bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301025{
1026 mutex_lock(&hdd_ctx->iface_change_lock);
1027 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1028 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001029 hdd_info("Modules not enabled, Present status: %d",
1030 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301031 return false;
1032 }
1033 mutex_unlock(&hdd_ctx->iface_change_lock);
1034 return true;
1035}
1036
1037/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001039 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 *
1041 * This function sets the IBSS power save config parameters to WMA
1042 * which will send it to firmware if FW supports IBSS power save
1043 * before vdev start.
1044 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301045 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 * on failure.
1047 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001048QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049{
1050 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001051 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001052
1053 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001054 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301055 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 }
1057
Jeff Johnson1b780e42017-10-31 14:11:45 -07001058 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001059 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1060 hdd_ctx->config->ibssATIMWinSize,
1061 VDEV_CMD);
1062 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001063 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301064 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 }
1066
Jeff Johnson1b780e42017-10-31 14:11:45 -07001067 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1069 hdd_ctx->config->isIbssPowerSaveAllowed,
1070 VDEV_CMD);
1071 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001072 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
1073 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301074 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075 }
1076
Jeff Johnson1b780e42017-10-31 14:11:45 -07001077 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001078 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1079 hdd_ctx->config->
1080 isIbssPowerCollapseAllowed, VDEV_CMD);
1081 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001082 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
1083 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301084 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 }
1086
Jeff Johnson1b780e42017-10-31 14:11:45 -07001087 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1089 hdd_ctx->config->isIbssAwakeOnTxRx,
1090 VDEV_CMD);
1091 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001092 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301093 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094 }
1095
Jeff Johnson1b780e42017-10-31 14:11:45 -07001096 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1098 hdd_ctx->config->ibssInactivityCount,
1099 VDEV_CMD);
1100 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001101 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301102 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 }
1104
Jeff Johnson1b780e42017-10-31 14:11:45 -07001105 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1107 hdd_ctx->config->ibssTxSpEndInactivityTime,
1108 VDEV_CMD);
1109 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001110 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1111 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301112 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113 }
1114
Jeff Johnson1b780e42017-10-31 14:11:45 -07001115 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001116 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1117 hdd_ctx->config->ibssPsWarmupTime,
1118 VDEV_CMD);
1119 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001120 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1121 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301122 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 }
1124
Jeff Johnson1b780e42017-10-31 14:11:45 -07001125 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1127 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1128 VDEV_CMD);
1129 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001130 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1131 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301132 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001133 }
1134
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301135 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136}
1137
Yue Macd359b72017-10-03 15:21:00 -07001138#ifdef FEATURE_RUNTIME_PM
1139/**
1140 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1141 * @hdd_ctx: HDD context
1142 *
1143 * Return: None
1144 */
1145static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1146{
1147 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1148
Yue Macd359b72017-10-03 15:21:00 -07001149 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001150 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001151
1152 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1153}
1154
1155/**
1156 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1157 * @hdd_ctx: HDD Context
1158 *
1159 * Return: None
1160 */
1161static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1162{
1163 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1164
Yue Macd359b72017-10-03 15:21:00 -07001165 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001166 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001167
1168 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1169}
1170
Yue Macd359b72017-10-03 15:21:00 -07001171#else /* FEATURE_RUNTIME_PM */
1172static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1173static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001174#endif /* FEATURE_RUNTIME_PM */
1175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176#define INTF_MACADDR_MASK 0x7
1177
1178/**
1179 * hdd_update_macaddr() - update mac address
1180 * @config: hdd configuration
1181 * @hw_macaddr: mac address
1182 *
1183 * Mac address for multiple virtual interface is found as following
1184 * i) The mac address of the first interface is just the actual hw mac address.
1185 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1186 * define the mac address for the remaining interfaces and locally
1187 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1188 * supported virtual interfaces, right now this is 0x07 (meaning 8
1189 * interface).
1190 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1191 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1192 *
1193 * Return: None
1194 */
1195void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301196 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197{
1198 int8_t i;
1199 uint8_t macaddr_b3, tmp_br3;
1200
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301201 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301202 QDF_MAC_ADDR_SIZE);
1203 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301204 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301205 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1207 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1208 INTF_MACADDR_MASK;
1209 macaddr_b3 += tmp_br3;
1210
1211 /* XOR-ing bit-24 of the mac address. This will give enough
1212 * mac address range before collision
1213 */
1214 macaddr_b3 ^= (1 << 7);
1215
1216 /* Set locally administered bit */
1217 config->intfMacAddr[i].bytes[0] |= 0x02;
1218 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001219 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220 MAC_ADDRESS_STR, i,
1221 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1222 }
1223}
1224
Kabilan Kannan44a58372017-12-06 18:16:11 -08001225static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1226{
1227 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1228 struct tdls_start_params tdls_cfg;
1229 struct tdls_user_config *config = &tdls_cfg.config;
1230 struct hdd_config *cfg = hdd_ctx->config;
1231 QDF_STATUS status;
1232
1233 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1234 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1235 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1236 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1237 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1238 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1239 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1240 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1241 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1242 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1243 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1244 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1245 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1246 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1247 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1248 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1249 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1250 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1251 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1252 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1253 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1254 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1255 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1256 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1257 (cfg->fEnableTDLSImplicitTrigger ?
1258 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1259 (cfg->fTDLSExternalControl ?
1260 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1261 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1262 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1263
1264 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1265 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1266 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1267 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1268 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1269 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1270 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1271 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001272 tdls_cfg.tdls_peer_context = hdd_ctx;
1273 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1274 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001275 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1276 tdls_cfg.tdls_wmm_cb_data = psoc;
1277 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1278 tdls_cfg.tdls_rx_cb_data = psoc;
1279 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1280
1281 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1282 if (status != QDF_STATUS_SUCCESS) {
1283 hdd_err("failed pmo psoc configuration");
1284 return -EINVAL;
1285 }
1286
1287 hdd_ctx->tdls_umac_comp_active = true;
1288 /* enable napier specific tdls data path */
1289 hdd_ctx->tdls_nap_active = true;
1290
1291 return 0;
1292}
1293
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001294static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001295 struct wma_tgt_services *cfg)
1296{
1297 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001298
1299 /* Set up UAPSD */
1300 config->apUapsdEnabled &= cfg->uapsd;
1301
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001302 /* 11AX mode support */
1303 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1304 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1305 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1306
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 /* 11AC mode support */
1308 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1309 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1310 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001311
1312 /* ARP offload: override user setting if invalid */
1313 config->fhostArpOffload &= cfg->arp_offload;
1314
1315#ifdef FEATURE_WLAN_SCAN_PNO
1316 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001317 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001318 if (cfg->pno_offload)
1319 config->PnoOffload = true;
1320#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321#ifdef FEATURE_WLAN_TDLS
1322 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301323 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1324 cfg->en_tdls_offchan;
1325 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1326 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001327 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001329 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001331#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1333 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1334#endif
Will Huang496b36c2017-07-11 16:38:50 +08001335 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001336 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001337 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001338 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001339
1340}
1341
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001342/**
1343 * hdd_update_vdev_nss() - sets the vdev nss
1344 * @hdd_ctx: HDD context
1345 *
1346 * Sets the Nss per vdev type based on INI
1347 *
1348 * Return: None
1349 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001350static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001351{
1352 struct hdd_config *cfg_ini = hdd_ctx->config;
1353 uint8_t max_supp_nss = 1;
1354
Naveen Rawat10b1c152017-01-18 11:16:06 -08001355 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001356 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001357 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1358 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1359 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001360
1361 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001362 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001363
1364 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001365 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001366}
1367
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301368/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301369 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1370 * @hdd_ctx: HDD context
1371 *
1372 * Updates wiphy vhtcap fields
1373 *
1374 * Return: None
1375 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001376static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301377{
1378 struct ieee80211_supported_band *band_5g =
1379 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1380 uint32_t val;
1381
1382 if (!band_5g) {
1383 hdd_debug("5GHz band disabled, skipping capability population");
1384 return;
1385 }
1386
1387 val = hdd_ctx->config->txBFCsnValue;
1388 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1389
1390 val = NUM_OF_SOUNDING_DIMENSIONS;
1391 band_5g->vht_cap.cap |=
1392 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1393
1394 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1395 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1396}
1397
1398/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301399 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1400 * @hdd_ctx: HDD context
1401 *
1402 * Sets the DBS capability as per INI and firmware capability
1403 *
1404 * Return: None
1405 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001406static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301407{
1408 struct hdd_config *cfg_ini = hdd_ctx->config;
1409 uint8_t hw_dbs_capable = 0;
1410
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001411 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1412 ((cfg_ini->dual_mac_feature_disable ==
1413 ENABLE_DBS_CXN_AND_SCAN) ||
1414 (cfg_ini->dual_mac_feature_disable ==
1415 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301416 hw_dbs_capable = 1;
1417
1418 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1419}
1420
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001421static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001422 struct wma_tgt_ht_cap *cfg)
1423{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301424 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425 uint32_t value, val32;
1426 uint16_t val16;
1427 struct hdd_config *pconfig = hdd_ctx->config;
1428 tSirMacHTCapabilityInfo *phtCapInfo;
1429 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1430 uint8_t enable_tx_stbc;
1431
1432 /* check and update RX STBC */
1433 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1434 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1435
1436 /* get the MPDU density */
1437 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301439 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001440 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 value = 0;
1442 }
1443
1444 /*
1445 * MPDU density:
1446 * override user's setting if value is larger
1447 * than the one supported by target
1448 */
1449 if (value > cfg->mpdu_density) {
1450 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1451 cfg->mpdu_density);
1452
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301453 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001454 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455 }
1456
1457 /* get the HT capability info */
1458 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301459 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001460 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 return;
1462 }
1463 val16 = (uint16_t) val32;
1464 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1465
1466 /* Set the LDPC capability */
1467 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1468
1469 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1470 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1471
1472 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1473 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1474
1475 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1476 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1477
1478 enable_tx_stbc = pconfig->enableTxSTBC;
1479
1480 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1481 pconfig->enable2x2 = 1;
1482 } else {
1483 pconfig->enable2x2 = 0;
1484 enable_tx_stbc = 0;
1485
1486 /* 1x1 */
1487 /* Update Rx Highest Long GI data Rate */
1488 if (sme_cfg_set_int(hdd_ctx->hHal,
1489 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001490 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301491 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001492 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 }
1494
1495 /* Update Tx Highest Long GI data Rate */
1496 if (sme_cfg_set_int
1497 (hdd_ctx->hHal,
1498 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001499 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301500 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001501 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001502 }
1503 }
1504 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1505 enable_tx_stbc = 0;
1506 phtCapInfo->txSTBC = enable_tx_stbc;
1507
1508 val32 = val16;
1509 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301510 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001511 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1513 value = SIZE_OF_SUPPORTED_MCS_SET;
1514 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301515 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001516 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001517
1518 if (pconfig->enable2x2) {
1519 for (value = 0; value < cfg->num_rf_chains; value++)
1520 mcs_set[value] =
1521 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1522
1523 status =
1524 sme_cfg_set_str(hdd_ctx->hHal,
1525 WNI_CFG_SUPPORTED_MCS_SET,
1526 mcs_set,
1527 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301528 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001529 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 }
1531 }
1532#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1533}
1534
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001535static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 struct wma_tgt_vht_cap *cfg)
1537{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301538 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539 uint32_t value = 0;
1540 struct hdd_config *pconfig = hdd_ctx->config;
1541 struct wiphy *wiphy = hdd_ctx->wiphy;
1542 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001543 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001544 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001545 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001546 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547
Dustin Brown5e06bd32016-10-04 12:49:10 -07001548 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001549 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001550 return;
1551 }
1552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 /* Get the current MPDU length */
1554 status =
1555 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1556 &value);
1557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301558 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001559 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 value = 0;
1561 }
1562
1563 /*
1564 * VHT max MPDU length:
1565 * override if user configured value is too high
1566 * that the target cannot support
1567 */
1568 if (value > cfg->vht_max_mpdu) {
1569 status = sme_cfg_set_int(hdd_ctx->hHal,
1570 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1571 cfg->vht_max_mpdu);
1572
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001573 if (status == QDF_STATUS_E_FAILURE)
1574 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 }
1576
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001577 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1578 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1579
1580 if (pconfig->enable2x2)
1581 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1582
1583 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1584 QDF_STATUS_E_FAILURE) {
1585 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1586 }
1587
1588 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1589 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1590 if (pconfig->enable2x2)
1591 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1592
1593 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1594 QDF_STATUS_E_FAILURE) {
1595 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1596 }
1597
1598 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1599 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1600 if (pconfig->enable2x2)
1601 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1602
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001603 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001604 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1605
1606 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1607 QDF_STATUS_E_FAILURE) {
1608 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1609 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001611 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 &value);
1613
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301614 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001615 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 value = 0;
1617 }
1618
jiad4a7a33c2017-08-08 15:32:24 +08001619 /* Set HW RX LDPC capability */
1620 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1621 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 status = sme_cfg_set_int(hdd_ctx->hHal,
1623 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001624 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001626 if (status == QDF_STATUS_E_FAILURE)
1627 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 }
1629
1630 /* Get current GI 80 value */
1631 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1632 &value);
1633
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301634 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001635 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 value = 0;
1637 }
1638
1639 /* set the Guard interval 80MHz */
1640 if (value && !cfg->vht_short_gi_80) {
1641 status = sme_cfg_set_int(hdd_ctx->hHal,
1642 WNI_CFG_VHT_SHORT_GI_80MHZ,
1643 cfg->vht_short_gi_80);
1644
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001645 if (status == QDF_STATUS_E_FAILURE)
1646 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647 }
1648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 /* Get VHT TX STBC cap */
1650 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1651
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301652 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001653 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 value = 0;
1655 }
1656
1657 /* VHT TX STBC cap */
1658 if (value && !cfg->vht_tx_stbc) {
1659 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1660 cfg->vht_tx_stbc);
1661
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001662 if (status == QDF_STATUS_E_FAILURE)
1663 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 }
1665
1666 /* Get VHT RX STBC cap */
1667 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1668
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301669 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001670 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671 value = 0;
1672 }
1673
1674 /* VHT RX STBC cap */
1675 if (value && !cfg->vht_rx_stbc) {
1676 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1677 cfg->vht_rx_stbc);
1678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001679 if (status == QDF_STATUS_E_FAILURE)
1680 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681 }
1682
1683 /* Get VHT SU Beamformer cap */
1684 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1685 &value);
1686
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301687 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001688 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 value = 0;
1690 }
1691
1692 /* set VHT SU Beamformer cap */
1693 if (value && !cfg->vht_su_bformer) {
1694 status = sme_cfg_set_int(hdd_ctx->hHal,
1695 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1696 cfg->vht_su_bformer);
1697
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001698 if (status == QDF_STATUS_E_FAILURE)
1699 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 }
1701
1702 /* check and update SU BEAMFORMEE capabality */
1703 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1704 pconfig->enableTxBF = cfg->vht_su_bformee;
1705
1706 status = sme_cfg_set_int(hdd_ctx->hHal,
1707 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1708 pconfig->enableTxBF);
1709
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001710 if (status == QDF_STATUS_E_FAILURE)
1711 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001712
1713 /* Get VHT MU Beamformer cap */
1714 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1715 &value);
1716
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301717 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001718 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719 value = 0;
1720 }
1721
1722 /* set VHT MU Beamformer cap */
1723 if (value && !cfg->vht_mu_bformer) {
1724 status = sme_cfg_set_int(hdd_ctx->hHal,
1725 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1726 cfg->vht_mu_bformer);
1727
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001728 if (status == QDF_STATUS_E_FAILURE)
1729 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 }
1731
1732 /* Get VHT MU Beamformee cap */
1733 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1734 &value);
1735
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301736 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001737 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 value = 0;
1739 }
1740
1741 /* set VHT MU Beamformee cap */
1742 if (value && !cfg->vht_mu_bformee) {
1743 status = sme_cfg_set_int(hdd_ctx->hHal,
1744 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1745 cfg->vht_mu_bformee);
1746
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001747 if (status == QDF_STATUS_E_FAILURE)
1748 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749 }
1750
1751 /* Get VHT MAX AMPDU Len exp */
1752 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1753 &value);
1754
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301755 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001756 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 value = 0;
1758 }
1759
1760 /*
1761 * VHT max AMPDU len exp:
1762 * override if user configured value is too high
1763 * that the target cannot support.
1764 * Even though Rome publish ampdu_len=7, it can
1765 * only support 4 because of some h/w bug.
1766 */
1767
1768 if (value > cfg->vht_max_ampdu_len_exp) {
1769 status = sme_cfg_set_int(hdd_ctx->hHal,
1770 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1771 cfg->vht_max_ampdu_len_exp);
1772
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001773 if (status == QDF_STATUS_E_FAILURE)
1774 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775 }
1776
1777 /* Get VHT TXOP PS CAP */
1778 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1779
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301780 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001781 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782 value = 0;
1783 }
1784
1785 /* set VHT TXOP PS cap */
1786 if (value && !cfg->vht_txop_ps) {
1787 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1788 cfg->vht_txop_ps);
1789
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001790 if (status == QDF_STATUS_E_FAILURE)
1791 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001792 }
1793
1794 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1795 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1796 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1797 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1798 else
1799 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1800
1801
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001802 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1803 status = sme_cfg_set_int(hdd_ctx->hHal,
1804 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1805 VHT_CAP_160_AND_80P80_SUPP);
1806 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001807 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001808 band_5g->vht_cap.cap |=
1809 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001810 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1811 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1812 status = sme_cfg_set_int(hdd_ctx->hHal,
1813 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1814 VHT_CAP_160_SUPP);
1815 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001816 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001817 band_5g->vht_cap.cap |=
1818 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001819 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1820 }
1821 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1822 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301823 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001824 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301825 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001826 &value);
1827 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301828 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001829 value = 0;
1830 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301831 /* set the Guard interval 160MHz */
1832 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001833 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301834 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1835 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001836
1837 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301838 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001839 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840
1841 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1842 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1843
1844 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1845 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1846 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1847 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1848
1849 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1850 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1851
1852 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1853 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1854 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1855 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1856 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1857 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1858
1859 band_5g->vht_cap.cap |=
1860 (cfg->vht_max_ampdu_len_exp <<
1861 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1862
1863 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1864 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1865 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1866 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1867 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1868 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1869 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1870 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1871
1872 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1873 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1874
1875}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001877/**
1878 * hdd_generate_macaddr_auto() - Auto-generate mac address
1879 * @hdd_ctx: Pointer to the HDD context
1880 *
1881 * Auto-generate mac address using device serial number.
1882 * Keep the first 3 bytes of OUI as before and replace
1883 * the last 3 bytes with the lower 3 bytes of serial number.
1884 *
1885 * Return: 0 for success
1886 * Non zero failure code for errors
1887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001888static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001889{
1890 unsigned int serialno = 0;
1891 struct qdf_mac_addr mac_addr = {
1892 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1893 };
1894
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001895 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001896 if (serialno == 0)
1897 return -EINVAL;
1898
1899 serialno &= 0x00ffffff;
1900
1901 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1902 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1903 mac_addr.bytes[5] = serialno & 0xff;
1904
1905 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1906 return 0;
1907}
1908
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301909/**
1910 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1911 * configuration to cfg_ini in HDD
1912 * @hdd_ctx: Pointer to hdd_ctx
1913 * @cfg: target configuration
1914 *
1915 * Return: None
1916 */
1917#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001918static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301919 struct wma_tgt_cfg *cfg)
1920{
1921 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1922}
1923#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001924static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301925 struct wma_tgt_cfg *cfg)
1926{
1927}
1928#endif
1929
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001930static int hdd_green_ap_update_config(struct hdd_context *hdd_ctx)
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301931{
1932 struct green_ap_user_cfg green_ap_cfg;
1933 struct hdd_config *cfg = hdd_ctx->config;
1934 QDF_STATUS status;
1935
1936 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1937 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1938 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1939 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1940
1941 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1942 &green_ap_cfg);
1943 if (status != QDF_STATUS_SUCCESS) {
1944 hdd_err("failed to update green ap user configuration");
1945 return -EINVAL;
1946 }
1947
1948 return 0;
1949}
1950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951void hdd_update_tgt_cfg(void *context, void *param)
1952{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001953 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001954 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001955 struct wma_tgt_cfg *cfg = param;
1956 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001957 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301958 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001959 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301960
Dustin Brownbd68fe12017-11-21 15:28:52 -08001961 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1962 if (ret) {
1963 hdd_err("Failed to create pdev; errno:%d", ret);
1964 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001965 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001966 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001967 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001968 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1969 hdd_err("dispatcher pdev open failed");
1970 QDF_BUG(0);
1971 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301972 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001973
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001974 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301975
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301976 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1977 cds_get_context(QDF_MODULE_ID_SOC));
1978 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1979 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301980 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1981 hdd_softap_hard_start_xmit);
1982 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1983 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301984
Naveen Rawat64e477e2016-05-20 10:34:56 -07001985 if (cds_cfg) {
1986 if (hdd_ctx->config->enable_sub_20_channel_width !=
1987 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1988 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1989 cds_cfg->sub_20_channel_width =
1990 WLAN_SUB_20_CH_WIDTH_NONE;
1991 } else {
1992 cds_cfg->sub_20_channel_width =
1993 hdd_ctx->config->enable_sub_20_channel_width;
1994 }
1995 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996
1997 /* first store the INI band capability */
1998 temp_band_cap = hdd_ctx->config->nBandCapability;
1999
2000 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05302001 hdd_ctx->is_fils_roaming_supported =
2002 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05302004 hdd_ctx->config->is_11k_offload_supported =
2005 cfg->services.is_11k_offload_supported;
2006
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08002007 /*
2008 * now overwrite the target band capability with INI
2009 * setting if INI setting is a subset
2010 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002011
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08002012 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
2013 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002014 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08002015 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
2016 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07002018 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 }
2020
Amar Singhal58b45ef2017-08-01 13:43:54 -07002021 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
2022
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302023 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 hdd_ctx->reg.reg_domain = cfg->reg_domain;
2025 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
2026 }
2027
2028 /* This can be extended to other configurations like ht, vht cap... */
2029
Anurag Chouhanc5548422016-02-24 18:33:27 +05302030 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002032 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07002034 static struct qdf_mac_addr default_mac_addr = {
2035 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
2036 };
2037 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
2038 &default_mac_addr)) {
2039 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
2040 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
2041 MAC_ADDRESS_STR,
2042 MAC_ADDR_ARRAY(hdd_ctx->config->
2043 intfMacAddr[0].bytes));
2044 } else {
2045 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2046 MAC_ADDRESS_STR,
2047 MAC_ADDR_ARRAY(hdd_ctx->config->
2048 intfMacAddr[0].bytes));
2049 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002050 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051 }
2052
2053 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002054 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002055
2056 hdd_ctx->max_intf_count = cfg->max_intf_count;
2057
Jeff Johnsonc875e242016-09-23 18:12:34 -07002058 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002060 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2061 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2062
2063 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002066 if (cfg->services.en_11ax) {
2067 hdd_info("11AX: 11ax is enabled - update HDD config");
2068 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2069 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002070
2071 hdd_update_vdev_nss(hdd_ctx);
2072
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302073 hdd_update_hw_dbs_capable(hdd_ctx);
2074
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002075 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002076 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002077 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002078 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002079
Nitesh Shahe50711f2017-04-26 16:30:45 +05302080 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2081 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2082 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002083 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002084 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002085
Rajeev Kumardd3bc602016-08-16 14:21:05 -07002086 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
2087 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302088 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302089 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302090
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302091 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002092 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2093 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302094 hdd_ctx->config->txBFCsnValue =
2095 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2096
Arif Hussainee10f902017-12-27 16:30:17 -08002097 status = sme_cfg_set_int(hdd_ctx->hHal,
2098 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2099 hdd_ctx->config->txBFCsnValue);
2100 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302101 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2102
2103
2104 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002105 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2106 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302107
2108 /*
2109 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2110 */
2111 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302112
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302113 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2114
Yue Macd359b72017-10-03 15:21:00 -07002115 /*
2116 * This needs to be done after HDD pdev is created and stored since
2117 * it will access the HDD pdev object lock.
2118 */
2119 hdd_runtime_suspend_context_init(hdd_ctx);
2120
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002121 /* Configure NAN datapath features */
2122 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002123 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002124 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002125 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2126 cfg->obss_detection_offloaded);
2127 if (QDF_IS_STATUS_ERROR(status))
2128 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002129
2130 status = sme_cfg_set_int(hdd_ctx->hHal,
2131 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2132 cfg->obss_color_collision_offloaded);
2133 if (QDF_IS_STATUS_ERROR(status))
2134 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135}
2136
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002137bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138{
Jeff Johnson9d295242017-08-29 14:39:48 -07002139 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002140 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002141
Jiachao Wuf610d912018-01-23 17:47:32 +08002142 if (!hdd_ctx) {
2143 hdd_info("Couldn't get hdd_ctx");
2144 return true;
2145 }
2146
2147 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002148 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002149 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302150 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002151 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152
Dustin Brown920397d2017-12-13 16:27:50 -08002153 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002154 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2155
2156 if ((QDF_SAP_MODE == adapter->device_mode ||
2157 QDF_P2P_GO_MODE == adapter->device_mode) &&
2158 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002159 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002160 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2161 true;
2162 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002163 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302164 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002165 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302166
2167 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002168}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169
2170/**
2171 * hdd_is_valid_mac_address() - validate MAC address
2172 * @pMacAddr: Pointer to the input MAC address
2173 *
2174 * This function validates whether the given MAC address is valid or not
2175 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2176 * where X is the hexa decimal digit character and separated by ':'
2177 * This algorithm works even if MAC address is not separated by ':'
2178 *
2179 * This code checks given input string mac contains exactly 12 hexadecimal
2180 * digits and a separator colon : appears in the input string only after
2181 * an even number of hex digits.
2182 *
2183 * Return: 1 for valid and 0 for invalid
2184 */
2185bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2186{
2187 int xdigit = 0;
2188 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002190 while (*pMacAddr) {
2191 if (isxdigit(*pMacAddr)) {
2192 xdigit++;
2193 } else if (':' == *pMacAddr) {
2194 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2195 break;
2196
2197 ++separator;
2198 } else {
2199 /* Invalid MAC found */
2200 return 0;
2201 }
2202 ++pMacAddr;
2203 }
2204 return xdigit == 12 && (separator == 5 || separator == 0);
2205}
2206
2207/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302208 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2209 * @dev: Handle to struct net_device to be updated.
2210 *
2211 * Return: None
2212 */
2213static void hdd_mon_mode_ether_setup(struct net_device *dev)
2214{
2215 dev->header_ops = NULL;
2216 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2217 dev->hard_header_len = ETH_HLEN;
2218 dev->mtu = ETH_DATA_LEN;
2219 dev->addr_len = ETH_ALEN;
2220 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2221 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2222 dev->priv_flags |= IFF_TX_SKB_SHARING;
2223
2224 memset(dev->broadcast, 0xFF, ETH_ALEN);
2225}
2226
2227/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002228 * __hdd__mon_open() - HDD Open function
2229 * @dev: Pointer to net_device structure
2230 *
2231 * This is called in response to ifconfig up
2232 *
2233 * Return: 0 for success; non-zero for failure
2234 */
2235static int __hdd_mon_open(struct net_device *dev)
2236{
2237 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002238 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2239 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002240
Dustin Brownfdf17c12018-03-14 12:55:34 -07002241 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002242
2243 ret = wlan_hdd_validate_context(hdd_ctx);
2244 if (ret)
2245 return ret;
2246
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302247 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002248
2249 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2250 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2251 if (ret) {
2252 hdd_err("Failed to start WLAN modules return");
2253 return ret;
2254 }
2255 hdd_err("hdd_wlan_start_modules() successful !");
2256
2257 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2258 ret = hdd_start_adapter(adapter);
2259 if (ret) {
2260 hdd_err("Failed to start adapter :%d",
2261 adapter->device_mode);
2262 return ret;
2263 }
2264 hdd_err("hdd_start_adapters() successful !");
2265 }
2266 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2267 }
2268
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002269 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002270
2271 if (!ret)
2272 ret = hdd_enable_monitor_mode(dev);
2273
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002274 return ret;
2275}
2276
2277/**
2278 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2279 * @dev: Pointer to net_device structure
2280 *
2281 * This is called in response to ifconfig up
2282 *
2283 * Return: 0 for success; non-zero for failure
2284 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002285static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002286{
2287 int ret;
2288
2289 cds_ssr_protect(__func__);
2290 ret = __hdd_mon_open(dev);
2291 cds_ssr_unprotect(__func__);
2292
2293 return ret;
2294}
2295
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002296static QDF_STATUS
2297wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2298{
2299 struct policy_mgr_dual_mac_config cfg = {0};
2300 QDF_STATUS status;
2301 uint32_t channel_select_logic_conc;
2302 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2303
2304 if (!hdd_ctx) {
2305 hdd_err("HDD context is NULL");
2306 return QDF_STATUS_E_FAILURE;
2307 }
2308
2309
2310 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2311 return QDF_STATUS_SUCCESS;
2312
2313 cfg.scan_config = 0;
2314 cfg.fw_mode_config = 0;
2315 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2316
2317 channel_select_logic_conc = hdd_ctx->config->
2318 channel_select_logic_conc;
2319
2320 if (hdd_ctx->config->dual_mac_feature_disable !=
2321 DISABLE_DBS_CXN_AND_SCAN) {
2322 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2323 hdd_ctx->hdd_psoc, &cfg.scan_config,
2324 &cfg.fw_mode_config,
2325 hdd_ctx->config->dual_mac_feature_disable,
2326 channel_select_logic_conc);
2327
2328 if (status != QDF_STATUS_SUCCESS) {
2329 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2330 status);
2331 return status;
2332 }
2333 }
2334
2335 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2336 cfg.scan_config, cfg.fw_mode_config);
2337
2338 status = sme_soc_set_dual_mac_config(cfg);
2339 if (status != QDF_STATUS_SUCCESS) {
2340 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2341 return status;
2342 }
2343
2344 return QDF_STATUS_SUCCESS;
2345}
2346
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002347/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 * hdd_start_adapter() - Wrapper function for device specific adapter
2349 * @adapter: pointer to HDD adapter
2350 *
2351 * This function is called to start the device specific adapter for
2352 * the mode passed in the adapter's device_mode.
2353 *
2354 * Return: 0 for success; non-zero for failure
2355 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002356int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302357{
2358
2359 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002360 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302361
Dustin Brownfdf17c12018-03-14 12:55:34 -07002362 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002363 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302364
2365 switch (device_mode) {
2366 case QDF_P2P_CLIENT_MODE:
2367 case QDF_P2P_DEVICE_MODE:
2368 case QDF_OCB_MODE:
2369 case QDF_STA_MODE:
2370 case QDF_MONITOR_MODE:
2371 ret = hdd_start_station_adapter(adapter);
2372 if (ret)
2373 goto err_start_adapter;
2374 break;
2375 case QDF_P2P_GO_MODE:
2376 case QDF_SAP_MODE:
2377 ret = hdd_start_ap_adapter(adapter);
2378 if (ret)
2379 goto err_start_adapter;
2380 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302381 case QDF_IBSS_MODE:
2382 /*
2383 * For IBSS interface is initialized as part of
2384 * hdd_init_station_mode()
2385 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002386 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302387 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002388 /* vdevs are dynamically managed by firmware in FTM */
2389 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302390 default:
2391 hdd_err("Invalid session type %d", device_mode);
2392 QDF_ASSERT(0);
2393 goto err_start_adapter;
2394 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002395
Arun Khandavallifae92942016-08-01 13:31:08 +05302396 if (hdd_set_fw_params(adapter))
2397 hdd_err("Failed to set the FW params for the adapter!");
2398
2399 /*
2400 * Action frame registered in one adapter which will
2401 * applicable to all interfaces
2402 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302403 ret = wlan_hdd_cfg80211_register_frames(adapter);
2404 if (ret < 0) {
2405 hdd_err("Failed to register frames - ret %d", ret);
2406 goto err_start_adapter;
2407 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002408 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302409
Dustin Browndb2a8be2017-12-20 11:49:56 -08002410exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002411 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002412
Arun Khandavallifae92942016-08-01 13:31:08 +05302413 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002414
Arun Khandavallifae92942016-08-01 13:31:08 +05302415err_start_adapter:
2416 return -EINVAL;
2417}
2418
2419/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302420 * hdd_enable_power_management() - API to Enable Power Management
2421 *
2422 * API invokes Bus Interface Layer power management functionality
2423 *
2424 * Return: None
2425 */
2426static void hdd_enable_power_management(void)
2427{
2428 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2429
2430 if (!hif_ctx) {
2431 hdd_err("Bus Interface Context is Invalid");
2432 return;
2433 }
2434
2435 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2436}
2437
2438/**
2439 * hdd_disable_power_management() - API to disable Power Management
2440 *
2441 * API disable Bus Interface Layer Power management functionality
2442 *
2443 * Return: None
2444 */
2445static void hdd_disable_power_management(void)
2446{
2447 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2448
2449 if (!hif_ctx) {
2450 hdd_err("Bus Interface Context is Invalid");
2451 return;
2452 }
2453
2454 hif_disable_power_management(hif_ctx);
2455}
2456
2457/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302458 * hdd_update_hw_sw_info() - API to update the HW/SW information
2459 *
2460 * API to update the HW and SW information in the driver
2461 *
2462 * Return: None
2463 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002464static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302465{
2466 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002467 size_t target_hw_name_len;
2468 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302469
2470 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2471 if (!hif_sc) {
2472 hdd_err("HIF context is NULL");
2473 return;
2474 }
2475
2476 /*
2477 * target hw version/revision would only be retrieved after firmware
2478 * download
2479 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002480 hif_get_hw_info(hif_sc,
2481 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302482 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002483 &target_hw_name);
2484
2485 if (hdd_ctx->target_hw_name)
2486 qdf_mem_free(hdd_ctx->target_hw_name);
2487
2488 target_hw_name_len = strlen(target_hw_name) + 1;
2489 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2490 if (hdd_ctx->target_hw_name)
2491 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2492 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302493
2494 /* Get the wlan hw/fw version */
2495 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302496}
2497
2498/**
gbian62edd7e2017-03-07 13:12:13 +08002499 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2500 * @hdd_ctx: Pointer to hdd context
2501 *
2502 * Return: none
2503 */
2504static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002505hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002506{
2507 uint8_t num_entries = 0;
2508 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2509 uint8_t *tx_sched_wrr_ac;
2510 int i;
2511 cds_context_type *cds_ctx;
2512
2513 if (NULL == hdd_ctx)
2514 return;
2515
2516 if (NULL == hdd_ctx->config) {
2517 /* Do nothing if hdd_ctx is invalid */
2518 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2519 return;
2520 }
2521
2522 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2523
2524 if (!cds_ctx) {
2525 hdd_err("Invalid CDS Context");
2526 return;
2527 }
2528
2529 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2530 switch (i) {
2531 case OL_TX_WMM_AC_BE:
2532 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2533 break;
2534 case OL_TX_WMM_AC_BK:
2535 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2536 break;
2537 case OL_TX_WMM_AC_VI:
2538 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2539 break;
2540 case OL_TX_WMM_AC_VO:
2541 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2542 break;
2543 default:
2544 tx_sched_wrr_ac = NULL;
2545 break;
2546 }
2547
2548 hdd_string_to_u8_array(tx_sched_wrr_ac,
2549 tx_sched_wrr_param,
2550 &num_entries,
2551 sizeof(tx_sched_wrr_param));
2552
2553 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2554 cds_ctx->ac_specs[i].wrr_skip_weight =
2555 tx_sched_wrr_param[0];
2556 cds_ctx->ac_specs[i].credit_threshold =
2557 tx_sched_wrr_param[1];
2558 cds_ctx->ac_specs[i].send_limit =
2559 tx_sched_wrr_param[2];
2560 cds_ctx->ac_specs[i].credit_reserve =
2561 tx_sched_wrr_param[3];
2562 cds_ctx->ac_specs[i].discard_weight =
2563 tx_sched_wrr_param[4];
2564 }
2565
2566 num_entries = 0;
2567 }
2568}
2569
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302570#ifdef IPA_OFFLOAD
2571/**
2572 * hdd_update_ipa_component_config() - update ipa config
2573 * @hdd_ctx: Pointer to hdd context
2574 *
2575 * Return: none
2576 */
2577static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2578{
2579 struct hdd_config *cfg = hdd_ctx->config;
2580 struct wlan_ipa_config ipa_cfg;
2581
2582 ipa_cfg.ipa_config = cfg->IpaConfig;
2583 ipa_cfg.desc_size = cfg->IpaDescSize;
2584 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2585 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2586 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2587 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2588 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2589 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2590 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2591
2592 ucfg_ipa_update_config(&ipa_cfg);
2593}
2594#else
2595static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2596{
2597}
2598#endif
2599
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002600#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002601static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2602 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2603{
Jeff Johnson9d295242017-08-29 14:39:48 -07002604 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002605 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002606
2607 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2608 if (!adapter) {
2609 hdd_err("Adapter is NULL");
2610 return PM_MAX_NUM_OF_MODE;
2611 }
2612
2613 return policy_mgr_convert_device_mode_to_qdf_type(
2614 adapter->device_mode);
2615}
2616
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002617static void hdd_register_policy_manager_callback(
2618 struct wlan_objmgr_psoc *psoc)
2619{
2620 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002621
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002622 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002623 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002624 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2625 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002626 hdd_cbacks.get_mode_for_non_connected_vdev =
2627 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302628 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002629
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002630 if (QDF_STATUS_SUCCESS !=
2631 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2632 hdd_err("HDD callback registration with policy manager failed");
2633 }
2634}
2635#else
2636static void hdd_register_policy_manager_callback(
2637 struct wlan_objmgr_psoc *psoc)
2638{
2639}
2640#endif
2641
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002642static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002643{
2644 struct nan_callbacks cb_obj = {0};
2645
2646 cb_obj.ndi_open = hdd_ndi_open;
2647 cb_obj.ndi_close = hdd_ndi_close;
2648 cb_obj.ndi_start = hdd_ndi_start;
2649 cb_obj.ndi_delete = hdd_ndi_delete;
2650 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2651 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2652
Naveen Rawat37f62c82017-03-26 22:24:43 -07002653 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2654 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002655 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002656
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002657 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2658}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002659
Dustin Brown26b3d042017-12-21 11:13:27 -08002660#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002661/**
2662 * hdd_check_for_leaks() - Perform runtime memory leak checks
2663 *
2664 * This API triggers runtime memory leak detection. This feature enforces the
2665 * policy that any memory allocated at runtime must also be released at runtime.
2666 *
2667 * Allocating memory at runtime and releasing it at unload is effectively a
2668 * memory leak for configurations which never unload (e.g. LONU, statically
2669 * compiled driver). Such memory leaks are NOT false positives, and must be
2670 * fixed.
2671 *
2672 * Return: None
2673 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002674static void hdd_check_for_leaks(void)
2675{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002676 /* DO NOT REMOVE these checks; for false positives, read above first */
2677
Dustin Brown677e0862017-10-10 16:30:09 -07002678 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002679 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002680 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002681}
2682
Dustin Brown26b3d042017-12-21 11:13:27 -08002683#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2684#else
2685static inline void hdd_check_for_leaks(void) {}
2686
2687#define hdd_debug_domain_set(domain)
2688#endif /* CONFIG_LEAK_DETECTION */
2689
gbian62edd7e2017-03-07 13:12:13 +08002690/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002691 * hdd_update_country_code - Update country code
2692 * @hdd_ctx: HDD context
2693 *
2694 * Update country code based on module parameter country_code
2695 *
2696 * Return: 0 on success and errno on failure
2697 */
2698static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2699{
2700 if (!country_code)
2701 return 0;
2702
2703 return hdd_reg_set_country(hdd_ctx, country_code);
2704}
2705
2706/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302707 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2708 * @hdd_ctx: HDD context
2709 * @adapter: HDD adapter
2710 * @reinit: flag to indicate from SSR or normal path
2711 *
2712 * This function maintains the driver state machine it will be invoked from
2713 * startup, reinit and change interface. Depending on the driver state shall
2714 * perform the opening of the modules.
2715 *
2716 * Return: 0 for success; non-zero for failure
2717 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002718int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2719 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302720 bool reinit)
2721{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002722 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302723 qdf_device_t qdf_dev;
2724 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302725 bool unint = false;
2726 void *hif_ctx;
2727
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002728 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302729
2730 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2731 if (!qdf_dev) {
2732 hdd_err("QDF Device Context is Invalid return");
2733 return -EINVAL;
2734 }
2735
Dustin Brown6f427922017-09-19 12:19:00 -07002736 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302737
Dustin Brown1fe30a82017-10-03 16:13:36 -07002738 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302739 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2740 mutex_unlock(&hdd_ctx->iface_change_lock);
2741 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002742 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302743 return 0;
2744 }
2745
Dustin Brown1fe30a82017-10-03 16:13:36 -07002746 hdd_ctx->start_modules_in_progress = true;
2747
Arun Khandavallifae92942016-08-01 13:31:08 +05302748 switch (hdd_ctx->driver_status) {
2749 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002750 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302751 unint = true;
2752 /* Fall through dont add break here */
2753 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002754 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2755
Dustin Brown26b3d042017-12-21 11:13:27 -08002756 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002757
Arun Khandavallifae92942016-08-01 13:31:08 +05302758 if (!reinit && !unint) {
2759 ret = pld_power_on(qdf_dev->dev);
2760 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002761 hdd_err("Failed to Powerup the device; errno: %d",
2762 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302763 goto release_lock;
2764 }
2765 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002766
2767 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2768 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302769 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2770 qdf_dev->bus_type,
2771 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2772 HIF_ENABLE_TYPE_PROBE);
2773 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002774 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302775 goto power_down;
2776 }
2777
2778 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302779 if (!hif_ctx) {
2780 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002781 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302782 goto power_down;
2783 }
2784
Arun Khandavallifae92942016-08-01 13:31:08 +05302785 status = ol_cds_init(qdf_dev, hif_ctx);
2786 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002787 hdd_err("No Memory to Create BMI Context; status: %d",
2788 status);
2789 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302790 goto hif_close;
2791 }
2792
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302793 hdd_update_ipa_component_config(hdd_ctx);
2794
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002795 ret = hdd_update_config(hdd_ctx);
2796 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002797 hdd_err("Failed to update configuration; errno: %d",
2798 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002799 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002800 }
2801
gbian62edd7e2017-03-07 13:12:13 +08002802 hdd_update_cds_ac_specs_params(hdd_ctx);
2803
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302804 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002805 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002806 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002807 ret = qdf_status_to_os_return(status);
2808 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302809 }
2810
Mukul Sharma9d797a02017-01-05 20:26:03 +05302811 /* initalize components configurations after psoc open */
2812 ret = hdd_update_components_config(hdd_ctx);
2813 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002814 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302815 ret);
2816 goto close;
2817 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002818 status = cds_dp_open(hdd_ctx->hdd_psoc);
2819 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002820 hdd_err("Failed to Open cds post open; status: %d",
2821 status);
2822 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002823 goto close;
2824 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302825
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002826 /*
2827 * NAN compoenet requires certian operations like, open adapter,
2828 * close adapter, etc. to be initiated by HDD, for those
2829 * register HDD callbacks with UMAC's NAN componenet.
2830 */
2831 hdd_nan_register_callbacks(hdd_ctx);
2832
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2834
Jeff Johnson3a280122017-09-13 07:42:00 -07002835 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302836 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002837 hdd_err("Failed to pre-enable CDS; status: %d", status);
2838 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002839 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302840 }
2841
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002842 hdd_register_policy_manager_callback(
2843 hdd_ctx->hdd_psoc);
2844
Amar Singhal0928b192017-12-01 10:50:54 -08002845 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2846
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302847 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302848 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002849 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302850
Arun Khandavallifae92942016-08-01 13:31:08 +05302851 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002852 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302853 break;
2854 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302855
Arun Khandavallifae92942016-08-01 13:31:08 +05302856 /* Fall through dont add break here */
2857 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002858 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2859
Arun Khandavallifae92942016-08-01 13:31:08 +05302860 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002861 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002862 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002863 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302864 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302865 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2866 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002867 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302868 break;
2869 }
Dustin Browndca39692017-11-09 15:30:25 -08002870
2871 ret = hdd_configure_cds(hdd_ctx, adapter);
2872 if (ret) {
2873 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002874 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302875 }
Dustin Browndca39692017-11-09 15:30:25 -08002876
Komal Seelamf2136bb2016-09-28 18:30:44 +05302877 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002878
Arun Khandavallifae92942016-08-01 13:31:08 +05302879 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002880 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302881 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002882
Arun Khandavallifae92942016-08-01 13:31:08 +05302883 default:
2884 hdd_err("WLAN start invoked in wrong state! :%d\n",
2885 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002886 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302887 goto release_lock;
2888 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002889
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302890 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002891 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2892 ret = hdd_update_country_code(hdd_ctx);
2893 if (ret)
2894 hdd_err("Failed to update command line country code!");
2895 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302896 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002897
Dustin Browne74003f2018-03-14 12:51:58 -07002898 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002899
Arun Khandavallifae92942016-08-01 13:31:08 +05302900 return 0;
2901
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002902post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002903 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002904 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002905 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002906
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002907cds_txrx_free:
2908 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002909
Arun Khandavallifae92942016-08-01 13:31:08 +05302910close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002911 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002912 hdd_info("Wlan transition aborted (now CLOSED)");
2913
Jeff Johnsone4b14592017-09-13 14:23:33 -07002914 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302915
Dustin Brown28b17892017-10-10 13:29:38 -07002916deinit_config:
2917 cds_deinit_ini_config();
2918
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002919cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302920 ol_cds_free();
2921
2922hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002923 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2924 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302925power_down:
2926 if (!reinit && !unint)
2927 pld_power_off(qdf_dev->dev);
2928release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302929 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302930 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002931
2932 /* many adapter resources are not freed by design in SSR case */
2933 if (!reinit)
2934 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002935 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002936
Dustin Browne74003f2018-03-14 12:51:58 -07002937 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002938
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002939 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302940}
2941
Naveen Rawat910726a2017-03-06 11:42:51 -08002942#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002943static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002944{
2945 int ret = os_if_wifi_pos_register_nl();
2946
2947 if (ret)
2948 hdd_err("os_if_wifi_pos_register_nl failed");
2949
2950 return ret;
2951}
2952
2953static int hdd_deactivate_wifi_pos(void)
2954{
2955 int ret = os_if_wifi_pos_deregister_nl();
2956
2957 if (ret)
2958 hdd_err("os_if_wifi_pos_deregister_nl failed");
2959
2960 return ret;
2961}
2962
2963/**
2964 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2965 * @hdd_ctx: hdd context
2966 *
2967 * Return: status of operation
2968 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002969static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002970{
2971 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2972 struct hdd_config *cfg = hdd_ctx->config;
2973
2974 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2975 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2976 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2977 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2978 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2979 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2980 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2981 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2982}
2983#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002984static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002985{
2986 return oem_activate_service(hdd_ctx);
2987}
2988
2989static int hdd_deactivate_wifi_pos(void)
2990{
2991 return 0;
2992}
2993
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002994static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002995{
2996}
2997#endif
2998
Arun Khandavallifae92942016-08-01 13:31:08 +05302999/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003000 * __hdd_open() - HDD Open function
3001 * @dev: Pointer to net_device structure
3002 *
3003 * This is called in response to ifconfig up
3004 *
3005 * Return: 0 for success; non-zero for failure
3006 */
3007static int __hdd_open(struct net_device *dev)
3008{
Jeff Johnson9d295242017-08-29 14:39:48 -07003009 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003010 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 int ret;
3012
Dustin Brownfdf17c12018-03-14 12:55:34 -07003013 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303014 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003015 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303017 /* Nothing to be done if device is unloading */
3018 if (cds_is_driver_unloading()) {
3019 hdd_err("Driver is unloading can not open the hdd");
3020 return -EBUSY;
3021 }
3022
Dustin Brown01847752017-10-25 13:56:27 -07003023 if (cds_is_driver_recovering()) {
3024 hdd_err("WLAN is currently recovering; Please try again.");
3025 return -EBUSY;
3026 }
3027
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303028 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3029 hdd_err("con_mode_handler is in progress; Please try again.");
3030 return -EBUSY;
3031 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303032
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303033 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303034 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3035
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303036 /*
3037 * This scenario can be hit in cases where in the wlan driver after
3038 * registering the netdevices and there is a failure in driver
3039 * initialization. So return error gracefully because the netdevices
3040 * will be de-registered as part of the load failure.
3041 */
3042
3043 if (!cds_is_driver_loaded()) {
3044 hdd_err("Failed to start the wlan driver!!");
3045 ret = -EIO;
3046 goto err_hdd_hdd_init_deinit_lock;
3047 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049
Arun Khandavallifae92942016-08-01 13:31:08 +05303050 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
3051 if (ret) {
3052 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303053 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303054 }
3055
3056
3057 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3058 ret = hdd_start_adapter(adapter);
3059 if (ret) {
3060 hdd_err("Failed to start adapter :%d",
3061 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303062 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303063 }
3064 }
3065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003066 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3067 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003068 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003069 /* Enable TX queues only when we are connected */
3070 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303071 WLAN_START_ALL_NETIF_QUEUE,
3072 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 }
3074
Naveen Rawat286def52016-09-23 15:38:02 -07003075 /* Enable carrier and transmit queues for NDI */
3076 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003077 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003078 wlan_hdd_netif_queue_control(adapter,
3079 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3080 WLAN_CONTROL_PATH);
3081 }
3082
Naveen Rawat910726a2017-03-06 11:42:51 -08003083 hdd_populate_wifi_pos_cfg(hdd_ctx);
3084
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303085err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303086 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303087 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003088 return ret;
3089}
3090
Arun Khandavallifae92942016-08-01 13:31:08 +05303091
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003092/**
3093 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3094 * @dev: Pointer to net_device structure
3095 *
3096 * This is called in response to ifconfig up
3097 *
3098 * Return: 0 for success; non-zero for failure
3099 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003100static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101{
3102 int ret;
3103
3104 cds_ssr_protect(__func__);
3105 ret = __hdd_open(dev);
3106 cds_ssr_unprotect(__func__);
3107
3108 return ret;
3109}
3110
3111/**
3112 * __hdd_stop() - HDD stop function
3113 * @dev: Pointer to net_device structure
3114 *
3115 * This is called in response to ifconfig down
3116 *
3117 * Return: 0 for success; non-zero for failure
3118 */
3119static int __hdd_stop(struct net_device *dev)
3120{
Jeff Johnson9d295242017-08-29 14:39:48 -07003121 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003122 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123 int ret;
3124
Dustin Brownfdf17c12018-03-14 12:55:34 -07003125 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303127 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003128 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129
3130 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303131 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133
3134 /* Nothing to be done if the interface is not opened */
3135 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003136 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 return -ENODEV;
3138 }
3139
3140 /* Make sure the interface is marked as closed */
3141 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303142
3143 hdd_debug("Disabling Auto Power save timer");
3144 sme_ps_disable_auto_ps_timer(
3145 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003146 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303147
3148 /*
3149 * Disable TX on the interface, after this hard_start_xmit() will not
3150 * be called on that interface
3151 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003152 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003153 hdd_device_mode_to_string(adapter->device_mode),
3154 adapter->device_mode);
3155
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303156 wlan_hdd_netif_queue_control(adapter,
3157 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3158 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159
3160 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003161 * NAN data interface is different in some sense. The traffic on NDI is
3162 * bursty in nature and depends on the need to transfer. The service
3163 * layer may down the interface after the usage and up again when
3164 * required. In some sense, the NDI is expected to be available
3165 * (like SAP) iface until NDI delete request is issued by the service
3166 * layer. Skip BSS termination and adapter deletion for NAN Data
3167 * interface (NDI).
3168 */
3169 if (WLAN_HDD_IS_NDI(adapter))
3170 return 0;
3171
3172 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173 * The interface is marked as down for outside world (aka kernel)
3174 * But the driver is pretty much alive inside. The driver needs to
3175 * tear down the existing connection on the netdev (session)
3176 * cleanup the data pipes and wait until the control plane is stabilized
3177 * for this interface. The call also needs to wait until the above
3178 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003179 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180 * That is intentional to be able to scan if it is a STA/P2P interface
3181 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003182 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183
3184 /* DeInit the adapter. This ensures datapath cleanup as well */
3185 hdd_deinit_adapter(hdd_ctx, adapter, true);
3186
Arun Khandavallifae92942016-08-01 13:31:08 +05303187
3188 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303189 * Upon wifi turn off, DUT has to flush the scan results so if
3190 * this is the last cli iface, flush the scan database.
3191 */
3192 if (!hdd_is_cli_iface_up(hdd_ctx))
3193 sme_scan_flush_result(hdd_ctx->hHal);
3194
3195 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303196 * Find if any iface is up. If any iface is up then can't put device to
3197 * sleep/power save mode
3198 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303199 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003200 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003201 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3202 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303203 hdd_prevent_suspend_timeout(
3204 hdd_ctx->config->iface_change_wait_time,
3205 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303206 }
3207
Dustin Browne74003f2018-03-14 12:51:58 -07003208 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209 return 0;
3210}
3211
3212/**
3213 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3214 * @dev: pointer to net_device structure
3215 *
3216 * This is called in response to ifconfig down
3217 *
3218 * Return: 0 for success and error number for failure
3219 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003220static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003221{
3222 int ret;
3223
3224 cds_ssr_protect(__func__);
3225 ret = __hdd_stop(dev);
3226 cds_ssr_unprotect(__func__);
3227
3228 return ret;
3229}
3230
3231/**
3232 * __hdd_uninit() - HDD uninit function
3233 * @dev: Pointer to net_device structure
3234 *
3235 * This is called during the netdev unregister to uninitialize all data
3236 * associated with the device
3237 *
3238 * Return: None
3239 */
3240static void __hdd_uninit(struct net_device *dev)
3241{
Jeff Johnson9d295242017-08-29 14:39:48 -07003242 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003243 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244
Dustin Brownfdf17c12018-03-14 12:55:34 -07003245 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246
3247 do {
3248 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003249 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 break;
3251 }
3252
Jeff Johnson399c6272017-08-30 10:51:00 -07003253 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3254 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003255 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256 break;
3257 }
3258
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003259 if (dev != adapter->dev)
3260 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261
Jeff Johnson399c6272017-08-30 10:51:00 -07003262 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
3264 /* after uninit our adapter structure will no longer be valid */
3265 adapter->dev = NULL;
3266 adapter->magic = 0;
3267 } while (0);
3268
Dustin Browne74003f2018-03-14 12:51:58 -07003269 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270}
3271
3272/**
3273 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3274 * @dev: pointer to net_device structure
3275 *
3276 * This is called during the netdev unregister to uninitialize all data
3277 * associated with the device
3278 *
3279 * Return: none
3280 */
3281static void hdd_uninit(struct net_device *dev)
3282{
3283 cds_ssr_protect(__func__);
3284 __hdd_uninit(dev);
3285 cds_ssr_unprotect(__func__);
3286}
3287
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003288static int hdd_open_cesium_nl_sock(void)
3289{
3290#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3291 struct netlink_kernel_cfg cfg = {
3292 .groups = WLAN_NLINK_MCAST_GRP_ID,
3293 .input = NULL
3294 };
3295#endif
3296 int ret = 0;
3297
3298#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3299 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3300#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3301 THIS_MODULE,
3302#endif
3303 &cfg);
3304#else
3305 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3306 WLAN_NLINK_MCAST_GRP_ID,
3307 NULL, NULL, THIS_MODULE);
3308#endif
3309
3310 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003311 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003312 ret = -ECONNREFUSED;
3313 }
3314
3315 return ret;
3316}
3317
3318static void hdd_close_cesium_nl_sock(void)
3319{
3320 if (NULL != cesium_nl_srv_sock) {
3321 netlink_kernel_release(cesium_nl_srv_sock);
3322 cesium_nl_srv_sock = NULL;
3323 }
3324}
3325
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326/**
3327 * __hdd_set_mac_address() - set the user specified mac address
3328 * @dev: Pointer to the net device.
3329 * @addr: Pointer to the sockaddr.
3330 *
3331 * This function sets the user specified mac address using
3332 * the command ifconfig wlanX hw ether <mac adress>.
3333 *
3334 * Return: 0 for success, non zero for failure
3335 */
3336static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3337{
Jeff Johnson9d295242017-08-29 14:39:48 -07003338 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003339 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303341 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303343 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344
Dustin Brownfdf17c12018-03-14 12:55:34 -07003345 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303347 if (netif_running(dev)) {
3348 hdd_err("On iface up, set mac address change isn't supported");
3349 return -EBUSY;
3350 }
3351
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3353 ret = wlan_hdd_validate_context(hdd_ctx);
3354 if (0 != ret)
3355 return ret;
3356
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303357 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3358
3359 if (qdf_is_macaddr_zero(&mac_addr)) {
3360 hdd_err("MAC is all zero");
3361 return -EINVAL;
3362 }
3363
3364 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3365 hdd_err("MAC is Broadcast");
3366 return -EINVAL;
3367 }
3368
3369 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3370 hdd_err("MAC is Multicast");
3371 return -EINVAL;
3372 }
3373
Jeff Johnson1e851a12017-10-28 14:36:12 -07003374 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3376
Dustin Browne74003f2018-03-14 12:51:58 -07003377 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303378 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379}
3380
3381/**
3382 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3383 * function from SSR
3384 * @dev: pointer to net_device structure
3385 * @addr: Pointer to the sockaddr
3386 *
3387 * This function sets the user specified mac address using
3388 * the command ifconfig wlanX hw ether <mac adress>.
3389 *
3390 * Return: 0 for success.
3391 */
3392static int hdd_set_mac_address(struct net_device *dev, void *addr)
3393{
3394 int ret;
3395
3396 cds_ssr_protect(__func__);
3397 ret = __hdd_set_mac_address(dev, addr);
3398 cds_ssr_unprotect(__func__);
3399
3400 return ret;
3401}
3402
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003403uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404{
3405 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003406
Anurag Chouhan6d760662016-02-20 16:05:43 +05303407 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3409 break;
3410 }
3411
Anurag Chouhan6d760662016-02-20 16:05:43 +05303412 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 return NULL;
3414
3415 hdd_ctx->config->intfAddrMask |= (1 << i);
3416 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3417}
3418
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003419void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3420 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421{
3422 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003423
Anurag Chouhan6d760662016-02-20 16:05:43 +05303424 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 if (!memcmp(releaseAddr,
3426 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3427 6)) {
3428 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3429 break;
3430 }
3431 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432}
3433
3434#ifdef WLAN_FEATURE_PACKET_FILTERING
3435/**
3436 * __hdd_set_multicast_list() - set the multicast address list
3437 * @dev: Pointer to the WLAN device.
3438 * @skb: Pointer to OS packet (sk_buff).
3439 *
3440 * This funciton sets the multicast address list.
3441 *
3442 * Return: None
3443 */
3444static void __hdd_set_multicast_list(struct net_device *dev)
3445{
Jeff Johnson9d295242017-08-29 14:39:48 -07003446 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003447 int i = 0, status;
3448 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003449 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303450 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3451 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3452 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453
Dustin Brownfdf17c12018-03-14 12:55:34 -07003454 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303455 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303456 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303459 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303460 goto out;
3461
Dustin Brownc788acb2017-08-01 17:43:51 -07003462 status = hdd_validate_adapter(adapter);
3463 if (status)
3464 goto out;
3465
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303466 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3467 hdd_err("%s: Driver module is closed", __func__);
3468 return;
3469 }
3470
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303471 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3472 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003473 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303474 goto out;
3475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303477 /* Delete already configured multicast address list */
3478 if (adapter->mc_addr_list.mc_cnt > 0) {
3479 hdd_info("clear previously configured MC address list");
3480 hdd_disable_and_flush_mc_addr_list(adapter,
3481 pmo_mc_list_change_notify);
3482 }
3483
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003485 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303486 hdd_disable_and_flush_mc_addr_list(adapter,
3487 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 } else {
3489 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303490 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003491 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303492 pmo_ucfg_max_mc_addr_supported(psoc));
3493 hdd_disable_and_flush_mc_addr_list(adapter,
3494 pmo_mc_list_change_notify);
3495 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003498 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303499 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500 if (i == mc_count)
3501 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303502 memset(&(mc_list_request->mc_addr[i].bytes),
3503 0, ETH_ALEN);
3504 memcpy(&(mc_list_request->mc_addr[i].bytes),
3505 ha->addr, ETH_ALEN);
3506 hdd_info("mlist[%d] = %pM", i,
3507 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508 i++;
3509 }
3510 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303511
3512 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003513 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303514 mc_list_request->count = mc_count;
3515 status = hdd_cache_mc_addr_list(mc_list_request);
3516 if (status == 0) {
3517 hdd_enable_mc_addr_filtering(adapter,
3518 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003519 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303520 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003521 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303522out:
3523 if (mc_list_request)
3524 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003525 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526}
3527
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303528
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529/**
3530 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3531 * @dev: pointer to net_device
3532 *
3533 * Return: none
3534 */
3535static void hdd_set_multicast_list(struct net_device *dev)
3536{
3537 cds_ssr_protect(__func__);
3538 __hdd_set_multicast_list(dev);
3539 cds_ssr_unprotect(__func__);
3540}
3541#endif
3542
3543/**
3544 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3545 * @dev: Pointer to the WLAN device.
3546 * @skb: Pointer to OS packet (sk_buff).
3547 *
3548 * This function is registered with the Linux OS for network
3549 * core to decide which queue to use first.
3550 *
3551 * Return: ac, Queue Index/access category corresponding to UP in IP header
3552 */
3553static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3554#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3555 , void *accel_priv
3556#endif
3557#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3558 , select_queue_fallback_t fallback
3559#endif
3560)
3561{
3562 return hdd_wmm_select_queue(dev, skb);
3563}
3564
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003565static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 .ndo_open = hdd_open,
3567 .ndo_stop = hdd_stop,
3568 .ndo_uninit = hdd_uninit,
3569 .ndo_start_xmit = hdd_hard_start_xmit,
3570 .ndo_tx_timeout = hdd_tx_timeout,
3571 .ndo_get_stats = hdd_get_stats,
3572 .ndo_do_ioctl = hdd_ioctl,
3573 .ndo_set_mac_address = hdd_set_mac_address,
3574 .ndo_select_queue = hdd_select_queue,
3575#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577#endif
3578};
3579
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003580/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003581static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003582 .ndo_open = hdd_mon_open,
3583 .ndo_stop = hdd_stop,
3584 .ndo_get_stats = hdd_get_stats,
3585};
3586
3587/**
3588 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003589 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003590 * Return: None
3591 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003592void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003593{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003594 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003595 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003596 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003597 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003598}
3599
3600/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003601 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3602 * @hdd_ctx: global hdd context
3603 * @macAddr: mac address to assign to the interface
3604 * @name: User-visible name of the interface
3605 *
3606 * hdd adapter pointer would point to the netdev->priv space, this function
3607 * would retrive the pointer, and setup the hdd adapter configuration.
3608 *
3609 * Return: the pointer to hdd adapter, otherwise NULL
3610 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003611static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003613 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614 const char *name)
3615{
Jeff Johnson5505db82017-11-02 21:19:23 -07003616 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003617 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003618 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303619 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 /*
3621 * cfg80211 initialization and registration....
3622 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003623 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003624#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3625 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003627 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3628 hdd_mon_mode_ether_setup : ether_setup),
3629 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630
Jeff Johnson5505db82017-11-02 21:19:23 -07003631 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632
3633 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003634 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635
Jeff Johnson9d295242017-08-29 14:39:48 -07003636 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003637 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303638 qdf_mem_set(sta_ctx->conn_info.staId,
3639 sizeof(sta_ctx->conn_info.staId),
3640 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003641 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003642 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003644 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303646 qdf_status = qdf_event_create(
3647 &adapter->qdf_session_open_event);
3648 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3649 hdd_err("Session open QDF event init failed!");
3650 free_netdev(adapter->dev);
3651 return NULL;
3652 }
3653
3654 qdf_status = qdf_event_create(
3655 &adapter->qdf_session_close_event);
3656 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3657 hdd_err("Session close QDF event init failed!");
3658 free_netdev(adapter->dev);
3659 return NULL;
3660 }
3661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303663 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664 init_completion(&adapter->linkup_event_var);
3665 init_completion(&adapter->cancel_rem_on_chan_var);
3666 init_completion(&adapter->rem_on_chan_ready_event);
3667 init_completion(&adapter->sta_authorized_event);
3668 init_completion(&adapter->offchannel_tx_event);
3669 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003670 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303671 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672
3673 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003674 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303675 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003677 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678
Jeff Johnson5505db82017-11-02 21:19:23 -07003679 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003681 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003683 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684
3685 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003686 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003688 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689
Jeff Johnson5505db82017-11-02 21:19:23 -07003690 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 hdd_set_station_ops(adapter->dev);
3693
Jeff Johnson5505db82017-11-02 21:19:23 -07003694 hdd_dev_setup_destructor(dev);
3695 dev->ieee80211_ptr = &adapter->wdev;
3696 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003698 adapter->wdev.netdev = dev;
3699 /* set dev's parent to underlying device */
3700 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 hdd_wmm_init(adapter);
3702 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303703 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704 }
3705
3706 return adapter;
3707}
3708
Jeff Johnson9d295242017-08-29 14:39:48 -07003709static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003711 struct net_device *dev = adapter->dev;
3712 int ret;
3713
Dustin Brown491d54b2018-03-14 12:39:11 -07003714 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003716 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003717 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3718
3719 ret = dev_alloc_name(dev, dev->name);
3720 if (ret < 0) {
3721 hdd_err(
3722 "unable to get dev name: %s, err = 0x%x",
3723 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303724 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003725 }
3726 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003727
3728 ret = register_netdevice(dev);
3729 if (ret) {
3730 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3731 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303732 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733 }
3734 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003735 ret = register_netdev(dev);
3736 if (ret) {
3737 hdd_err("register_netdev(%s) failed, err = 0x%x",
3738 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303739 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 }
3741 }
3742 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3743
Dustin Browne74003f2018-03-14 12:51:58 -07003744 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003745
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303746 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747}
3748
Krunal Sonib51eec72017-11-20 21:53:01 -08003749QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750{
Krunal Sonib51eec72017-11-20 21:53:01 -08003751 struct hdd_adapter *adapter;
3752 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753
Krunal Sonib51eec72017-11-20 21:53:01 -08003754 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3755 if (!hdd_ctx) {
3756 hdd_err("Invalid HDD_CTX");
3757 return QDF_STATUS_E_FAILURE;
3758 }
3759
3760 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3761 if (NULL == adapter) {
3762 hdd_err("NULL adapter");
3763 return QDF_STATUS_E_INVAL;
3764 }
3765 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303766 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003767 hdd_debug("session %d opened", adapter->session_id);
3768
3769 return QDF_STATUS_SUCCESS;
3770}
3771
3772QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3773{
3774 struct hdd_adapter *adapter;
3775 struct hdd_context *hdd_ctx;
3776
3777 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3778 if (!hdd_ctx) {
3779 hdd_err("Invalid HDD_CTX");
3780 return QDF_STATUS_E_FAILURE;
3781 }
3782
3783 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003784 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003785 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303786 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003787 }
3788
3789 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003790 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303791 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 }
3793
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003794 /*
3795 * For NAN Data interface, the close session results in the final
3796 * indication to the userspace
3797 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003798 if (adapter->device_mode == QDF_NDI_MODE)
3799 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003801 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3802
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 /*
3804 * We can be blocked while waiting for scheduled work to be
3805 * flushed, and the adapter structure can potentially be freed, in
3806 * which case the magic will have been reset. So make sure the
3807 * magic is still good, and hence the adapter structure is still
3808 * valid, before signaling completion
3809 */
3810 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303811 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303813 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814}
3815
Jeff Johnson9d295242017-08-29 14:39:48 -07003816int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817{
Dustin Brownd28772b2017-03-17 14:16:07 -07003818 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819
Dustin Brownd28772b2017-03-17 14:16:07 -07003820 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003821 if (QDF_IS_STATUS_ERROR(status))
3822 return qdf_status_to_os_return(status);
3823
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003824 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003825 if (QDF_IS_STATUS_ERROR(status))
3826 return qdf_status_to_os_return(status);
3827
3828 if (wma_capability_enhanced_mcast_filter())
3829 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3830 else
3831 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003832
3833 return qdf_status_to_os_return(status);
3834}
3835
Jeff Johnson9d295242017-08-29 14:39:48 -07003836int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003837{
3838 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003839 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003840 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003841 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003842
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003843 vdev_id = adapter->session_id;
3844 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003845
3846 /* vdev created sanity check */
3847 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003848 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003849 return -EINVAL;
3850 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003851 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003852
Dustin Brownd28772b2017-03-17 14:16:07 -07003853 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303854 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003855 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003856 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003857 if (QDF_IS_STATUS_ERROR(status)) {
3858 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003859 errno = qdf_status_to_os_return(status);
3860 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003861 }
3862
3863 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303864 status = qdf_wait_for_event_completion(
3865 &adapter->qdf_session_close_event,
3866 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3867 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003868 if (adapter->device_mode == QDF_NDI_MODE)
3869 hdd_ndp_session_end_handler(adapter);
3870 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303871 adapter->session_id = HDD_SESSION_ID_INVALID;
3872 if (QDF_STATUS_E_TIMEOUT != status) {
3873 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003874 errno = -ETIMEDOUT;
3875 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303876 } else if (adapter->qdf_session_close_event.force_set) {
3877 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003878 errno = -EINVAL;
3879 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303880 } else {
3881 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003882 errno = -EINVAL;
3883 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303884 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003885 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003886
Yue Maf9782842017-05-08 12:49:49 -07003887release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003888 /*
3889 * In SSR or driver unloading case, directly exit may cause objects
3890 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003891 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003892 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003893 return errno;
3894
Sandeep Puligillaef415362017-08-30 16:37:13 -07003895 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003896 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003897 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003898 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003899 return errno;
3900 }
3901
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003902 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003903
3904 return 0;
3905}
3906
Krunal Sonib51eec72017-11-20 21:53:01 -08003907static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3908 struct sme_session_params *session_param,
3909 csr_roam_completeCallback callback,
3910 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003911{
Dustin Brownd28772b2017-03-17 14:16:07 -07003912 uint32_t type;
3913 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003914 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003915
3916 /* determine vdev (sub)type */
3917 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303918 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003919 hdd_err("failed to get vdev type: %d", status);
3920 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003922 session_param->sme_session_id = adapter->session_id;
3923 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3924 session_param->type_of_persona = type;
3925 session_param->subtype_of_persona = sub_type;
3926 session_param->session_open_cb = hdd_sme_open_session_callback;
3927 session_param->session_close_cb = hdd_sme_close_session_callback;
3928 session_param->callback = callback;
3929 session_param->callback_ctx = callback_ctx;
3930
3931 return 0;
3932}
3933
3934int hdd_vdev_create(struct hdd_adapter *adapter,
3935 csr_roam_completeCallback callback, void *ctx)
3936{
3937 QDF_STATUS status;
3938 int errno;
3939 struct hdd_context *hdd_ctx;
3940 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003941
3942 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003943
3944 /* do vdev create via objmgr */
3945 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003946 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003947 if (errno) {
3948 hdd_err("failed to create objmgr vdev: %d", errno);
3949 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003951
3952 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303953 status = qdf_event_reset(&adapter->qdf_session_open_event);
3954 if (QDF_STATUS_SUCCESS != status) {
3955 hdd_err("failed to reinit session open event");
3956 return -EINVAL;
3957 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003958 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3959 callback, ctx);
3960 if (errno) {
3961 hdd_err("failed to populating SME params");
3962 goto objmgr_vdev_destroy_procedure;
3963 }
3964
3965 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003966 if (QDF_IS_STATUS_ERROR(status)) {
3967 hdd_err("failed to open sme session: %d", status);
3968 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003969 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003970 }
3971
3972 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303973 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3974 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3975 if (QDF_STATUS_SUCCESS != status) {
3976 if (adapter->qdf_session_open_event.force_set) {
3977 /*
3978 * SSR/PDR has caused shutdown, which has forcefully
3979 * set the event. Return without the closing session.
3980 */
3981 adapter->session_id = HDD_SESSION_ID_INVALID;
3982 hdd_err("Session open event forcefully set");
3983 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303984 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003985
3986 if (QDF_STATUS_E_TIMEOUT == status)
3987 hdd_err("Session failed to open within timeout period");
3988 else
3989 hdd_err("Failed to wait for session open event(status-%d)",
3990 status);
3991 errno = -ETIMEDOUT;
3992 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3993 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003994 }
3995
3996 /* firmware ready for component communication, raise vdev_ready event */
3997 errno = hdd_vdev_ready(adapter);
3998 if (errno) {
3999 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004000 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004001 }
4002
Jeff Johnson1b780e42017-10-31 14:11:45 -07004003 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004004
4005 return 0;
4006
4007 /*
4008 * Due to legacy constraints, we need to destroy in the same order as
4009 * create. So, split error handling into 2 cases to accommodate.
4010 */
4011
Krunal Soni4a020c72017-10-30 20:58:40 -07004012objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004013 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004014
4015 return errno;
4016
Krunal Soni4a020c72017-10-30 20:58:40 -07004017hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004018 QDF_BUG(!hdd_vdev_destroy(adapter));
4019
4020 return errno;
4021}
4022
Jeff Johnson9d295242017-08-29 14:39:48 -07004023QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004024{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004025 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004026 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004027 QDF_STATUS status;
4028 int ret_val;
4029
Dustin Brownd28772b2017-03-17 14:16:07 -07004030 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4031 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
4032 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004033 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004034
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004035 hdd_roam_profile_init(adapter);
4036 hdd_register_wext(adapter->dev);
4037
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004038 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039
Jeff Johnsond377dce2017-10-04 10:32:42 -07004040 qdf_mem_set(sta_ctx->conn_info.staId,
4041 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304042
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004043 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004044 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304045 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004047 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 hdd_ctx->config->OperatingChannel;
4049
4050 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004051 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
4053 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304054 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004055 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 status, status);
4057 goto error_init_txrx;
4058 }
4059
4060 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4061
4062 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304063 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004064 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 status, status);
4066 goto error_wmm_init;
4067 }
4068
4069 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4070
Jeff Johnson1b780e42017-10-31 14:11:45 -07004071 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 WMI_PDEV_PARAM_BURST_ENABLE,
4073 hdd_ctx->config->enableSifsBurst,
4074 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004075 if (ret_val)
4076 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304078 /*
4079 * In case of USB tethering, LRO is disabled. If SSR happened
4080 * during that time, then as part of SSR init, do not enable
4081 * the LRO again. Keep the LRO state same as before SSR.
4082 */
4083 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07004084 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304085
4086 /* rcpi info initialization */
4087 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4088
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304089 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091error_wmm_init:
4092 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4093 hdd_deinit_tx_rx(adapter);
4094error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004095 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004096 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 return status;
4099}
4100
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304101/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004102 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304103 * @hdd_ctx: global hdd context
4104 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004105 * @rtnl_held: Used to indicate whether or not the caller is holding
4106 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304107 *
4108 * This function De-initializes the STA/P2P/OCB adapter.
4109 *
4110 * Return: None.
4111 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004112static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004113 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004114 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304115{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004116 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304117
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304118 if (adapter->dev) {
4119 if (rtnl_held)
4120 adapter->dev->wireless_handlers = NULL;
4121 else {
4122 rtnl_lock();
4123 adapter->dev->wireless_handlers = NULL;
4124 rtnl_unlock();
4125 }
4126 }
4127
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304128 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4129 hdd_deinit_tx_rx(adapter);
4130 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4131 }
4132
4133 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4134 hdd_wmm_adapter_close(adapter);
4135 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4136 }
4137
Krunal Sonib51eec72017-11-20 21:53:01 -08004138
Dustin Browne74003f2018-03-14 12:51:58 -07004139 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304140}
4141
Krunal Sonib51eec72017-11-20 21:53:01 -08004142void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4143 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 bool rtnl_held)
4145{
Dustin Brown491d54b2018-03-14 12:39:11 -07004146 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004149 case QDF_STA_MODE:
4150 case QDF_P2P_CLIENT_MODE:
4151 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004152 case QDF_IBSS_MODE:
4153 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004155 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004156 break;
4157 }
4158
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004159 case QDF_SAP_MODE:
4160 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004162 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 break;
4164 }
4165
4166 default:
4167 break;
4168 }
4169
Dustin Browne74003f2018-03-14 12:51:58 -07004170 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171}
4172
Jeff Johnson9d295242017-08-29 14:39:48 -07004173static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004174 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175{
Jeff Johnson5505db82017-11-02 21:19:23 -07004176 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177
4178 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004179 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004181 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 return;
4183 }
4184
Alok Kumarb64650c2018-03-23 17:05:11 +05304185 hdd_nud_deinit_tracking(adapter);
4186 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4187
Rajeev Kumardca5f812016-02-04 17:28:06 -08004188 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 /*
4191 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4192 * the driver is almost closed and cannot handle either control
4193 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004194 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4195 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196 * is not right. Setting this flag helps hdd_stop() to recognize that
4197 * the interface is closed and restricts any operations on that
4198 */
4199 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4200
4201 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004202 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004203 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004204 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004205 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 /*
4207 * Note that the adapter is no longer valid at this point
4208 * since the memory has been reclaimed
4209 */
4210 }
4211}
4212
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004213static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004214 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215{
Jeff Johnson9d295242017-08-29 14:39:48 -07004216 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004217
Dustin Brown920397d2017-12-13 16:27:50 -08004218 hdd_for_each_adapter(hdd_ctx, adapter) {
4219 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4220 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304221 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223 }
Dustin Brown920397d2017-12-13 16:27:50 -08004224
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304225 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004227
Arun Khandavalli2358d522016-05-16 18:05:37 +05304228#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4229/**
4230 * hdd_set_fw_log_params() - Set log parameters to FW
4231 * @hdd_ctx: HDD Context
4232 * @adapter: HDD Adapter
4233 *
4234 * This function set the FW Debug log level based on the INI.
4235 *
4236 * Return: None
4237 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004238static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004239 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304240{
4241 uint8_t count = 0, numentries = 0,
4242 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4243 uint32_t value = 0;
4244 int ret;
4245
Arun Khandavallifae92942016-08-01 13:31:08 +05304246 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4247 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004248 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304249 return;
4250 }
4251
Arun Khandavallifae92942016-08-01 13:31:08 +05304252 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304253 hdd_ctx->fw_log_settings.dl_type =
4254 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004255 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304256 WMI_DBGLOG_TYPE,
4257 hdd_ctx->config->enableFwLogType,
4258 DBG_CMD);
4259 if (ret != 0)
4260 hdd_err("Failed to enable FW log type ret %d",
4261 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304262
4263 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304264 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004265 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304266 WMI_DBGLOG_LOG_LEVEL,
4267 hdd_ctx->config->enableFwLogLevel,
4268 DBG_CMD);
4269 if (ret != 0)
4270 hdd_err("Failed to enable FW log level ret %d",
4271 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304272
4273 hdd_string_to_u8_array(
4274 hdd_ctx->config->enableFwModuleLogLevel,
4275 moduleloglevel,
4276 &numentries,
4277 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4278
4279 while (count < numentries) {
4280 /*
4281 * FW module log level input string looks like
4282 * below:
4283 * gFwDebugModuleLoglevel=<FW Module ID>,
4284 * <Log Level>,...
4285 * For example:
4286 * gFwDebugModuleLoglevel=
4287 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4288 * Above input string means :
4289 * For FW module ID 1 enable log level 0
4290 * For FW module ID 2 enable log level 1
4291 * For FW module ID 3 enable log level 2
4292 * For FW module ID 4 enable log level 3
4293 * For FW module ID 5 enable log level 4
4294 * For FW module ID 6 enable log level 5
4295 * For FW module ID 7 enable log level 6
4296 */
4297
Nishank Aggarwale239d962017-03-03 12:26:02 +05304298 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4299 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4300 hdd_err("Module id %d and dbglog level %d input length is more than max",
4301 moduleloglevel[count],
4302 moduleloglevel[count + 1]);
4303 return;
4304 }
4305
4306 value = moduleloglevel[count] << 16;
4307 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004308 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304309 WMI_DBGLOG_MOD_LOG_LEVEL,
4310 value, DBG_CMD);
4311 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304312 hdd_err("Failed to enable FW module log level %d ret %d",
4313 value, ret);
4314
4315 count += 2;
4316 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304317
Arun Khandavalli2358d522016-05-16 18:05:37 +05304318}
4319#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004320static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004321 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304322{
4323}
4324
4325#endif
4326
4327/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004328 * hdd_configure_chain_mask() - programs chain mask to firmware
4329 * @adapter: HDD adapter
4330 *
4331 * Return: 0 on success or errno on failure
4332 */
4333static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4334{
4335 int ret_val;
4336 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4337
4338 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4339 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4340 hdd_ctx->config->txchainmask1x1,
4341 hdd_ctx->config->rxchainmask1x1);
4342 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4343 hdd_ctx->config->dual_mac_feature_disable,
4344 hdd_ctx->config->tx_chain_mask_2g,
4345 hdd_ctx->config->rx_chain_mask_2g);
4346 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4347 hdd_ctx->config->tx_chain_mask_5g,
4348 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004349 hdd_debug("enable_bt_chain_separation %d",
4350 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004351
Liangwei Dong22810e82018-03-15 03:42:12 -04004352 if (hdd_ctx->config->enable2x2 &&
4353 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004354 hdd_info("2x2 enabled. skip chain mask programming");
4355 return 0;
4356 }
4357
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004358 if (hdd_ctx->config->dual_mac_feature_disable !=
4359 DISABLE_DBS_CXN_AND_SCAN) {
4360 hdd_info("DBS enabled(%d). skip chain mask programming",
4361 hdd_ctx->config->dual_mac_feature_disable);
4362 return 0;
4363 }
4364
Naveen Rawatdacb5032018-02-08 15:23:24 -08004365 if (hdd_ctx->lte_coex_ant_share) {
4366 hdd_info("lte ant sharing enabled. skip chainmask programming");
4367 return 0;
4368 }
4369
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004370 if (hdd_ctx->config->txchainmask1x1) {
4371 ret_val = sme_cli_set_command(adapter->session_id,
4372 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4373 hdd_ctx->config->txchainmask1x1,
4374 PDEV_CMD);
4375 if (ret_val)
4376 goto error;
4377 }
4378
4379 if (hdd_ctx->config->rxchainmask1x1) {
4380 ret_val = sme_cli_set_command(adapter->session_id,
4381 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4382 hdd_ctx->config->rxchainmask1x1,
4383 PDEV_CMD);
4384 if (ret_val)
4385 goto error;
4386 }
4387
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004388 if (hdd_ctx->config->txchainmask1x1 ||
4389 hdd_ctx->config->rxchainmask1x1) {
4390 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4391 return 0;
4392 }
4393
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004394 if (hdd_ctx->config->tx_chain_mask_2g) {
4395 ret_val = sme_cli_set_command(adapter->session_id,
4396 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4397 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4398 if (0 != ret_val)
4399 goto error;
4400 }
4401
4402 if (hdd_ctx->config->rx_chain_mask_2g) {
4403 ret_val = sme_cli_set_command(adapter->session_id,
4404 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4405 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4406 if (0 != ret_val)
4407 goto error;
4408 }
4409
4410 if (hdd_ctx->config->tx_chain_mask_5g) {
4411 ret_val = sme_cli_set_command(adapter->session_id,
4412 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4413 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4414 if (0 != ret_val)
4415 goto error;
4416 }
4417
4418 if (hdd_ctx->config->rx_chain_mask_5g) {
4419 ret_val = sme_cli_set_command(adapter->session_id,
4420 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4421 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4422 if (0 != ret_val)
4423 goto error;
4424 }
4425
4426 return 0;
4427
4428error:
4429 hdd_err("WMI PDEV set param failed %d", ret_val);
4430 return -EINVAL;
4431}
4432
4433/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304434 * hdd_set_fw_params() - Set parameters to firmware
4435 * @adapter: HDD adapter
4436 *
4437 * This function Sets various parameters to fw once the
4438 * adapter is started.
4439 *
4440 * Return: 0 on success or errno on failure
4441 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004442int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304443{
4444 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004445 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304446
Dustin Brownfdf17c12018-03-14 12:55:34 -07004447 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304448
4449 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4450 if (!hdd_ctx)
4451 return -EINVAL;
4452
Dustin Brown732ab9c2017-06-15 13:24:09 -07004453 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4454 hdd_debug("FTM Mode is active; nothing to do");
4455 return 0;
4456 }
4457
Jeff Johnson1b780e42017-10-31 14:11:45 -07004458 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304459 WMI_PDEV_PARAM_DTIM_SYNTH,
4460 hdd_ctx->config->enable_lprx, PDEV_CMD);
4461 if (ret) {
4462 hdd_err("Failed to set LPRx");
4463 goto error;
4464 }
4465
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304466
4467 ret = sme_cli_set_command(
4468 adapter->session_id,
4469 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4470 hdd_ctx->config->enable_dtim_selection_diversity,
4471 PDEV_CMD);
4472 if (ret) {
4473 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4474 goto error;
4475 }
4476
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304477 ret = sme_cli_set_command(
4478 adapter->session_id,
4479 WMI_PDEV_PARAM_TX_SCH_DELAY,
4480 hdd_ctx->config->enable_tx_sch_delay,
4481 PDEV_CMD);
4482 if (ret) {
4483 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4484 goto error;
4485 }
4486
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304487 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004488 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304489 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4490 hdd_ctx->config->upper_brssi_thresh);
4491
Jeff Johnson1b780e42017-10-31 14:11:45 -07004492 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304493 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4494 hdd_ctx->config->lower_brssi_thresh);
4495
Jeff Johnson1b780e42017-10-31 14:11:45 -07004496 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304497 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4498 hdd_ctx->config->enable_dtim_1chrx);
4499 }
4500
Dustin Brown732ab9c2017-06-15 13:24:09 -07004501 if (hdd_ctx->config->enable2x2) {
4502 hdd_debug("configuring 2x2 mode fw params");
4503
Jeff Johnson1b780e42017-10-31 14:11:45 -07004504 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004505 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4506 hdd_ctx->config->enable_cck_tx_fir_override,
4507 PDEV_CMD);
4508 if (ret) {
4509 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4510 ret);
4511 goto error;
4512 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004513
4514 if (hdd_configure_chain_mask(adapter))
4515 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004516 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304517#define HDD_DTIM_1CHAIN_RX_ID 0x5
4518#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004519 hdd_debug("configuring 1x1 mode fw params");
4520
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004521 /*
4522 * Disable DTIM 1 chain Rx when in 1x1,
4523 * we are passing two value
4524 * as param_id << 29 | param_value.
4525 * Below param_value = 0(disable)
4526 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004527 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004528 WMI_STA_SMPS_PARAM_CMDID,
4529 HDD_DTIM_1CHAIN_RX_ID <<
4530 HDD_SMPS_PARAM_VALUE_S,
4531 VDEV_CMD);
4532 if (ret) {
4533 hdd_err("DTIM 1 chain set failed %d", ret);
4534 goto error;
4535 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304536
Arun Khandavalli2358d522016-05-16 18:05:37 +05304537#undef HDD_DTIM_1CHAIN_RX_ID
4538#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004539
4540 if (hdd_configure_chain_mask(adapter))
4541 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004542 }
4543
Jeff Johnson1b780e42017-10-31 14:11:45 -07004544 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004545 WMI_PDEV_PARAM_HYST_EN,
4546 hdd_ctx->config->enableMemDeepSleep,
4547 PDEV_CMD);
4548 if (ret) {
4549 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4550 goto error;
4551 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304552
Jeff Johnson1b780e42017-10-31 14:11:45 -07004553 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004554 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4555 hdd_ctx->config->rts_profile,
4556 VDEV_CMD);
4557 if (ret) {
4558 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4559 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304560 }
4561
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004562 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4563
Jeff Johnson1b780e42017-10-31 14:11:45 -07004564 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004565 GEN_VDEV_PARAM_AMSDU,
4566 hdd_ctx->config->max_amsdu_num,
4567 GEN_CMD);
4568 if (ret != 0) {
4569 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4570 goto error;
4571 }
4572
Arun Khandavalli2358d522016-05-16 18:05:37 +05304573 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004574 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004575
Arun Khandavalli2358d522016-05-16 18:05:37 +05304576 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304577
Arun Khandavalli2358d522016-05-16 18:05:37 +05304578error:
4579 return -EINVAL;
4580}
4581
Ryan Hsu07495ea2016-01-21 15:25:39 -08004582/**
4583 * hdd_open_adapter() - open and setup the hdd adatper
4584 * @hdd_ctx: global hdd context
4585 * @session_type: type of the interface to be created
4586 * @iface_name: User-visible name of the interface
4587 * @macAddr: MAC address to assign to the interface
4588 * @name_assign_type: the name of assign type of the netdev
4589 * @rtnl_held: the rtnl lock hold flag
4590 *
4591 * This function open and setup the hdd adpater according to the device
4592 * type request, assign the name, the mac address assigned, and then prepared
4593 * the hdd related parameters, queue, lock and ready to start.
4594 *
4595 * Return: the pointer of hdd adapter, otherwise NULL.
4596 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004597struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004598 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004599 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004600 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601{
Jeff Johnson9d295242017-08-29 14:39:48 -07004602 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304603 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604
4605 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4606 /*
4607 * Max limit reached on the number of vdevs configured by the
4608 * host. Return error
4609 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304610 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4611 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 return NULL;
4613 }
4614
4615 if (macAddr == NULL) {
4616 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304617 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 return NULL;
4619 }
4620 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304621 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304622 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4623 " already exists",
4624 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 return NULL;
4626 }
4627
4628 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004629 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 /* Reset locally administered bit if the device mode is STA */
4631 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304632 hdd_info("locally administered bit reset in sta mode: "
4633 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004635 case QDF_P2P_CLIENT_MODE:
4636 case QDF_P2P_DEVICE_MODE:
4637 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004638 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304639 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004640 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4641 name_assign_type,
4642 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643
4644 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304645 hdd_err("failed to allocate adapter for session %d",
4646 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647 return NULL;
4648 }
4649
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004650 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004652 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304654 else if (QDF_MONITOR_MODE == session_type)
4655 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656 else
4657 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4658
4659 adapter->device_mode = session_type;
4660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 /*
4663 * Workqueue which gets scheduled in IPv4 notification
4664 * callback
4665 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004666 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668
4669#ifdef WLAN_NS_OFFLOAD
4670 /*
4671 * Workqueue which gets scheduled in IPv6
4672 * notification callback.
4673 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004674 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004675 hdd_ipv6_notifier_work_queue);
4676#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004678 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004679 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680
4681 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004682 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304684 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4685 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304686
Ravi Joshi1a292562017-05-18 16:28:54 -07004687 /* Initialize NAN Data Interface */
4688 if (QDF_NDI_MODE == session_type) {
4689 status = hdd_init_nan_data_mode(adapter);
4690 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004691 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004692 }
4693
Alok Kumarb64650c2018-03-23 17:05:11 +05304694 hdd_nud_init_tracking(adapter);
4695
4696 qdf_mutex_create(&adapter->disconnection_status_lock);
4697
Ravi Joshi1a292562017-05-18 16:28:54 -07004698 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004699
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004700 case QDF_P2P_GO_MODE:
4701 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004702 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4703 name_assign_type,
4704 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004705 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004706 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304707 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004708 return NULL;
4709 }
4710
4711 adapter->wdev.iftype =
4712 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004713 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004714 NL80211_IFTYPE_P2P_GO;
4715 adapter->device_mode = session_type;
4716
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004717 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004718 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004720
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004721 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004722 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304723 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4724 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304725
4726 /*
4727 * Workqueue which gets scheduled in IPv4 notification
4728 * callback
4729 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004730 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304731 hdd_ipv4_notifier_work_queue);
4732
4733#ifdef WLAN_NS_OFFLOAD
4734 /*
4735 * Workqueue which gets scheduled in IPv6
4736 * notification callback.
4737 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004738 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304739 hdd_ipv6_notifier_work_queue);
4740#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304742 case QDF_FTM_MODE:
4743 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4744 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004745 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304746 if (NULL == adapter) {
4747 hdd_err("Failed to allocate adapter for FTM mode");
4748 return NULL;
4749 }
4750 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4751 adapter->device_mode = session_type;
4752 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004753 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004754 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004755
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304756 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004757 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304758 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304759 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4760 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304761 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004763 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304764 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765 return NULL;
4766 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004767
hqueaa33ee2017-05-04 17:56:35 +08004768 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4769
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304770 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004772 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004773 }
4774
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304775 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 if (NULL != adapter) {
4777 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4778 adapter = NULL;
4779 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004781 return NULL;
4782 }
4783
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304784 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004785 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4786 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788 /* Adapter successfully added. Increment the vdev count */
4789 hdd_ctx->current_intf_count++;
4790
Jeff Johnson5880d792016-08-15 13:32:30 -07004791 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792 hdd_ctx->current_intf_count);
4793
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004794 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795 }
4796
Rajeev Kumardca5f812016-02-04 17:28:06 -08004797 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004798 hdd_err("Interface %s wow debug_fs init failed",
4799 netdev_name(adapter->dev));
4800
4801 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4802 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803
4804 return adapter;
4805
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004807 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304808 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809
4810 return NULL;
4811}
4812
Nirav Shaheb017be2018-02-15 11:20:58 +05304813#ifdef MSM_PLATFORM
4814static inline
4815void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4816{
4817 cancel_work_sync(&hdd_ctx->bus_bw_work);
4818}
4819#else
4820static inline
4821void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4822{
4823}
4824#endif
4825
Jeff Johnson9d295242017-08-29 14:39:48 -07004826QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004827 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004828{
Dustin Brown920397d2017-12-13 16:27:50 -08004829 /*
4830 * Here we are stopping global bus_bw timer & work per adapter.
4831 *
4832 * The reason is to fix one race condition between
4833 * bus bandwidth work and cleaning up an adapter.
4834 * Under some conditions, it is possible for the bus bandwidth
4835 * work to access a particularly destroyed adapter, leading to
4836 * use-after-free.
4837 */
4838 hdd_debug("wait for bus bw work to flush");
4839 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4840 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004841
Dustin Brown920397d2017-12-13 16:27:50 -08004842 /* cleanup adapter */
4843 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4844 adapter->device_mode);
4845 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4846 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847
Dustin Brown920397d2017-12-13 16:27:50 -08004848 /* conditionally restart the bw timer */
4849 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850
Dustin Brown920397d2017-12-13 16:27:50 -08004851 /* Adapter removed. Decrement vdev count */
4852 if (hdd_ctx->current_intf_count != 0)
4853 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004854
Dustin Brown920397d2017-12-13 16:27:50 -08004855 /* Fw will take care incase of concurrency */
4856 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857}
4858
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004859/**
4860 * hdd_close_all_adapters - Close all open adapters
4861 * @hdd_ctx: Hdd context
4862 * rtnl_held: True if RTNL lock held
4863 *
4864 * Close all open adapters.
4865 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304866 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004868QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004869{
Dustin Brown920397d2017-12-13 16:27:50 -08004870 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304871 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872
Dustin Brown491d54b2018-03-14 12:39:11 -07004873 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004874
4875 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004876 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4877 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304878 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004879 adapter->mac_addr.bytes);
4880 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4881
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304882 /* Adapter removed. Decrement vdev count */
4883 if (hdd_ctx->current_intf_count != 0)
4884 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 }
Dustin Brown920397d2017-12-13 16:27:50 -08004886 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887
Dustin Browne74003f2018-03-14 12:51:58 -07004888 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304890 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891}
4892
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004893void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304895 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004897
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004898 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004899 case QDF_STA_MODE:
4900 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004902 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004903 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004904 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 break;
4906 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004907 case QDF_SAP_MODE:
4908 case QDF_P2P_GO_MODE:
4909 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004911 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004912 break;
4913 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004914 case QDF_FTM_MODE:
4915 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004916 default:
4917 /*
4918 * wlan_hdd_reset_prob_rspies should not have been called
4919 * for these kind of devices
4920 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004921 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004922 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 return;
4924 }
4925
Anurag Chouhanc5548422016-02-24 18:33:27 +05304926 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004927 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928 updateIE.ieBufferlength = 0;
4929 updateIE.pAdditionIEBuffer = NULL;
4930 updateIE.append = true;
4931 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004932 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004933 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304934 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004935 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004936 }
4937}
4938
Dustin Browndb2a8be2017-12-20 11:49:56 -08004939QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4940 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004941{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304942 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004943 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004944 union iwreq_data wrqu;
4945 tSirUpdateIE updateIE;
4946 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304947 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004948
Dustin Brown491d54b2018-03-14 12:39:11 -07004949 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004950
Alok Kumarb64650c2018-03-23 17:05:11 +05304951 hdd_nud_ignore_tracking(adapter, true);
4952 hdd_nud_reset_tracking(adapter);
4953
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004954 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304955 wlan_hdd_netif_queue_control(adapter,
4956 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4957 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004958 /*
4959 * if this is the last active connection check & stop the
4960 * opportunistic timer first
4961 */
4962 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4963 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4964 policy_mgr_convert_device_mode_to_qdf_type(
4965 adapter->device_mode), NULL) == 1)) ||
4966 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4967 policy_mgr_check_and_stop_opportunistic_timer(
4968 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004969 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004970 case QDF_STA_MODE:
4971 case QDF_P2P_CLIENT_MODE:
4972 case QDF_IBSS_MODE:
4973 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004974 case QDF_NDI_MODE:
4975 if ((QDF_NDI_MODE == adapter->device_mode) ||
4976 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4978 hdd_is_connecting(
4979 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004980 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004981 roam_profile = hdd_roam_profile(adapter);
4982 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004983 if (QDF_NDI_MODE == adapter->device_mode)
4984 qdf_ret_status = sme_roam_disconnect(
4985 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004986 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004987 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004988 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004989 eCSR_BSS_TYPE_START_IBSS)
4990 qdf_ret_status = sme_roam_disconnect(
4991 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004992 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004993 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004994 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004995 qdf_ret_status =
4996 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004997 hdd_debug("Send disconnected event to userspace");
4998 wlan_hdd_cfg80211_indicate_disconnect(
4999 adapter->dev, true,
5000 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08005001 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005002 qdf_ret_status = sme_roam_disconnect(
5003 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005004 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005005 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005006 /* success implies disconnect command got
5007 * queued up successfully
5008 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005009 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5010 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011 rc = wait_for_completion_timeout(
5012 &adapter->disconnect_comp_var,
5013 msecs_to_jiffies
5014 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005015 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005016 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005017 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005018 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5019 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020 memset(&wrqu, '\0', sizeof(wrqu));
5021 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5022 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5023 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5024 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305025 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005026 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005027
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305028 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305029 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030
5031#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005032 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033#endif
5034
5035 hdd_deregister_tx_flow_control(adapter);
5036
5037#ifdef WLAN_NS_OFFLOAD
5038#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005039 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005040#endif
5041#endif
5042
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305043 if (adapter->device_mode == QDF_STA_MODE)
5044 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5045 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005046
5047 if (wlan_hdd_try_disconnect(adapter)) {
5048 hdd_err("Error: Can't disconnect adapter");
5049 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005050 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005051
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305052 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053 break;
5054
Rajeev Kumar3b906202018-02-01 10:55:14 -08005055 case QDF_MONITOR_MODE:
5056 wlan_hdd_scan_abort(adapter);
5057 hdd_deregister_tx_flow_control(adapter);
5058 hdd_vdev_destroy(adapter);
5059 break;
5060
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005061 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005062 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305063 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305064 sap_config = &adapter->session.ap.sap_config;
5065 if (sap_config)
5066 wlansap_reset_sap_config_add_ie(sap_config,
5067 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305068 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005069 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005070
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005071 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005072 if (QDF_SAP_MODE == adapter->device_mode) {
5073 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5074 cds_flush_delayed_work(
5075 &adapter->acs_pending_work);
5076 clear_bit(ACS_PENDING, &adapter->event_flags);
5077 }
5078 }
Krunal Soni22208392017-09-29 18:10:34 -07005079 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005080
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005082 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005083 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5085
5086 hdd_deregister_tx_flow_control(adapter);
5087
Kapil Guptac1224bf2017-06-22 21:22:40 +05305088 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 mutex_lock(&hdd_ctx->sap_lock);
5090 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305091 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305092 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093
5094 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095 status = wlansap_stop_bss(
5096 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005097
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305098 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005099 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305101 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305102 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305103 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305104 qdf_wait_for_event_completion(
5105 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005106 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005107
Anurag Chouhance0dc992016-02-16 18:18:03 +05305108 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005109 hdd_err("failure waiting for wlansap_stop_bss %d",
5110 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111 }
5112 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005113 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005114 }
5115 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005116 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5117 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005118 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005119 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305120 adapter->device_mode,
5121 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122
Anurag Chouhanc5548422016-02-24 18:33:27 +05305123 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005124 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005125 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126 updateIE.ieBufferlength = 0;
5127 updateIE.pAdditionIEBuffer = NULL;
5128 updateIE.append = false;
5129 updateIE.notify = false;
5130 /* Probe bcn reset */
5131 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5132 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305133 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005134 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 }
5136 /* Assoc resp reset */
5137 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5138 &updateIE,
5139 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305140 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005141 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 }
5143 /* Reset WNI_CFG_PROBE_RSP Flags */
5144 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005146 qdf_mem_free(adapter->session.ap.beacon);
5147 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305148 /*
5149 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5150 */
5151 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5152 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5153
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305154#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005155 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305156#endif
5157
5158#ifdef WLAN_NS_OFFLOAD
5159#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005160 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305161#endif
5162#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005163
5164 hdd_vdev_destroy(adapter);
5165
Krunal Sonib51eec72017-11-20 21:53:01 -08005166 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005168 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005169 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005170 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005171 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005172 hdd_deregister_tx_flow_control(adapter);
5173 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 break;
5175 default:
5176 break;
5177 }
5178
Dustin Brown04348372017-12-14 16:13:39 -08005179 if (adapter->scan_info.default_scan_ies) {
5180 qdf_mem_free(adapter->scan_info.default_scan_ies);
5181 adapter->scan_info.default_scan_ies = NULL;
5182 }
5183
Dustin Browne74003f2018-03-14 12:51:58 -07005184 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005185
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305186 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187}
5188
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305189/**
5190 * hdd_deinit_all_adapters - deinit all adapters
5191 * @hdd_ctx: HDD context
5192 * @rtnl_held: True if RTNL lock held
5193 *
5194 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005195void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305196{
Jeff Johnson9d295242017-08-29 14:39:48 -07005197 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305198
Dustin Brown491d54b2018-03-14 12:39:11 -07005199 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305200
Dustin Brown920397d2017-12-13 16:27:50 -08005201 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305202 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305203
Dustin Browne74003f2018-03-14 12:51:58 -07005204 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305205}
5206
Dustin Browndb2a8be2017-12-20 11:49:56 -08005207QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208{
Jeff Johnson9d295242017-08-29 14:39:48 -07005209 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210
Dustin Brown491d54b2018-03-14 12:39:11 -07005211 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305213 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5214
Dustin Brown920397d2017-12-13 16:27:50 -08005215 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005216 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217
Dustin Browne74003f2018-03-14 12:51:58 -07005218 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005219
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305220 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221}
5222
Paul Zhang84fa9382017-11-10 21:18:21 +08005223static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5224 struct hdd_adapter *adapter)
5225{
5226 switch (adapter->device_mode) {
5227 case QDF_STA_MODE:
5228 case QDF_P2P_CLIENT_MODE:
5229 case QDF_IBSS_MODE:
5230 case QDF_P2P_DEVICE_MODE:
5231 case QDF_NDI_MODE:
5232 wlan_hdd_scan_abort(adapter);
5233 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5234 if (adapter->device_mode == QDF_STA_MODE)
5235 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5236 adapter->dev);
5237 break;
5238 case QDF_P2P_GO_MODE:
5239 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5240 break;
5241 case QDF_SAP_MODE:
5242 wlan_hdd_undo_acs(adapter);
5243 break;
5244 default:
5245 break;
5246 }
5247}
5248
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005249QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250{
Jeff Johnson9d295242017-08-29 14:39:48 -07005251 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005252 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005253 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005254 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255
Dustin Brown491d54b2018-03-14 12:39:11 -07005256 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305258 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5259
Dustin Brown920397d2017-12-13 16:27:50 -08005260 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005261 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5262 hdd_device_mode_to_string(adapter->device_mode),
5263 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305264
5265 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005266 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305267 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005268 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005269 adapter->session.station.hdd_reassoc_scenario = false;
5270 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305271
Arun Khandavallicc544b32017-01-30 19:52:16 +05305272 if (hdd_ctx->config->sap_internal_restart &&
5273 adapter->device_mode == QDF_SAP_MODE) {
5274 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305275 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305276 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005277 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005278 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005279 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005280 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5281 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305282 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305283 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286
Paul Zhang84fa9382017-11-10 21:18:21 +08005287 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005288
5289 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005290 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005291 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005292 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305293 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5295 hdd_wmm_adapter_close(adapter);
5296 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5297 }
5298
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305299 if (adapter->device_mode == QDF_STA_MODE)
5300 hdd_clear_fils_connection_info(adapter);
5301
Wu Gao3545e642017-07-14 19:24:41 +08005302 if (adapter->device_mode == QDF_SAP_MODE) {
5303 /*
5304 * If adapter is SAP, set session ID to invalid
5305 * since SAP session will be cleanup during SSR.
5306 */
Wu Gao36717432016-11-21 15:09:48 +08005307 wlansap_set_invalid_session(
5308 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5309
Wu Gao3545e642017-07-14 19:24:41 +08005310 wlansap_cleanup_cac_timer(
5311 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5312 }
5313
Yue Ma42654682018-01-11 16:55:24 -08005314 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005315 if (adapter->device_mode == QDF_STA_MODE ||
5316 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005317 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005318 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005319 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005320
5321 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5322 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005323 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5324 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5325 if (adapter->sta_info[sta_id].in_use) {
5326 hdd_debug("[SSR] deregister STA with ID %d",
5327 sta_id);
5328 hdd_softap_deregister_sta(adapter,
5329 sta_id);
5330 adapter->sta_info[sta_id].in_use = 0;
5331 }
5332 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005333 }
5334
Alok Kumarb64650c2018-03-23 17:05:11 +05305335 hdd_nud_reset_tracking(adapter);
5336 hdd_nud_ignore_tracking(adapter, true);
5337 hdd_set_disconnect_status(adapter, false);
5338
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005339 hdd_softap_deinit_tx_rx(adapter);
5340
Yue Maf9782842017-05-08 12:49:49 -07005341 /* Destroy vdev which will be recreated during reinit. */
5342 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 }
5344
Dustin Browne74003f2018-03-14 12:51:58 -07005345 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305347 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348}
5349
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005350bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305351{
Dustin Brown920397d2017-12-13 16:27:50 -08005352 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305353 bool close_modules = true;
5354
Arun Khandavalliba479c42017-07-26 21:29:40 +05305355 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5356 hdd_info("FTM mode, don't close the module");
5357 return false;
5358 }
5359
Dustin Brown920397d2017-12-13 16:27:50 -08005360 hdd_for_each_adapter(hdd_ctx, adapter) {
5361 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5362 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005363 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305364 close_modules = false;
5365 break;
5366 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305367 }
5368
5369 return close_modules;
5370}
5371
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305372bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305373{
5374 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5375 return true;
5376 else
5377 return false;
5378}
5379
Anurag Chouhanc4092922016-09-08 15:56:11 +05305380#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005381 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305382struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5383 struct ieee80211_channel *channel,
5384 const u8 *bssid, const u8 *ssid,
5385 size_t ssid_len)
5386{
5387 return cfg80211_get_bss(wiphy, channel, bssid,
5388 ssid, ssid_len,
5389 WLAN_CAPABILITY_ESS,
5390 WLAN_CAPABILITY_ESS);
5391}
5392#else
5393struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5394 struct ieee80211_channel *channel,
5395 const u8 *bssid, const u8 *ssid,
5396 size_t ssid_len)
5397{
5398 return cfg80211_get_bss(wiphy, channel, bssid,
5399 ssid, ssid_len,
5400 IEEE80211_BSS_TYPE_ESS,
5401 IEEE80211_PRIVACY_ANY);
5402}
5403#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305404
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305405#if defined CFG80211_CONNECT_BSS || \
5406 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305407#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305408 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305409/**
5410 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5411 * @timeout_reason: reason for connect timeout
5412 *
5413 * This function is used to convert host timeout
5414 * reason enum to kernel specific enum.
5415 *
5416 * Return: nl timeout enum
5417 */
5418static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5419 tSirResultCodes timeout_reason)
5420{
5421 switch (timeout_reason) {
5422 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5423 return NL80211_TIMEOUT_SCAN;
5424 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5425 return NL80211_TIMEOUT_AUTH;
5426 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5427 return NL80211_TIMEOUT_ASSOC;
5428 default:
5429 return NL80211_TIMEOUT_UNSPECIFIED;
5430 }
5431}
5432
5433/**
5434 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5435 * @dev: network device
5436 * @bssid: bssid to which we want to associate
5437 * @timeout_reason: reason for connect timeout
5438 *
5439 * This API is used to send connection timeout reason to supplicant
5440 *
5441 * Return: void
5442 */
5443static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5444 const u8 *bssid,
5445 tSirResultCodes timeout_reason)
5446{
5447 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005448
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305449 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5450
5451 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5452 nl_timeout_reason);
5453}
5454
5455/**
5456 * __hdd_connect_bss() - API to send connection status to supplicant
5457 * @dev: network device
5458 * @bssid: bssid to which we want to associate
5459 * @req_ie: Request Information Element
5460 * @req_ie_len: len of the req IE
5461 * @resp_ie: Response IE
5462 * @resp_ie_len: len of ht response IE
5463 * @status: status
5464 * @gfp: Kernel Flag
5465 * @timeout_reason: reason for connect timeout
5466 *
5467 * Return: void
5468 */
5469static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5470 struct cfg80211_bss *bss, const u8 *req_ie,
5471 size_t req_ie_len, const u8 *resp_ie,
5472 size_t resp_ie_len, int status, gfp_t gfp,
5473 tSirResultCodes timeout_reason)
5474{
5475 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005476
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305477 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5478
5479 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5480 resp_ie, resp_ie_len, status, gfp,
5481 nl_timeout_reason);
5482}
5483#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305484#if defined CFG80211_CONNECT_TIMEOUT || \
5485 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305486static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5487 const u8 *bssid,
5488 tSirResultCodes timeout_reason)
5489{
5490 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5491}
5492#endif
5493
5494static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5495 struct cfg80211_bss *bss, const u8 *req_ie,
5496 size_t req_ie_len, const u8 *resp_ie,
5497 size_t resp_ie_len, int status, gfp_t gfp,
5498 tSirResultCodes timeout_reason)
5499{
5500 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5501 resp_ie, resp_ie_len, status, gfp);
5502}
5503#endif
5504
Abhishek Singha84d3952016-09-13 13:45:05 +05305505/**
5506 * hdd_connect_bss() - API to send connection status to supplicant
5507 * @dev: network device
5508 * @bssid: bssid to which we want to associate
5509 * @req_ie: Request Information Element
5510 * @req_ie_len: len of the req IE
5511 * @resp_ie: Response IE
5512 * @resp_ie_len: len of ht response IE
5513 * @status: status
5514 * @gfp: Kernel Flag
5515 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305516 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305517 *
5518 * The API is a wrapper to send connection status to supplicant
5519 *
5520 * Return: Void
5521 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305522#if defined CFG80211_CONNECT_TIMEOUT || \
5523 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305524static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5525 struct cfg80211_bss *bss, const u8 *req_ie,
5526 size_t req_ie_len, const u8 *resp_ie,
5527 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305528 bool connect_timeout,
5529 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305530{
5531 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305532 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305533 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305534 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5535 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305536}
5537#else
5538static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5539 struct cfg80211_bss *bss, const u8 *req_ie,
5540 size_t req_ie_len, const u8 *resp_ie,
5541 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305542 bool connect_timeout,
5543 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305544{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305545 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5546 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305547}
5548#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305549
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305550#if defined(WLAN_FEATURE_FILS_SK)
5551#if defined(CFG80211_CONNECT_DONE) || \
5552 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5553#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5554 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305555/**
5556 * hdd_populate_fils_params() - Populate FILS keys to connect response
5557 * @fils_params: connect response to supplicant
5558 * @fils_kek: FILS kek
5559 * @fils_kek_len: FILS kek length
5560 * @pmk: FILS PMK
5561 * @pmk_len: FILS PMK length
5562 * @pmkid: PMKID
5563 * @fils_seq_num: FILS Seq number
5564 *
5565 * Return: None
5566 */
5567static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5568 *fils_params, const uint8_t *fils_kek,
5569 size_t fils_kek_len, const uint8_t *pmk,
5570 size_t pmk_len, const uint8_t *pmkid,
5571 uint16_t fils_seq_num)
5572{
5573 /* Increament seq number to be used for next FILS */
5574 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5575 fils_params->update_erp_next_seq_num = true;
5576 fils_params->fils_kek = fils_kek;
5577 fils_params->fils_kek_len = fils_kek_len;
5578 fils_params->pmk = pmk;
5579 fils_params->pmk_len = pmk_len;
5580 fils_params->pmkid = pmkid;
5581}
5582#else
5583static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5584 *fils_params, const uint8_t
5585 *fils_kek, size_t fils_kek_len,
5586 const uint8_t *pmk, size_t pmk_len,
5587 const uint8_t *pmkid,
5588 uint16_t fils_seq_num)
5589{ }
5590#endif
5591
Jeff Johnson172237b2017-11-07 15:32:59 -08005592void hdd_update_hlp_info(struct net_device *dev,
5593 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305594{
5595 struct sk_buff *skb;
5596 uint16_t skb_len;
5597 struct llc_snap_hdr_t *llc_hdr;
5598 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305599 uint8_t *hlp_data;
5600 uint16_t hlp_data_len;
5601 struct fils_join_rsp_params *roam_fils_params
5602 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305603 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5604
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305605 if (!roam_fils_params) {
5606 hdd_err("FILS Roam Param NULL");
5607 return;
5608 }
5609
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005610 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305611 hdd_err("FILS HLP Data NULL, len %d",
5612 roam_fils_params->hlp_data_len);
5613 return;
5614 }
5615
5616 hlp_data = roam_fils_params->hlp_data;
5617 hlp_data_len = roam_fils_params->hlp_data_len;
5618
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305619 /* Calculate skb length */
5620 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5621 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5622 if (skb == NULL) {
5623 hdd_err("HLP packet nbuf alloc fails");
5624 return;
5625 }
5626
5627 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5628 QDF_MAC_ADDR_SIZE);
5629 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5630 QDF_MAC_ADDR_SIZE);
5631
5632 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5633 if (IS_SNAP(llc_hdr)) {
5634 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5635 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5636 }
5637
5638 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5639
5640 /*
5641 * This HLP packet is formed from HLP info encapsulated
5642 * in assoc response frame which is AEAD encrypted.
5643 * Hence, this checksum validation can be set unnecessary.
5644 * i.e. network layer need not worry about checksum.
5645 */
5646 skb->ip_summed = CHECKSUM_UNNECESSARY;
5647
5648 status = hdd_rx_packet_cbk(padapter, skb);
5649 if (QDF_IS_STATUS_ERROR(status)) {
5650 hdd_err("Sending HLP packet fails");
5651 return;
5652 }
5653 hdd_debug("send HLP packet to netif successfully");
5654}
5655
5656/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305657 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5658 * @dev: network device
5659 * @bssid: bssid to which we want to associate
5660 * @bss: cfg80211 bss info
5661 * @roam_info: information about connected bss
5662 * @req_ie: Request Information Element
5663 * @req_ie_len: len of the req IE
5664 * @resp_ie: Response IE
5665 * @resp_ie_len: len of ht response IE
5666 * @status: status
5667 * @gfp: allocation flags
5668 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5669 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305670 *
5671 * This API is used as wrapper to send FILS key/sequence number
5672 * params etc. to supplicant in case of FILS connection
5673 *
5674 * Return: None
5675 */
5676static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005677 struct cfg80211_bss *bss,
5678 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305679 const u8 *req_ie, size_t req_ie_len,
5680 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005681 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305682 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305683{
5684 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305685 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5686 struct fils_join_rsp_params *roam_fils_params =
5687 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005688
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305689 qdf_mem_zero(&fils_params, sizeof(fils_params));
5690
5691 if (!roam_fils_params) {
5692 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5693 } else {
5694 fils_params.status = status;
5695 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005696 fils_params.timeout_reason =
5697 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305698 fils_params.req_ie = req_ie;
5699 fils_params.req_ie_len = req_ie_len;
5700 fils_params.resp_ie = resp_ie;
5701 fils_params.resp_ie_len = resp_ie_len;
5702 fils_params.bss = bss;
5703 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5704 roam_fils_params->kek_len,
5705 roam_fils_params->fils_pmk,
5706 roam_fils_params->fils_pmk_len,
5707 roam_fils_params->fils_pmkid,
5708 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305709 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305710 }
5711 hdd_debug("FILS indicate connect status %d seq no %d",
5712 fils_params.status,
5713 fils_params.fils_erp_next_seq_num);
5714
5715 cfg80211_connect_done(dev, &fils_params, gfp);
5716
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305717 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305718 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305719
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305720 /* Clear all the FILS key info */
5721 if (roam_fils_params && roam_fils_params->fils_pmk)
5722 qdf_mem_free(roam_fils_params->fils_pmk);
5723 if (roam_fils_params)
5724 qdf_mem_free(roam_fils_params);
5725 roam_info->fils_join_rsp = NULL;
5726}
5727#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005728static inline void
5729hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005730 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005731 const u8 *req_ie, size_t req_ie_len,
5732 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5733 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305734 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305735{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305736#endif
5737#endif
5738
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305739#if defined(WLAN_FEATURE_FILS_SK) && \
5740 (defined(CFG80211_CONNECT_DONE) || \
5741 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305742/**
5743 * hdd_fils_update_connect_results() - API to send fils connection status to
5744 * supplicant.
5745 * @dev: network device
5746 * @bssid: bssid to which we want to associate
5747 * @bss: cfg80211 bss info
5748 * @roam_info: information about connected bss
5749 * @req_ie: Request Information Element
5750 * @req_ie_len: len of the req IE
5751 * @resp_ie: Response IE
5752 * @resp_ie_len: len of ht response IE
5753 * @status: status
5754 * @gfp: allocation flags
5755 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5756 * @timeout_reason: reason for connect timeout
5757 *
5758 * The API is a wrapper to send connection status to supplicant
5759 *
5760 * Return: 0 if success else failure
5761 */
5762static int hdd_fils_update_connect_results(struct net_device *dev,
5763 const u8 *bssid,
5764 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005765 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305766 size_t req_ie_len, const u8 *resp_ie,
5767 size_t resp_ie_len, u16 status, gfp_t gfp,
5768 bool connect_timeout,
5769 tSirResultCodes timeout_reason)
5770{
Dustin Brown491d54b2018-03-14 12:39:11 -07005771 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305772 if (!roam_info || !roam_info->is_fils_connection)
5773 return -EINVAL;
5774
5775 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5776 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305777 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305778 return 0;
5779}
5780#else
5781static inline int hdd_fils_update_connect_results(struct net_device *dev,
5782 const u8 *bssid,
5783 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005784 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305785 size_t req_ie_len, const u8 *resp_ie,
5786 size_t resp_ie_len, u16 status, gfp_t gfp,
5787 bool connect_timeout,
5788 tSirResultCodes timeout_reason)
5789{
5790 return -EINVAL;
5791}
5792#endif
5793
Anurag Chouhanc4092922016-09-08 15:56:11 +05305794/**
5795 * hdd_connect_result() - API to send connection status to supplicant
5796 * @dev: network device
5797 * @bssid: bssid to which we want to associate
5798 * @roam_info: information about connected bss
5799 * @req_ie: Request Information Element
5800 * @req_ie_len: len of the req IE
5801 * @resp_ie: Response IE
5802 * @resp_ie_len: len of ht response IE
5803 * @status: status
5804 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305805 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305806 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305807 *
5808 * The API is a wrapper to send connection status to supplicant
5809 * and allow runtime suspend
5810 *
5811 * Return: Void
5812 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305813void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005814 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305815 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305816 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305817 bool connect_timeout,
5818 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305819{
Jeff Johnson9d295242017-08-29 14:39:48 -07005820 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305821 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005822 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305823
5824 if (WLAN_STATUS_SUCCESS == status) {
5825 struct ieee80211_channel *chan;
5826 int freq;
5827 int chan_no = roam_info->pBssDesc->channelId;
5828
5829 if (chan_no <= 14)
5830 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005831 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305832 else
5833 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005834 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305835
5836 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5837 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5838 roam_info->u.pConnectedProfile->SSID.ssId,
5839 roam_info->u.pConnectedProfile->SSID.length);
5840 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305841
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305842 if (hdd_fils_update_connect_results(dev, bssid, bss,
5843 roam_info, req_ie, req_ie_len, resp_ie,
5844 resp_ie_len, status, gfp, connect_timeout,
5845 timeout_reason) != 0) {
5846 hdd_connect_bss(dev, bssid, bss, req_ie,
5847 req_ie_len, resp_ie, resp_ie_len,
5848 status, gfp, connect_timeout, timeout_reason);
5849 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305850
Jingxiang Geb49aa302018-01-17 20:54:15 +08005851 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005852 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305853}
5854#else
5855void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005856 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305857 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305858 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305859 bool connect_timeout,
5860 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305861{
Jeff Johnson9d295242017-08-29 14:39:48 -07005862 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005863 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305864
Anurag Chouhanc4092922016-09-08 15:56:11 +05305865 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5866 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005867
Jingxiang Geb49aa302018-01-17 20:54:15 +08005868 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005869 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305870}
5871#endif
5872
5873
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005874QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875{
Jeff Johnson9d295242017-08-29 14:39:48 -07005876 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005877#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005878 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005879#endif
5880 eConnectionState connState;
5881
Dustin Brown491d54b2018-03-14 12:39:11 -07005882 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005883
Dustin Brown920397d2017-12-13 16:27:50 -08005884 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305885 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005886 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305887
Yue Ma42654682018-01-11 16:55:24 -08005888 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5889 hdd_device_mode_to_string(adapter->device_mode),
5890 adapter->device_mode);
5891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892 hdd_wmm_init(adapter);
5893
5894 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005895 case QDF_STA_MODE:
5896 case QDF_P2P_CLIENT_MODE:
5897 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898
5899 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5900 ->conn_info.connState;
5901
Krunal Sonib51eec72017-11-20 21:53:01 -08005902 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005904 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005905
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005906 /* Indicate disconnect event to supplicant
5907 * if associated previously
5908 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005910 eConnectionState_IbssConnected == connState ||
5911 eConnectionState_NotConnected == connState ||
5912 eConnectionState_IbssDisconnected == connState ||
5913 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005914 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916 memset(&wrqu, '\0', sizeof(wrqu));
5917 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5918 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5919 wireless_send_event(adapter->dev, SIOCGIWAP,
5920 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005921 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005922 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005923
5924 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305925 wlan_hdd_cfg80211_indicate_disconnect(
5926 adapter->dev, false,
5927 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005928 } else if (eConnectionState_Connecting == connState) {
5929 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005930 * Indicate connect failure to supplicant if we
5931 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305933 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305934 NULL, 0, NULL, 0,
5935 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005936 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 }
5938
5939 hdd_register_tx_flow_control(adapter,
5940 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005941 hdd_tx_resume_cb,
5942 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943
Alok Kumarb64650c2018-03-23 17:05:11 +05305944 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 break;
5946
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005947 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005948 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005949 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005951 break;
5952
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005953 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005955 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005956 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5957#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005958 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 /* event supplicant to restart */
5960 cfg80211_del_sta(adapter->dev,
5961 (const u8 *)&bcastMac.bytes[0],
5962 GFP_KERNEL);
5963#endif
5964 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305965 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005966 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305967 hdd_set_mon_rx_cb(adapter->dev);
5968 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5969 adapter->mon_bandwidth);
5970 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005971 default:
5972 break;
5973 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005974 /*
5975 * Action frame registered in one adapter which will
5976 * applicable to all interfaces
5977 */
5978 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005979 }
5980
Dustin Browne74003f2018-03-14 12:51:58 -07005981 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005982
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305983 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984}
5985
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005986QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005987 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005988{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305989 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005990 qdf_list_node_t *node;
5991
5992 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005993
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005994 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005995 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005996 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005997
5998 if (QDF_IS_STATUS_ERROR(status))
5999 return status;
6000
6001 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6002
6003 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006004}
6005
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006006QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006007 struct hdd_adapter *current_adapter,
6008 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306010 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006011 qdf_list_node_t *node;
6012
6013 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006014
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006015 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006016 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006017 &current_adapter->node,
6018 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006019 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006020
6021 if (QDF_IS_STATUS_ERROR(status))
6022 return status;
6023
6024 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 return status;
6027}
6028
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006029QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006030 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006031{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306032 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006033
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006034 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006035 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006036 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006038 return status;
6039}
6040
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006041QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006042 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006043{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306044 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006045 qdf_list_node_t *node;
6046
6047 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006048
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006049 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006050 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006051 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006052
6053 if (QDF_IS_STATUS_ERROR(status))
6054 return status;
6055
6056 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006058 return status;
6059}
6060
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006061QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006062 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306064 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006065
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006066 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006067 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006068 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070 return status;
6071}
6072
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006073QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006074 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306076 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006077
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006078 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006079 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006080 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006081
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006082 return status;
6083}
6084
Jeff Johnson9d295242017-08-29 14:39:48 -07006085struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006086 tSirMacAddr macAddr)
6087{
Jeff Johnson9d295242017-08-29 14:39:48 -07006088 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089
Dustin Brown920397d2017-12-13 16:27:50 -08006090 hdd_for_each_adapter(hdd_ctx, adapter) {
6091 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6092 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006093 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006094 }
6095
6096 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097}
6098
Jeff Johnson9d295242017-08-29 14:39:48 -07006099struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006100 uint32_t vdev_id)
6101{
Jeff Johnson9d295242017-08-29 14:39:48 -07006102 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103
Dustin Brown920397d2017-12-13 16:27:50 -08006104 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006105 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006107 }
6108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109 return NULL;
6110}
6111
Abhishek Singh7996eb72015-12-30 17:24:02 +05306112/**
6113 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6114 * the sessionid
6115 * @hdd_ctx: hdd context.
6116 * @sme_session_id: sme session is for the adapter to get.
6117 *
6118 * This function is used to get the adapter with provided session id
6119 *
6120 * Return: adapter pointer if found
6121 *
6122 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006123struct hdd_adapter *
6124hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6125 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306126{
Jeff Johnson9d295242017-08-29 14:39:48 -07006127 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306128
Dustin Brown920397d2017-12-13 16:27:50 -08006129 hdd_for_each_adapter(hdd_ctx, adapter) {
6130 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306131 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306132 }
Dustin Brown920397d2017-12-13 16:27:50 -08006133
Abhishek Singh7996eb72015-12-30 17:24:02 +05306134 return NULL;
6135}
6136
Jeff Johnson9d295242017-08-29 14:39:48 -07006137struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006138 const char *iface_name)
6139{
Jeff Johnson9d295242017-08-29 14:39:48 -07006140 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006141
Dustin Brown920397d2017-12-13 16:27:50 -08006142 hdd_for_each_adapter(hdd_ctx, adapter) {
6143 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006144 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006145 }
Dustin Brown920397d2017-12-13 16:27:50 -08006146
Naveen Rawat4edb6822017-04-12 10:09:17 -07006147 return NULL;
6148}
6149
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006150/**
6151 * hdd_get_adapter() - to get adapter matching the mode
6152 * @hdd_ctx: hdd context
6153 * @mode: adapter mode
6154 *
6155 * This routine will return the pointer to adapter matching
6156 * with the passed mode.
6157 *
6158 * Return: pointer to adapter or null
6159 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006160struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006161 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006162{
Jeff Johnson9d295242017-08-29 14:39:48 -07006163 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006164
Dustin Brown920397d2017-12-13 16:27:50 -08006165 hdd_for_each_adapter(hdd_ctx, adapter) {
6166 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168 }
6169
6170 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171}
6172
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306173enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6174{
6175 struct hdd_context *hdd_ctx;
6176 struct hdd_adapter *adapter;
6177
6178 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6179 if (!hdd_ctx) {
6180 hdd_err("Invalid HDD context");
6181 return QDF_MAX_NO_OF_MODE;
6182 }
6183
6184 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6185 if (!adapter) {
6186 hdd_err("Invalid HDD adapter");
6187 return QDF_MAX_NO_OF_MODE;
6188 }
6189
6190 return adapter->device_mode;
6191}
6192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006193/**
6194 * hdd_get_operating_channel() - return operating channel of the device mode
6195 * @hdd_ctx: Pointer to the HDD context.
6196 * @mode: Device mode for which operating channel is required.
6197 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006198 * QDF_STA_MODE,
6199 * QDF_P2P_CLIENT_MODE,
6200 * QDF_SAP_MODE,
6201 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 *
6203 * This API returns the operating channel of the requested device mode
6204 *
6205 * Return: channel number. "0" id the requested device is not found OR it is
6206 * not connected.
6207 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006208uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006209 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006210{
Jeff Johnson9d295242017-08-29 14:39:48 -07006211 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006212 uint8_t operatingChannel = 0;
6213
Dustin Brown920397d2017-12-13 16:27:50 -08006214 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 if (mode == adapter->device_mode) {
6216 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006217 case QDF_STA_MODE:
6218 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006219 if (hdd_conn_is_connected
6220 (WLAN_HDD_GET_STATION_CTX_PTR
6221 (adapter))) {
6222 operatingChannel =
6223 (WLAN_HDD_GET_STATION_CTX_PTR
6224 (adapter))->conn_info.
6225 operationChannel;
6226 }
6227 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006228 case QDF_SAP_MODE:
6229 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230 /* softap connection info */
6231 if (test_bit
6232 (SOFTAP_BSS_STARTED,
6233 &adapter->event_flags))
6234 operatingChannel =
6235 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006236 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006237 break;
6238 default:
6239 break;
6240 }
6241
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006242 /* Found the device of interest. break the loop */
6243 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 }
Dustin Brown920397d2017-12-13 16:27:50 -08006246
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247 return operatingChannel;
6248}
6249
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006250static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 hdd_ctx)
6252{
Jeff Johnson9d295242017-08-29 14:39:48 -07006253 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254
Dustin Brown491d54b2018-03-14 12:39:11 -07006255 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006256
Dustin Brown920397d2017-12-13 16:27:50 -08006257 hdd_for_each_adapter(hdd_ctx, adapter) {
6258 if (adapter->device_mode == QDF_STA_MODE ||
6259 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6260 adapter->device_mode == QDF_IBSS_MODE ||
6261 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6262 adapter->device_mode == QDF_SAP_MODE ||
6263 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006264 wlan_hdd_cfg80211_deregister_frames(adapter);
6265 hdd_unregister_wext(adapter->dev);
6266 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267 }
6268
Dustin Browne74003f2018-03-14 12:51:58 -07006269 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306271 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272}
6273
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006274QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275{
Jeff Johnson9d295242017-08-29 14:39:48 -07006276 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277
Dustin Brown491d54b2018-03-14 12:39:11 -07006278 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279
Dustin Brown920397d2017-12-13 16:27:50 -08006280 hdd_for_each_adapter(hdd_ctx, adapter) {
6281 if (adapter->device_mode == QDF_STA_MODE ||
6282 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6283 adapter->device_mode == QDF_IBSS_MODE ||
6284 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6285 adapter->device_mode == QDF_SAP_MODE ||
6286 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006287 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006288 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306289 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006291 }
6292
Dustin Browne74003f2018-03-14 12:51:58 -07006293 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306295 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296}
6297
Dustin Brownf27bce82016-11-03 12:52:27 -07006298/**
6299 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6300 * adapters
6301 * @hdd_ctx: The HDD context containing the adapters to operate on
6302 *
6303 * return: QDF_STATUS_SUCCESS
6304 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006305static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006306{
Jeff Johnson9d295242017-08-29 14:39:48 -07006307 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006308 int err;
6309
Dustin Brown491d54b2018-03-14 12:39:11 -07006310 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006311
Dustin Brown920397d2017-12-13 16:27:50 -08006312 hdd_for_each_adapter(hdd_ctx, adapter) {
6313 if (adapter->device_mode == QDF_STA_MODE ||
6314 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6315 adapter->device_mode == QDF_IBSS_MODE ||
6316 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6317 adapter->device_mode == QDF_SAP_MODE ||
6318 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006319 err = wlan_hdd_sched_scan_stop(adapter->dev);
6320 if (err)
6321 hdd_err("Unable to stop scheduled scan");
6322 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006323 }
6324
Dustin Browne74003f2018-03-14 12:51:58 -07006325 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006326
6327 return QDF_STATUS_SUCCESS;
6328}
6329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006330#ifdef WLAN_NS_OFFLOAD
6331/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006332 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006333 * @hdd_ctx: Pointer to hdd context
6334 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006335 * Unregister for IPv6 address change notifications.
6336 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 * Return: None
6338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006339static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340{
6341 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342}
6343
6344/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006345 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 * @hdd_ctx: Pointer to hdd context
6347 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006348 * Register for IPv6 address change notifications.
6349 *
6350 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006352static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006353{
6354 int ret;
6355
6356 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6357 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006358 if (ret) {
6359 hdd_err("Failed to register IPv6 notifier: %d", ret);
6360 goto out;
6361 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006362
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006363 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006364out:
6365 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366}
6367#else
6368/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006369 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006370 * @hdd_ctx: Pointer to hdd context
6371 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006372 * Unregister for IPv6 address change notifications.
6373 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374 * Return: None
6375 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006376static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006377{
6378}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006379
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006380/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006381 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006382 * @hdd_ctx: Pointer to hdd context
6383 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006384 * Register for IPv6 address change notifications.
6385 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386 * Return: None
6387 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006388static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006390 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391}
6392#endif
6393
Alok Kumarb64650c2018-03-23 17:05:11 +05306394void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6395{
6396 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6397 adapter->disconnection_in_progress = status;
6398 qdf_mutex_release(&adapter->disconnection_status_lock);
6399 hdd_debug("setting disconnection status: %d", status);
6400}
6401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006403 * hdd_register_notifiers - Register netdev notifiers.
6404 * @hdd_ctx: HDD context
6405 *
6406 * Register netdev notifiers like IPv4 and IPv6.
6407 *
6408 * Return: 0 on success and errno on failure
6409 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006410static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006411{
6412 int ret;
6413
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006414 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6415 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306416 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006417
6418 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6419 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6420 if (ret) {
6421 hdd_err("Failed to register IPv4 notifier: %d", ret);
6422 goto unregister_ip6_notifier;
6423 }
6424
Alok Kumarb64650c2018-03-23 17:05:11 +05306425 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6426 if (ret) {
6427 hdd_err("Failed to register netevent notifier: %d",
6428 ret);
6429 goto unregister_inetaddr_notifier;
6430 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006431 return 0;
6432
Alok Kumarb64650c2018-03-23 17:05:11 +05306433unregister_inetaddr_notifier:
6434 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006435unregister_ip6_notifier:
6436 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006437out:
6438 return ret;
6439
6440}
6441
6442/**
6443 * hdd_unregister_notifiers - Unregister netdev notifiers.
6444 * @hdd_ctx: HDD context
6445 *
6446 * Unregister netdev notifiers like IPv4 and IPv6.
6447 *
6448 * Return: None.
6449 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006450void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006451{
Alok Kumarb64650c2018-03-23 17:05:11 +05306452 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006453 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6454
6455 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006456}
6457
6458/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006459 * hdd_exit_netlink_services - Exit netlink services
6460 * @hdd_ctx: HDD context
6461 *
6462 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6463 * nl service.
6464 *
6465 * Return: None.
6466 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006467static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006468{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006469 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006470 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006471 ptt_sock_deactivate_svc();
6472
6473 nl_srv_exit();
6474}
6475
6476/**
6477 * hdd_init_netlink_services- Init netlink services
6478 * @hdd_ctx: HDD context
6479 *
6480 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6481 * nl service.
6482 *
6483 * Return: 0 on success and errno on failure.
6484 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006485static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006486{
6487 int ret;
6488
Ryan Hsuceddceb2016-04-28 10:20:14 -07006489 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006490 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006491 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006492 goto out;
6493 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006494 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006495
Naveen Rawat910726a2017-03-06 11:42:51 -08006496 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006497 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006498 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006499 goto err_nl_srv;
6500 }
6501
6502 ret = ptt_sock_activate_svc();
6503 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006504 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006505 goto err_nl_srv;
6506 }
6507
6508 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006509 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006510 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006511
6512 ret = cnss_diag_activate_service();
6513 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006514 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006515 goto err_close_cesium;
6516 }
6517
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006518 ret = spectral_scan_activate_service();
6519 if (ret) {
6520 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6521 goto err_close_cesium;
6522 }
6523
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006524 return 0;
6525
6526err_close_cesium:
6527 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006528 ptt_sock_deactivate_svc();
6529err_nl_srv:
6530 nl_srv_exit();
6531out:
6532 return ret;
6533}
6534
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006535/**
6536 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6537 * @hdd_ctx: HDD context.
6538 *
6539 * Destroy RX wakelock.
6540 *
6541 * Return: None.
6542 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006543static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006544{
6545 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6546}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006547
6548/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006549 * hdd_rx_wake_lock_create() - Create RX wakelock
6550 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006551 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006552 * Create RX wakelock.
6553 *
6554 * Return: None.
6555 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006556static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006557{
6558 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6559}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006560
6561/**
Houston Hoffman160db392016-10-10 17:37:51 -07006562 * hdd_context_deinit() - Deinitialize HDD context
6563 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006564 *
Houston Hoffman160db392016-10-10 17:37:51 -07006565 * Deinitialize HDD context along with all the feature specific contexts but
6566 * do not free hdd context itself. Caller of this API is supposed to free
6567 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006568 *
Houston Hoffman160db392016-10-10 17:37:51 -07006569 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006570 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006571static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006572{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306573 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6574
Houston Hoffman160db392016-10-10 17:37:51 -07006575 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006576
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006577 hdd_sap_context_destroy(hdd_ctx);
6578
6579 hdd_rx_wake_lock_destroy(hdd_ctx);
6580
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006581 hdd_scan_context_destroy(hdd_ctx);
6582
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006583 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006584
Houston Hoffman160db392016-10-10 17:37:51 -07006585 return 0;
6586}
6587
6588/**
6589 * hdd_context_destroy() - Destroy HDD context
6590 * @hdd_ctx: HDD context to be destroyed.
6591 *
6592 * Free config and HDD context as well as destroy all the resources.
6593 *
6594 * Return: None
6595 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006596static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006597{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006598 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306599
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306600 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6601
Houston Hoffman160db392016-10-10 17:37:51 -07006602 hdd_context_deinit(hdd_ctx);
6603
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306604 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006605 hdd_ctx->config = NULL;
6606
6607 wiphy_free(hdd_ctx->wiphy);
6608}
6609
6610/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306611 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6612 *
6613 * This function is used to destroy bug report lock
6614 *
6615 * Return: None
6616 */
6617static void wlan_destroy_bug_report_lock(void)
6618{
6619 p_cds_contextType p_cds_context;
6620
6621 p_cds_context = cds_get_global_context();
6622 if (!p_cds_context) {
6623 hdd_err("cds context is NULL");
6624 return;
6625 }
6626
6627 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6628}
6629
6630/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631 * hdd_wlan_exit() - HDD WLAN exit function
6632 * @hdd_ctx: Pointer to the HDD Context
6633 *
6634 * This is the driver exit point (invoked during rmmod)
6635 *
6636 * Return: None
6637 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006638static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306641 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642
Dustin Brown491d54b2018-03-14 12:39:11 -07006643 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006644
Dustin Brown6f427922017-09-19 12:19:00 -07006645 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306646
6647 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648
Prashanth Bhattaab004382016-10-11 16:08:11 -07006649 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
6651#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306652 if (QDF_TIMER_STATE_RUNNING ==
6653 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6654 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655 }
6656
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306657 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306658 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006659 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006660 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006661 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6662 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6663 hdd_ctx->last_acs_channel_list = NULL;
6664 hdd_ctx->num_of_channels = 0;
6665 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006667
Arun Khandavallifae92942016-08-01 13:31:08 +05306668 mutex_lock(&hdd_ctx->iface_change_lock);
6669 driver_status = hdd_ctx->driver_status;
6670 mutex_unlock(&hdd_ctx->iface_change_lock);
6671
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672 /*
6673 * Powersave Offload Case
6674 * Disable Idle Power Save Mode
6675 */
6676 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006677 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306678 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679
Arun Khandavallifae92942016-08-01 13:31:08 +05306680 if (driver_status != DRIVER_MODULES_CLOSED) {
6681 hdd_unregister_wext_all_adapters(hdd_ctx);
6682 /*
6683 * Cancel any outstanding scan requests. We are about to close
6684 * all of our adapters, but an adapter structure is what SME
6685 * passes back to our callback function. Hence if there
6686 * are any outstanding scan requests then there is a
6687 * race condition between when the adapter is closed and
6688 * when the callback is invoked. We try to resolve that
6689 * race condition here by canceling any outstanding scans
6690 * before we close the adapters.
6691 * Note that the scans may be cancelled in an asynchronous
6692 * manner, so ideally there needs to be some kind of
6693 * synchronization. Rather than introduce a new
6694 * synchronization here, we will utilize the fact that we are
6695 * about to Request Full Power, and since that is synchronized,
6696 * the expectation is that by the time Request Full Power has
6697 * completed, all scans will be cancelled
6698 */
6699 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006700 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006701 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006702 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703 }
6704
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306705 unregister_netdevice_notifier(&hdd_netdev_notifier);
6706
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006707 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306708
Dustin Brown021cecd2017-12-11 13:56:43 -08006709 hdd_driver_memdump_deinit();
6710
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306711 qdf_nbuf_deinit_replenish_timer();
6712
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306713 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6714 hdd_info("Release wakelock for monitor mode!");
6715 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6716 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6717 }
6718
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306719 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6720 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6721 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6722
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723 /*
6724 * Close CDS
6725 * This frees pMac(HAL) context. There should not be any call
6726 * that requires pMac access after this.
6727 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006729 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730
Dustin Brownd005ad82018-01-19 10:32:13 -08006731 hdd_close_all_adapters(hdd_ctx, false);
6732
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306733 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306734 /*
6735 * If there is re_init failure wiphy would have already de-registered
6736 * check the wiphy status before un-registering again
6737 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306738 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306739 wiphy_unregister(wiphy);
6740 wlan_hdd_cfg80211_deinit(wiphy);
6741 hdd_lpass_notify_stop(hdd_ctx);
6742 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006743
Arun Khandavallifae92942016-08-01 13:31:08 +05306744 hdd_exit_netlink_services(hdd_ctx);
6745 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306746#ifdef FEATURE_WLAN_CH_AVOID
6747 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6748#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306749
Abhishek Singhe9068f12017-03-31 14:14:52 +05306750 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6751 if (driver_status)
6752 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006753
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006754 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006755}
6756
6757void __hdd_wlan_exit(void)
6758{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006759 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760
Dustin Brown491d54b2018-03-14 12:39:11 -07006761 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762
Anurag Chouhan6d760662016-02-20 16:05:43 +05306763 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006765 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006766 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767 return;
6768 }
6769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 /* Do all the cleanup before deregistering the driver */
6771 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006772
Dustin Browne74003f2018-03-14 12:51:58 -07006773 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006774}
6775
6776#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006777/**
6778 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006779 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006780 *
6781 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6782 * Then new ACS request will do a fresh scan without reusing the cached
6783 * scan information.
6784 *
6785 * Return: void
6786 */
Tang Yingying523322d2017-01-17 23:28:43 +08006787static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006789 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006791 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006792 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006793 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6794 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6795 hdd_ctx->last_acs_channel_list = NULL;
6796 hdd_ctx->num_of_channels = 0;
6797 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798
6799 if (!hdd_ctx->hHal)
6800 return;
6801 sme_scan_flush_result(hdd_ctx->hHal);
6802}
6803#endif
6804
6805#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006806int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6807 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006808{
6809 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306810 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006811 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006812
6813 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6814
6815 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306816 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006817 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006819 if (!hdd_ctx->hHal)
6820 return -EINVAL;
6821
Jeff Johnsone7672e72017-10-21 15:10:04 -07006822 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006823 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306824 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006825 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826 return -EINVAL;
6827 }
6828
6829 return 0;
6830}
6831#endif
6832
6833/**
6834 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6835 * @state: state
6836 *
6837 * This function notifies FW with modem power status
6838 *
6839 * Return: 0 if successful, error number otherwise
6840 */
6841int hdd_wlan_notify_modem_power_state(int state)
6842{
6843 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306844 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006845 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006846
Anurag Chouhan6d760662016-02-20 16:05:43 +05306847 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006848 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306849 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006850 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852 if (!hdd_ctx->hHal)
6853 return -EINVAL;
6854
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306855 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6856 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006857 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006858 state);
6859 return -EINVAL;
6860 }
6861 return 0;
6862}
6863
6864/**
6865 *
6866 * hdd_post_cds_enable_config() - HDD post cds start config helper
6867 * @adapter - Pointer to the HDD
6868 *
6869 * Return: None
6870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006871QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306873 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874
6875 /*
6876 * Send ready indication to the HDD. This will kick off the MAC
6877 * into a 'running' state and should kick off an initial scan.
6878 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306879 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6880 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006881 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6882 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306883 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006884 }
6885
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306886 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006887}
6888
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306889struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6890{
6891 struct hdd_adapter *adapter;
6892
6893 hdd_for_each_adapter(hdd_ctx, adapter) {
6894 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6895 return adapter;
6896 }
6897
6898 return NULL;
6899}
6900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901/* wake lock APIs for HDD */
6902void hdd_prevent_suspend(uint32_t reason)
6903{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306904 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006905}
6906
6907void hdd_allow_suspend(uint32_t reason)
6908{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306909 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910}
6911
6912void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6913{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306914 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6915 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916}
6917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006918/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006919QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006921
Amar Singhal6f8592b2017-04-26 14:31:58 -07006922 return sme_init_chan_list(hdd_ctx->hHal,
6923 hdd_ctx->reg.alpha2,
6924 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925}
6926
6927/**
6928 * hdd_is_5g_supported() - check if hardware supports 5GHz
6929 * @hdd_ctx: Pointer to the hdd context
6930 *
6931 * HDD function to know if hardware supports 5GHz
6932 *
6933 * Return: true if hardware supports 5GHz
6934 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006935bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006937 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006938 return true;
6939
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006940 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006941 return true;
6942 else
6943 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006944}
6945
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006946static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947{
6948 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006949 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950
6951 wiphy = hdd_ctx->wiphy;
6952
6953 /*
6954 * The channel information in
6955 * wiphy needs to be initialized before wiphy registration
6956 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006957 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6958 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006959 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006960 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006961 }
6962
6963#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6964 wiphy->wowlan = &wowlan_support_reg_init;
6965#else
6966 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6967 WIPHY_WOWLAN_MAGIC_PKT |
6968 WIPHY_WOWLAN_DISCONNECT |
6969 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6970 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6971 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6972 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6973 WIPHY_WOWLAN_RFKILL_RELEASE;
6974
6975 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6976 WOW_MAX_FILTERS_PER_LIST);
6977 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6978 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6979#endif
6980
6981 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006982 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306983 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006984 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306985 return ret_val;
6986 }
6987
Amar Singhal2d812012018-02-03 15:06:47 +08006988 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989
Amar Singhale4f28ee2015-10-21 14:36:56 -07006990 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991}
6992
Mohit Khannaca4173b2017-09-12 21:52:19 -07006993#ifdef MSM_PLATFORM
6994/**
6995 * hdd_display_periodic_stats() - Function to display periodic stats
6996 * @hdd_ctx - handle to hdd context
6997 * @bool data_in_interval - true, if data detected in bw time interval
6998 *
6999 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7000 * Stats show up in wlan driver logs.
7001 *
7002 * Returns: None
7003 */
7004static inline
7005void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7006 bool data_in_interval)
7007{
7008 static u32 counter;
7009 static bool data_in_time_period;
7010 ol_txrx_pdev_handle pdev;
7011
7012 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7013 return;
7014
7015 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7016 if (!pdev) {
7017 hdd_err("pdev is NULL");
7018 return;
7019 }
7020
7021 counter++;
7022 if (data_in_interval)
7023 data_in_time_period = data_in_interval;
7024
7025 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7026 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7027 if (data_in_time_period) {
7028 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7029 CDP_TXRX_PATH_STATS,
7030 QDF_STATS_VERBOSITY_LEVEL_LOW);
7031 wlan_hdd_display_netif_queue_history
7032 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7033 qdf_dp_trace_dump_stats();
7034 }
7035 counter = 0;
7036 data_in_time_period = false;
7037 }
7038}
7039
Ravi Joshie2331e82015-07-01 18:18:54 -07007040/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007041 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007042 * @hdd_ctx - handle to hdd context
7043 * @tx_packets - transmit packet count
7044 * @rx_packets - receive packet count
7045 *
7046 * The function controls the bus bandwidth and dynamic control of
7047 * tcp delayed ack configuration
7048 *
7049 * Returns: None
7050 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007051
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007052static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007053 const uint64_t tx_packets,
7054 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007056 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007057 uint64_t temp_rx = 0;
7058 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007059 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007060 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007061 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007062 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007063 uint16_t index = 0;
7064 bool vote_level_change = false;
7065 bool rx_level_change = false;
7066 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067
Mohit Khannaca4173b2017-09-12 21:52:19 -07007068 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007069 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007070 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007071 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007072 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007073 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007074 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007075 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007078 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7079 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007081 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007082 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05307083 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307084 if (hdd_ctx->hbw_requested) {
7085 pld_remove_pm_qos(hdd_ctx->parent_dev);
7086 hdd_ctx->hbw_requested = false;
7087 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307088 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007089 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007090 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307091 if (!hdd_ctx->hbw_requested) {
7092 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7093 hdd_ctx->hbw_requested = true;
7094 }
7095
Nirav Shah3bbfa512016-05-12 16:43:49 +05307096 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007097 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007098 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007099 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007101
Mohit Khannaf8f96822017-05-17 17:11:59 -07007102 qdf_dp_trace_throttle_live_mode(
7103 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7104
Mohit Khannae71e2262015-11-10 09:37:24 -08007105 /* fine-tuning parameters for RX Flows */
7106 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007109
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307110 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
7111 hdd_disable_lro_for_low_tput(hdd_ctx, true);
7112 else
7113 hdd_disable_lro_for_low_tput(hdd_ctx, false);
7114
Ravi Joshifed83572016-10-07 16:20:37 -07007115 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7116 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7117 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7118 next_rx_level = WLAN_SVC_TP_HIGH;
7119 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007120 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007121 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007122 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007123 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007126 struct wlan_rx_tp_data rx_tp_data = {0};
7127
Ravi Joshie2331e82015-07-01 18:18:54 -07007128 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007129 next_rx_level, temp_rx);
7130 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007131 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007132 /* Send throughput indication only if it is enabled.
7133 * Disabling tcp_del_ack will revert the tcp stack behavior
7134 * to default delayed ack. Note that this will disable the
7135 * dynamic delayed ack mechanism across the system
7136 */
7137 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007138 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7139
Mohit Khanna6272fb682017-04-13 09:34:36 -07007140 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7141 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7142
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007143 rx_tp_data.level = next_rx_level;
7144 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7145 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7146 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007147 }
7148
Mohit Khannae71e2262015-11-10 09:37:24 -08007149 /* fine-tuning parameters for TX Flows */
7150 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7151 hdd_ctx->prev_tx = tx_packets;
7152 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7153 next_tx_level = WLAN_SVC_TP_HIGH;
7154 else
7155 next_tx_level = WLAN_SVC_TP_LOW;
7156
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007157 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7158 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007159 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7160 next_tx_level, temp_tx);
7161 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007162 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307163 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7164 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007165 &next_tx_level,
7166 sizeof(next_tx_level));
7167 }
7168
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007169 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007170 if (vote_level_change || tx_level_change || rx_level_change) {
7171 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7172 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7173 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7174 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7175 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7176 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7177 hdd_ctx->hdd_txrx_hist_idx++;
7178 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7179 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007180
7181 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007182}
7183
7184#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307185static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007187 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307188 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07007189 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307190 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307191 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7192 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007193 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307194 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007195 bool connected = false;
7196 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7197
Prashanth Bhattaab004382016-10-11 16:08:11 -07007198 if (wlan_hdd_validate_context(hdd_ctx))
7199 return;
7200
Jeff Johnson214671b2017-10-30 19:45:23 -07007201 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007202 goto restart_timer;
7203
Dustin Brown920397d2017-12-13 16:27:50 -08007204 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307205 /*
7206 * Validate magic so we don't end up accessing
7207 * an invalid adapter.
7208 */
7209 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7210 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007211
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007212 if ((adapter->device_mode == QDF_STA_MODE ||
7213 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7215 != eConnectionState_Associated) {
7216
7217 continue;
7218 }
7219
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007220 if ((adapter->device_mode == QDF_SAP_MODE ||
7221 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007222 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223
7224 continue;
7225 }
7226
7227 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7228 adapter->prev_tx_packets);
7229 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7230 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307231
7232 if (adapter->device_mode == QDF_SAP_MODE ||
7233 adapter->device_mode == QDF_P2P_GO_MODE ||
7234 adapter->device_mode == QDF_IBSS_MODE) {
7235
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007236 ret = cdp_get_intra_bss_fwd_pkts_count(
7237 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007238 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307239 &fwd_tx_packets, &fwd_rx_packets);
7240 if (ret == A_OK) {
7241 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7242 fwd_tx_packets,
7243 adapter->prev_fwd_tx_packets);
7244 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7245 fwd_tx_packets,
7246 adapter->prev_fwd_rx_packets);
7247 }
7248 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007249
7250 total_rx += adapter->stats.rx_packets;
7251 total_tx += adapter->stats.tx_packets;
7252
7253 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7254 adapter->prev_tx_packets = adapter->stats.tx_packets;
7255 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307256 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7257 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007258 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7259 connected = true;
7260 }
7261
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307262 /* add intra bss forwarded tx and rx packets */
7263 tx_packets += fwd_tx_packets_diff;
7264 rx_packets += fwd_rx_packets_diff;
7265
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307266 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7267 &ipa_rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007268 tx_packets += (uint64_t)ipa_tx_packets;
7269 rx_packets += (uint64_t)ipa_rx_packets;
7270
7271 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007272 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273 return;
7274 }
7275
Yuanyuan Liu13738502016-04-06 17:41:37 -07007276 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007277
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +05307278 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05307279 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280
Jingxiang Gec64e1932017-08-22 14:38:59 +08007281restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007282 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007283 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007284 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307285 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007286 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007287 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007288}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007289
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307290/**
7291 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7292 * @arg: Argument of timer function
7293 *
7294 * Schedule a workqueue in this function where all the processing is done.
7295 *
7296 * Return: None.
7297 */
7298static void __hdd_bus_bw_cbk(void *arg)
7299{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007300 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307301
7302 if (wlan_hdd_validate_context(hdd_ctx))
7303 return;
7304
7305 schedule_work(&hdd_ctx->bus_bw_work);
7306}
7307
7308/**
7309 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7310 * @arg: Argument of timer function
7311 *
7312 * Return: None.
7313 */
7314static void hdd_bus_bw_cbk(void *arg)
7315{
7316 cds_ssr_protect(__func__);
7317 __hdd_bus_bw_cbk(arg);
7318 cds_ssr_unprotect(__func__);
7319}
7320
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007321int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007322{
7323 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307324 INIT_WORK(&hdd_ctx->bus_bw_work,
7325 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007326 hdd_ctx->bus_bw_timer_running = false;
7327 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307328 qdf_timer_init(NULL,
7329 &hdd_ctx->bus_bw_timer,
7330 hdd_bus_bw_cbk, (void *)hdd_ctx,
7331 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007332
7333 return 0;
7334}
7335
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007336void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007337{
Dustin Brownfce08d12017-01-17 16:29:38 -08007338 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007339 hdd_reset_tcp_delack(hdd_ctx);
7340
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007341 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307342 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307343 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007344 hdd_ctx->bus_bw_timer_running = false;
7345 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007346}
Lin Baic5c06882017-09-21 13:58:43 +08007347
7348void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7349{
7350 if (hdd_ctx)
7351 cancel_work_sync(&hdd_ctx->bus_bw_work);
7352}
jiadcdaf9bd2017-10-26 12:20:21 +08007353
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354#endif
7355
7356/**
Nirav Shahed34b212016-04-25 10:59:16 +05307357 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7358 * @hdd_ctx: hdd context
7359 *
7360 * Return: 0 for success or error code
7361 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007362static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307363{
7364 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7365 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7366 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007367 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307368 return -ENOMEM;
7369 }
7370 return 0;
7371}
7372
7373/**
7374 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7375 * @hdd_ctx: hdd context
7376 *
7377 * Return: none
7378 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007379void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307380{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307381 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7382 return;
7383
7384 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7385 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307386}
7387
Nirav Shahda008342016-05-17 18:50:40 +05307388static uint8_t *convert_level_to_string(uint32_t level)
7389{
7390 switch (level) {
7391 /* initialize the wlan sub system */
7392 case WLAN_SVC_TP_NONE:
7393 return "NONE";
7394 case WLAN_SVC_TP_LOW:
7395 return "LOW";
7396 case WLAN_SVC_TP_MEDIUM:
7397 return "MED";
7398 case WLAN_SVC_TP_HIGH:
7399 return "HIGH";
7400 default:
7401 return "INVAL";
7402 }
7403}
7404
Nirav Shahed34b212016-04-25 10:59:16 +05307405
7406/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007407 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7408 * @hdd_ctx: hdd context
7409 *
7410 * Return: none
7411 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007412void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413{
7414 int i;
7415
7416#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007417 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307418 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007419 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420 hdd_ctx->config->busBandwidthHighThreshold,
7421 hdd_ctx->config->busBandwidthMediumThreshold,
7422 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007423 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307424 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007425 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426 hdd_ctx->config->tcpDelackThresholdHigh,
7427 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007428 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307429 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007430#endif
7431
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007432 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307433 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7434
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007435 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007436
7437 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007438 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007439 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007440 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7441 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7442 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7443 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7444 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007445 hdd_ctx->hdd_txrx_hist[i].
7446 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007447 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007448 hdd_ctx->hdd_txrx_hist[i].
7449 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007450 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007451 hdd_ctx->hdd_txrx_hist[i].
7452 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007453 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007454}
7455
7456/**
7457 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7458 * @hdd_ctx: hdd context
7459 *
7460 * Return: none
7461 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007462void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007463{
7464 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307465 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7466 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007467}
7468
Mohit Khannaca4173b2017-09-12 21:52:19 -07007469/* length of the netif queue log needed per adapter */
7470#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7471
7472/**
7473 *
7474 * hdd_display_netif_queue_history_compact() - display compact netifq history
7475 * @hdd_ctx: hdd context
7476 *
7477 * Return: none
7478 */
7479static void
7480hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7481{
7482 int adapter_num = 0;
7483 int i;
7484 int bytes_written;
7485 u32 tbytes;
7486 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007487 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007488 char *comb_log_str;
7489 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007490 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007491
jiadbdefb252018-01-03 14:27:06 +08007492 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7493 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7494 if (!comb_log_str) {
7495 hdd_err("failed to alloc comb_log_str");
7496 return;
7497 }
7498
Mohit Khannaca4173b2017-09-12 21:52:19 -07007499 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007500
Dustin Brown920397d2017-12-13 16:27:50 -08007501 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007502 curr_time = qdf_system_ticks();
7503 total = curr_time - adapter->start_time;
7504 delta = curr_time - adapter->last_time;
7505
7506 if (adapter->pause_map) {
7507 pause = adapter->total_pause_time + delta;
7508 unpause = adapter->total_unpause_time;
7509 } else {
7510 unpause = adapter->total_unpause_time + delta;
7511 pause = adapter->total_pause_time;
7512 }
7513
7514 tbytes = 0;
7515 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7516 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7517 if (adapter->queue_oper_stats[i].pause_count == 0)
7518 continue;
7519 tbytes +=
7520 snprintf(
7521 &temp_str[tbytes],
7522 (tbytes >= sizeof(temp_str) ?
7523 0 : sizeof(temp_str) - tbytes),
7524 "%d(%d,%d) ",
7525 i,
7526 adapter->queue_oper_stats[i].
7527 pause_count,
7528 adapter->queue_oper_stats[i].
7529 unpause_count);
7530 }
7531 if (tbytes >= sizeof(temp_str))
7532 hdd_warn("log truncated");
7533
7534 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007535 bytes_written >= comb_log_str_size ? 0 :
7536 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007537 "[%d %d] (%d) %u/%ums %s|",
7538 adapter->session_id, adapter->device_mode,
7539 adapter->pause_map,
7540 qdf_system_ticks_to_msecs(pause),
7541 qdf_system_ticks_to_msecs(total),
7542 temp_str);
7543
Mohit Khannaca4173b2017-09-12 21:52:19 -07007544 adapter_num++;
7545 }
7546
7547 /* using QDF_TRACE to avoid printing function name */
7548 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7549 "STATS |%s", comb_log_str);
7550
jiadbdefb252018-01-03 14:27:06 +08007551 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007552 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007553
7554 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007555}
7556
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007557/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007558 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007559 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560 *
7561 * Return: none
7562 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007563void
7564wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7565 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007566{
7567
Jeff Johnson9d295242017-08-29 14:39:48 -07007568 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307570 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571
Mohit Khannaca4173b2017-09-12 21:52:19 -07007572 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7573 hdd_display_netif_queue_history_compact(hdd_ctx);
7574 return;
7575 }
7576
Dustin Brown920397d2017-12-13 16:27:50 -08007577 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007578 hdd_debug("Netif queue operation statistics:");
7579 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007580 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007581 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307582 curr_time = qdf_system_ticks();
7583 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307584 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307585 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307586 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307587 unpause = adapter->total_unpause_time;
7588 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307589 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307590 pause = adapter->total_pause_time;
7591 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007592 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307593 qdf_system_ticks_to_msecs(total),
7594 qdf_system_ticks_to_msecs(pause),
7595 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007596 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007597
Nirav Shahda008342016-05-17 18:50:40 +05307598 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7599 qdf_time_t pause_delta = 0;
7600
7601 if (adapter->pause_map & (1 << i))
7602 pause_delta = delta;
7603
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007604 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007605 hdd_debug("%s: %d: %d: %ums",
7606 hdd_reason_type_to_string(i),
7607 adapter->queue_oper_stats[i].pause_count,
7608 adapter->queue_oper_stats[i].unpause_count,
7609 qdf_system_ticks_to_msecs(
7610 adapter->queue_oper_stats[i].total_pause_time +
7611 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007612 }
7613
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007614 hdd_debug("Netif queue operation history:");
7615 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307616 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7617
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007618 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007619
7620 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007621 /* using hdd_log to avoid printing function name */
7622 if (adapter->queue_oper_history[i].time == 0)
7623 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007624 hdd_debug("%d: %u: %s: %s: %x",
7625 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007627 hdd_action_type_to_string(
7628 adapter->queue_oper_history[i].netif_action),
7629 hdd_reason_type_to_string(
7630 adapter->queue_oper_history[i].netif_reason),
7631 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007632 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007634}
7635
7636/**
7637 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7638 * @hdd_ctx: hdd context
7639 *
7640 * Return: none
7641 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007642void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643{
Jeff Johnson9d295242017-08-29 14:39:48 -07007644 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007645
Dustin Brown920397d2017-12-13 16:27:50 -08007646 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307647 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307649 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007650 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307651 adapter->history_index = 0;
7652 adapter->start_time = adapter->last_time = qdf_system_ticks();
7653 adapter->total_pause_time = 0;
7654 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007655 }
7656}
7657
7658/**
7659 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7660 * @halHandle: Hal handle
7661 * @pContext: Pointer to the context
7662 * @sessionId: Session ID
7663 * @scanId: Scan ID
7664 * @status: Status
7665 *
7666 * This is the callback to be executed when 11d scan is completed to flush out
7667 * the scan results
7668 *
7669 * 11d scan is done during driver load and is a passive scan on all
7670 * channels supported by the device, 11d scans may find some APs on
7671 * frequencies which are forbidden to be used in the regulatory domain
7672 * the device is operating in. If these APs are notified to the supplicant
7673 * it may try to connect to these APs, thus flush out all the scan results
7674 * which are present in SME after 11d scan is done.
7675 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307676 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007677 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307678static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679 uint8_t sessionId, uint32_t scanId,
7680 eCsrScanStatus status)
7681{
Dustin Brown491d54b2018-03-14 12:39:11 -07007682 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007683
7684 sme_scan_flush_result(halHandle);
7685
Dustin Browne74003f2018-03-14 12:51:58 -07007686 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007687
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307688 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007689}
7690
7691#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7692/**
7693 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7694 * @hdd_ctx: hdd global context
7695 *
7696 * Return: none
7697 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007698static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007699{
7700 uint8_t i;
7701
7702 mutex_init(&hdd_ctx->op_ctx.op_lock);
7703 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7704 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7705 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7706 }
7707}
7708#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007709static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007710{
7711}
7712#endif
7713
Yingying Tang95409972016-10-20 15:16:15 +08007714#ifdef WLAN_FEATURE_WOW_PULSE
7715/**
7716 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007717 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007718 * @enable: enable or disable this behaviour
7719 *
7720 * Return: int
7721 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007722static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007723{
7724 struct hdd_config *pcfg_ini = phddctx->config;
7725 struct wow_pulse_mode wow_pulse_set_info;
7726 QDF_STATUS status;
7727
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007728 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007729
7730 if (false == phddctx->config->wow_pulse_support)
7731 return 0;
7732
7733 /* prepare the request to send to SME */
7734 if (enable == true) {
7735 wow_pulse_set_info.wow_pulse_enable = true;
7736 wow_pulse_set_info.wow_pulse_pin =
7737 pcfg_ini->wow_pulse_pin;
7738 wow_pulse_set_info.wow_pulse_interval_low =
7739 pcfg_ini->wow_pulse_interval_low;
7740 wow_pulse_set_info.wow_pulse_interval_high =
7741 pcfg_ini->wow_pulse_interval_high;
7742 } else {
7743 wow_pulse_set_info.wow_pulse_enable = false;
7744 wow_pulse_set_info.wow_pulse_pin = 0;
7745 wow_pulse_set_info.wow_pulse_interval_low = 0;
7746 wow_pulse_set_info.wow_pulse_interval_high = 0;
7747 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007748 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007749 wow_pulse_set_info.wow_pulse_enable,
7750 wow_pulse_set_info.wow_pulse_pin,
7751 wow_pulse_set_info.wow_pulse_interval_low,
7752 wow_pulse_set_info.wow_pulse_interval_high);
7753
7754 status = sme_set_wow_pulse(&wow_pulse_set_info);
7755 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007756 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007757 return -EIO;
7758 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007759 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007760 return 0;
7761}
7762#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007763static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007764{
7765 return 0;
7766}
7767#endif
7768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007769#ifdef WLAN_FEATURE_FASTPATH
7770/**
7771 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7772 * @hdd_cfg: hdd config
7773 * @context: lower layer context
7774 *
7775 * Return: none
7776 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307777void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007778 void *context)
7779{
7780 if (hdd_cfg->fastpath_enable)
7781 hif_enable_fastpath(context);
7782}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007783#endif
7784
Yuanyuan Liu13738502016-04-06 17:41:37 -07007785#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007786/**
7787 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007788 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007789 * @level: thermal level
7790 *
7791 * Change IPA data path to SW path when the thermal throttle level greater
7792 * than 0, and restore the original data path when throttle level is 0
7793 *
7794 * Return: none
7795 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007796static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007797{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007798 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007800 /* Change IPA to SW path when throttle level greater than 0 */
7801 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307802 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007803 else
7804 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307805 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007806}
7807
7808/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307809 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7810 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307811 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007812 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307813 * Get a safe channel to restart SAP. PCL already takes into account the
7814 * unsafe channels. So, the PCL is validated with the ACS range to provide
7815 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007816 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307817 * Return: Channel number to restart SAP in case of success. In case of any
7818 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007819 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307820static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007821 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007822{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307823 struct sir_pcl_list pcl;
7824 QDF_STATUS status;
7825 uint32_t i, j;
7826 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007827 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307828 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007829 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007830
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307831 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7832 if (!hdd_ctx) {
7833 hdd_err("invalid HDD context");
7834 return INVALID_CHANNEL_ID;
7835 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007836
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307837 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7838 if (!hal_handle) {
7839 hdd_err("invalid HAL handle");
7840 return INVALID_CHANNEL_ID;
7841 }
7842
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007843 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7844 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007845 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7846 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307847 if (QDF_IS_STATUS_ERROR(status)) {
7848 hdd_err("Get PCL failed");
7849 return INVALID_CHANNEL_ID;
7850 }
7851
Frank Liudc2cefb2017-06-21 15:38:18 +08007852 /*
7853 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7854 * channel is unsafe channel, the pcl may be empty, instead of return,
7855 * try to choose a safe channel from acs range.
7856 */
7857 if (!pcl.pcl_len)
7858 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307859
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007860 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007861 adapter->session.ap.sap_config.acs_cfg.start_ch,
7862 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307863
7864 /* PCL already takes unsafe channel into account */
7865 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007866 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307867 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007868 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307869 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007870 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007871 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307872 return pcl.pcl_list[i];
7873 }
7874 }
7875
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007876 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307877
7878 /* Try for safe channel from all valid channel */
7879 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007880 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7881 &pcl.pcl_len);
7882 if (ret) {
7883 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307884 return INVALID_CHANNEL_ID;
7885 }
7886
7887 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007888 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307889 found = false;
7890 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007891 if (pcl.pcl_list[i] ==
7892 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007893 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307894 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007895 break;
7896 }
7897 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307898
7899 if (found)
7900 continue;
7901
7902 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007903 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307904 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007905 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007906 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307907 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007908 }
7909 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307910
7911 return INVALID_CHANNEL_ID;
7912}
Nirav Shaheb017be2018-02-15 11:20:58 +05307913#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307914
7915/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007916 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307917 * @adapter: AP adapter
7918 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007919 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307920 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007921 * Moves the SAP interface by invoking the function which
7922 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307923 *
7924 * Return: None
7925 */
Min Liu2fef5792018-01-19 17:59:42 +08007926void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7927 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307928{
Jeff Johnson87251032017-08-29 13:31:11 -07007929 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307930 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007931 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307932
7933 if (!adapter) {
7934 hdd_err("invalid adapter");
7935 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007936 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307937
7938 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7939
7940 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7941 if (!hal_handle) {
7942 hdd_err("invalid HAL handle");
7943 return;
7944 }
7945
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007946 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7947
Jeff Johnson91df29d2017-10-27 19:29:50 -07007948 hdd_ap_ctx->sap_config.channel = channel;
7949 hdd_ap_ctx->sap_config.ch_params.ch_width =
7950 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307951
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007952 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007953 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307954
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007955 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007956 hdd_ap_ctx->sap_config.channel,
7957 hdd_ap_ctx->sap_config.sec_ch,
7958 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307959
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007960 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007961 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007962 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007963}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307964
Jeff Johnson9d295242017-08-29 14:39:48 -07007965int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307966{
7967 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307968 int status;
7969 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307970
7971 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7972
7973 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007974 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307975 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007976 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307977 }
7978 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007979 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307980 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307981 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007982 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307983 WLAN_VENDOR_ACS_WAIT_TIME);
7984 if (qdf_status != QDF_STATUS_SUCCESS) {
7985 hdd_err("failed to start external acs timer");
7986 return -ENOSPC;
7987 }
7988 /* Update config to application */
7989 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007990 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307991
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307992 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307993}
7994
Nirav Shaheb017be2018-02-15 11:20:58 +05307995#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307996/**
7997 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7998 * @hdd_ctx: hdd context pointer
7999 *
8000 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8001 * and if ACS is enabled, driver will ask userspace to restart the
8002 * sap. User space on LTE coex indication restart driver.
8003 *
8004 * Return - none
8005 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008006void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308007{
Dustin Brown920397d2017-12-13 16:27:50 -08008008 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308009 uint32_t i;
8010 bool found = false;
8011 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008012
Dustin Brown920397d2017-12-13 16:27:50 -08008013 hdd_for_each_adapter(hdd_ctxt, adapter) {
8014 if (!(adapter->device_mode == QDF_SAP_MODE &&
8015 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008016 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008017 adapter->device_mode,
8018 adapter->session.ap.sap_config.
8019 acs_cfg.acs_mode);
8020 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308021 }
8022
8023 found = false;
8024 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008025 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308026 hdd_ctxt->unsafe_channel_list[i]) {
8027 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008028 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008029 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308030 break;
8031 }
8032 }
8033
8034 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008035 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008036 adapter->session.ap.operating_channel);
8037 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308038 }
8039
Kapil Gupta8878ad92017-02-13 11:56:04 +05308040 if (hdd_ctxt->config->vendor_acs_support &&
8041 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008042 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308043 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008044 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308045 } else
8046 restart_chan =
8047 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008048 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308049 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008050 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308051 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008052 /*
8053 * SAP restart due to unsafe channel. While
8054 * restarting the SAP, make sure to clear
8055 * acs_channel, channel to reset to
8056 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308057 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008058 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308059 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008060 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308061 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008062 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308063 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8064 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008065 hdd_debug("driver to start sap: %d",
8066 hdd_ctxt->config->sap_internal_restart);
8067 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008068 hdd_switch_sap_channel(adapter, restart_chan,
8069 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008070 else
8071 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308072 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308073 }
8074}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008076/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008077 * hdd_init_channel_avoidance() - Initialize channel avoidance
8078 * @hdd_ctx: HDD global context
8079 *
8080 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008081 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008082 * down to the lower layers. Then subscribe to subsequent channel
8083 * avoidance events.
8084 *
8085 * Return: None
8086 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008087static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008088{
8089 uint16_t unsafe_channel_count;
8090 int index;
8091
Yuanyuan Liu13738502016-04-06 17:41:37 -07008092 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8093 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008094 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008095 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008096
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008097 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008098 hdd_ctx->unsafe_channel_count);
8099
Anurag Chouhan6d760662016-02-20 16:05:43 +05308100 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008101 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008102
8103 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008104 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008105 hdd_ctx->unsafe_channel_list[index]);
8106
8107 }
8108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008109}
Dustin Brown676a2322017-08-15 13:16:13 -07008110
Jeff Johnson9d295242017-08-29 14:39:48 -07008111static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008112 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008113{
8114 uint8_t restart_chan;
8115
8116 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8117 if (!restart_chan) {
8118 hdd_alert("fail to restart SAP");
8119 return;
8120 }
8121
8122 /* SAP restart due to unsafe channel. While restarting
8123 * the SAP, make sure to clear acs_channel, channel to
8124 * reset to 0. Otherwise these settings will override
8125 * the ACS while restart.
8126 */
8127 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008128 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008129
8130 hdd_debug("sending coex indication");
8131
8132 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8133 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008134 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008135}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008136
8137int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8138 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8139{
8140 uint32_t size;
8141 uint16_t *unsafe_list;
8142 uint16_t chan_count;
8143
8144 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8145 return -EINVAL;
8146
8147 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8148 NUM_CHANNELS);
8149 if (chan_count) {
8150 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8151 unsafe_list = qdf_mem_malloc(size);
8152 if (!unsafe_list) {
8153 hdd_err("No memory for unsafe chan list size%d",
8154 size);
8155 return -ENOMEM;
8156 }
8157 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8158 } else {
8159 unsafe_list = NULL;
8160 }
8161
8162 *local_unsafe_list = unsafe_list;
8163 *local_unsafe_list_count = chan_count;
8164
8165 return 0;
8166}
8167
8168bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8169 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8170{
8171 int i, j;
8172
8173 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8174 return true;
8175 if (local_unsafe_list_count == 0)
8176 return false;
8177 for (i = 0; i < local_unsafe_list_count; i++) {
8178 for (j = 0; j < local_unsafe_list_count; j++)
8179 if (local_unsafe_list[i] ==
8180 hdd_ctx->unsafe_channel_list[j])
8181 break;
8182 if (j >= local_unsafe_list_count)
8183 break;
8184 }
8185 if (i >= local_unsafe_list_count) {
8186 hdd_info("unsafe chan list same");
8187 return false;
8188 }
8189
8190 return true;
8191}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008192#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008193static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008194{
8195}
Dustin Brown676a2322017-08-15 13:16:13 -07008196
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008197static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008198{
8199}
Dustin Brown676a2322017-08-15 13:16:13 -07008200
Jeff Johnson9d295242017-08-29 14:39:48 -07008201static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008202 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008203{
8204 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8205}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008206#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008207
8208/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008209 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8210 * user space
8211 * @frame_ind: Management frame data to be informed.
8212 *
8213 * This function is used to indicate management frame to
8214 * user space
8215 *
8216 * Return: None
8217 *
8218 */
8219void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8220{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008221 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008222 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008223 int i;
8224
Rajeev Kumard004abc2016-02-17 12:09:56 -08008225 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008226 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008227
8228 if (0 != wlan_hdd_validate_context(hdd_ctx))
8229 return;
8230
8231 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8232 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8233 adapter =
8234 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8235 if (adapter)
8236 break;
8237 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008238 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8239 hdd_for_each_adapter(hdd_ctx, adapter) {
8240 if ((NULL != adapter) &&
8241 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8242 __hdd_indicate_mgmt_frame(adapter,
8243 frame_ind->frame_len,
8244 frame_ind->frameBuf,
8245 frame_ind->frameType,
8246 frame_ind->rxChan,
8247 frame_ind->rxRssi);
8248 }
8249 }
8250 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008251 } else {
8252 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8253 frame_ind->sessionId);
8254 }
8255
8256 if ((NULL != adapter) &&
8257 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8258 __hdd_indicate_mgmt_frame(adapter,
8259 frame_ind->frame_len,
8260 frame_ind->frameBuf,
8261 frame_ind->frameType,
8262 frame_ind->rxChan,
8263 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008264}
8265
Kapil Gupta8878ad92017-02-13 11:56:04 +05308266void hdd_acs_response_timeout_handler(void *context)
8267{
8268 struct hdd_external_acs_timer_context *timer_context =
8269 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008270 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008271 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308272 uint8_t reason;
8273
Dustin Brown491d54b2018-03-14 12:39:11 -07008274 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308275 if (!timer_context) {
8276 hdd_err("invlaid timer context");
8277 return;
8278 }
8279 adapter = timer_context->adapter;
8280 reason = timer_context->reason;
8281
8282
8283 if ((!adapter) ||
8284 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8285 hdd_err("invalid adapter or adapter has invalid magic");
8286 return;
8287 }
8288 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8289 if (wlan_hdd_validate_context(hdd_ctx))
8290 return;
8291
8292 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8293 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8294 else
8295 return;
8296
8297 hdd_err("ACS timeout happened for %s reason %d",
8298 adapter->dev->name, reason);
8299 switch (reason) {
8300 /* SAP init case */
8301 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8302 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8303 false);
8304 wlan_hdd_cfg80211_start_acs(adapter);
8305 break;
8306 /* DFS detected on current channel */
8307 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8308 wlan_sap_update_next_channel(
8309 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8310 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008311 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308312 break;
8313 /* LTE coex event on current channel */
8314 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8315 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8316 break;
8317 default:
8318 hdd_info("invalid reason for timer invoke");
8319
8320 }
8321}
8322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008323/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008324 * hdd_override_ini_config - Override INI config
8325 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008326 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008327 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008328 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008329 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008331static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008332{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008333
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008334 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8335 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008336 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008337 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008338 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008339 if (0 == enable_11d || 1 == enable_11d) {
8340 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008341 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008342 }
Leo Chang11545d62016-10-17 14:53:50 -07008343
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308344 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008345 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008346 hdd_debug("IpaConfig override to %d",
8347 hdd_ctx->config->IpaConfig);
8348 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308349
8350 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8351 !hdd_ctx->config->enable_bcast_probe_rsp) {
8352 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8353 hdd_ctx->config->rssi_assoc_reject_enabled,
8354 hdd_ctx->config->enable_bcast_probe_rsp);
8355 hdd_ctx->config->oce_sta_enabled = 0;
8356 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008357}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008358
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008359/**
8360 * hdd_set_trace_level_for_each - Set trace level for each INI config
8361 * @hdd_ctx - HDD context
8362 *
8363 * Set trace level for each module based on INI config.
8364 *
8365 * Return: None
8366 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008367static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008368{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308369 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8370 hdd_ctx->config->qdf_trace_enable_wdi);
8371 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8372 hdd_ctx->config->qdf_trace_enable_hdd);
8373 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8374 hdd_ctx->config->qdf_trace_enable_sme);
8375 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8376 hdd_ctx->config->qdf_trace_enable_pe);
8377 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8378 hdd_ctx->config->qdf_trace_enable_wma);
8379 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8380 hdd_ctx->config->qdf_trace_enable_sys);
8381 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8382 hdd_ctx->config->qdf_trace_enable_qdf);
8383 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8384 hdd_ctx->config->qdf_trace_enable_sap);
8385 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8386 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8387 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8388 hdd_ctx->config->qdf_trace_enable_bmi);
8389 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8390 hdd_ctx->config->qdf_trace_enable_cfg);
8391 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8392 hdd_ctx->config->qdf_trace_enable_epping);
8393 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8394 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8395 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008396 hdd_ctx->config->qdf_trace_enable_txrx);
8397 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8398 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308399 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8400 hdd_ctx->config->qdf_trace_enable_htc);
8401 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8402 hdd_ctx->config->qdf_trace_enable_hif);
8403 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8404 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8405 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8406 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008407 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8408 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008409 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8410 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008411 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8412 hdd_ctx->config->qdf_trace_enable_regulatory);
8413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008414 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008415}
8416
8417/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008418 * hdd_context_init() - Initialize HDD context
8419 * @hdd_ctx: HDD context.
8420 *
8421 * Initialize HDD context along with all the feature specific contexts.
8422 *
8423 * return: 0 on success and errno on failure.
8424 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008425static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008426{
8427 int ret;
8428
8429 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8430 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8431
8432 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308433 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008434
8435 init_completion(&hdd_ctx->mc_sus_event_var);
8436 init_completion(&hdd_ctx->ready_to_suspend);
8437
8438 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308439 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008440 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308441
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008442 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008443
8444 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8445
8446 ret = hdd_scan_context_init(hdd_ctx);
8447 if (ret)
8448 goto list_destroy;
8449
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008450 hdd_rx_wake_lock_create(hdd_ctx);
8451
8452 ret = hdd_sap_context_init(hdd_ctx);
8453 if (ret)
8454 goto scan_destroy;
8455
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008456 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8457
8458 hdd_init_offloaded_packets_ctx(hdd_ctx);
8459
8460 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8461 hdd_ctx->config);
8462 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008463 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008464
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308465 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8466 "monitor_mode_wakelock");
8467
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008468 return 0;
8469
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008470sap_destroy:
8471 hdd_sap_context_destroy(hdd_ctx);
8472
8473scan_destroy:
8474 hdd_scan_context_destroy(hdd_ctx);
8475 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008476list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008477 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008478
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008479 return ret;
8480}
8481
8482/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308483 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8484 * @hdd_ctx: pointer to hdd context
8485 *
8486 * Return: status of initialization
8487 * 0 - success
8488 * negative value - failure
8489 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008490static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308491{
8492 int ret;
8493
8494 if (!hdd_ctx->config->probe_req_ie_whitelist)
8495 return 0;
8496
8497 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8498 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8499 hdd_ctx->config->probe_req_ie_whitelist = false;
8500 return -EINVAL;
8501 }
8502
8503 /* parse ini string probe req oui */
8504 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8505 if (ret) {
8506 hdd_err("parsing error: disable ie whitelisting");
8507 hdd_ctx->config->probe_req_ie_whitelist = false;
8508 }
8509
8510 return ret;
8511}
8512
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308513/**
8514 * hdd_iface_change_callback() - Function invoked when stop modules expires
8515 * @priv: pointer to hdd context
8516 *
8517 * This function is invoked when the timer waiting for the interface change
8518 * expires, it shall cut-down the power to wlan and stop all the modules.
8519 *
8520 * Return: void
8521 */
8522static void hdd_iface_change_callback(void *priv)
8523{
8524 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8525 int ret;
8526 int status = wlan_hdd_validate_context(hdd_ctx);
8527
8528 if (status)
8529 return;
8530
Dustin Brown491d54b2018-03-14 12:39:11 -07008531 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308532 hdd_debug("Interface change timer expired close the modules!");
8533 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8534 if (ret)
8535 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008536 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308537}
8538
Nirav Shaheb017be2018-02-15 11:20:58 +05308539#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8540static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8541{
8542 wlan_logging_set_log_to_console(hdd_ctx->config->
8543 wlan_logging_to_console);
8544 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8545}
8546#else
8547static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8548{ }
8549#endif
8550
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308551/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008552 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308553 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008554 *
8555 * Allocate and initialize HDD context. HDD context is allocated as part of
8556 * wiphy allocation and then context is initialized.
8557 *
8558 * Return: HDD context on success and ERR_PTR on failure
8559 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008560static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008561{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308562 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008563 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008564 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008565
Dustin Brown491d54b2018-03-14 12:39:11 -07008566 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008567
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008568 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008569 if (hdd_ctx == NULL) {
8570 ret = -ENOMEM;
8571 goto err_out;
8572 }
8573
Dustin Brown6f427922017-09-19 12:19:00 -07008574 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8575 hdd_iface_change_callback,
8576 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308577
8578 mutex_init(&hdd_ctx->iface_change_lock);
8579
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008580 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308581 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008582
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308583 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008584 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008585 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008586 ret = -ENOMEM;
8587 goto err_free_hdd_context;
8588 }
8589
8590 /* Read and parse the qcom_cfg.ini file */
8591 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308592 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308593 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008594 WLAN_INI_FILE);
8595 ret = -EINVAL;
8596 goto err_free_config;
8597 }
8598
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308599 ie_whitelist_attrs_init(hdd_ctx);
8600
Dustin Brown7f939932017-05-18 15:02:17 -07008601 hdd_debug("setting timer multiplier: %u",
8602 hdd_ctx->config->timer_multiplier);
8603 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8604
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008605
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308606 if (hdd_ctx->config->fhostNSOffload)
8607 hdd_ctx->ns_offload_enable = true;
8608
Abhishek Singh5ea86532016-04-27 14:10:53 +05308609 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8610
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008611 hdd_override_ini_config(hdd_ctx);
8612
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008613 ret = hdd_context_init(hdd_ctx);
8614
8615 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008616 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008617
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008618 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308619 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008620
Anurag Chouhan6d760662016-02-20 16:05:43 +05308621 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008622 goto skip_multicast_logging;
8623
8624 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8625
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008626 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8627 if (ret)
8628 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308629
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008630 ret = hdd_init_netlink_services(hdd_ctx);
8631 if (ret)
8632 goto err_deinit_txrx_histogram;
8633
Nirav Shaheb017be2018-02-15 11:20:58 +05308634 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308635
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008636skip_multicast_logging:
8637 hdd_set_trace_level_for_each(hdd_ctx);
8638
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008639 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8640
Dustin Browne74003f2018-03-14 12:51:58 -07008641 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008642
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008643 return hdd_ctx;
8644
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008645err_deinit_txrx_histogram:
8646 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8647
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008648err_deinit_hdd_context:
8649 hdd_context_deinit(hdd_ctx);
8650
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008651err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308652 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008653
8654err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308655 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008656 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008657
8658err_out:
8659 return ERR_PTR(ret);
8660}
8661
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008662#ifdef WLAN_OPEN_P2P_INTERFACE
8663/**
8664 * hdd_open_p2p_interface - Open P2P interface
8665 * @hdd_ctx: HDD context
8666 * @rtnl_held: True if RTNL lock held
8667 *
8668 * Open P2P interface during probe. This function called to open the P2P
8669 * interface at probe along with STA interface.
8670 *
8671 * Return: 0 on success and errno on failure
8672 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008673static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008674{
Jeff Johnson9d295242017-08-29 14:39:48 -07008675 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008676 uint8_t *p2p_dev_addr;
8677
8678 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8679 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008680 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008681 hdd_ctx->config->intfMacAddr[0].bytes,
8682 sizeof(tSirMacAddr));
8683
8684 /*
8685 * Generate the P2P Device Address. This consists of
8686 * the device's primary MAC address with the locally
8687 * administered bit set.
8688 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008689 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008690 } else {
8691 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8692 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008693 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008694 return -ENOSPC;
8695 }
8696
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008697 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8698 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008699 }
8700
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008701 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008702 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008703 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008704
8705 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008706 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008707 return -ENOSPC;
8708 }
8709
8710 return 0;
8711}
8712#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008713static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008714 bool rtnl_held)
8715{
8716 return 0;
8717}
8718#endif
8719
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008720static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008721{
Jeff Johnson9d295242017-08-29 14:39:48 -07008722 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008723 int ret = 0;
8724
8725 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8726 wlan_hdd_get_intf_addr(hdd_ctx),
8727 NET_NAME_UNKNOWN, rtnl_held);
8728 if (adapter == NULL) {
8729 hdd_err("Failed to open 802.11p interface");
8730 ret = -ENOSPC;
8731 }
8732
8733 return ret;
8734}
8735
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008736/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308737 * hdd_start_station_adapter()- Start the Station Adapter
8738 * @adapter: HDD adapter
8739 *
8740 * This function initializes the adapter for the station mode.
8741 *
8742 * Return: 0 on success or errno on failure.
8743 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008744int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308745{
8746 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008747 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308748
Dustin Brownfdf17c12018-03-14 12:55:34 -07008749 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008750 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8751 hdd_err("session is already opened, %d",
8752 adapter->session_id);
8753 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8754 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308755
Krunal Sonib51eec72017-11-20 21:53:01 -08008756 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8757 if (ret) {
8758 hdd_err("failed to create vdev: %d", ret);
8759 return ret;
8760 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308761 status = hdd_init_station_mode(adapter);
8762
8763 if (QDF_STATUS_SUCCESS != status) {
8764 hdd_err("Error Initializing station mode: %d", status);
8765 return qdf_status_to_os_return(status);
8766 }
8767
Arun Khandavallifae92942016-08-01 13:31:08 +05308768 hdd_register_tx_flow_control(adapter,
8769 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008770 hdd_tx_resume_cb,
8771 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308772
Dustin Browne74003f2018-03-14 12:51:58 -07008773 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308774 return 0;
8775}
8776
8777/**
8778 * hdd_start_ap_adapter()- Start AP Adapter
8779 * @adapter: HDD adapter
8780 *
8781 * This function initializes the adapter for the AP mode.
8782 *
8783 * Return: 0 on success errno on failure.
8784 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008785int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308786{
8787 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008788 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008789 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008790 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308791
Dustin Brown491d54b2018-03-14 12:39:11 -07008792 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308793
Krunal Sonib51eec72017-11-20 21:53:01 -08008794 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8795 hdd_err("session is already opened, %d",
8796 adapter->session_id);
8797 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8798 }
8799 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008800 * In SSR case no need to create new sap context.
8801 * Otherwise create sap context first and then create
8802 * vdev as while creating the vdev, driver needs to
8803 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008804 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008805 if (adapter->session.ap.sap_context) {
8806 is_ssr = true;
8807 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008808 hdd_err("sap creation failed");
8809 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8810 }
8811
8812 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8813 adapter->session.ap.sap_context);
8814 if (ret) {
8815 hdd_err("failed to create vdev, status:%d", ret);
8816 hdd_sap_destroy_ctx(adapter);
8817 return ret;
8818 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008819
8820 if (adapter->device_mode == QDF_SAP_MODE)
8821 sme_cli_set_command(adapter->session_id,
8822 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8823 (bool)(hdd_ctx->config->fine_time_meas_cap &
8824 WMI_FW_AP_RTT_RESPR),
8825 VDEV_CMD);
8826
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008827 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308828
8829 if (QDF_STATUS_SUCCESS != status) {
8830 hdd_err("Error Initializing the AP mode: %d", status);
8831 return qdf_status_to_os_return(status);
8832 }
8833
Arun Khandavallifae92942016-08-01 13:31:08 +05308834 hdd_register_tx_flow_control(adapter,
8835 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008836 hdd_softap_tx_resume_cb,
8837 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308838
Dustin Browne74003f2018-03-14 12:51:58 -07008839 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308840 return 0;
8841}
8842
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308843static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8844 bool rtnl_held)
8845{
8846 struct hdd_adapter *adapter;
8847
8848 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8849 hdd_ctx->config->enableConcurrentSTA,
8850 wlan_hdd_get_intf_addr(hdd_ctx),
8851 NET_NAME_UNKNOWN, rtnl_held);
8852
8853 if (!adapter)
8854 return -ENOSPC;
8855
8856 return 0;
8857}
8858
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308859/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008860 * hdd_open_interfaces - Open all required interfaces
8861 * hdd_ctx: HDD context
8862 * rtnl_held: True if RTNL lock is held
8863 *
8864 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8865 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008866 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008868static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008869{
Jeff Johnson9d295242017-08-29 14:39:48 -07008870 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008871 int ret;
8872
Ravi Joshia307f632017-07-17 23:41:41 -07008873 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008874 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8875 con_mode == QDF_GLOBAL_FTM_MODE) {
8876 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8877 QDF_MONITOR_MODE : QDF_FTM_MODE;
8878
8879 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8880 wlan_hdd_get_intf_addr(hdd_ctx),
8881 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008882 if (!adapter) {
8883 hdd_err("open adapter failed");
8884 return -ENOSPC;
8885 }
Lin Bai1c678482017-12-18 18:29:11 +08008886
Ravi Joshia307f632017-07-17 23:41:41 -07008887 return 0;
8888 }
8889
Jeff Johnson957bc272017-02-02 08:54:48 -08008890 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308891 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008892 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008893
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008894 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008895 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008896 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008897
8898 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008899 return -ENOSPC;
8900
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308901 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8902 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8903 if (ret)
8904 hdd_err("Cannot create concurrent STA interface");
8905 }
8906
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008907 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8908 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008909 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008910
8911 /* Open 802.11p Interface */
8912 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008913 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8914 if (ret)
8915 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008916 }
8917
Jeff Johnson957bc272017-02-02 08:54:48 -08008918 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008919
Jeff Johnson957bc272017-02-02 08:54:48 -08008920err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008921 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008922 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008923}
8924
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008925
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308926#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8927/**
8928 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8929 * @cds_cfg: CDS Configuration
8930 * @hdd_ctx: Pointer to hdd context
8931 *
8932 * Return: none
8933 */
8934static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8935 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008936 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308937{
8938 cds_cfg->tx_flow_stop_queue_th =
8939 hdd_ctx->config->TxFlowStopQueueThreshold;
8940 cds_cfg->tx_flow_start_queue_offset =
8941 hdd_ctx->config->TxFlowStartQueueOffset;
8942}
8943#else
8944static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8945 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008946 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308947{
8948}
8949#endif
8950
8951#ifdef FEATURE_WLAN_RA_FILTERING
8952/**
8953 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8954 * @cds_cfg: CDS Configuration
8955 * @hdd_ctx: Pointer to hdd context
8956 *
8957 * Return: none
8958 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308959static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008960 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308961{
8962 cds_cfg->ra_ratelimit_interval =
8963 hdd_ctx->config->RArateLimitInterval;
8964 cds_cfg->is_ra_ratelimit_enabled =
8965 hdd_ctx->config->IsRArateLimitEnabled;
8966}
8967#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308968static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008969 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308970{
8971}
8972#endif
8973
8974/**
8975 * hdd_update_cds_config() - API to update cds configuration parameters
8976 * @hdd_ctx: HDD Context
8977 *
8978 * Return: 0 for Success, errno on failure
8979 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008980static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308981{
8982 struct cds_config_info *cds_cfg;
8983
8984 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8985 if (!cds_cfg) {
8986 hdd_err("failed to allocate cds config");
8987 return -ENOMEM;
8988 }
8989
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008990 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008991 if (!hdd_ctx->config->nMaxPsPoll ||
8992 !hdd_ctx->config->enablePowersaveOffload) {
8993 cds_cfg->powersave_offload_enabled =
8994 hdd_ctx->config->enablePowersaveOffload;
8995 } else {
8996 if ((hdd_ctx->config->enablePowersaveOffload ==
8997 PS_QPOWER_NODEEPSLEEP) ||
8998 (hdd_ctx->config->enablePowersaveOffload ==
8999 PS_LEGACY_NODEEPSLEEP))
9000 cds_cfg->powersave_offload_enabled =
9001 PS_LEGACY_NODEEPSLEEP;
9002 else
9003 cds_cfg->powersave_offload_enabled =
9004 PS_LEGACY_DEEPSLEEP;
9005 hdd_info("Qpower disabled in cds config, %d",
9006 cds_cfg->powersave_offload_enabled);
9007 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309008 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9009 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9010 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9011 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309012
9013 /*
9014 * Copy the DFS Phyerr Filtering Offload status.
9015 * This parameter reflects the value of the
9016 * dfs_phyerr_filter_offload flag as set in the ini.
9017 */
9018 cds_cfg->dfs_phyerr_filter_offload =
9019 hdd_ctx->config->fDfsPhyerrFilterOffload;
9020 if (hdd_ctx->config->ssdp)
9021 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9022
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309023 cds_cfg->force_target_assert_enabled =
9024 hdd_ctx->config->crash_inject_enabled;
9025
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309026 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9027 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9028
9029 cds_cfg->ap_maxoffload_reorderbuffs =
9030 hdd_ctx->config->apMaxOffloadReorderBuffs;
9031
9032 cds_cfg->ap_disable_intrabss_fwd =
9033 hdd_ctx->config->apDisableIntraBssFwd;
9034
9035 cds_cfg->dfs_pri_multiplier =
9036 hdd_ctx->config->dfsRadarPriMultiplier;
9037 cds_cfg->reorder_offload =
9038 hdd_ctx->config->reorderOffloadSupport;
9039
9040 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309041 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009042 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9043 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009044 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009045 hdd_ctx->config->IpaUcTxBufCount);
9046 hdd_ctx->config->IpaUcTxBufCount =
9047 rounddown_pow_of_two(
9048 hdd_ctx->config->IpaUcTxBufCount);
9049 if (!hdd_ctx->config->IpaUcTxBufCount) {
9050 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309051 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009052 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009053 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009054 hdd_ctx->config->IpaUcTxBufCount);
9055 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309056 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9057 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009058 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9059 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009060 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009061 hdd_ctx->config->IpaUcRxIndRingCount);
9062 hdd_ctx->config->IpaUcRxIndRingCount =
9063 rounddown_pow_of_two(
9064 hdd_ctx->config->IpaUcRxIndRingCount);
9065 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9066 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309067 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009068 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009069 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009070 hdd_ctx->config->IpaUcRxIndRingCount);
9071 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309072 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009073 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309074 cds_cfg->uc_tx_partition_base =
9075 hdd_ctx->config->IpaUcTxPartitionBase;
9076 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9077
9078 cds_cfg->ip_tcp_udp_checksum_offload =
9079 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009080 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309081 cds_cfg->ce_classify_enabled =
9082 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009083 cds_cfg->bpf_packet_filter_enable =
9084 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309085 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9086 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9087 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009088 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009089 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009090 cds_cfg->max_msdus_per_rxinorderind =
9091 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009092 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009093 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309094 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9095 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309096 cds_cfg->auto_power_save_fail_mode =
9097 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309098
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309099 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009100 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009101 cds_cfg->delay_before_vdev_stop =
9102 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309103
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309104 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9105 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9106 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009107 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309108 cds_init_ini_config(cds_cfg);
9109 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309110
9111exit:
9112 qdf_mem_free(cds_cfg);
9113 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309114}
9115
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009116/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009117 * hdd_update_user_config() - API to update user configuration
9118 * parameters to obj mgr which are used by multiple components
9119 * @hdd_ctx: HDD Context
9120 *
9121 * Return: 0 for Success, errno on failure
9122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009123static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009124{
9125 struct wlan_objmgr_psoc_user_config *user_config;
9126
9127 user_config = qdf_mem_malloc(sizeof(*user_config));
9128 if (user_config == NULL) {
9129 hdd_alert("Failed to alloc memory for user_config!");
9130 return -ENOMEM;
9131 }
9132
9133 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9134 user_config->dual_mac_feature_disable =
9135 hdd_ctx->config->dual_mac_feature_disable;
9136 user_config->indoor_channel_support =
9137 hdd_ctx->config->indoor_channel_support;
9138 user_config->is_11d_support_enabled =
9139 hdd_ctx->config->Is11dSupportEnabled;
9140 user_config->is_11h_support_enabled =
9141 hdd_ctx->config->Is11hSupportEnabled;
9142 user_config->optimize_chan_avoid_event =
9143 hdd_ctx->config->goptimize_chan_avoid_event;
9144 user_config->skip_dfs_chnl_in_p2p_search =
9145 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009146 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009147 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9148
9149 qdf_mem_free(user_config);
9150 return 0;
9151}
9152
9153/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009154 * hdd_init_thermal_info - Initialize thermal level
9155 * @hdd_ctx: HDD context
9156 *
9157 * Initialize thermal level at SME layer and set the thermal level callback
9158 * which would be called when a configured thermal threshold is hit.
9159 *
9160 * Return: 0 on success and errno on failure
9161 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009162static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009163{
9164 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309165 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009166
9167 thermal_param.smeThermalMgmtEnabled =
9168 hdd_ctx->config->thermalMitigationEnable;
9169 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9170
Poddar, Siddarth83905022016-04-16 17:56:08 -07009171 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9172 hdd_ctx->config->throttle_dutycycle_level0;
9173 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9174 hdd_ctx->config->throttle_dutycycle_level1;
9175 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9176 hdd_ctx->config->throttle_dutycycle_level2;
9177 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9178 hdd_ctx->config->throttle_dutycycle_level3;
9179
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009180 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9181 hdd_ctx->config->thermalTempMinLevel0;
9182 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9183 hdd_ctx->config->thermalTempMaxLevel0;
9184 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9185 hdd_ctx->config->thermalTempMinLevel1;
9186 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9187 hdd_ctx->config->thermalTempMaxLevel1;
9188 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9189 hdd_ctx->config->thermalTempMinLevel2;
9190 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9191 hdd_ctx->config->thermalTempMaxLevel2;
9192 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9193 hdd_ctx->config->thermalTempMinLevel3;
9194 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9195 hdd_ctx->config->thermalTempMaxLevel3;
9196
9197 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9198
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309199 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309200 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009201
9202 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9203 hdd_set_thermal_level_cb);
9204
9205 return 0;
9206
9207}
9208
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009209#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9210/**
9211 * hdd_hold_rtnl_lock - Hold RTNL lock
9212 *
9213 * Hold RTNL lock
9214 *
9215 * Return: True if held and false otherwise
9216 */
9217static inline bool hdd_hold_rtnl_lock(void)
9218{
9219 rtnl_lock();
9220 return true;
9221}
9222
9223/**
9224 * hdd_release_rtnl_lock - Release RTNL lock
9225 *
9226 * Release RTNL lock
9227 *
9228 * Return: None
9229 */
9230static inline void hdd_release_rtnl_lock(void)
9231{
9232 rtnl_unlock();
9233}
9234#else
9235static inline bool hdd_hold_rtnl_lock(void) { return false; }
9236static inline void hdd_release_rtnl_lock(void) { }
9237#endif
9238
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009239#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009240
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309241/* MAX iwpriv command support */
9242#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309243#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309244#define MAX_PKTLOG_SIZE 16
9245
9246/**
9247 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9248 * @hdd_ctx: hdd context
9249 * @set_value2: pktlog buffer size value
9250 *
9251 *
9252 * Return: 0 for success or error.
9253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009254static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309255{
9256 struct sir_wifi_start_log start_log = { 0 };
9257 QDF_STATUS status;
9258
9259 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9260 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9261 start_log.ini_triggered = cds_is_packet_log_enabled();
9262 start_log.user_triggered = 1;
9263 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309264 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309265
9266 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9267 if (!QDF_IS_STATUS_SUCCESS(status)) {
9268 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009269 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309270 return -EINVAL;
9271 }
9272
9273 return 0;
9274}
9275
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009276/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309277 * hdd_pktlog_clear_buff() - clear pktlog buffer
9278 * @hdd_ctx: hdd context
9279 *
9280 * Return: 0 for success or error.
9281 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009282static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309283{
9284 struct sir_wifi_start_log start_log;
9285 QDF_STATUS status;
9286
9287 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9288 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9289 start_log.ini_triggered = cds_is_packet_log_enabled();
9290 start_log.user_triggered = 1;
9291 start_log.size = 0;
9292 start_log.is_pktlog_buff_clear = true;
9293
9294 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9295 if (!QDF_IS_STATUS_SUCCESS(status)) {
9296 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009297 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309298 return -EINVAL;
9299 }
9300
9301 return 0;
9302}
9303
9304
9305/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009306 * hdd_process_pktlog_command() - process pktlog command
9307 * @hdd_ctx: hdd context
9308 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309309 * @set_value2: pktlog buffer size value
9310 *
9311 * This function process pktlog command.
9312 * set_value2 only matters when set_value is 3 (set buff size)
9313 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009314 *
9315 * Return: 0 for success or error.
9316 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009317int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309318 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009319{
9320 int ret;
9321 bool enable;
9322 uint8_t user_triggered = 0;
9323
9324 ret = wlan_hdd_validate_context(hdd_ctx);
9325 if (0 != ret)
9326 return ret;
9327
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009328 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009329
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309330 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009331 hdd_err("invalid pktlog value %d", set_value);
9332 return -EINVAL;
9333 }
9334
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309335 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9336 if (set_value2 <= 0) {
9337 hdd_err("invalid pktlog size %d", set_value2);
9338 return -EINVAL;
9339 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9340 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9341 return -EINVAL;
9342 }
9343 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309344 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9345 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309346 }
9347
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009348 /*
9349 * set_value = 0 then disable packetlog
9350 * set_value = 1 enable packetlog forcefully
9351 * set_vlaue = 2 then disable packetlog if disabled through ini or
9352 * enable packetlog with AUTO type.
9353 */
9354 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9355 true : false;
9356
9357 if (1 == set_value) {
9358 enable = true;
9359 user_triggered = 1;
9360 }
9361
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309362 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009363}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009364
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009365/**
9366 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9367 * @hdd_ctx: HDD context
9368 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309369 * @user_triggered: triggered through iwpriv
9370 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009371 *
9372 * Return: 0 on success; error number otherwise
9373 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009374int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309375 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009376{
9377 struct sir_wifi_start_log start_log;
9378 QDF_STATUS status;
9379
9380 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9381 start_log.verbose_level =
9382 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009383 start_log.ini_triggered = cds_is_packet_log_enabled();
9384 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309385 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309386 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309387 /*
9388 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9389 * commands. Host uses this flag to decide whether to send pktlog
9390 * disable command to fw without sending pktlog enable command
9391 * previously. For eg, If vendor sends pktlog disable command without
9392 * sending pktlog enable command, then host discards the packet
9393 * but for iwpriv command, host will send it to fw.
9394 */
9395 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009396 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9397 if (!QDF_IS_STATUS_SUCCESS(status)) {
9398 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009399 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009400 return -EINVAL;
9401 }
9402
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309403 if (enable == true)
9404 hdd_ctx->is_pktlog_enabled = 1;
9405 else
9406 hdd_ctx->is_pktlog_enabled = 0;
9407
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009408 return 0;
9409}
9410#endif /* REMOVE_PKT_LOG */
9411
Komal Seelam92fff912016-03-24 11:51:41 +05309412/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009413 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9414 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309415 * @dev: Device Pointer
9416 * @num: Number of Valid Mac address
9417 *
9418 * Return: Pointer to MAC address buffer
9419 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009420static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9421 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309422{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009423 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309424}
Komal Seelam92fff912016-03-24 11:51:41 +05309425
9426/**
9427 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9428 * @hdd_ctx: HDD Context
9429 * @num: Number of random mac addresses needed
9430 *
9431 * Generate random addresses using bit manipulation on the base mac address
9432 *
9433 * Return: None
9434 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009435void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309436{
9437 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9438 uint32_t iter;
9439 struct hdd_config *ini = hdd_ctx->config;
9440 uint8_t *buf = NULL;
9441 uint8_t macaddr_b3, tmp_br3;
9442 uint8_t *src = ini->intfMacAddr[0].bytes;
9443
9444 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9445 buf = ini->intfMacAddr[iter].bytes;
9446 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9447 macaddr_b3 = buf[3];
9448 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9449 INTF_MACADDR_MASK;
9450 macaddr_b3 += tmp_br3;
9451 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9452 buf[0] |= 0x02;
9453 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009454 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309455 }
9456}
9457
9458/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009459 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309460 * @hdd_ctx: HDD Context
9461 *
9462 * API to get mac addresses from platform driver and update the driver
9463 * structures and configure FW with the base mac address.
9464 * Return: int
9465 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009466static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309467{
9468 uint32_t no_of_mac_addr, iter;
9469 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9470 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9471 uint8_t *addr, *buf;
9472 struct device *dev = hdd_ctx->parent_dev;
9473 struct hdd_config *ini = hdd_ctx->config;
9474 tSirMacAddr mac_addr;
9475 QDF_STATUS status;
9476
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009477 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309478
9479 if (no_of_mac_addr == 0 || !addr) {
9480 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9481 return -EINVAL;
9482 }
9483
9484 if (no_of_mac_addr > max_mac_addr)
9485 no_of_mac_addr = max_mac_addr;
9486
9487 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9488
9489 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9490 buf = ini->intfMacAddr[iter].bytes;
9491 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009492 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309493 }
9494
9495 status = sme_set_custom_mac_addr(mac_addr);
9496
9497 if (!QDF_IS_STATUS_SUCCESS(status))
9498 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009499
Komal Seelam92fff912016-03-24 11:51:41 +05309500 if (no_of_mac_addr < max_mac_addr)
9501 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9502 no_of_mac_addr);
9503 return 0;
9504}
9505
9506/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009507 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9508 * @hdd_ctx: HDD Context
9509 *
9510 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9511 * will generate its own MAC and update it to FW.
9512 *
9513 * Return: 0 for success
9514 * Non-zero error code for failure
9515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009516static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009517{
9518 tSirMacAddr customMacAddr;
9519 QDF_STATUS status;
9520
9521 qdf_mem_copy(&customMacAddr,
9522 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9523 sizeof(tSirMacAddr));
9524 status = sme_set_custom_mac_addr(customMacAddr);
9525 if (!QDF_IS_STATUS_SUCCESS(status))
9526 return -EAGAIN;
9527 return 0;
9528}
9529
9530/**
Komal Seelam92fff912016-03-24 11:51:41 +05309531 * hdd_initialize_mac_address() - API to get wlan mac addresses
9532 * @hdd_ctx: HDD Context
9533 *
9534 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9535 * is provisioned with mac addresses, driver uses it, else it will use
9536 * wlan_mac.bin to update HW MAC addresses.
9537 *
9538 * Return: None
9539 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009540static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309541{
9542 QDF_STATUS status;
9543 int ret;
9544
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009545 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309546 if (ret == 0)
9547 return;
9548
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009549 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9550 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309551
9552 status = hdd_update_mac_config(hdd_ctx);
9553
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009554 if (QDF_IS_STATUS_SUCCESS(status))
9555 return;
9556
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009557 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9558 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009559
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009560 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009561 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009562 if (ret != 0) {
9563 hdd_err("MAC address out-of-sync, ret:%d", ret);
9564 QDF_ASSERT(ret);
9565 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009566 }
Komal Seelam92fff912016-03-24 11:51:41 +05309567}
9568
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009569static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009570{
9571 int vdev_id = 0;
9572 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9573 int value = hdd_ctx->config->smart_chainmask_enabled;
9574 int vpdev = PDEV_CMD;
9575 int ret;
9576
Naveen Rawat247a8682017-06-05 15:00:31 -07009577 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009578 if (ret)
9579 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9580
9581 return ret;
9582}
9583
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009584static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009585{
9586 int vdev_id = 0;
9587 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9588 int value = hdd_ctx->config->alternative_chainmask_enabled;
9589 int vpdev = PDEV_CMD;
9590 int ret;
9591
Naveen Rawat247a8682017-06-05 15:00:31 -07009592 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009593 if (ret)
9594 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9595 ret);
9596
9597 return ret;
9598}
9599
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009600static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009601{
9602 int vdev_id = 0;
9603 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9604 int value = hdd_ctx->config->ani_enabled;
9605 int vpdev = PDEV_CMD;
9606 int ret;
9607
Naveen Rawat247a8682017-06-05 15:00:31 -07009608 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009609 if (ret)
9610 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9611
9612 return ret;
9613}
9614
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009615/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009616 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9617 * @hdd_ctx: HDD context
9618 *
9619 * Pre configurations to be done at lower layer before calling cds enable.
9620 *
9621 * Return: 0 on success and errno on failure.
9622 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009623static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009624{
9625 int ret;
9626 QDF_STATUS status;
9627 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009628 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009629
Leo Changfdb45c32016-10-28 11:09:23 -07009630 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009631 /*
9632 * Set 802.11p config
9633 * TODO-OCB: This has been temporarily added here to ensure this
9634 * parameter is set in CSR when we init the channel list. This should
9635 * be removed once the 5.9 GHz channels are added to the regulatory
9636 * domain.
9637 */
9638 hdd_set_dot11p_config(hdd_ctx);
9639
9640 /*
9641 * Note that the cds_pre_enable() sequence triggers the cfg download.
9642 * The cfg download must occur before we update the SME config
9643 * since the SME config operation must access the cfg database
9644 */
9645 status = hdd_set_sme_config(hdd_ctx);
9646
9647 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009648 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009649 ret = qdf_status_to_os_return(status);
9650 goto out;
9651 }
9652
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009653 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9654 if (QDF_STATUS_SUCCESS != status) {
9655 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9656 ret = qdf_status_to_os_return(status);
9657 goto out;
9658 }
9659
Naveen Rawat247a8682017-06-05 15:00:31 -07009660 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009661 hdd_ctx->config->tx_chain_mask_1ss,
9662 PDEV_CMD);
9663 if (0 != ret) {
9664 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9665 goto out;
9666 }
9667
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009668 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9669 if (ret)
9670 goto out;
9671
9672 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9673 if (ret)
9674 goto out;
9675
Jeff Johnson12a744b2017-04-04 08:19:37 -07009676 ret = hdd_set_ani_enabled(hdd_ctx);
9677 if (ret)
9678 goto out;
9679
Naveen Rawat247a8682017-06-05 15:00:31 -07009680 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009681 hdd_ctx->config->arp_ac_category,
9682 PDEV_CMD);
9683 if (0 != ret) {
9684 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9685 hdd_ctx->config->arp_ac_category, ret);
9686 goto out;
9687 }
9688
Prashanth Bhatta07998752016-04-28 12:35:33 -07009689 status = hdd_set_sme_chan_list(hdd_ctx);
9690 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009691 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009692 ret = qdf_status_to_os_return(status);
9693 goto out;
9694 }
9695
9696 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009697 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009698 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009699 ret = -EINVAL;
9700 goto out;
9701 }
9702
Prashanth Bhatta07998752016-04-28 12:35:33 -07009703 /*
9704 * Set the MAC Address Currently this is used by HAL to add self sta.
9705 * Remove this once self sta is added as part of session open.
9706 */
9707 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9708 hdd_ctx->config->intfMacAddr[0].bytes,
9709 sizeof(hdd_ctx->config->intfMacAddr[0]));
9710
9711 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9712 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9713 hal_status, hal_status);
9714 ret = -EINVAL;
9715 goto out;
9716 }
9717
9718 hdd_init_channel_avoidance(hdd_ctx);
9719
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309720 /* update enable sap mandatory chan list */
9721 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9722 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009723out:
9724 return ret;
9725}
9726
9727/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009728 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9729 * @context_ptr - hdd context pointer
9730 * @event_ptr - event structure pointer
9731 *
9732 * This is the p2p listen offload stop event handler, it sends vendor
9733 * event back to supplicant to notify the stop reason.
9734 *
9735 * Return: None
9736 */
9737static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9738 void *event_ptr)
9739{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009740 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009741 struct sir_p2p_lo_event *evt = event_ptr;
9742 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009743 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009744
Dustin Brown491d54b2018-03-14 12:39:11 -07009745 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009746
9747 if (hdd_ctx == NULL) {
9748 hdd_err("Invalid HDD context pointer");
9749 return;
9750 }
9751
Peng Xu5c682812017-08-06 07:39:13 -07009752 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9753 if (!adapter) {
9754 hdd_err("Cannot find adapter by vdev_id = %d",
9755 evt->vdev_id);
9756 return;
9757 }
9758
Peng Xu8fdaa492016-06-22 10:20:47 -07009759 vendor_event =
9760 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009761 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009762 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9763 GFP_KERNEL);
9764
9765 if (!vendor_event) {
9766 hdd_err("cfg80211_vendor_event_alloc failed");
9767 return;
9768 }
9769
9770 if (nla_put_u32(vendor_event,
9771 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9772 evt->reason_code)) {
9773 hdd_err("nla put failed");
9774 kfree_skb(vendor_event);
9775 return;
9776 }
9777
9778 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009779 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9780 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009781}
9782
9783/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309784 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9785 * @hdd_ctx: HDD context
9786 *
9787 * This function sends the adaptive dwell time config configuration to the
9788 * firmware via WMA
9789 *
9790 * Return: 0 - success, < 0 - failure
9791 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009792static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309793{
9794 QDF_STATUS status;
9795 struct adaptive_dwelltime_params dwelltime_params;
9796
9797 dwelltime_params.is_enabled =
9798 hdd_ctx->config->adaptive_dwell_mode_enabled;
9799 dwelltime_params.dwelltime_mode =
9800 hdd_ctx->config->global_adapt_dwelltime_mode;
9801 dwelltime_params.lpf_weight =
9802 hdd_ctx->config->adapt_dwell_lpf_weight;
9803 dwelltime_params.passive_mon_intval =
9804 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9805 dwelltime_params.wifi_act_threshold =
9806 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9807
9808 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9809 &dwelltime_params);
9810
9811 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9812 if (!QDF_IS_STATUS_SUCCESS(status)) {
9813 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9814 return -EAGAIN;
9815 }
9816 return 0;
9817}
9818
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009819int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309820{
9821 QDF_STATUS status;
9822 struct wmi_dbs_scan_sel_params dbs_scan_params;
9823 uint32_t i = 0;
9824 uint8_t count = 0, numentries = 0;
9825 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9826 * CDS_DBS_SCAN_CLIENTS_MAX];
9827
9828 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309829 if ((hdd_ctx->config->dual_mac_feature_disable ==
9830 DISABLE_DBS_CXN_AND_SCAN) ||
9831 (hdd_ctx->config->dual_mac_feature_disable ==
9832 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309833 return -EINVAL;
9834
9835 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9836 dbs_scan_config, &numentries,
9837 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9838 * CDS_DBS_SCAN_CLIENTS_MAX));
9839
9840 hdd_info("numentries %hu", numentries);
9841 if (!numentries) {
9842 hdd_info("Donot send scan_selection_config");
9843 return 0;
9844 }
9845
9846 /* hdd_set_fw_log_params */
9847 dbs_scan_params.num_clients = 0;
9848 while (count < (numentries - 2)) {
9849 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9850 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9851 dbs_scan_params.num_non_dbs_scans[i] =
9852 dbs_scan_config[count + 2];
9853 dbs_scan_params.num_clients++;
9854 hdd_debug("module:%d NDS:%d NNDS:%d",
9855 dbs_scan_params.module_id[i],
9856 dbs_scan_params.num_dbs_scans[i],
9857 dbs_scan_params.num_non_dbs_scans[i]);
9858 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9859 i++;
9860 }
9861
9862 dbs_scan_params.pdev_id = 0;
9863
9864 hdd_debug("clients:%d pdev:%d",
9865 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9866
9867 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9868 &dbs_scan_params);
9869 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9870 if (!QDF_IS_STATUS_SUCCESS(status)) {
9871 hdd_err("Failed to send DBS Scan selection configuration!");
9872 return -EAGAIN;
9873 }
9874 return 0;
9875}
9876
Arun Khandavallid4349a92016-07-25 11:10:43 +05309877#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9878/**
9879 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9880 * @hdd_ctx: HDD context
9881 *
9882 * Set auto shutdown callback to get indications from firmware to indicate
9883 * userspace to shutdown WLAN after a configured amount of inactivity.
9884 *
9885 * Return: 0 on success and errno on failure.
9886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009887static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309888{
9889 QDF_STATUS status;
9890
9891 if (!hdd_ctx->config->WlanAutoShutdown)
9892 return 0;
9893
9894 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9895 wlan_hdd_auto_shutdown_cb);
9896 if (status != QDF_STATUS_SUCCESS)
9897 hdd_err("Auto shutdown feature could not be enabled: %d",
9898 status);
9899
9900 return qdf_status_to_os_return(status);
9901}
9902#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009903static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309904{
9905 return 0;
9906}
9907#endif
9908
9909/**
9910 * hdd_features_init() - Init features
9911 * @hdd_ctx: HDD context
9912 * @adapter: Primary adapter context
9913 *
9914 * Initialize features and their feature context after WLAN firmware is up.
9915 *
9916 * Return: 0 on success and errno on failure.
9917 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009918static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309919{
9920 tSirTxPowerLimit hddtxlimit;
9921 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309922 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309923 int ret;
9924
Dustin Brown491d54b2018-03-14 12:39:11 -07009925 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309926
Arun Khandavallid4349a92016-07-25 11:10:43 +05309927 /* FW capabilities received, Set the Dot11 mode */
9928 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009929 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9930 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309931
Arun Khandavallid4349a92016-07-25 11:10:43 +05309932
9933 if (hdd_ctx->config->fIsImpsEnabled)
9934 hdd_set_idle_ps_config(hdd_ctx, true);
9935 else
9936 hdd_set_idle_ps_config(hdd_ctx, false);
9937
Poddar, Siddarth37033032017-10-11 15:47:40 +05309938 /* Send Enable/Disable data stall detection cmd to FW */
9939 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9940 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9941
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309942 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009943 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309944
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309945 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9946 hdd_warn("Error in setting Voltage Corner mode config to FW");
9947
Arun Khandavallid4349a92016-07-25 11:10:43 +05309948 if (hdd_lro_init(hdd_ctx))
9949 hdd_err("Unable to initialize LRO in fw");
9950
9951 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9952 hdd_err("Unable to send adaptive dwelltime setting to FW");
9953
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309954 if (hdd_dbs_scan_selection_init(hdd_ctx))
9955 hdd_err("Unable to send DBS scan selection setting to FW");
9956
Arun Khandavallid4349a92016-07-25 11:10:43 +05309957 ret = hdd_init_thermal_info(hdd_ctx);
9958 if (ret) {
9959 hdd_err("Error while initializing thermal information");
9960 goto deregister_frames;
9961 }
9962
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309963 /**
9964 * In case of SSR/PDR, if pktlog was enabled manually before
9965 * SSR/PDR, Then enabled it again automatically after Wlan
9966 * device up.
9967 */
9968 if (cds_is_driver_recovering()) {
9969 if (hdd_ctx->is_pktlog_enabled)
9970 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009971 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309972
Arun Khandavallid4349a92016-07-25 11:10:43 +05309973 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9974 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9975 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9976 if (!QDF_IS_STATUS_SUCCESS(status))
9977 hdd_err("Error setting txlimit in sme: %d", status);
9978
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009979 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309980
Arun Khandavallid4349a92016-07-25 11:10:43 +05309981 ret = hdd_register_cb(hdd_ctx);
9982 if (ret) {
9983 hdd_err("Failed to register HDD callbacks!");
9984 goto deregister_frames;
9985 }
9986
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309987 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9988 status = sme_enable_disable_chanavoidind_event(
9989 hdd_ctx->hHal, 0);
9990 if (!QDF_IS_STATUS_SUCCESS(status)) {
9991 hdd_err("Failed to disable Chan Avoidance Indication");
9992 goto deregister_cb;
9993 }
9994 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309995
Manjeet Singha9cae432017-02-28 11:58:22 +05309996 if (hdd_ctx->config->enable_5g_band_pref) {
9997 band_pref_params.rssi_boost_threshold_5g =
9998 hdd_ctx->config->rssi_boost_threshold_5g;
9999 band_pref_params.rssi_boost_factor_5g =
10000 hdd_ctx->config->rssi_boost_factor_5g;
10001 band_pref_params.max_rssi_boost_5g =
10002 hdd_ctx->config->max_rssi_boost_5g;
10003 band_pref_params.rssi_penalize_threshold_5g =
10004 hdd_ctx->config->rssi_penalize_threshold_5g;
10005 band_pref_params.rssi_penalize_factor_5g =
10006 hdd_ctx->config->rssi_penalize_factor_5g;
10007 band_pref_params.max_rssi_penalize_5g =
10008 hdd_ctx->config->max_rssi_penalize_5g;
10009 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10010 }
10011
Arun Khandavallid4349a92016-07-25 11:10:43 +053010012 /* register P2P Listen Offload event callback */
10013 if (wma_is_p2p_lo_capable())
10014 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10015 wlan_hdd_p2p_lo_event_callback);
10016
10017 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10018
10019 if (ret)
10020 goto deregister_cb;
10021
Dustin Brown11638b72018-01-25 17:37:25 +053010022 wlan_hdd_init_chan_info(hdd_ctx);
10023
Dustin Browne74003f2018-03-14 12:51:58 -070010024 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010025 return 0;
10026
10027deregister_cb:
10028 hdd_deregister_cb(hdd_ctx);
10029deregister_frames:
10030 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010031 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010032}
10033
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010034/**
10035 * hdd_features_deinit() - Deinit features
10036 * @hdd_ctx: HDD context
10037 *
10038 * De-Initialize features and their feature context.
10039 *
10040 * Return: none.
10041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010042static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010043{
Dustin Brown11638b72018-01-25 17:37:25 +053010044 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010045 wlan_hdd_tsf_deinit(hdd_ctx);
10046}
10047
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010048/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010049 * hdd_register_bcn_cb() - register scan beacon callback
10050 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010051 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010052 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010053 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010054static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010055{
10056 QDF_STATUS status;
10057
10058 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10059 wlan_cfg80211_inform_bss_frame,
10060 SCAN_CB_TYPE_INFORM_BCN);
10061 if (!QDF_IS_STATUS_SUCCESS(status)) {
10062 hdd_err("failed with status code %08d [x%08x]",
10063 status, status);
10064 return status;
10065 }
10066
10067 return QDF_STATUS_SUCCESS;
10068}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010069
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010070/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010071 * hdd_configure_cds() - Configure cds modules
10072 * @hdd_ctx: HDD context
10073 * @adapter: Primary adapter context
10074 *
10075 * Enable Cds modules after WLAN firmware is up.
10076 *
10077 * Return: 0 on success and errno on failure.
10078 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010079int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010080{
10081 int ret;
10082 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010083 int set_value;
10084 uint32_t num_abg_tx_chains = 0;
10085 uint32_t num_11b_tx_chains = 0;
10086 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -070010087 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010088
10089 if (hdd_ctx->config->sifs_burst_duration) {
10090 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10091 hdd_ctx->config->sifs_burst_duration;
10092
10093 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10094 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10095 set_value, PDEV_CMD);
10096 }
10097
10098 if (hdd_ctx->config->is_force_1x1)
10099 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10100 1, PDEV_CMD);
10101 /* set chip power save failure detected callback */
10102 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10103 hdd_chip_pwr_save_fail_detected_cb);
10104
10105 if (hdd_ctx->config->max_mpdus_inampdu) {
10106 set_value = hdd_ctx->config->max_mpdus_inampdu;
10107 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10108 set_value, PDEV_CMD);
10109 }
10110
10111 if (hdd_ctx->config->enable_rts_sifsbursting) {
10112 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10113 sme_cli_set_command(0,
10114 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10115 set_value, PDEV_CMD);
10116 }
10117
10118 if (hdd_ctx->config->sap_get_peer_info) {
10119 set_value = hdd_ctx->config->sap_get_peer_info;
10120 sme_cli_set_command(0,
10121 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10122 set_value, PDEV_CMD);
10123 }
10124
10125 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10126 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10127 if (!hdd_ctx->config->enable2x2) {
10128 if (num_11b_tx_chains > 1)
10129 num_11b_tx_chains = 1;
10130 if (num_11ag_tx_chains > 1)
10131 num_11ag_tx_chains = 1;
10132 }
10133 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10134 num_11b_tx_chains);
10135 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10136 num_11ag_tx_chains);
10137 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10138 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010139
10140 ret = hdd_pre_enable_configure(hdd_ctx);
10141 if (ret) {
10142 hdd_err("Failed to pre-configure cds");
10143 goto out;
10144 }
10145
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010146 /* Always get latest IPA resources allocated from cds_open and configure
10147 * IPA module before configuring them to FW. Sequence required as crash
10148 * observed otherwise.
10149 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010150 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10151 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010152 hdd_err("Failed to setup pipes");
10153 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010154 }
10155
Arun Khandavallifae92942016-08-01 13:31:08 +053010156 /*
10157 * Start CDS which starts up the SME/MAC/HAL modules and everything
10158 * else
10159 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010160 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010161
10162 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010163 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010164 goto out;
10165 }
10166
10167 status = hdd_post_cds_enable_config(hdd_ctx);
10168 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010169 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010170 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010171 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010172 status = hdd_register_bcn_cb(hdd_ctx);
10173 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010174 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010175 goto cds_disable;
10176 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010177
10178 ret = hdd_features_init(hdd_ctx, adapter);
10179 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010180 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010181
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010182 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010183 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010184 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10185 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010186 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010187 goto cds_disable;
10188 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010189 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10190 wlan_hdd_send_mode_change_event);
10191 if (!QDF_IS_STATUS_SUCCESS(status)) {
10192 hdd_debug("Failed to register mode change cb with Policy Manager");
10193 goto cds_disable;
10194 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010195
Himanshu Agarwalb229a142017-12-21 10:16:45 +053010196 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010197 hdd_debug("enhance green ap is not enabled");
10198
Nachiket Kukadedd302662017-07-13 17:31:44 +053010199 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10200 hdd_debug("Failed to set wow pulse");
10201
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010202 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10203 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010204 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10205 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10206
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010207
10208 if (hdd_ctx->config->enable_phy_reg_retention)
10209 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10210 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10211
Arun Khandavallifae92942016-08-01 13:31:08 +053010212 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010213
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010214cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010215 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010216
Arun Khandavallifae92942016-08-01 13:31:08 +053010217out:
10218 return -EINVAL;
10219}
10220
10221/**
10222 * hdd_deconfigure_cds() -De-Configure cds
10223 * @hdd_ctx: HDD context
10224 *
10225 * Deconfigure Cds modules before WLAN firmware is down.
10226 *
10227 * Return: 0 on success and errno on failure.
10228 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010229static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010230{
10231 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010232 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010233
Dustin Brown491d54b2018-03-14 12:39:11 -070010234 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010235
10236 /* De-init features */
10237 hdd_features_deinit(hdd_ctx);
10238
Arun Khandavallifae92942016-08-01 13:31:08 +053010239 /* De-register the SME callbacks */
10240 hdd_deregister_cb(hdd_ctx);
10241
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010242 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10243 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10244 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10245 }
10246
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010247 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010248 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10249 hdd_err("Failed to Disable the CDS Modules! :%d",
10250 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010251 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010252 }
10253
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010254 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010255 hdd_err("Failed to disconnect pipes");
10256 ret = -EINVAL;
10257 }
10258
Dustin Browne74003f2018-03-14 12:51:58 -070010259 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010260 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010261}
10262
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010263#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10264static void hdd_deregister_policy_manager_callback(
10265 struct wlan_objmgr_psoc *psoc)
10266{
10267 if (QDF_STATUS_SUCCESS !=
10268 policy_mgr_deregister_hdd_cb(psoc)) {
10269 hdd_err("HDD callback deregister with policy manager failed");
10270 }
10271}
10272#else
10273static void hdd_deregister_policy_manager_callback(
10274 struct wlan_objmgr_psoc *psoc)
10275{
10276}
10277#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010278
10279/**
10280 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10281 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010282 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010283 *
10284 * This function maintains the driver state machine it will be invoked from
10285 * exit, shutdown and con_mode change handler. Depending on the driver state
10286 * shall perform the stopping/closing of the modules.
10287 *
10288 * Return: 0 for success; non-zero for failure
10289 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010290int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010291{
10292 void *hif_ctx;
10293 qdf_device_t qdf_ctx;
10294 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010295 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010296 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010297 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10298 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010299 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010300 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010301
Dustin Brown491d54b2018-03-14 12:39:11 -070010302 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010303 hdd_alert("stop WLAN module: entering driver status=%d",
10304 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010305
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010306 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10307
Arun Khandavallifae92942016-08-01 13:31:08 +053010308 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10309 if (!qdf_ctx) {
10310 hdd_err("QDF device context NULL");
10311 return -EINVAL;
10312 }
10313
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010314 mutex_lock(&hdd_ctx->iface_change_lock);
10315 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010316 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010317
Dustin Brown70111822017-03-30 15:31:40 -070010318 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010319 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010320 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010321 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010322
10323 cds_print_external_threads();
10324
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010325 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010326 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010327 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10328 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010329 hdd_prevent_suspend_timeout(
10330 hdd_ctx->config->iface_change_wait_time,
10331 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010332 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010333 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010334 return 0;
10335 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010336 }
10337
Arun Khandavallifae92942016-08-01 13:31:08 +053010338 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10339
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010340 /* free user wowl patterns */
10341 hdd_free_user_wowl_ptrns();
10342
Arun Khandavallifae92942016-08-01 13:31:08 +053010343 switch (hdd_ctx->driver_status) {
10344 case DRIVER_MODULES_UNINITIALIZED:
10345 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010346 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010347 case DRIVER_MODULES_CLOSED:
10348 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010349 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010350 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010351 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10352
Komal Seelamf2136bb2016-09-28 18:30:44 +053010353 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010354 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010355 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010356 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010357 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010358 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010359 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010360
Arun Khandavallifae92942016-08-01 13:31:08 +053010361 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010362 hdd_info("Wlan transitioned (now OPENED)");
10363
10364 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010365 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010366 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010367 break;
10368 default:
10369 hdd_err("Trying to stop wlan in a wrong state: %d",
10370 hdd_ctx->driver_status);
10371 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010372 ret = -EINVAL;
10373 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010374 }
10375
Amar Singhal18081642018-01-26 16:04:13 -080010376 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010377 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010378
Rajeev Kumarbe021242017-02-16 16:12:23 -080010379 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010380 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10381 hdd_err("Failed to process post CDS disable Modules! :%d",
10382 qdf_status);
10383 ret = -EINVAL;
10384 QDF_ASSERT(0);
10385 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010386
psimhadeea0a12017-12-18 14:50:02 -080010387 hdd_runtime_suspend_context_deinit(hdd_ctx);
10388
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010389 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10390 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10391 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10392 ret = -EINVAL;
10393 QDF_ASSERT(0);
10394 }
10395
Jeff Johnsone4b14592017-09-13 14:23:33 -070010396 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010397 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010398 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010399 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010400 QDF_ASSERT(0);
10401 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010402
Amar Singhal410675c2018-01-10 12:14:21 -080010403 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010404 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10405 if (ret) {
10406 hdd_err("Failed to destroy pdev; errno:%d", ret);
10407 QDF_ASSERT(0);
10408 }
10409
10410 /*
10411 * Reset total mac phy during module stop such that during
10412 * next module start same psoc is used to populate new service
10413 * ready data
10414 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010415 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10416 if (tgt_hdl)
10417 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10418
Liangwei Dong50a64a72018-01-11 01:17:00 -050010419
Arun Khandavallifae92942016-08-01 13:31:08 +053010420 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10421 if (!hif_ctx) {
10422 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010423 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010424 }
10425
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010426 if (hdd_ctx->target_hw_name) {
10427 qdf_mem_free(hdd_ctx->target_hw_name);
10428 hdd_ctx->target_hw_name = NULL;
10429 }
10430
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010431 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010432
10433 ol_cds_free();
10434
Dustin Brown70111822017-03-30 15:31:40 -070010435 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010436 ret = pld_power_off(qdf_ctx->dev);
10437 if (ret)
10438 hdd_err("CNSS power down failed put device into Low power mode:%d",
10439 ret);
10440 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010441
Dustin Brown4bc0a622017-12-06 15:56:50 -080010442 /* many adapter resources are not freed by design in SSR case */
10443 if (!is_recovery_stop)
10444 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010445 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010446
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010447 /* Once the firmware sequence is completed reset this flag */
10448 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010449 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010450 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010451
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010452done:
10453 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010454 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010455 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010456 hdd_alert("stop WLAN module: exit driver status=%d",
10457 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010458
Dustin Browne74003f2018-03-14 12:51:58 -070010459 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010460
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010461 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010462}
10463
Arun Khandavallifae92942016-08-01 13:31:08 +053010464
10465/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010466 * hdd_state_info_dump() - prints state information of hdd layer
10467 * @buf: buffer pointer
10468 * @size: size of buffer to be filled
10469 *
10470 * This function is used to dump state information of hdd layer
10471 *
10472 * Return: None
10473 */
10474static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10475{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010476 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010477 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010478 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010479 uint16_t len = 0;
10480 char *buf = *buf_ptr;
10481
10482 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10483 if (!hdd_ctx) {
10484 hdd_err("Failed to get hdd context ");
10485 return;
10486 }
10487
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010488 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010489
10490 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010491 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010492 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010493 "\n is_scheduler_suspended %d",
10494 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010495
Dustin Brown920397d2017-12-13 16:27:50 -080010496 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010497 if (adapter->dev)
10498 len += scnprintf(buf + len, *size - len,
10499 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010500 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010501 "\n device_mode: %d", adapter->device_mode);
10502 switch (adapter->device_mode) {
10503 case QDF_STA_MODE:
10504 case QDF_P2P_CLIENT_MODE:
10505 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10506 len += scnprintf(buf + len, *size - len,
10507 "\n connState: %d",
10508 hdd_sta_ctx->conn_info.connState);
10509 break;
10510
10511 default:
10512 break;
10513 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010514 }
10515
10516 *size -= len;
10517 *buf_ptr += len;
10518}
10519
10520/**
10521 * hdd_register_debug_callback() - registration function for hdd layer
10522 * to print hdd state information
10523 *
10524 * Return: None
10525 */
10526static void hdd_register_debug_callback(void)
10527{
10528 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10529}
10530
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010531/*
10532 * wlan_init_bug_report_lock() - Initialize bug report lock
10533 *
10534 * This function is used to create bug report lock
10535 *
10536 * Return: None
10537 */
10538static void wlan_init_bug_report_lock(void)
10539{
10540 p_cds_contextType p_cds_context;
10541
10542 p_cds_context = cds_get_global_context();
10543 if (!p_cds_context) {
10544 hdd_err("cds context is NULL");
10545 return;
10546 }
10547
10548 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10549}
10550
Mohit Khannaf8f96822017-05-17 17:11:59 -070010551void hdd_dp_trace_init(struct hdd_config *config)
10552{
10553
10554 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10555 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10556 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10557 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10558 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10559 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10560 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010561 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010562
10563 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10564 &num_entries, sizeof(config_params));
10565
10566 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010567 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010568 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010569 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010570 else if (bw_compute_interval > 1000) {
10571 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10572 thresh_time_limit = 1;
10573 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010574 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10575
10576 switch (num_entries) {
10577 case 4:
10578 proto_bitmap = config_params[3];
10579 case 3:
10580 verbosity = config_params[2];
10581 case 2:
10582 thresh = config_params[1];
10583 case 1:
10584 live_mode = config_params[0];
10585 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010586 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010587 live_mode, thresh, thresh_time_limit,
10588 verbosity, proto_bitmap);
10589 };
10590
10591 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10592 verbosity, proto_bitmap);
10593
10594}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010595/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010596 * hdd_wlan_startup() - HDD init function
10597 * @dev: Pointer to the underlying device
10598 *
10599 * This is the driver startup code executed once a WLAN device has been detected
10600 *
10601 * Return: 0 for success, < 0 for failure
10602 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010603int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010604{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010605 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010606 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010607 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010608 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010609
Dustin Brown491d54b2018-03-14 12:39:11 -070010610 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010611
Arun Khandavallifae92942016-08-01 13:31:08 +053010612 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010613
10614 if (IS_ERR(hdd_ctx))
10615 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010616
Abhishek Singhe9068f12017-03-31 14:14:52 +053010617 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10618 DEFAULT_PSOC_ID);
10619 if (ret) {
10620 hdd_err("Psoc creation fails!");
10621 QDF_BUG(0);
10622 goto err_hdd_free_context;
10623 }
10624
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010625 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010626#ifdef FEATURE_WLAN_CH_AVOID
10627 mutex_init(&hdd_ctx->avoid_freq_lock);
10628#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010629
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010630 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010631 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010632
Dustin Brown021cecd2017-12-11 13:56:43 -080010633 hdd_driver_memdump_init();
10634
Jeff Johnson957bc272017-02-02 08:54:48 -080010635 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010636 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010637 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010638 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010639 }
10640
Yingying Tang80e15f32016-09-27 18:23:01 +080010641 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010642
Anurag Chouhan6d760662016-02-20 16:05:43 +053010643 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010644
10645 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010646 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010647 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010648 }
10649
Prashanth Bhatta07998752016-04-28 12:35:33 -070010650 ret = hdd_wiphy_init(hdd_ctx);
10651 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010652 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010653 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010654 }
10655
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010656 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010657 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010658
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010659 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010660
Paul Zhangfb02f452017-12-22 11:58:43 +080010661 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10662 if (ret) {
10663 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010664 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010665 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010666
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010667 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010668
Jeff Johnson957bc272017-02-02 08:54:48 -080010669 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10670 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010671 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010672 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010673 }
10674
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010675 hdd_release_rtnl_lock();
10676 rtnl_held = false;
10677
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010678 wlan_hdd_update_11n_mode(hdd_ctx->config);
10679
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010680#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010681 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010682 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010683 hdd_skip_acs_scan_timer_handler,
10684 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010685 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010686 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010687 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010688#endif
10689
Prashanth Bhattaab004382016-10-11 16:08:11 -070010690 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010691
Jeff Johnson9afc5012016-09-23 13:56:27 -070010692 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010693
Nirav Shahbd36b062016-07-18 11:12:59 +053010694 if (hdd_ctx->rps)
10695 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010696
Paul Zhangfb02f452017-12-22 11:58:43 +080010697 ret = hdd_register_notifiers(hdd_ctx);
10698 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010699 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010700
Paul Zhangfb02f452017-12-22 11:58:43 +080010701 status = wlansap_global_init();
10702 if (QDF_IS_STATUS_ERROR(status)) {
10703 hdd_unregister_notifiers(hdd_ctx);
10704 goto err_close_adapters;
10705 }
10706
Arun Khandavallifae92942016-08-01 13:31:08 +053010707 if (hdd_ctx->config->fIsImpsEnabled)
10708 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010709 else
10710 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010711
Mukul Sharma07bd8752017-10-10 16:58:14 +053010712 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010713 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10714 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010715 hdd_prevent_suspend_timeout(
10716 hdd_ctx->config->iface_change_wait_time,
10717 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10718 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010719
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010720 goto success;
10721
Jeff Johnson957bc272017-02-02 08:54:48 -080010722err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010723 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010724
Jeff Johnson46bde382017-02-01 15:31:16 -080010725err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010726 if (rtnl_held)
10727 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010728
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010729 unregister_netdevice_notifier(&hdd_netdev_notifier);
10730
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010731err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010732 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010733
Arun Khandavallifae92942016-08-01 13:31:08 +053010734err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010735 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010736
Dustin Brown021cecd2017-12-11 13:56:43 -080010737err_memdump_deinit:
10738 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010739
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010740 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010741 hdd_exit_netlink_services(hdd_ctx);
10742
Dustin Brown20912462017-06-07 13:48:25 -070010743 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10744
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010745err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010746 if (cds_is_fw_down())
10747 hdd_err("Not setting the complete event as fw is down");
10748 else
10749 hdd_start_complete(ret);
10750
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010751 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010752 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010753 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754
10755success:
Dustin Browne74003f2018-03-14 12:51:58 -070010756 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010757 return 0;
10758}
10759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010760/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010761 * hdd_wlan_update_target_info() - update target type info
10762 * @hdd_ctx: HDD context
10763 * @context: hif context
10764 *
10765 * Update target info received from firmware in hdd context
10766 * Return:None
10767 */
10768
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010769void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010770{
10771 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10772
10773 if (!tgt_info) {
10774 hdd_err("Target info is Null");
10775 return;
10776 }
10777
10778 hdd_ctx->target_type = tgt_info->target_type;
10779}
10780
10781/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010782 * hdd_get_nud_stats_cb() - callback api to update the stats
10783 * received from the firmware
10784 * @data: pointer to adapter.
10785 * @rsp: pointer to data received from FW.
10786 *
10787 * This is called when wlan driver received response event for
10788 * get arp stats to firmware.
10789 *
10790 * Return: None
10791 */
10792static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10793{
10794 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10795 struct hdd_nud_stats_context *context;
10796 int status;
10797 struct hdd_adapter *adapter = NULL;
10798
Dustin Brown491d54b2018-03-14 12:39:11 -070010799 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010800
10801 if (!rsp) {
10802 hdd_err("data is null");
10803 return;
10804 }
10805
10806 status = wlan_hdd_validate_context(hdd_ctx);
10807 if (0 != status)
10808 return;
10809
10810 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10811 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10812 hdd_err("Invalid adapter or adapter has invalid magic");
10813 return;
10814 }
10815
Dustin Brown5e89ef82018-03-14 11:50:23 -070010816 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10817 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10818 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10819 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10820 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10821 rsp->out_of_order_arp_rsp_drop_cnt);
10822 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10823 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10824 hdd_info("rsp->ba_session_establishment_status :%x",
10825 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010826
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010827 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010828 adapter->dad |= rsp->dad_detected;
10829 adapter->con_status = rsp->connect_status;
10830
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010831 /* Flag true indicates connectivity check stats present. */
10832 if (rsp->connect_stats_present) {
10833 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10834 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10835 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10836 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10837 rsp->icmpv4_rsp_recvd;
10838 }
10839
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010840 spin_lock(&hdd_context_lock);
10841 context = &hdd_ctx->nud_stats_context;
10842 complete(&context->response_event);
10843 spin_unlock(&hdd_context_lock);
10844
Dustin Browne74003f2018-03-14 12:51:58 -070010845 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010846}
10847
10848/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010849 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010850 * @hdd_ctx: HDD context
10851 *
10852 * Register the HDD callbacks to CDS/SME.
10853 *
10854 * Return: 0 for success or Error code for failure
10855 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010856int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010857{
10858 QDF_STATUS status;
10859 int ret = 0;
10860
Dustin Brown491d54b2018-03-14 12:39:11 -070010861 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010862
10863 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10864
10865 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10866 hdd_send_oem_data_rsp_msg);
10867
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010868 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10869 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010870 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10871 sme_nan_register_callback(hdd_ctx->hHal,
10872 wlan_hdd_cfg80211_nan_callback);
10873 sme_stats_ext_register_callback(hdd_ctx->hHal,
10874 wlan_hdd_cfg80211_stats_ext_callback);
10875
10876 sme_ext_scan_register_callback(hdd_ctx->hHal,
10877 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010878 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10879 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010880
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010881 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10882 hdd_rssi_threshold_breached);
10883
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010884 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10885
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010886 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10887 wlan_hdd_cfg80211_link_layer_stats_callback);
10888
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010889 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10890
Zhang Qianca38fb12016-12-23 11:10:48 +080010891 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10892 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10893
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010894 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10895 hdd_lost_link_info_cb);
10896 /* print error and not block the startup process */
10897 if (!QDF_IS_STATUS_SUCCESS(status))
10898 hdd_err("set lost link info callback failed");
10899
Poddar, Siddarth34872782017-08-10 14:08:51 +053010900 ret = hdd_register_data_stall_detect_cb();
10901 if (ret) {
10902 hdd_err("Register data stall detect detect callback failed.");
10903 return ret;
10904 }
10905
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010906 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10907
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010908 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010909 hdd_set_connection_in_progress,
10910 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010911
10912 status = sme_congestion_register_callback(hdd_ctx->hHal,
10913 hdd_update_cca_info_cb);
10914 if (!QDF_IS_STATUS_SUCCESS(status))
10915 hdd_err("set congestion callback failed");
10916
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010917 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10918 hdd_bt_activity_cb);
10919 if (!QDF_IS_STATUS_SUCCESS(status))
10920 hdd_err("set bt activity info callback failed");
10921
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010922 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10923 hdd_tx_queue_cb);
10924 if (!QDF_IS_STATUS_SUCCESS(status))
10925 hdd_err("Register tx queue callback failed");
10926
Dustin Browne74003f2018-03-14 12:51:58 -070010927 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010928
10929 return ret;
10930}
10931
10932/**
10933 * hdd_deregister_cb() - De-Register HDD callbacks.
10934 * @hdd_ctx: HDD context
10935 *
10936 * De-Register the HDD callbacks to CDS/SME.
10937 *
10938 * Return: void
10939 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010940void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010941{
10942 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010943 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010944
Dustin Brown491d54b2018-03-14 12:39:11 -070010945 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010946
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010947 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010948 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10949 if (!QDF_IS_STATUS_SUCCESS(status))
10950 hdd_err("De-register of dcc stats callback failed: %d",
10951 status);
10952
10953 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010954 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10955
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010956 sme_stats_ext_register_callback(hdd_ctx->hHal,
10957 wlan_hdd_cfg80211_stats_ext_callback);
10958
10959 sme_nan_deregister_callback(hdd_ctx->hHal);
10960 status = sme_reset_tsfcb(hdd_ctx->hHal);
10961 if (!QDF_IS_STATUS_SUCCESS(status))
10962 hdd_err("Failed to de-register tsfcb the callback:%d",
10963 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010964
Poddar, Siddarth34872782017-08-10 14:08:51 +053010965 ret = hdd_deregister_data_stall_detect_cb();
10966 if (ret)
10967 hdd_err("Failed to de-register data stall detect event callback");
10968
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010969 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10970 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10971
Dustin Browne74003f2018-03-14 12:51:58 -070010972 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010973}
10974
10975/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010976 * hdd_softap_sta_deauth() - handle deauth req from HDD
10977 * @adapter: Pointer to the HDD
10978 * @enable: bool value
10979 *
10980 * This to take counter measure to handle deauth req from HDD
10981 *
10982 * Return: None
10983 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010984QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010985 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010986{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010987 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010988
Dustin Brown491d54b2018-03-14 12:39:11 -070010989 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010991 /* Ignore request to deauth bcmc station */
10992 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010993 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010994
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010995 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010996 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10997 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010998
Dustin Browne74003f2018-03-14 12:51:58 -070010999 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011000 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011001}
11002
11003/**
11004 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11005 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011006 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011007 *
11008 * This to take counter measure to handle deauth req from HDD
11009 *
11010 * Return: None
11011 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011012void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011013 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011014{
Dustin Brown491d54b2018-03-14 12:39:11 -070011015 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011016
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011017 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011018 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011019 return;
11020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011021 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011022 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011023}
11024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011025/**
11026 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11027 * @hdd_ctx: HDD Context
11028 *
11029 * API to find if there is any STA or P2P-Client is connected
11030 *
11031 * Return: true if connected; false otherwise
11032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011033QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011034{
11035 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11036}
11037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011038/**
11039 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11040 * @adapter: HDD adapter pointer
11041 *
11042 * This function loop through each adapter and disable roaming on each STA
11043 * device mode except the input adapter.
11044 *
11045 * Note: On the input adapter roaming is not enabled yet hence no need to
11046 * disable.
11047 *
11048 * Return: None
11049 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011050void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011051{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011052 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011053 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011054
11055 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011056 hdd_ctx->config->isRoamOffloadScanEnabled &&
11057 QDF_STA_MODE == adapter->device_mode &&
11058 policy_mgr_is_sta_active_connection_exists(
11059 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011060 hdd_debug("Connect received on STA session Id(%d)",
11061 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011062 /*
11063 * Loop through adapter and disable roaming for each STA device
11064 * mode except the input adapter.
11065 */
Dustin Brown920397d2017-12-13 16:27:50 -080011066 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011067 if (QDF_STA_MODE == adapterIdx->device_mode &&
11068 adapter->session_id != adapterIdx->session_id) {
11069 hdd_debug("Disable Roaming on session Id(%d)",
11070 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011071 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11072 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011073 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011074 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011075 }
11076 }
11077}
11078
11079/**
11080 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11081 * @adapter: HDD adapter pointer
11082 *
11083 * This function loop through each adapter and enable roaming on each STA
11084 * device mode except the input adapter.
11085 * Note: On the input adapter no need to enable roaming because link got
11086 * disconnected on this.
11087 *
11088 * Return: None
11089 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011090void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011091{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011092 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011093 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011094
11095 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011096 hdd_ctx->config->isRoamOffloadScanEnabled &&
11097 QDF_STA_MODE == adapter->device_mode &&
11098 policy_mgr_is_sta_active_connection_exists(
11099 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011100 hdd_debug("Disconnect received on STA session Id(%d)",
11101 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011102 /*
11103 * Loop through adapter and enable roaming for each STA device
11104 * mode except the input adapter.
11105 */
Dustin Brown920397d2017-12-13 16:27:50 -080011106 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011107 if (QDF_STA_MODE == adapterIdx->device_mode &&
11108 adapter->session_id != adapterIdx->session_id) {
11109 hdd_debug("Enabling Roaming on session Id(%d)",
11110 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011111 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11112 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011113 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114 REASON_CONNECT);
11115 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011116 }
11117 }
11118}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011119
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011120/**
11121 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11122 * @skb: sk buffer pointer
11123 *
11124 * Sends the bcast message to SVC multicast group with generic nl socket
11125 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11126 *
11127 * Return: None
11128 */
11129static void nl_srv_bcast_svc(struct sk_buff *skb)
11130{
11131#ifdef CNSS_GENL
11132 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11133#else
11134 nl_srv_bcast(skb);
11135#endif
11136}
11137
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011138void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139{
11140 struct sk_buff *skb;
11141 struct nlmsghdr *nlh;
11142 tAniMsgHdr *ani_hdr;
11143 void *nl_data = NULL;
11144 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011145 struct radio_index_tlv *radio_info;
11146 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011147
11148 if (in_interrupt() || irqs_disabled() || in_atomic())
11149 flags = GFP_ATOMIC;
11150
11151 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11152
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011153 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011154 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011155
11156 nlh = (struct nlmsghdr *)skb->data;
11157 nlh->nlmsg_pid = 0; /* from kernel */
11158 nlh->nlmsg_flags = 0;
11159 nlh->nlmsg_seq = 0;
11160 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11161
11162 ani_hdr = NLMSG_DATA(nlh);
11163 ani_hdr->type = type;
11164
11165 switch (type) {
11166 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011167 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011168 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011169 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011170 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011171 ani_hdr->length = 0;
11172 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011173 break;
11174 case WLAN_SVC_WLAN_STATUS_IND:
11175 case WLAN_SVC_WLAN_VERSION_IND:
11176 case WLAN_SVC_DFS_CAC_START_IND:
11177 case WLAN_SVC_DFS_CAC_END_IND:
11178 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11179 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11180 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011181 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011182 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011183 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011184 ani_hdr->length = len;
11185 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11186 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11187 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011188 break;
11189
11190 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011191 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192 type);
11193 kfree_skb(skb);
11194 return;
11195 }
11196
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011197 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011198 * Add radio index at the end of the svc event in TLV format
11199 * to maintain the backward compatibility with userspace
11200 * applications.
11201 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011202
11203 tlv_len = 0;
11204
11205 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11206 < WLAN_NL_MAX_PAYLOAD) {
11207 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11208 sizeof(*ani_hdr) + len);
11209 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11210 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11211 radio_info->radio = radio;
11212 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011213 hdd_debug("Added radio index tlv - radio index %d",
11214 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011215 }
11216
11217 nlh->nlmsg_len += tlv_len;
11218 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11219
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011220 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011221}
11222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011223#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11224void wlan_hdd_auto_shutdown_cb(void)
11225{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011226 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011227
11228 if (!hdd_ctx)
11229 return;
11230
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011231 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011232 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11233 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011234}
11235
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011236void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011237{
Jeff Johnson9d295242017-08-29 14:39:48 -070011238 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011239 bool ap_connected = false, sta_connected = false;
11240 tHalHandle hal_handle;
11241
11242 hal_handle = hdd_ctx->hHal;
11243 if (hal_handle == NULL)
11244 return;
11245
11246 if (hdd_ctx->config->WlanAutoShutdown == 0)
11247 return;
11248
11249 if (enable == false) {
11250 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011251 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011252 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011253 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011254 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011255 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256 return;
11257 }
11258
11259 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011260 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11261 hdd_for_each_adapter(hdd_ctx, adapter) {
11262 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011263 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11264 conn_info.connState ==
11265 eConnectionState_Associated) {
11266 sta_connected = true;
11267 break;
11268 }
11269 }
Dustin Brown920397d2017-12-13 16:27:50 -080011270
11271 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011272 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011273 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274 ap_connected = true;
11275 break;
11276 }
11277 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011278 }
11279 }
11280
11281 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011282 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011283 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011284 }
Jeff Johnson68755312017-02-10 11:46:55 -080011285
11286 if (sme_set_auto_shutdown_timer(hal_handle,
11287 hdd_ctx->config->WlanAutoShutdown)
11288 != QDF_STATUS_SUCCESS)
11289 hdd_err("Failed to start wlan auto shutdown timer");
11290 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011291 hdd_info("Auto Shutdown timer for %d seconds enabled",
11292 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011293}
11294#endif
11295
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011296struct hdd_adapter *
11297hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11298 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011299{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011300 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011301 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302
11303 con_sap_adapter = NULL;
11304
Dustin Brown920397d2017-12-13 16:27:50 -080011305 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011306 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11307 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011308 adapter != this_sap_adapter) {
11309 if (check_start_bss) {
11310 if (test_bit(SOFTAP_BSS_STARTED,
11311 &adapter->event_flags)) {
11312 con_sap_adapter = adapter;
11313 break;
11314 }
11315 } else {
11316 con_sap_adapter = adapter;
11317 break;
11318 }
11319 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011320 }
11321
11322 return con_sap_adapter;
11323}
11324
11325#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011326static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011327{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011328 return adapter->device_mode == QDF_STA_MODE ||
11329 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011330}
11331
Jeff Johnson9d295242017-08-29 14:39:48 -070011332static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011333{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011334 return adapter->device_mode == QDF_SAP_MODE ||
11335 adapter->device_mode == QDF_P2P_GO_MODE;
11336}
11337
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011338static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011339{
Dustin Brown920397d2017-12-13 16:27:50 -080011340 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011341
Dustin Brown920397d2017-12-13 16:27:50 -080011342 hdd_for_each_adapter(hdd_ctx, adapter) {
11343 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011344 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11345 conn_info.connState == eConnectionState_Associated) {
11346 return true;
11347 }
11348
Dustin Brown920397d2017-12-13 16:27:50 -080011349 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011350 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011351 return true;
11352 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011353 }
11354
11355 return false;
11356}
11357
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011358static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011359{
11360 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011361
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011362 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011363 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011364 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011365
Dustin Brown5ec6b552017-03-31 12:11:40 -070011366 return is_running;
11367}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011368
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011369static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011370{
11371 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11372 hdd_ctx->bus_bw_timer_running = true;
11373 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11374 hdd_ctx->config->busBandwidthComputeInterval);
11375 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11376}
11377
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011378void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011379{
Dustin Brown491d54b2018-03-14 12:39:11 -070011380 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011381
11382 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11383 hdd_debug("Bandwidth compute timer already started");
11384 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011385 }
11386
Dustin Brown5ec6b552017-03-31 12:11:40 -070011387 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11388
Dustin Browne74003f2018-03-14 12:51:58 -070011389 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011390}
11391
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011392void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011393{
Dustin Brown491d54b2018-03-14 12:39:11 -070011394 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011395
11396 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11397 hdd_debug("Bandwidth compute timer already started");
11398 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011399 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011400
11401 if (hdd_any_adapter_is_assoc(hdd_ctx))
11402 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11403
Dustin Browne74003f2018-03-14 12:51:58 -070011404 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011405}
11406
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011407static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011408{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011409 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011410
11411 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11412 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11413 hdd_ctx->bus_bw_timer_running = false;
11414 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11415
11416 hdd_reset_tcp_delack(hdd_ctx);
11417}
11418
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011419void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011420{
Dustin Brown491d54b2018-03-14 12:39:11 -070011421 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011422
11423 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11424 hdd_debug("Bandwidth compute timer already stopped");
11425 return;
11426 }
11427
11428 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11429
Dustin Browne74003f2018-03-14 12:51:58 -070011430 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011431}
11432
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011433void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011434{
Dustin Brown491d54b2018-03-14 12:39:11 -070011435 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011436
11437 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11438 hdd_debug("Bandwidth compute timer already stopped");
11439 return;
11440 }
11441
11442 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11443 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11444
Dustin Browne74003f2018-03-14 12:51:58 -070011445 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011446}
11447#endif
11448
11449/**
11450 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11451 * and sta's operating channel.
11452 * @sta_adapter: Describe the first argument to foobar.
11453 * @ap_adapter: Describe the second argument to foobar.
11454 * @roam_profile: Roam profile of AP to which STA wants to connect.
11455 * @concurrent_chnl_same: If both SAP and STA channels are same then
11456 * set this flag to true else false.
11457 *
11458 * This function checks the sap's operating channel and sta's operating channel.
11459 * if both are same then it will return false else it will restart the sap in
11460 * sta's channel and return true.
11461 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011462 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011463 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011464QDF_STATUS
11465wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11466 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011467 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011468 tScanResultHandle *scan_cache,
11469 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011470{
Jeff Johnson87251032017-08-29 13:31:11 -070011471 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011472 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011473 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011474 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011475 *concurrent_chnl_same = true;
11476
11477 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11478 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011479 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011480 scan_cache,
11481 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011482 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011483 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011484 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011485 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011487 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011488 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011489 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011490 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011491 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011492 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011493 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011494 }
11495 }
11496 } else {
11497 /*
11498 * Lets handle worst case scenario here, Scan cache lookup is
11499 * failed so we have to stop the SAP to avoid any channel
11500 * discrepancy between SAP's channel and STA's channel.
11501 * Return the status as failure so caller function could know
11502 * that scan look up is failed.
11503 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011504 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011505 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011506 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011507 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011508}
11509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011510/**
11511 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11512 * @ap_adapter: SAP adapter
11513 *
11514 * This function will process the stopping of sap adapter.
11515 *
11516 * Return: None
11517 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011518void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011519{
Jeff Johnson87251032017-08-29 13:31:11 -070011520 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011521 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011522 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011523 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011524
11525 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011526 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011527 return;
11528 }
11529
11530 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11531 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011532 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011533 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011535 mutex_lock(&hdd_ctx->sap_lock);
11536 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011537 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011539 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011540 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011541 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011542 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011543 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011544 qdf_stop_bss_event,
11545 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011546 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011547 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011548 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011549 return;
11550 }
11551 }
11552 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011553 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11554 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011555 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011556 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011557 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011558 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011559 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011560 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011561 }
11562 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011563}
11564
11565/**
11566 * wlan_hdd_start_sap() - this function starts bss of SAP.
11567 * @ap_adapter: SAP adapter
11568 *
11569 * This function will process the starting of sap adapter.
11570 *
11571 * Return: None
11572 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011573void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011574{
Jeff Johnson87251032017-08-29 13:31:11 -070011575 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011576 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011577 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011578 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011579 tsap_Config_t *sap_config;
11580
11581 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011582 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011583 return;
11584 }
11585
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011586 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011587 hdd_err("SoftAp role has not been enabled");
11588 return;
11589 }
11590
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011591 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11592 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11593 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011594 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011595
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011596 mutex_lock(&hdd_ctx->sap_lock);
11597 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11598 goto end;
11599
11600 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011601 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011602 goto end;
11603 }
11604
Wei Song2f76f642016-11-18 16:32:53 +080011605 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011606 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011607 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011608 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011609 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011610 goto end;
11611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011612 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011613 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011614 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011615 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011616 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011617 goto end;
11618 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011619 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011620 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011621 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011622 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011623 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11624 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011625 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011626 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011627 true);
11628 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011629 mutex_unlock(&hdd_ctx->sap_lock);
11630
11631 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011632end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011633 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011634 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011635 /* SAP context and beacon cleanup will happen during driver unload
11636 * in hdd_stop_adapter
11637 */
11638 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011641
11642/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011643 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11644 * mac scan config
11645 * @status: Status of set antenna mode
11646 *
11647 * Callback on setting the dual mac configuration
11648 *
11649 * Return: None
11650 */
11651void wlan_hdd_soc_set_antenna_mode_cb(
11652 enum set_antenna_mode_status status)
11653{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011654 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011655
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011656 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011657
11658 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11659 if (0 != wlan_hdd_validate_context(hdd_ctx))
11660 return;
11661
11662 /* Signal the completion of set dual mac config */
11663 complete(&hdd_ctx->set_antenna_mode_cmpl);
11664}
11665
11666/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011667 * hdd_get_fw_version() - Get FW version
11668 * @hdd_ctx: pointer to HDD context.
11669 * @major_spid: FW version - major spid.
11670 * @minor_spid: FW version - minor spid
11671 * @ssid: FW version - ssid
11672 * @crmid: FW version - crmid
11673 *
11674 * This function is called to get the firmware build version stored
11675 * as part of the HDD context
11676 *
11677 * Return: None
11678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011679void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011680 uint32_t *major_spid, uint32_t *minor_spid,
11681 uint32_t *siid, uint32_t *crmid)
11682{
11683 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11684 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11685 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11686 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11687}
11688
11689#ifdef QCA_CONFIG_SMP
11690/**
11691 * wlan_hdd_get_cpu() - get cpu_index
11692 *
11693 * Return: cpu_index
11694 */
11695int wlan_hdd_get_cpu(void)
11696{
11697 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011698
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011699 put_cpu();
11700 return cpu_index;
11701}
11702#endif
11703
11704/**
11705 * hdd_get_fwpath() - get framework path
11706 *
11707 * This function is used to get the string written by
11708 * userspace to start the wlan driver
11709 *
11710 * Return: string
11711 */
11712const char *hdd_get_fwpath(void)
11713{
11714 return fwpath.string;
11715}
11716
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011717static int hdd_qdf_print_init(void)
11718{
11719 int qdf_print_idx;
11720 QDF_STATUS status;
11721
11722 status = qdf_print_setup();
11723 if (status != QDF_STATUS_SUCCESS) {
11724 pr_err("qdf_print_setup failed\n");
11725 return -EINVAL;
11726 }
11727
11728 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11729
11730 if (qdf_print_idx < 0) {
11731 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11732 qdf_print_idx);
11733 return -EINVAL;
11734 }
11735
11736 qdf_set_pidx(qdf_print_idx);
11737
11738 return 0;
11739}
11740
11741static void hdd_qdf_print_deinit(void)
11742{
11743 int qdf_print_idx;
11744
11745 qdf_print_idx = qdf_get_pidx();
11746 qdf_print_ctrl_cleanup(qdf_print_idx);
11747}
11748
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011749/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011750 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011751 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011752 * This function initilizes CDS global context with the help of cds_init. This
11753 * has to be the first function called after probe to get a valid global
11754 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011755 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011756 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011757 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011758int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011759{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011760 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011761 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011762
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011763 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011764 if (QDF_IS_STATUS_ERROR(status)) {
11765 hdd_err("Failed to allocate CDS context");
11766 ret = -ENOMEM;
11767 goto err_out;
11768 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011769
11770 wlan_init_bug_report_lock();
11771
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011772#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11773 wlan_logging_sock_init_svc();
11774#endif
11775
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011776 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11777 (void *)hdd_drv_ops_inactivity_handler, NULL,
11778 QDF_TIMER_TYPE_SW);
11779
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011780 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011781 hdd_qdf_print_init();
11782
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011783 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011784
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011785err_out:
11786 return ret;
11787}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011788
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011789/**
11790 * hdd_deinit() - Deinitialize Driver
11791 *
11792 * This function frees CDS global context with the help of cds_deinit. This
11793 * has to be the last function call in remove callback to free the global
11794 * context.
11795 */
11796void hdd_deinit(void)
11797{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011798 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011799
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011800 wlan_destroy_bug_report_lock();
11801 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011802
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011803 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011804#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11805 wlan_logging_sock_deinit_svc();
11806#endif
11807}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011808
Yue Ma6e7b1a02017-04-03 14:17:46 -070011809#ifdef QCA_WIFI_NAPIER_EMULATION
11810#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11811#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011812#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011813#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011814
Sachin Ahujadddd2632017-03-07 19:07:24 +053011815static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11816 struct file *file)
11817{
11818 return 0;
11819}
11820
11821static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11822 const char __user *user_buf,
11823 size_t count,
11824 loff_t *f_pos)
11825{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011826 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011827 static const char wlan_off_str[] = "OFF";
11828 static const char wlan_on_str[] = "ON";
11829 int ret;
11830 unsigned long rc;
11831
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011832 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011833 pr_err("Failed to read buffer\n");
11834 return -EINVAL;
11835 }
11836
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011837 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011838 pr_debug("Wifi turning off from UI\n");
11839 goto exit;
11840 }
11841
Sachin Ahuja16904db2017-12-13 19:56:57 +053011842 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11843 pr_info("Wifi Turning On from UI\n");
11844 }
11845
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011846 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011847 pr_err("Invalid value received from framework");
11848 goto exit;
11849 }
11850
11851 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011852 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011853 rc = wait_for_completion_timeout(&wlan_start_comp,
11854 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11855 if (!rc) {
11856 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11857 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011858 return ret;
11859 }
11860
11861 hdd_start_complete(0);
11862 }
11863
11864exit:
11865 return count;
11866}
11867
11868
11869const struct file_operations wlan_hdd_state_fops = {
11870 .owner = THIS_MODULE,
11871 .open = wlan_hdd_state_ctrl_param_open,
11872 .write = wlan_hdd_state_ctrl_param_write,
11873};
11874
11875static int wlan_hdd_state_ctrl_param_create(void)
11876{
11877 unsigned int wlan_hdd_state_major = 0;
11878 int ret;
11879 struct device *dev;
11880
11881 device = MKDEV(wlan_hdd_state_major, 0);
11882
11883 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11884 if (ret) {
11885 pr_err("Failed to register qcwlanstate");
11886 goto dev_alloc_err;
11887 }
11888 wlan_hdd_state_major = MAJOR(device);
11889
11890 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11891 if (IS_ERR(class)) {
11892 pr_err("wlan_hdd_state class_create error");
11893 goto class_err;
11894 }
11895
11896 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11897 if (IS_ERR(dev)) {
11898 pr_err("wlan_hdd_statedevice_create error");
11899 goto err_class_destroy;
11900 }
11901
11902 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11903 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11904 if (ret) {
11905 pr_err("Failed to add cdev error");
11906 goto cdev_add_err;
11907 }
11908
11909 pr_info("wlan_hdd_state %s major(%d) initialized",
11910 WLAN_MODULE_NAME, wlan_hdd_state_major);
11911
11912 return 0;
11913
11914cdev_add_err:
11915 device_destroy(class, device);
11916err_class_destroy:
11917 class_destroy(class);
11918class_err:
11919 unregister_chrdev_region(device, dev_num);
11920dev_alloc_err:
11921 return -ENODEV;
11922}
11923
11924static void wlan_hdd_state_ctrl_param_destroy(void)
11925{
11926 cdev_del(&wlan_hdd_state_cdev);
11927 device_destroy(class, device);
11928 class_destroy(class);
11929 unregister_chrdev_region(device, dev_num);
11930
11931 pr_info("Device node unregistered");
11932}
11933
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011934/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011935 * component_init - API to init cld component's
11936 *
11937 * Return: None
11938 */
11939static void component_init(void)
11940{
11941 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011942 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011943 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011944 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011945}
11946
11947/**
11948 * component_deinit - API to deinit cld component's
11949 *
11950 * Return: None
11951 */
11952static void component_deinit(void)
11953{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011954 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011955 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011956 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011957 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011958}
11959
11960void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11961{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011962 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011963 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011964}
11965
11966void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11967{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011968 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011969 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011970}
11971
11972/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011973 * __hdd_module_init - Module init helper
11974 *
11975 * Module init helper function used by both module and static driver.
11976 *
11977 * Return: 0 for success, errno on failure
11978 */
11979static int __hdd_module_init(void)
11980{
11981 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011982
Dustin Brown96cd9632017-11-13 12:45:04 -080011983 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011984 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011985 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011986 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011987
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011988 pld_init();
11989
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011990 ret = hdd_init();
11991 if (ret) {
11992 pr_err("hdd_init failed %x\n", ret);
11993 goto err_hdd_init;
11994 }
11995
Rajeev Kumar97767a02016-11-30 11:20:40 -080011996 dispatcher_init();
11997
Mukul Sharmad75a6672017-06-22 15:40:53 +053011998 /* Ensure to call post objmgr init */
11999 component_init();
12000
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012001 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012002
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012003 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012004
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012005 ret = wlan_hdd_register_driver();
12006 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012007 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12008 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012009 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012010 }
12011
Sachin Ahuja16904db2017-12-13 19:56:57 +053012012 ret = wlan_hdd_state_ctrl_param_create();
12013 if (ret) {
12014 pr_err("wlan_hdd_state_create:%x\n", ret);
12015 goto out;
12016 }
12017
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012018 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012019
12020 return 0;
12021out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012022 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012023 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012024 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012025 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012026
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012027err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012028 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012029 return ret;
12030}
12031
12032/**
12033 * __hdd_module_exit - Module exit helper
12034 *
12035 * Module exit helper function used by both module and static driver.
12036 */
12037static void __hdd_module_exit(void)
12038{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012039
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012040 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12041 QWLAN_VERSIONSTR);
12042
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012043 hdd_wait_for_recovery_completion();
12044
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012045 wlan_hdd_unregister_driver();
12046
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012047 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012048
Mukul Sharmad75a6672017-06-22 15:40:53 +053012049 /* Ensure to call prior to objmgr deinit */
12050 component_deinit();
12051
Rajeev Kumar97767a02016-11-30 11:20:40 -080012052 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012053
12054 hdd_sysfs_destroy_version_interface();
12055
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012056 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012057 pld_deinit();
12058
Sachin Ahujadddd2632017-03-07 19:07:24 +053012059 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012060}
12061
Arun Khandavallifae92942016-08-01 13:31:08 +053012062#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012063/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012064 * wlan_boot_cb() - Wlan boot callback
12065 * @kobj: object whose directory we're creating the link in.
12066 * @attr: attribute the user is interacting with
12067 * @buff: the buffer containing the user data
12068 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012069 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012070 * This callback is invoked when the fs is ready to start the
12071 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012072 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012073 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012074 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012075static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012076 struct kobj_attribute *attr,
12077 const char *buf,
12078 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012079{
Arun Khandavallifae92942016-08-01 13:31:08 +053012080
Arun Khandavallifae92942016-08-01 13:31:08 +053012081 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012082 pr_err("%s: wlan driver already initialized\n", __func__);
12083 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012084 }
12085
Arun Khandavallifae92942016-08-01 13:31:08 +053012086 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012087 pr_err("%s: wlan driver initialization failed\n", __func__);
12088 return -EIO;
12089 }
12090
12091 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012092
12093 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012094}
Arun Khandavallifae92942016-08-01 13:31:08 +053012095
12096/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012097 * hdd_sysfs_cleanup() - cleanup sysfs
12098 *
12099 * Return: None
12100 *
12101 */
12102static void hdd_sysfs_cleanup(void)
12103{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012104 /* remove from group */
12105 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12106 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12107 wlan_loader->attr_group);
12108
12109 /* unlink the object from parent */
12110 kobject_del(wlan_loader->boot_wlan_obj);
12111
12112 /* free the object */
12113 kobject_put(wlan_loader->boot_wlan_obj);
12114
12115 kfree(wlan_loader->attr_group);
12116 kfree(wlan_loader);
12117
12118 wlan_loader = NULL;
12119}
12120
12121/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012122 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12123 * ready
12124 *
12125 * This is creates the syfs entry boot_wlan. Which shall be invoked
12126 * when the filesystem is ready.
12127 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012128 * QDF API cannot be used here since this function is called even before
12129 * initializing WLAN driver.
12130 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012131 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012132 */
12133static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012134{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012135 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012136
12137 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012138 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012139 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012140
12141 wlan_loader->boot_wlan_obj = NULL;
12142 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12143 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012144 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012145 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012146
12147 wlan_loader->loaded_state = 0;
12148 wlan_loader->attr_group->attrs = attrs;
12149
12150 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12151 kernel_kobj);
12152 if (!wlan_loader->boot_wlan_obj) {
12153 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012154 goto error_return;
12155 }
12156
12157 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12158 wlan_loader->attr_group);
12159 if (ret) {
12160 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12161 goto error_return;
12162 }
12163
12164 return 0;
12165
12166error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012167 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012168
12169 return ret;
12170}
12171
12172/**
12173 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12174 *
12175 * Return: 0 on success or errno on failure
12176 */
12177static int wlan_deinit_sysfs(void)
12178{
Arun Khandavallifae92942016-08-01 13:31:08 +053012179 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012180 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012181 return -EINVAL;
12182 }
12183
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012184 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012185 return 0;
12186}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012187
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012188#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012189
12190#ifdef MODULE
12191/**
12192 * __hdd_module_init - Module init helper
12193 *
12194 * Module init helper function used by both module and static driver.
12195 *
12196 * Return: 0 for success, errno on failure
12197 */
12198static int hdd_module_init(void)
12199{
Arun Khandavallifae92942016-08-01 13:31:08 +053012200 if (__hdd_module_init()) {
12201 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012202 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012203 }
12204
Dustin Brownab482ac2017-06-09 17:00:44 -070012205 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012206}
12207#else
12208static int __init hdd_module_init(void)
12209{
12210 int ret = -EINVAL;
12211
12212 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012213 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012214 pr_err("Failed to create sysfs entry for loading wlan");
12215
12216 return ret;
12217}
12218#endif
12219
12220
12221#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012222/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012223 * hdd_module_exit() - Exit function
12224 *
12225 * This is the driver exit point (invoked when module is unloaded using rmmod)
12226 *
12227 * Return: None
12228 */
12229static void __exit hdd_module_exit(void)
12230{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012231 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012232}
Arun Khandavallifae92942016-08-01 13:31:08 +053012233#else
12234static void __exit hdd_module_exit(void)
12235{
12236 __hdd_module_exit();
12237 wlan_deinit_sysfs();
12238}
12239#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012240
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012241static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12242{
12243 return param_set_copystring(kmessage, kp);
12244}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012245
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012246/**
12247 * is_con_mode_valid() check con mode is valid or not
12248 * @mode: global con mode
12249 *
12250 * Return: TRUE on success FALSE on failure
12251 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012252static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012253{
12254 switch (mode) {
12255 case QDF_GLOBAL_MONITOR_MODE:
12256 case QDF_GLOBAL_FTM_MODE:
12257 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012258 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012259 return true;
12260 default:
12261 return false;
12262 }
12263}
12264
12265/**
12266 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12267 * @mode: global con mode
12268 *
12269 * Return: adapter mode
12270 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012271static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012272 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012273{
12274
12275 switch (mode) {
12276 case QDF_GLOBAL_MISSION_MODE:
12277 return QDF_STA_MODE;
12278 case QDF_GLOBAL_MONITOR_MODE:
12279 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012280 case QDF_GLOBAL_EPPING_MODE:
12281 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012282 case QDF_GLOBAL_FTM_MODE:
12283 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012284 case QDF_GLOBAL_QVIT_MODE:
12285 return QDF_QVIT_MODE;
12286 default:
12287 return QDF_MAX_NO_OF_MODE;
12288 }
12289}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012290
Dustin Brown27cd9942017-09-27 16:11:44 -070012291static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012292 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012293{
12294 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12295 return;
12296
12297 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012298 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012299 hdd_info("Release wakelock for monitor mode!");
12300 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12301 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12302 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012303 case QDF_GLOBAL_FTM_MODE:
12304 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012305 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012306 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012307
Dustin Brown27cd9942017-09-27 16:11:44 -070012308 break;
12309 default:
12310 break;
12311 }
12312}
12313
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012314static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012315 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012316{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012317 int driver_status;
12318
12319 driver_status = hdd_ctx->driver_status;
12320
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012321 switch (curr_mode) {
12322 case QDF_GLOBAL_MISSION_MODE:
12323 case QDF_GLOBAL_MONITOR_MODE:
12324 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012325 hdd_deinit_all_adapters(hdd_ctx, false);
12326 hdd_close_all_adapters(hdd_ctx, false);
12327 break;
12328 case QDF_GLOBAL_EPPING_MODE:
12329 epping_disable();
12330 epping_close();
12331 break;
12332 default:
12333 return;
12334 }
12335}
12336
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012337static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012338 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012339{
Jeff Johnson9d295242017-08-29 14:39:48 -070012340 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012341 int ret = 0;
12342 bool rtnl_held;
12343 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12344 QDF_STATUS status;
12345
12346 if (!qdf_dev) {
12347 hdd_err("qdf device context is Null return!");
12348 return -EINVAL;
12349 }
12350
12351 rtnl_held = hdd_hold_rtnl_lock();
12352 switch (mode) {
12353 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012354 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12355 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012356 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012357 break;
12358 case QDF_GLOBAL_FTM_MODE:
12359 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12360 wlan_hdd_get_intf_addr(hdd_ctx),
12361 NET_NAME_UNKNOWN, rtnl_held);
12362 if (adapter == NULL)
12363 ret = -EINVAL;
12364 break;
12365 case QDF_GLOBAL_MONITOR_MODE:
12366 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12367 wlan_hdd_get_intf_addr(hdd_ctx),
12368 NET_NAME_UNKNOWN, rtnl_held);
12369 if (adapter == NULL)
12370 ret = -EINVAL;
12371 break;
12372 case QDF_GLOBAL_EPPING_MODE:
12373 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012374 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012375 hdd_err("Failed to open in eeping mode: %d", status);
12376 ret = -EINVAL;
12377 break;
12378 }
12379 ret = epping_enable(qdf_dev->dev);
12380 if (ret) {
12381 hdd_err("Failed to enable in epping mode : %d", ret);
12382 epping_close();
12383 }
12384 break;
12385 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012386 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012387 ret = -ENOTSUPP;
12388 break;
12389 }
12390 hdd_release_rtnl_lock();
12391 rtnl_held = false;
12392 return ret;
12393}
12394
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012395/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012396 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012397 * @kmessage: con mode name on which driver to be bring up
12398 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012399 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012400 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012401 * This function is invoked when user updates con mode using sys entry,
12402 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012403 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012404 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012405 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012406static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012407 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012408{
12409 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012410 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012411 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012412 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012413 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012414
Dustin Brownab6029b2017-05-24 13:04:19 -070012415 hdd_info("con_mode handler: %s", kmessage);
12416
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012417 ret = wlan_hdd_validate_context(hdd_ctx);
12418 if (ret)
12419 return ret;
12420
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012421 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012422 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012423
Dustin Brown20024e32018-01-03 12:34:58 -080012424 ret = kstrtoint(kmessage, 0, &new_con_mode);
12425 if (ret) {
12426 hdd_err("Failed to parse con_mode '%s'", kmessage);
12427 goto reset_flags;
12428 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012429 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012430
Dustin Brown20024e32018-01-03 12:34:58 -080012431 if (!is_con_mode_valid(new_con_mode)) {
12432 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012433 ret = -EINVAL;
12434 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012435 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012436
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012437 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012438 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012439 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012440 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012441 ret = 0;
12442 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012443 }
12444
Dustin Brown27cd9942017-09-27 16:11:44 -070012445 /* ensure adapters are stopped */
12446 hdd_stop_present_mode(hdd_ctx, curr_mode);
12447
Frank Liu6666f832018-01-04 10:06:05 +080012448 /* Cleanup present mode before switching to new mode */
12449 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12450
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012451 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012452 if (ret) {
12453 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012454 goto reset_flags;
12455 }
12456
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012457
Dustin Brown20024e32018-01-03 12:34:58 -080012458 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012459
Frank Liu6666f832018-01-04 10:06:05 +080012460 /*
12461 * Set ACTIVE domain before adapters created, otherwise check domain
12462 * match will fail when cleanup adapters.
12463 */
12464 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012465 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012466 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012467 if (ret) {
12468 hdd_err("Failed to register for new mode");
12469 goto reset_flags;
12470 }
12471
Dustin Brown20024e32018-01-03 12:34:58 -080012472 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012473 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12474 hdd_err("invalid adapter");
12475 ret = -EINVAL;
12476 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012477 }
12478
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012479 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012480 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012481 hdd_err("Failed to get adapter:%d", adapter_mode);
12482 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012483 }
12484
12485 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12486 if (ret) {
12487 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012488 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012489 }
12490
Dustin Brown20024e32018-01-03 12:34:58 -080012491 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012492 if (hdd_start_adapter(adapter)) {
12493 hdd_err("Failed to start %s adapter", kmessage);
12494 ret = -EINVAL;
12495 goto reset_flags;
12496 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012497
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012498 hdd_info("Acquire wakelock for monitor mode!");
12499 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12500 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12501 }
12502
Dustin Brown20024e32018-01-03 12:34:58 -080012503 /* con_mode is a global module parameter */
12504 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012505 hdd_info("Mode successfully changed to %s", kmessage);
12506 ret = 0;
12507
12508reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012509 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012510 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012511 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012512 return ret;
12513}
12514
12515
12516static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12517{
12518 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012519 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012520
12521 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12522 ret = wlan_hdd_validate_context(hdd_ctx);
12523 if (ret)
12524 return ret;
12525
12526 cds_ssr_protect(__func__);
12527 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12528 cds_ssr_unprotect(__func__);
12529
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012530 return ret;
12531}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012532
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012533static int con_mode_handler_ftm(const char *kmessage,
12534 struct kernel_param *kp)
12535{
12536 int ret;
12537
12538 ret = param_set_int(kmessage, kp);
12539
12540 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12541 pr_err("Only FTM mode supported!");
12542 return -ENOTSUPP;
12543 }
12544
12545 hdd_set_conparam(con_mode_ftm);
12546 con_mode = con_mode_ftm;
12547
12548 return ret;
12549}
12550
Ravi Joshia307f632017-07-17 23:41:41 -070012551static int con_mode_handler_monitor(const char *kmessage,
12552 struct kernel_param *kp)
12553{
12554 int ret;
12555
12556 ret = param_set_int(kmessage, kp);
12557
12558 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12559 pr_err("Only Monitor mode supported!");
12560 return -ENOTSUPP;
12561 }
12562
12563 hdd_set_conparam(con_mode_monitor);
12564 con_mode = con_mode_monitor;
12565
12566 return ret;
12567}
12568
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012569/**
12570 * hdd_get_conparam() - driver exit point
12571 *
12572 * This is the driver exit point (invoked when module is unloaded using rmmod)
12573 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012574 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012575 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012576enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012577{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012578 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012579}
12580
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012581void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012582{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012583 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012584}
12585
Komal Seelamc11bb222016-01-27 18:57:10 +053012586/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012587 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12588 * @hdd_ctx: HDD context
12589 *
12590 * Cleans up the pre cac interface, if it exists
12591 *
12592 * Return: None
12593 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012594void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012595{
12596 uint8_t session_id;
12597 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012598 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012599
12600 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12601 if (QDF_IS_STATUS_ERROR(status)) {
12602 hdd_err("failed to get pre cac vdev id");
12603 return;
12604 }
12605
12606 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12607 if (!precac_adapter) {
12608 hdd_err("invalid pre cac adapater");
12609 return;
12610 }
12611
12612 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12613 wlan_hdd_sap_pre_cac_failure,
12614 (void *)precac_adapter);
12615 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12616
12617}
12618
12619/**
Komal Seelamec702b02016-02-24 18:42:16 +053012620 * hdd_update_ol_config - API to update ol configuration parameters
12621 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012622 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012623 * Return: void
12624 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012625static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012626{
Komal Seelamec702b02016-02-24 18:42:16 +053012627 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012628 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012629
Komal Seelamec702b02016-02-24 18:42:16 +053012630 if (!ol_ctx)
12631 return;
12632
12633 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12634 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12635 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12636 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012637 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012638
12639 ol_init_ini_config(ol_ctx, &cfg);
12640}
12641
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012642#ifdef FEATURE_RUNTIME_PM
12643/**
12644 * hdd_populate_runtime_cfg() - populate runtime configuration
12645 * @hdd_ctx: hdd context
12646 * @cfg: pointer to the configuration memory being populated
12647 *
12648 * Return: void
12649 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012650static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012651 struct hif_config_info *cfg)
12652{
12653 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12654 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12655}
12656#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012657static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012658 struct hif_config_info *cfg)
12659{
12660}
12661#endif
12662
Komal Seelamec702b02016-02-24 18:42:16 +053012663/**
12664 * hdd_update_hif_config - API to update HIF configuration parameters
12665 * @hdd_ctx: HDD Context
12666 *
12667 * Return: void
12668 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012669static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012670{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012671 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012672 struct hif_config_info cfg;
12673
12674 if (!scn)
12675 return;
12676
12677 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012678 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012679 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012680
12681 if (hdd_ctx->config->prevent_link_down)
12682 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012683}
12684
12685/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012686 * hdd_update_dp_config() - Propagate config parameters to Lithium
12687 * datapath
12688 * @hdd_ctx: HDD Context
12689 *
12690 * Return: 0 for success/errno for failure
12691 */
12692static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12693{
12694 struct cdp_config_params params;
12695 QDF_STATUS status;
12696
12697 params.tso_enable = hdd_ctx->config->tso_enable;
12698 params.lro_enable = hdd_ctx->config->lro_enable;
12699#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12700 params.tx_flow_stop_queue_threshold =
12701 hdd_ctx->config->TxFlowStopQueueThreshold;
12702 params.tx_flow_start_queue_offset =
12703 hdd_ctx->config->TxFlowStartQueueOffset;
12704#endif
12705 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12706 params.napi_enable = hdd_ctx->napi_enable;
12707 params.tcp_udp_checksumoffload =
12708 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12709
12710 status = cdp_update_config_parameters(
12711 cds_get_context(QDF_MODULE_ID_SOC),
12712 &params);
12713 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012714 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012715 return status;
12716 }
12717
12718 return 0;
12719}
12720
12721/**
Komal Seelamec702b02016-02-24 18:42:16 +053012722 * hdd_update_config() - Initialize driver per module ini parameters
12723 * @hdd_ctx: HDD Context
12724 *
12725 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012726 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012727 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012728int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012729{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012730 int ret;
12731
Komal Seelamec702b02016-02-24 18:42:16 +053012732 hdd_update_ol_config(hdd_ctx);
12733 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012734 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12735 ret = hdd_update_cds_config_ftm(hdd_ctx);
12736 else
12737 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012738 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012739
12740 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012741}
12742
Mukul Sharma9d797a02017-01-05 20:26:03 +053012743#ifdef FEATURE_WLAN_RA_FILTERING
12744/**
12745 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12746 * @psoc_cfg: pmo psoc Configuration
12747 * @hdd_ctx: Pointer to hdd context
12748 *
12749 * Return: none
12750 */
12751static inline void hdd_ra_populate_pmo_config(
12752 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012753 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012754{
12755 psoc_cfg->ra_ratelimit_interval =
12756 hdd_ctx->config->RArateLimitInterval;
12757 psoc_cfg->ra_ratelimit_enable =
12758 hdd_ctx->config->IsRArateLimitEnabled;
12759}
12760#else
12761static inline void hdd_ra_populate_pmo_config(
12762 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012763 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012764{
12765}
12766#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012767
Mukul Sharma9d797a02017-01-05 20:26:03 +053012768/**
12769 * hdd_update_pmo_config - API to update pmo configuration parameters
12770 * @hdd_ctx: HDD context
12771 *
12772 * Return: void
12773 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012774static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012775{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012776 struct pmo_psoc_cfg psoc_cfg;
12777 QDF_STATUS status;
12778
12779 /*
12780 * Value of hdd_ctx->wowEnable can be,
12781 * 0 - Disable both magic pattern match and pattern byte match.
12782 * 1 - Enable magic pattern match on all interfaces.
12783 * 2 - Enable pattern byte match on all interfaces.
12784 * 3 - Enable both magic patter and pattern byte match on
12785 * all interfaces.
12786 */
12787 psoc_cfg.magic_ptrn_enable =
12788 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12789 psoc_cfg.ptrn_match_enable_all_vdev =
12790 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012791 psoc_cfg.ptrn_id_per_vdev =
12792 wma_is_service_enabled(wmi_service_unified_wow_capability);
12793 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012794 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012795 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012796 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012797 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012798 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012799 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12800 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012801 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012802 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012803 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012804 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12805 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12806 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012807 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012808 psoc_cfg.auto_power_save_fail_mode =
12809 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012810
12811 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012812 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12813 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012814
Dustin Brownb9987af2018-03-01 17:15:11 -080012815 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12816 if (QDF_IS_STATUS_ERROR(status))
12817 hdd_err("failed pmo psoc configuration; status:%d", status);
12818
12819 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012820}
12821
Abhishek Singhb20db962017-03-03 21:28:46 +053012822#ifdef FEATURE_WLAN_SCAN_PNO
12823static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12824 struct hdd_config *cfg)
12825{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012826 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12827
Abhishek Singhb20db962017-03-03 21:28:46 +053012828 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12829 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12830 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12831 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12832 pno_cfg->channel_prediction_full_scan =
12833 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012834 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12835 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12836 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12837 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012838}
12839#else
12840static inline void
12841hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012842 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012843{
Abhishek Singhb20db962017-03-03 21:28:46 +053012844}
12845#endif
12846
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012847void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12848 struct hdd_config *cfg)
12849{
12850 uint8_t i = 0;
12851
12852 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12853 if (!ie_whitelist->white_list)
12854 return;
12855
12856 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12857 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12858 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12859 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12860 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12861 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12862 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12863 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12864
12865 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12866 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12867 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12868}
12869
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012870uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12871{
12872 uint8_t i, score;
12873
12874 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12875 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12876 if (score > MAX_INDEX_SCORE)
12877 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12878 MAX_INDEX_SCORE, i);
12879 }
12880
12881 return per_index_score;
12882}
12883
12884/**
12885 * hdd_update_score_config - API to update candidate scoring related params
12886 * configuration parameters
12887 * @score_config: score config to update
12888 * @cfg: config params
12889 *
12890 * Return: 0 if success else err
12891 */
12892static void hdd_update_score_config(
12893 struct scoring_config *score_config, struct hdd_config *cfg)
12894{
12895 int total_weight;
12896
12897 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12898 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12899 score_config->weight_cfg.vht_caps_weightage =
12900 cfg->vht_caps_weightage;
12901 score_config->weight_cfg.he_caps_weightage =
12902 cfg->he_caps_weightage;
12903 score_config->weight_cfg.chan_width_weightage =
12904 cfg->chan_width_weightage;
12905 score_config->weight_cfg.chan_band_weightage =
12906 cfg->chan_band_weightage;
12907 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12908 score_config->weight_cfg.beamforming_cap_weightage =
12909 cfg->beamforming_cap_weightage;
12910 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12911 score_config->weight_cfg.channel_congestion_weightage =
12912 cfg->channel_congestion_weightage;
12913 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12914
12915 total_weight = score_config->weight_cfg.rssi_weightage +
12916 score_config->weight_cfg.ht_caps_weightage +
12917 score_config->weight_cfg.vht_caps_weightage +
12918 score_config->weight_cfg.he_caps_weightage +
12919 score_config->weight_cfg.chan_width_weightage +
12920 score_config->weight_cfg.chan_band_weightage +
12921 score_config->weight_cfg.nss_weightage +
12922 score_config->weight_cfg.beamforming_cap_weightage +
12923 score_config->weight_cfg.pcl_weightage +
12924 score_config->weight_cfg.channel_congestion_weightage +
12925 score_config->weight_cfg.oce_wan_weightage;
12926
12927 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12928 hdd_err("total weight is greater than %d fallback to default values",
12929 BEST_CANDIDATE_MAX_WEIGHT);
12930
12931 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12932 score_config->weight_cfg.ht_caps_weightage =
12933 HT_CAPABILITY_WEIGHTAGE;
12934 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12935 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12936 score_config->weight_cfg.chan_width_weightage =
12937 CHAN_WIDTH_WEIGHTAGE;
12938 score_config->weight_cfg.chan_band_weightage =
12939 CHAN_BAND_WEIGHTAGE;
12940 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12941 score_config->weight_cfg.beamforming_cap_weightage =
12942 BEAMFORMING_CAP_WEIGHTAGE;
12943 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12944 score_config->weight_cfg.channel_congestion_weightage =
12945 CHANNEL_CONGESTION_WEIGHTAGE;
12946 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12947 }
12948
12949 score_config->bandwidth_weight_per_index =
12950 hdd_limit_max_per_index_score(
12951 cfg->bandwidth_weight_per_index);
12952 score_config->nss_weight_per_index =
12953 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12954 score_config->band_weight_per_index =
12955 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12956
12957 score_config->rssi_score.best_rssi_threshold =
12958 cfg->best_rssi_threshold;
12959 score_config->rssi_score.good_rssi_threshold =
12960 cfg->good_rssi_threshold;
12961 score_config->rssi_score.bad_rssi_threshold =
12962 cfg->bad_rssi_threshold;
12963 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12964 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12965 score_config->rssi_score.good_rssi_bucket_size =
12966 cfg->good_rssi_bucket_size;
12967 score_config->rssi_score.bad_rssi_bucket_size =
12968 cfg->bad_rssi_bucket_size;
12969 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12970 cfg->rssi_pref_5g_rssi_thresh;
12971
12972 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12973 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12974 hdd_limit_max_per_index_score(
12975 cfg->esp_qbss_score_slots3_to_0);
12976 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12977 hdd_limit_max_per_index_score(
12978 cfg->esp_qbss_score_slots7_to_4);
12979 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12980 hdd_limit_max_per_index_score(
12981 cfg->esp_qbss_score_slots11_to_8);
12982 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12983 hdd_limit_max_per_index_score(
12984 cfg->esp_qbss_score_slots15_to_12);
12985
12986 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12987 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12988 hdd_limit_max_per_index_score(
12989 cfg->oce_wan_score_slots3_to_0);
12990 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12991 hdd_limit_max_per_index_score(
12992 cfg->oce_wan_score_slots7_to_4);
12993 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12994 hdd_limit_max_per_index_score(
12995 cfg->oce_wan_score_slots11_to_8);
12996 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12997 hdd_limit_max_per_index_score(
12998 cfg->oce_wan_score_slots15_to_12);
12999
13000
13001 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13002 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13003 score_config->nss = cfg->enable2x2 ? 2 : 1;
13004
13005 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13006 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13007 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13008 score_config->he_cap = 1;
13009
13010 if (score_config->he_cap ||
13011 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13012 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13013 score_config->vht_cap = 1;
13014
13015 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13016 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13017 score_config->ht_cap = 1;
13018
13019 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13020 score_config->vht_24G_cap = 1;
13021
13022 if (cfg->enableTxBF)
13023 score_config->beamformee_cap = 1;
13024
13025}
13026
Abhishek Singh257a9482017-03-06 16:52:39 +053013027/**
bings81fe50a2017-11-27 14:33:26 +080013028 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13029 * @hdd_ctx: HDD context
13030 *
13031 * Return: 0 if success else err
13032 */
13033static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13034{
13035 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13036 struct hdd_config *cfg = hdd_ctx->config;
13037 struct dfs_user_config dfs_cfg;
13038 QDF_STATUS status;
13039
13040 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13041 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13042 if (QDF_IS_STATUS_ERROR(status)) {
13043 hdd_err("failed dfs psoc configuration");
13044 return -EINVAL;
13045 }
13046
13047 return 0;
13048}
13049
13050/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013051 * hdd_update_scan_config - API to update scan configuration parameters
13052 * @hdd_ctx: HDD context
13053 *
13054 * Return: 0 if success else err
13055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013056static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013057{
13058 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13059 struct scan_user_cfg scan_cfg;
13060 struct hdd_config *cfg = hdd_ctx->config;
13061 QDF_STATUS status;
13062
13063 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13064 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13065 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13066 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13067 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13068 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13069 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013070 /* convert to ms */
13071 scan_cfg.scan_cache_aging_time =
13072 cfg->scanAgingTimeout * 1000;
13073 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13074 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13075 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13076 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013077 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013078 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013079 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13080 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013081 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013082 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013083 scan_cfg.sta_miracast_mcc_rest_time =
13084 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013085
Abhishek Singhb20db962017-03-03 21:28:46 +053013086 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013087 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013088 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013089
Abhishek Singh257a9482017-03-06 16:52:39 +053013090 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13091 if (status != QDF_STATUS_SUCCESS) {
13092 hdd_err("failed pmo psoc configuration");
13093 return -EINVAL;
13094 }
13095
13096 return 0;
13097}
Abhishek Singh257a9482017-03-06 16:52:39 +053013098
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013099int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013100{
13101 int ret;
13102
13103 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013104 if (ret)
13105 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013106
Abhishek Singh257a9482017-03-06 16:52:39 +053013107 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013108 if (ret)
13109 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013110
Frank Liud4b2fa02017-03-29 11:46:48 +080013111 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013112 if (ret)
13113 return ret;
13114
13115 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013116 if (ret)
13117 return ret;
13118
13119 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013120
13121 return ret;
13122}
13123
Agrawal Ashish65634612016-08-18 13:24:32 +053013124/**
13125 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13126 * @mode : cfg80211 DFS mode
13127 *
13128 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13129 */
13130enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13131{
13132 switch (mode) {
13133 case DFS_MODE_ENABLE:
13134 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013135 case DFS_MODE_DISABLE:
13136 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013137 case DFS_MODE_DEPRIORITIZE:
13138 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013139 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013140 hdd_debug("ACS dfs mode is NONE");
13141 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013142 }
13143}
13144
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013145/**
13146 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13147 * @hddctx: pointer to hdd context
13148 * @set_value: enable/disable
13149 *
13150 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13151 * Host(even though it is duplicate). When Host send vendor command
13152 * disable,FW doesn't perform any action. Whenever any change in
13153 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13154 *
13155 * return - 0 on success, appropriate error values on failure.
13156 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013157int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013158{
13159 QDF_STATUS status;
13160
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013161 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013162 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013163
13164 if (!hddctx->config->goptimize_chan_avoid_event) {
13165 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13166 return -EINVAL;
13167 }
13168
13169 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13170 if (!QDF_IS_STATUS_SUCCESS(status)) {
13171 hdd_err("Failed to send chan avoid command to SME");
13172 return -EINVAL;
13173 }
13174 return 0;
13175}
Agrawal Ashish65634612016-08-18 13:24:32 +053013176
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013177/**
13178 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13179 * @value: value to set
13180 *
13181 * This function will set the passed value to roaming in progress flag.
13182 *
13183 * Return: None
13184 */
13185void hdd_set_roaming_in_progress(bool value)
13186{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013187 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013188
13189 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13190 if (!hdd_ctx) {
13191 hdd_err("HDD context is NULL");
13192 return;
13193 }
13194
13195 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013196 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013197}
13198
13199/**
13200 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013201 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013202 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013203 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013204 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013205bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013206{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013207 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013208 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013209
13210 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13211 if (!hdd_ctx) {
13212 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013213 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013214 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013215 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13216 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013217 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13218 hdd_ctx->roaming_in_progress);
13219
13220 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013221}
13222
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013223/**
13224 * hdd_is_connection_in_progress() - check if connection is in
13225 * progress
13226 * @session_id: session id
13227 * @reason: scan reject reason
13228 *
13229 * Go through each adapter and check if Connection is in progress
13230 *
13231 * Return: true if connection is in progress else false
13232 */
13233bool hdd_is_connection_in_progress(uint8_t *session_id,
13234 enum scan_reject_states *reason)
13235{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013236 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013237 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013238 uint8_t sta_id = 0;
13239 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013240 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013241
13242 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13243 if (!hdd_ctx) {
13244 hdd_err("HDD context is NULL");
13245 return false;
13246 }
13247
Dustin Brown920397d2017-12-13 16:27:50 -080013248 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013249 hdd_info("Adapter with device mode %s(%d) exists",
13250 hdd_device_mode_to_string(adapter->device_mode),
13251 adapter->device_mode);
13252 if (((QDF_STA_MODE == adapter->device_mode)
13253 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13254 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13255 && (eConnectionState_Connecting ==
13256 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13257 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013258 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013259 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013260 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013261 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013262 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013263 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013264 }
13265 return true;
13266 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013267 /*
13268 * sme_neighbor_middle_of_roaming is for LFR2
13269 * hdd_is_roaming_in_progress is for LFR3
13270 */
13271 if (((QDF_STA_MODE == adapter->device_mode) &&
13272 sme_neighbor_middle_of_roaming(
13273 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013274 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013275 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013276 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013277 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013278 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013279 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013280 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013281 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013282 }
13283 return true;
13284 }
13285 if ((QDF_STA_MODE == adapter->device_mode) ||
13286 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13287 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13288 hdd_sta_ctx =
13289 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13290 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013291 hdd_sta_ctx->conn_info.connState)
13292 && sme_is_sta_key_exchange_in_progress(
13293 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013294 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013295 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013296 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013297 " is in middle of WPS/EAPOL exchange.",
13298 MAC_ADDR_ARRAY(sta_mac));
13299 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013300 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013301 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013302 }
13303 return true;
13304 }
13305 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13306 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13307 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13308 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013309 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013310 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013311 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013312 continue;
13313
13314 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013315 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013316 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013317 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013318 " of SAP/GO is in middle of WPS/EAPOL exchange",
13319 MAC_ADDR_ARRAY(sta_mac));
13320 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013321 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013322 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013323 }
13324 return true;
13325 }
13326 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013327 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013328 return true;
13329 }
13330 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013331 }
Dustin Brown920397d2017-12-13 16:27:50 -080013332
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013333 return false;
13334}
13335
13336/**
13337 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013338 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013339 *
13340 * Return: None
13341 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013342void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013343{
Jeff Johnson87251032017-08-29 13:31:11 -070013344 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013345 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013346 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013347 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013348 tsap_Config_t *sap_config;
13349 void *sap_ctx;
13350
13351 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013352 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013353 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013354
13355 mutex_lock(&hdd_ctx->sap_lock);
13356 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13357 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013358 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13359 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13360 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13361 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013362 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013363 qdf_stop_bss_event,
13364 SME_CMD_TIMEOUT_VALUE);
13365
13366 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013367 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013368 goto end;
13369 }
13370 }
13371 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013372 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013373 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013374 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013375 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013376 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013377
13378 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013379 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013380 wlansap_reset_sap_config_add_ie(sap_config,
13381 eUPDATE_IE_ALL);
13382 goto end;
13383 }
13384
13385 qdf_event_reset(&hostapd_state->qdf_event);
13386 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13387 sap_config,
13388 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013389 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013390 wlansap_reset_sap_config_add_ie(sap_config,
13391 eUPDATE_IE_ALL);
13392 goto end;
13393 }
13394
Jeff Johnson6867ec32017-09-29 20:30:20 -070013395 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013396 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013397 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013398 SME_CMD_TIMEOUT_VALUE);
13399 wlansap_reset_sap_config_add_ie(sap_config,
13400 eUPDATE_IE_ALL);
13401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013402 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013403 goto end;
13404 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013405 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013406 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013407 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013408 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13409 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013410 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013411 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013412 ap_adapter->device_mode,
13413 true);
13414 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013415 }
13416end:
13417 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013418}
13419
13420/**
13421 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13422 * with non dfs acs
13423 *
13424 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13425 *
13426 * Return: None
13427 */
13428void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13429{
Jeff Johnson9d295242017-08-29 14:39:48 -070013430 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013431 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013432 cds_context_type *cds_ctx;
13433
13434 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13435 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013436 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013437 return;
13438 }
13439
13440 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13441 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013442 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013443 return;
13444 }
13445
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013446 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13447 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013448 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013449 return;
13450 }
13451
13452 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013453 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13454 &ap_adapter->event_flags) &&
13455 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013456 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013457
Jeff Johnson6867ec32017-09-29 20:30:20 -070013458 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013459 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013460 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013461 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013462 acs_cfg.acs_mode = true;
13463
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013464 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013465 }
13466}
13467
13468/**
13469 * hdd_set_connection_in_progress() - to set the connection in
13470 * progress flag
13471 * @value: value to set
13472 *
13473 * This function will set the passed value to connection in progress flag.
13474 * If value is previously being set to true then no need to set it again.
13475 *
13476 * Return: true if value is being set correctly and false otherwise.
13477 */
13478bool hdd_set_connection_in_progress(bool value)
13479{
13480 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013481 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013482
13483 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13484 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013485 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013486 return false;
13487 }
13488
13489 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13490 /*
13491 * if the value is set to true previously and if someone is
13492 * trying to make it true again then it could be some race
13493 * condition being triggered. Avoid this situation by returning
13494 * false
13495 */
13496 if (hdd_ctx->connection_in_progress && value)
13497 status = false;
13498 else
13499 hdd_ctx->connection_in_progress = value;
13500 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13501 return status;
13502}
13503
Jeff Johnson9d295242017-08-29 14:39:48 -070013504int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013505{
13506 if (!adapter) {
13507 hdd_err("Invalid adapter");
13508 return -EINVAL;
13509 }
13510 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013511 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013512 WMA_VDEV_MCC_SET_TIME_QUOTA,
13513 set_value, VDEV_CMD);
13514 return 0;
13515
13516}
13517
Jeff Johnson9d295242017-08-29 14:39:48 -070013518int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013519{
13520 if (!adapter) {
13521 hdd_err("Invalid adapter");
13522 return -EINVAL;
13523 }
13524
13525 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013526 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013527 WMA_VDEV_MCC_SET_TIME_LATENCY,
13528 set_value, VDEV_CMD);
13529 return 0;
13530}
13531
Jeff Johnson9d295242017-08-29 14:39:48 -070013532struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013533 *psoc, uint8_t vdev_id)
13534{
Jeff Johnson9d295242017-08-29 14:39:48 -070013535 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013536 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013537
13538 /*
13539 * Currently PSOC is not being used. But this logic will
13540 * change once we have the converged implementation of
13541 * HDD context per PSOC in place. This would break if
13542 * multiple vdev objects reuse the vdev id.
13543 */
13544 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13545 if (!adapter)
13546 hdd_err("Get adapter by vdev id failed");
13547
13548 return adapter;
13549}
13550
Jeff Johnson9d295242017-08-29 14:39:48 -070013551int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013552 int8_t *rssi, int8_t *snr)
13553{
13554 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013555 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013556
Jeff Johnson025618c2018-03-18 14:41:00 -070013557 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013558 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013559 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013560 if (QDF_STATUS_SUCCESS != status) {
13561 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13562 return -EINVAL;
13563 }
13564
13565 return 0;
13566}
13567
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013568/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013569 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13570 * @adapter - HDD adapter
13571 * @tos - type of service
13572 * @status - status of the traffic
13573 *
13574 * Return: 0 on success and non zero value on failure
13575 */
13576
13577int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13578 bool is_tos_active)
13579{
13580 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013581 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013582 uint32_t max_off_chan_time = 0;
13583 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013584 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013585 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013586
13587 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13588 ret = wlan_hdd_validate_context(hdd_ctx);
13589
13590 if (ret < 0) {
13591 hdd_err("failed to set limit off chan params");
13592 return ret;
13593 }
13594
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013595 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13596
13597 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013598 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013599 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013600 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013601
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013602 if (adapter->active_ac) {
13603 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013604 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013605 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13606 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13607 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013608 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013609 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013610 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13611 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13612 PM_LATENCY);
13613 } else {
13614 /*ignore this command if only BE/BK is active */
13615 is_tos_active = false;
13616 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13617 hdd_ctx->config->conc_system_pref);
13618 }
13619 } else {
13620 /* No active tos */
13621 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13622 hdd_ctx->config->conc_system_pref);
13623 }
13624
Jeff Johnson1b780e42017-10-31 14:11:45 -070013625 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013626 is_tos_active, max_off_chan_time,
13627 hdd_ctx->config->nRestTimeConc, true);
13628 if (!QDF_IS_STATUS_SUCCESS(status)) {
13629 hdd_err("failed to set limit off chan params");
13630 ret = -EINVAL;
13631 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013632
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013633 return ret;
13634}
13635
13636/**
13637 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13638 * @adapter - HDD adapter
13639 *
13640 * Return: 0 on success and non zero value on failure
13641 */
13642int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13643{
13644 struct hdd_context *hdd_ctx;
13645 int ret;
13646 QDF_STATUS status;
13647 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13648
13649 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13650 ret = wlan_hdd_validate_context(hdd_ctx);
13651 if (ret < 0)
13652 return ret;
13653
13654 /* set the system preferece to default */
13655 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13656 hdd_ctx->config->conc_system_pref);
13657
13658 /* clear the bitmap */
13659 adapter->active_ac = 0;
13660
13661 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013662 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013663
Jeff Johnson1b780e42017-10-31 14:11:45 -070013664 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013665 false, 0, 0, false);
13666 if (!QDF_IS_STATUS_SUCCESS(status)) {
13667 hdd_err("failed to reset limit off chan params");
13668 ret = -EINVAL;
13669 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013670
13671 return ret;
13672}
13673
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013674/**
13675 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13676 * @drv_op: Enum indicating driver op
13677 *
13678 * Return: none
13679 */
13680void hdd_start_driver_ops_timer(int drv_op)
13681{
13682 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13683 switch (drv_op) {
13684 case eHDD_DRV_OP_PROBE:
13685 memcpy(drv_ops_string, "probe", sizeof("probe"));
13686 break;
13687 case eHDD_DRV_OP_REMOVE:
13688 memcpy(drv_ops_string, "remove", sizeof("remove"));
13689 break;
13690 case eHDD_DRV_OP_SHUTDOWN:
13691 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13692 break;
13693 case eHDD_DRV_OP_REINIT:
13694 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13695 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013696 case eHDD_DRV_OP_IFF_UP:
13697 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13698 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013699 }
13700
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013701 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013702 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13703 HDD_OPS_INACTIVITY_TIMEOUT);
13704}
13705
13706/**
13707 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13708 *
13709 * Return: none
13710 */
13711void hdd_stop_driver_ops_timer(void)
13712{
13713 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13714}
13715
13716/**
13717 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13718 * inactivity timer
13719 *
13720 * Return: None
13721 */
13722void hdd_drv_ops_inactivity_handler(void)
13723{
13724 hdd_err("%s: %d Sec timer expired while in .%s",
13725 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13726
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013727 if (hdd_drv_ops_task) {
13728 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13729 qdf_print_thread_trace(hdd_drv_ops_task);
13730 } else {
13731 hdd_err("hdd_drv_ops_task is null");
13732 }
13733
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013734 /* Driver shutdown is stuck, no recovery possible at this point */
13735 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13736 sizeof("shutdown")))
13737 QDF_BUG(0);
13738
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013739 if (cds_is_fw_down()) {
13740 hdd_err("FW is down");
13741 return;
13742 }
13743
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013744 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013745 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013746 else
13747 QDF_BUG(0);
13748}
13749
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013750void hdd_pld_ipa_uc_shutdown_pipes(void)
13751{
13752 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13753
13754 if (!hdd_ctx)
13755 return;
13756
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013757 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013758}
13759
Yun Parkff6a16a2017-09-26 16:38:18 -070013760/**
13761 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13762 * @struct hdd_context *hdd_ctx
13763 * @struct hdd_adapter *padapter
13764 * @bool enble
13765 *
13766 * Return: none
13767 */
13768void hdd_set_rx_mode_rps(bool enable)
13769{
13770 struct cds_config_info *cds_cfg = cds_get_ini_config();
13771 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13772 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13773
13774 if (adapter && hdd_ctx &&
13775 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13776 if (enable && !cds_cfg->rps_enabled)
13777 hdd_send_rps_ind(adapter);
13778 else if (!enable && cds_cfg->rps_enabled)
13779 hdd_send_rps_disable_ind(adapter);
13780 }
13781}
13782
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013783bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13784{
13785 struct hdd_adapter *adapter = NULL;
13786
13787 hdd_for_each_adapter(hdd_ctx, adapter) {
13788 if ((adapter->device_mode == QDF_STA_MODE ||
13789 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13790 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13791 &adapter->event_flags)){
13792 return true;
13793 }
13794 }
13795
13796 return false;
13797}
13798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013799/* Register the module init/exit functions */
13800module_init(hdd_module_init);
13801module_exit(hdd_module_exit);
13802
13803MODULE_LICENSE("Dual BSD/GPL");
13804MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13805MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013807module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13808 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013809
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013810module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13811 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13812
Ravi Joshia307f632017-07-17 23:41:41 -070013813module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13814 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013816module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13817 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13818
13819module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13820
13821module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13822
13823module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);