blob: 8bc79922a64ade7bb14e4096581e1173b5589bd2 [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>
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530136
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530137#ifdef CNSS_GENL
138#include <net/cnss_nl.h>
139#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800140#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800141#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530142
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530143#include <wlan_green_ap_ucfg_api.h>
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800144#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800145#ifdef MODULE
146#define WLAN_MODULE_NAME module_name(THIS_MODULE)
147#else
148#define WLAN_MODULE_NAME "wlan"
149#endif
150
151#ifdef TIMER_MANAGER
152#define TIMER_MANAGER_STR " +TIMER_MANAGER"
153#else
154#define TIMER_MANAGER_STR ""
155#endif
156
157#ifdef MEMORY_DEBUG
158#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
159#else
160#define MEMORY_DEBUG_STR ""
161#endif
162
Dustin Brownc1034df2018-02-07 14:51:32 -0800163#ifdef PANIC_ON_BUG
164#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
165#else
166#define PANIC_ON_BUG_STR ""
167#endif
168
Sachin Ahujadddd2632017-03-07 19:07:24 +0530169int wlan_start_ret_val;
170static DECLARE_COMPLETION(wlan_start_comp);
171static unsigned int dev_num = 1;
172static struct cdev wlan_hdd_state_cdev;
173static struct class *class;
174static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530175#ifndef MODULE
176static struct gwlan_loader *wlan_loader;
177static ssize_t wlan_boot_cb(struct kobject *kobj,
178 struct kobj_attribute *attr,
179 const char *buf, size_t count);
180struct gwlan_loader {
181 bool loaded_state;
182 struct kobject *boot_wlan_obj;
183 struct attribute_group *attr_group;
184};
185
186static struct kobj_attribute wlan_boot_attribute =
187 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
188
189static struct attribute *attrs[] = {
190 &wlan_boot_attribute.attr,
191 NULL,
192};
193
194#define MODULE_INITIALIZED 1
195#endif
196
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530197#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
198#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800199#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530200
201static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800202static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530203static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800205/* the Android framework expects this param even though we don't use it */
206#define BUF_LEN 20
207static char fwpath_buffer[BUF_LEN];
208static struct kparam_string fwpath = {
209 .string = fwpath_buffer,
210 .maxlen = BUF_LEN,
211};
212
213static char *country_code;
214static int enable_11d = -1;
215static int enable_dfs_chan_scan = -1;
216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800217/*
218 * spinlock for synchronizing asynchronous request/response
219 * (full description of use in wlan_hdd_main.h)
220 */
221DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530222DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800224#define WLAN_NLINK_CESIUM 30
225
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530226static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800227
228#define WOW_MAX_FILTER_LISTS 1
229#define WOW_MAX_FILTERS_PER_LIST 4
230#define WOW_MIN_PATTERN_SIZE 6
231#define WOW_MAX_PATTERN_SIZE 64
232
233#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
234static const struct wiphy_wowlan_support wowlan_support_reg_init = {
235 .flags = WIPHY_WOWLAN_ANY |
236 WIPHY_WOWLAN_MAGIC_PKT |
237 WIPHY_WOWLAN_DISCONNECT |
238 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
239 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
240 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
241 WIPHY_WOWLAN_4WAY_HANDSHAKE |
242 WIPHY_WOWLAN_RFKILL_RELEASE,
243 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
244 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
245 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
246};
247#endif
248
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700249static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
250 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
262 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
264 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
265 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
266 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700284 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700285 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700286 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530287 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800288 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700289};
290
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530291int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
292 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
293 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
294 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
295 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
296};
297
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530299struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300
301struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800302#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700303static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800304#endif
305
Sachin Ahujadddd2632017-03-07 19:07:24 +0530306void hdd_start_complete(int ret)
307{
308 wlan_start_ret_val = ret;
309
310 complete(&wlan_start_comp);
311}
312
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313/**
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +0530314 * hdd_check_green_ap_enable() - to check whether to enable green ap or not
315 * @hdd_ctx: hdd context
316 * @enable_green_ap: 1 - enable green ap enabled, 0 - disbale green ap
317 *
318 * Return: 0 - success, < 0 - failure
319 */
320static int hdd_check_green_ap_enable(struct hdd_context *hdd_ctx,
321 bool *enable_green_ap)
322{
323 uint8_t num_sessions, mode;
324 QDF_STATUS status;
325
326 for (mode = 0;
327 mode < QDF_MAX_NO_OF_MODE;
328 mode++) {
329 if (mode == QDF_SAP_MODE || mode == QDF_P2P_GO_MODE)
330 continue;
331
332 status = policy_mgr_mode_specific_num_active_sessions(
333 hdd_ctx->hdd_psoc, mode, &num_sessions);
334 hdd_debug("No. of active sessions for mode: %d is %d",
335 mode, num_sessions);
336 if (status != QDF_STATUS_SUCCESS) {
337 hdd_err("Failed to get num sessions for mode: %d",
338 mode);
339 return -EINVAL;
340 } else if (num_sessions) {
341 *enable_green_ap = false;
342 return 0;
343 }
344 }
345 *enable_green_ap = true;
346 return 0;
347}
348
349int hdd_start_green_ap_state_mc(struct hdd_context *hdd_ctx,
350 enum QDF_OPMODE mode, bool is_session_start)
351{
352 struct hdd_config *cfg;
353 bool enable_green_ap = false;
354 uint8_t num_sap_sessions = 0, num_p2p_go_sessions = 0, ret = 0;
355
356 cfg = hdd_ctx->config;
357 if (!cfg) {
358 hdd_err("NULL hdd config");
359 return -EINVAL;
360 }
361
362 if (!cfg->enable2x2 || !cfg->enableGreenAP) {
363 hdd_info("Green AP support not present: enable2x2: %d, enableGreenAp: %d",
364 cfg->enable2x2, cfg->enableGreenAP);
365 return 0;
366 }
367
368 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->hdd_psoc,
369 QDF_SAP_MODE,
370 &num_sap_sessions);
371 policy_mgr_mode_specific_num_active_sessions(hdd_ctx->hdd_psoc,
372 QDF_P2P_GO_MODE,
373 &num_p2p_go_sessions);
374
375 switch (mode) {
376 case QDF_STA_MODE:
377 case QDF_P2P_CLIENT_MODE:
378 case QDF_IBSS_MODE:
379 if (!num_sap_sessions && !num_p2p_go_sessions)
380 return 0;
381
382 if (is_session_start) {
383 hdd_debug("Disabling Green AP");
384 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
385 false);
386 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
387 } else {
388 ret = hdd_check_green_ap_enable(hdd_ctx,
389 &enable_green_ap);
390 if (!ret) {
391 if (enable_green_ap) {
392 hdd_debug("Enabling Green AP");
393 ucfg_green_ap_set_ps_config(
394 hdd_ctx->hdd_pdev, true);
395 wlan_green_ap_start(hdd_ctx->hdd_pdev);
396 }
397 } else {
398 hdd_err("Failed to check Green AP enable status");
399 }
400 }
401 break;
402 case QDF_SAP_MODE:
403 case QDF_P2P_GO_MODE:
404 if (is_session_start) {
405 ret = hdd_check_green_ap_enable(hdd_ctx,
406 &enable_green_ap);
407 if (!ret) {
408 if (enable_green_ap) {
409 hdd_debug("Enabling Green AP");
410 ucfg_green_ap_set_ps_config(
411 hdd_ctx->hdd_pdev, true);
412 wlan_green_ap_start(hdd_ctx->hdd_pdev);
413 }
414 } else {
415 hdd_err("Failed to check Green AP enable status");
416 }
417 } else {
418 if (!num_sap_sessions && !num_p2p_go_sessions) {
419 hdd_debug("Disabling Green AP");
420 ucfg_green_ap_set_ps_config(hdd_ctx->hdd_pdev,
421 false);
422 wlan_green_ap_stop(hdd_ctx->hdd_pdev);
423 }
424 }
425 break;
426 default:
427 break;
428 }
429 return ret;
430}
431
432/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530433 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700434 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530435 *
436 * Return: none
437 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700438static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530439{
Jeff Johnson9d295242017-08-29 14:39:48 -0700440 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530441
Dustin Brown920397d2017-12-13 16:27:50 -0800442 hdd_for_each_adapter(hdd_ctx, adapter)
443 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530444}
445
446/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800447 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
448 * @vdev_id: vdev_id
449 * @action: action type
450 * @reason: reason type
451 *
452 * Return: none
453 */
454void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
455 enum netif_action_type action, enum netif_reason_type reason)
456{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700457 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700458 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800459
460 if (!hdd_ctx) {
461 hdd_err("hdd ctx is NULL");
462 return;
463 }
464 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
465
466 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467}
468
469/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700470 * Store WLAN driver version and timestamp info in global variables such that
471 * crash debugger can extract them from driver debug symbol and crashdump for
472 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800474#ifdef BUILD_TAG
475uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
476#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700478#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479
480/**
481 * hdd_device_mode_to_string() - return string conversion of device mode
482 * @device_mode: device mode
483 *
484 * This utility function helps log string conversion of device mode.
485 *
486 * Return: string conversion of device mode, if match found;
487 * "Unknown" otherwise.
488 */
489const char *hdd_device_mode_to_string(uint8_t device_mode)
490{
491 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800492 CASE_RETURN_STRING(QDF_STA_MODE);
493 CASE_RETURN_STRING(QDF_SAP_MODE);
494 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
495 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
496 CASE_RETURN_STRING(QDF_FTM_MODE);
497 CASE_RETURN_STRING(QDF_IBSS_MODE);
498 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
499 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700500 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 default:
502 return "Unknown";
503 }
504}
505
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530506/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500507 * hdd_get_valid_chan() - return current chan list from regulatory.
508 * @hdd_ctx: HDD context
509 * @chan_list: buf hold returned chan list
510 * @chan_num: input buf size and output returned chan num
511 *
512 * This function helps get current available chan list from regulatory
513 * module. It excludes the "disabled" and "invalid" channels.
514 *
515 * Return: 0 for success.
516 */
517static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
518 uint8_t *chan_list,
519 uint32_t *chan_num)
520{
521 int i = 0, j = 0;
522 struct regulatory_channel *cur_chan_list;
523 struct wlan_objmgr_pdev *pdev;
524
525 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
526 return -EINVAL;
527
528 pdev = hdd_ctx->hdd_pdev;
529 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
530 sizeof(struct regulatory_channel));
531 if (!cur_chan_list)
532 return -ENOMEM;
533
534 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
535 QDF_STATUS_SUCCESS) {
536 qdf_mem_free(cur_chan_list);
537 return -EINVAL;
538 }
539
540 for (i = 0; i < NUM_CHANNELS; i++) {
541 uint32_t ch = cur_chan_list[i].chan_num;
542 enum channel_state state = wlan_reg_get_channel_state(pdev,
543 ch);
544
545 if (state != CHANNEL_STATE_DISABLE &&
546 state != CHANNEL_STATE_INVALID &&
547 j < *chan_num) {
548 chan_list[j] = (uint8_t)ch;
549 j++;
550 }
551 }
552 *chan_num = j;
553 qdf_mem_free(cur_chan_list);
554 return 0;
555}
556
557/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530558 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
559 * @adapter: HDD adapter
560 * @chan_number: Channel number
561 * @chan_bw: Bandwidth
562 *
563 * Checks if the given bandwidth is valid for the given channel number.
564 *
565 * Return: 0 for success, non-zero for failure
566 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700567int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530568 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800569 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530570{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500571 uint8_t chan[NUM_CHANNELS];
572 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530573 bool found = false;
574 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500575 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530576
577 hal = WLAN_HDD_GET_HAL_CTX(adapter);
578 if (!hal) {
579 hdd_err("Invalid HAL context");
580 return -EINVAL;
581 }
582
Liangwei Dong17bf2662018-01-05 02:02:05 -0500583 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
584 &len);
585 if (ret) {
586 hdd_err("error %d in getting valid channel list", ret);
587 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530588 }
589
590 for (i = 0; i < len; i++) {
591 if (chan[i] == chan_number) {
592 found = true;
593 break;
594 }
595 }
596
597 if (found == false) {
598 hdd_err("Channel not in driver's valid channel list");
599 return -EOPNOTSUPP;
600 }
601
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700602 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
603 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530604 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
605 return -EINVAL;
606 }
607
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700608 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530609 if (chan_bw == CH_WIDTH_80MHZ) {
610 hdd_err("BW80 not possible in 2.4GHz band");
611 return -EINVAL;
612 }
613 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
614 (chan_bw != CH_WIDTH_MAX)) {
615 hdd_err("Only BW20 possible on channel 14");
616 return -EINVAL;
617 }
618 }
619
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700620 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530621 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
622 (chan_bw != CH_WIDTH_MAX)) {
623 hdd_err("Only BW20 possible on channel 165");
624 return -EINVAL;
625 }
626 }
627
628 return 0;
629}
630
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530631/**
632 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
633 *
634 * Block the unloading of the driver (or) interface up until the
635 * cds recovery is completed
636 *
637 * Return: true for recovery completion else false
638 */
639static bool hdd_wait_for_recovery_completion(void)
640{
641 int retry = 0;
642
643 /* Wait for recovery to complete */
644 while (cds_is_driver_recovering()) {
645 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
646 hdd_err("Recovery in progress; wait here!!!");
647 msleep(1000);
648 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
649 hdd_err("SSR never completed, error");
650 /*
651 * Trigger the bug_on in the internal builds, in the
652 * customer builds self-recovery will be enabled
653 * in those cases just return error.
654 */
655 if (cds_is_self_recovery_enabled())
656 return false;
657 QDF_BUG(0);
658 }
659 }
660
661 hdd_info("Recovery completed successfully!");
662 return true;
663}
664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800665static int __hdd_netdev_notifier_call(struct notifier_block *nb,
666 unsigned long state, void *data)
667{
668#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
669 struct netdev_notifier_info *dev_notif_info = data;
670 struct net_device *dev = dev_notif_info->dev;
671#else
672 struct net_device *dev = data;
673#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700674 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700675 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800676
Dustin Brownfdf17c12018-03-14 12:55:34 -0700677 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679 /* Make sure that this callback corresponds to our device. */
680 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
681 return NOTIFY_DONE;
682
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530683 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700685 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686 return NOTIFY_DONE;
687 }
688
689 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700690 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800691 return NOTIFY_DONE;
692 }
693
694 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
695 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800696 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530697 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800698 return NOTIFY_DONE;
699 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800700
701 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
702 hdd_err("%s: Driver module is closed", __func__);
703 return NOTIFY_DONE;
704 }
705
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530706 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800707 return NOTIFY_DONE;
708
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800709 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800710 dev->name, state);
711
712 switch (state) {
713 case NETDEV_REGISTER:
714 break;
715
716 case NETDEV_UNREGISTER:
717 break;
718
719 case NETDEV_UP:
720 sme_ch_avoid_update_req(hdd_ctx->hHal);
721 break;
722
723 case NETDEV_DOWN:
724 break;
725
726 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700727 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 complete(&adapter->linkup_event_var);
729 break;
730
731 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700732 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
733 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530734 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700735 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736 } else {
hqueaa33ee2017-05-04 17:56:35 +0800737 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800738 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530740 /*
741 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
742 * of return status of hdd_stop call, kernel resets the IFF_UP
743 * flag after which driver does not send the cfg80211_scan_done.
744 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
745 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530746 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 break;
748
749 default:
750 break;
751 }
752
753 return NOTIFY_DONE;
754}
755
756/**
757 * hdd_netdev_notifier_call() - netdev notifier callback function
758 * @nb: pointer to notifier block
759 * @state: state
760 * @ndev: ndev pointer
761 *
762 * Return: 0 on success, error number otherwise.
763 */
764static int hdd_netdev_notifier_call(struct notifier_block *nb,
765 unsigned long state,
766 void *ndev)
767{
768 int ret;
769
770 cds_ssr_protect(__func__);
771 ret = __hdd_netdev_notifier_call(nb, state, ndev);
772 cds_ssr_unprotect(__func__);
773
774 return ret;
775}
776
777struct notifier_block hdd_netdev_notifier = {
778 .notifier_call = hdd_netdev_notifier_call,
779};
780
781/* variable to hold the insmod parameters */
782static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800783
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530784static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700785int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530786
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800787/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530790/**
791 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
792 * @ch_width: NL channel width
793 *
794 * Converts the NL channel width to the driver's internal representation
795 *
796 * Return: Converted channel width. In case of non matching NL channel width,
797 * CH_WIDTH_MAX will be returned.
798 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800799enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530800{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800801 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700802
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800803 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530804 switch (ch_width) {
805 case NL80211_CHAN_WIDTH_20_NOHT:
806 case NL80211_CHAN_WIDTH_20:
807 return CH_WIDTH_20MHZ;
808 case NL80211_CHAN_WIDTH_40:
809 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530810 case NL80211_CHAN_WIDTH_80:
811 return CH_WIDTH_80MHZ;
812 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800813 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
814 return CH_WIDTH_80P80MHZ;
815 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
816 return CH_WIDTH_160MHZ;
817 else
818 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530819 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800820 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
821 return CH_WIDTH_160MHZ;
822 else
823 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530824 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800825 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530826 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800827 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530828 default:
829 hdd_err("Invalid channel width %d, setting to default",
830 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800831 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530832 }
833}
834
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530835/* wlan_hdd_find_opclass() - Find operating class for a channel
836 * @hal: handler to HAL
837 * @channel: channel id
838 * @bw_offset: bandwidth offset
839 *
840 * Function invokes sme api to find the operating class
841 *
842 * Return: operating class
843 */
844uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
845 uint8_t bw_offset)
846{
847 uint8_t opclass = 0;
848
849 sme_get_opclass(hal, channel, bw_offset, &opclass);
850 return opclass;
851}
852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530854 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530855 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 * @bitmask: Bitmask of log levels to be enabled
857 *
858 * Called immediately after the cfg.ini is read in order to configure
859 * the desired trace levels.
860 *
861 * Return: None
862 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530863int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530865 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530866 int qdf_print_idx = -1;
867 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868 /*
869 * if the bitmask is the default value, then a bitmask was not
870 * specified in cfg.ini, so leave the logging level alone (it
871 * will remain at the "compiled in" default value)
872 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700873 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530874 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530876 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530878 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530879 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530880 QDF_TRACE_LEVEL_NONE, 0);
881
882 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530883 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530885 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 while (0 != bitmask) {
887 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530888 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530889 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530890 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530891 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 level++;
895 bitmask >>= 1;
896 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530897 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898}
899
900/**
Chris Guo1751acf2017-07-03 14:09:01 +0800901 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
902 * @hdd_ctx: HDD context pointer
903 *
904 * Return: 0 if the context is valid. Error code otherwise
905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700906int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800907{
908 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
909 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
910 return -ENODEV;
911 }
912
913 if (cds_is_driver_recovering()) {
914 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
915 (void *)_RET_IP_, cds_get_driver_state());
916 return -EAGAIN;
917 }
918
919 if (hdd_ctx->start_modules_in_progress ||
920 hdd_ctx->stop_modules_in_progress) {
921 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
922 (void *)_RET_IP_);
923 return -EAGAIN;
924 }
925
926 return 0;
927}
928
929
930/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 * wlan_hdd_validate_context() - check the HDD context
932 * @hdd_ctx: HDD context pointer
933 *
934 * Return: 0 if the context is valid. Error code otherwise
935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700936int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530939 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940 return -ENODEV;
941 }
942
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800943 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800944 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530945 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 return -EAGAIN;
947 }
948
Yue Ma9f275d92017-09-14 16:58:41 -0700949 if (cds_is_load_or_unload_in_progress()) {
950 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
951 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700953 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530954
955 if (hdd_ctx->start_modules_in_progress ||
956 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800957 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530958 (void *)_RET_IP_);
959 return -EAGAIN;
960 }
961
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530962 if (cds_is_driver_in_bad_state()) {
963 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
964 (void *)_RET_IP_, cds_get_driver_state());
965 return -ENODEV;
966 }
967
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530968 if (cds_is_fw_down()) {
969 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
970 (void *)_RET_IP_, cds_get_driver_state());
971 return -ENODEV;
972 }
973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 return 0;
975}
976
Jeff Johnson9d295242017-08-29 14:39:48 -0700977int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700978{
979 if (!adapter) {
980 hdd_err("adapter is null");
981 return -EINVAL;
982 }
983
984 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
985 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
986 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
987 return -EINVAL;
988 }
989
990 if (!adapter->dev) {
991 hdd_err("adapter net_device is null");
992 return -EINVAL;
993 }
994
995 if (!(adapter->dev->flags & IFF_UP)) {
996 hdd_info("adapter net_device is not up");
997 return -EAGAIN;
998 }
999
Jeff Johnson1b780e42017-10-31 14:11:45 -07001000 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -07001001 hdd_info("adapter session is not open");
1002 return -EAGAIN;
1003 }
1004
Jeff Johnson1b780e42017-10-31 14:11:45 -07001005 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
1006 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001007 return -EINVAL;
1008 }
1009
1010 return 0;
1011}
1012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301014 * wlan_hdd_validate_modules_state() - Check modules status
1015 * @hdd_ctx: HDD context pointer
1016 *
1017 * Check's the driver module's state and returns true if the
1018 * modules are enabled returns false if modules are closed.
1019 *
1020 * Return: True if modules are enabled or false.
1021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001022bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301023{
1024 mutex_lock(&hdd_ctx->iface_change_lock);
1025 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1026 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001027 hdd_info("Modules not enabled, Present status: %d",
1028 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301029 return false;
1030 }
1031 mutex_unlock(&hdd_ctx->iface_change_lock);
1032 return true;
1033}
1034
1035/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001037 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 *
1039 * This function sets the IBSS power save config parameters to WMA
1040 * which will send it to firmware if FW supports IBSS power save
1041 * before vdev start.
1042 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301043 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 * on failure.
1045 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001046QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047{
1048 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001049 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050
1051 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001052 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301053 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 }
1055
Jeff Johnson1b780e42017-10-31 14:11:45 -07001056 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1058 hdd_ctx->config->ibssATIMWinSize,
1059 VDEV_CMD);
1060 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001061 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301062 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 }
1064
Jeff Johnson1b780e42017-10-31 14:11:45 -07001065 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1067 hdd_ctx->config->isIbssPowerSaveAllowed,
1068 VDEV_CMD);
1069 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001070 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
1071 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301072 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 }
1074
Jeff Johnson1b780e42017-10-31 14:11:45 -07001075 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1077 hdd_ctx->config->
1078 isIbssPowerCollapseAllowed, VDEV_CMD);
1079 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001080 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
1081 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301082 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 }
1084
Jeff Johnson1b780e42017-10-31 14:11:45 -07001085 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001086 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1087 hdd_ctx->config->isIbssAwakeOnTxRx,
1088 VDEV_CMD);
1089 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001090 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301091 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001092 }
1093
Jeff Johnson1b780e42017-10-31 14:11:45 -07001094 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1096 hdd_ctx->config->ibssInactivityCount,
1097 VDEV_CMD);
1098 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001099 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301100 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101 }
1102
Jeff Johnson1b780e42017-10-31 14:11:45 -07001103 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1105 hdd_ctx->config->ibssTxSpEndInactivityTime,
1106 VDEV_CMD);
1107 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001108 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1109 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301110 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 }
1112
Jeff Johnson1b780e42017-10-31 14:11:45 -07001113 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1115 hdd_ctx->config->ibssPsWarmupTime,
1116 VDEV_CMD);
1117 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001118 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1119 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301120 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001121 }
1122
Jeff Johnson1b780e42017-10-31 14:11:45 -07001123 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1125 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1126 VDEV_CMD);
1127 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001128 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1129 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301130 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 }
1132
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301133 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134}
1135
Yue Macd359b72017-10-03 15:21:00 -07001136#ifdef FEATURE_RUNTIME_PM
1137/**
1138 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1139 * @hdd_ctx: HDD context
1140 *
1141 * Return: None
1142 */
1143static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1144{
1145 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1146
Yue Macd359b72017-10-03 15:21:00 -07001147 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001148 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001149
1150 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1151}
1152
1153/**
1154 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1155 * @hdd_ctx: HDD Context
1156 *
1157 * Return: None
1158 */
1159static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1160{
1161 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1162
Yue Macd359b72017-10-03 15:21:00 -07001163 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001164 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001165
1166 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1167}
1168
Yue Macd359b72017-10-03 15:21:00 -07001169#else /* FEATURE_RUNTIME_PM */
1170static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1171static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001172#endif /* FEATURE_RUNTIME_PM */
1173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001174#define INTF_MACADDR_MASK 0x7
1175
1176/**
1177 * hdd_update_macaddr() - update mac address
1178 * @config: hdd configuration
1179 * @hw_macaddr: mac address
1180 *
1181 * Mac address for multiple virtual interface is found as following
1182 * i) The mac address of the first interface is just the actual hw mac address.
1183 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1184 * define the mac address for the remaining interfaces and locally
1185 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1186 * supported virtual interfaces, right now this is 0x07 (meaning 8
1187 * interface).
1188 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1189 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1190 *
1191 * Return: None
1192 */
1193void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301194 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195{
1196 int8_t i;
1197 uint8_t macaddr_b3, tmp_br3;
1198
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301199 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301200 QDF_MAC_ADDR_SIZE);
1201 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301202 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301203 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1205 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1206 INTF_MACADDR_MASK;
1207 macaddr_b3 += tmp_br3;
1208
1209 /* XOR-ing bit-24 of the mac address. This will give enough
1210 * mac address range before collision
1211 */
1212 macaddr_b3 ^= (1 << 7);
1213
1214 /* Set locally administered bit */
1215 config->intfMacAddr[i].bytes[0] |= 0x02;
1216 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001217 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001218 MAC_ADDRESS_STR, i,
1219 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1220 }
1221}
1222
Kabilan Kannan44a58372017-12-06 18:16:11 -08001223static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1224{
1225 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1226 struct tdls_start_params tdls_cfg;
1227 struct tdls_user_config *config = &tdls_cfg.config;
1228 struct hdd_config *cfg = hdd_ctx->config;
1229 QDF_STATUS status;
1230
1231 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1232 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1233 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1234 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1235 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1236 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1237 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1238 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1239 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1240 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1241 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1242 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1243 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1244 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1245 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1246 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1247 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1248 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1249 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1250 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1251 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1252 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1253 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1254 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1255 (cfg->fEnableTDLSImplicitTrigger ?
1256 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1257 (cfg->fTDLSExternalControl ?
1258 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1259 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1260 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1261
1262 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1263 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1264 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1265 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1266 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1267 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1268 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1269 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001270 tdls_cfg.tdls_peer_context = hdd_ctx;
1271 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1272 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001273 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1274 tdls_cfg.tdls_wmm_cb_data = psoc;
1275 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1276 tdls_cfg.tdls_rx_cb_data = psoc;
1277 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1278
1279 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1280 if (status != QDF_STATUS_SUCCESS) {
1281 hdd_err("failed pmo psoc configuration");
1282 return -EINVAL;
1283 }
1284
1285 hdd_ctx->tdls_umac_comp_active = true;
1286 /* enable napier specific tdls data path */
1287 hdd_ctx->tdls_nap_active = true;
1288
1289 return 0;
1290}
1291
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001292static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 struct wma_tgt_services *cfg)
1294{
1295 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296
1297 /* Set up UAPSD */
1298 config->apUapsdEnabled &= cfg->uapsd;
1299
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001300 /* 11AX mode support */
1301 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1302 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1303 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1304
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 /* 11AC mode support */
1306 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1307 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1308 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001309
1310 /* ARP offload: override user setting if invalid */
1311 config->fhostArpOffload &= cfg->arp_offload;
1312
1313#ifdef FEATURE_WLAN_SCAN_PNO
1314 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001315 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001316 if (cfg->pno_offload)
1317 config->PnoOffload = true;
1318#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319#ifdef FEATURE_WLAN_TDLS
1320 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301321 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1322 cfg->en_tdls_offchan;
1323 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1324 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001325 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001327 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1331 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1332#endif
Will Huang496b36c2017-07-11 16:38:50 +08001333 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001334 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001335 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001336 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337
1338}
1339
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001340/**
1341 * hdd_update_vdev_nss() - sets the vdev nss
1342 * @hdd_ctx: HDD context
1343 *
1344 * Sets the Nss per vdev type based on INI
1345 *
1346 * Return: None
1347 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001348static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001349{
1350 struct hdd_config *cfg_ini = hdd_ctx->config;
1351 uint8_t max_supp_nss = 1;
1352
Naveen Rawat10b1c152017-01-18 11:16:06 -08001353 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001354 max_supp_nss = 2;
1355
1356 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001357 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001358
1359 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001360 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001361}
1362
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301363/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301364 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1365 * @hdd_ctx: HDD context
1366 *
1367 * Updates wiphy vhtcap fields
1368 *
1369 * Return: None
1370 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001371static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301372{
1373 struct ieee80211_supported_band *band_5g =
1374 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1375 uint32_t val;
1376
1377 if (!band_5g) {
1378 hdd_debug("5GHz band disabled, skipping capability population");
1379 return;
1380 }
1381
1382 val = hdd_ctx->config->txBFCsnValue;
1383 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1384
1385 val = NUM_OF_SOUNDING_DIMENSIONS;
1386 band_5g->vht_cap.cap |=
1387 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1388
1389 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1390 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1391}
1392
1393/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301394 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1395 * @hdd_ctx: HDD context
1396 *
1397 * Sets the DBS capability as per INI and firmware capability
1398 *
1399 * Return: None
1400 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001401static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301402{
1403 struct hdd_config *cfg_ini = hdd_ctx->config;
1404 uint8_t hw_dbs_capable = 0;
1405
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001406 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1407 ((cfg_ini->dual_mac_feature_disable ==
1408 ENABLE_DBS_CXN_AND_SCAN) ||
1409 (cfg_ini->dual_mac_feature_disable ==
1410 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301411 hw_dbs_capable = 1;
1412
1413 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1414}
1415
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001416static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 struct wma_tgt_ht_cap *cfg)
1418{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420 uint32_t value, val32;
1421 uint16_t val16;
1422 struct hdd_config *pconfig = hdd_ctx->config;
1423 tSirMacHTCapabilityInfo *phtCapInfo;
1424 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1425 uint8_t enable_tx_stbc;
1426
1427 /* check and update RX STBC */
1428 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1429 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1430
1431 /* get the MPDU density */
1432 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1433
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301434 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001435 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 value = 0;
1437 }
1438
1439 /*
1440 * MPDU density:
1441 * override user's setting if value is larger
1442 * than the one supported by target
1443 */
1444 if (value > cfg->mpdu_density) {
1445 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1446 cfg->mpdu_density);
1447
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301448 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001449 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450 }
1451
1452 /* get the HT capability info */
1453 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301454 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001455 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 return;
1457 }
1458 val16 = (uint16_t) val32;
1459 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1460
1461 /* Set the LDPC capability */
1462 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1463
1464 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1465 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1466
1467 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1468 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1469
1470 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1471 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1472
1473 enable_tx_stbc = pconfig->enableTxSTBC;
1474
1475 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1476 pconfig->enable2x2 = 1;
1477 } else {
1478 pconfig->enable2x2 = 0;
1479 enable_tx_stbc = 0;
1480
1481 /* 1x1 */
1482 /* Update Rx Highest Long GI data Rate */
1483 if (sme_cfg_set_int(hdd_ctx->hHal,
1484 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001485 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301486 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001487 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 }
1489
1490 /* Update Tx Highest Long GI data Rate */
1491 if (sme_cfg_set_int
1492 (hdd_ctx->hHal,
1493 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001494 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301495 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001496 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 }
1498 }
1499 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1500 enable_tx_stbc = 0;
1501 phtCapInfo->txSTBC = enable_tx_stbc;
1502
1503 val32 = val16;
1504 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301505 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001506 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1508 value = SIZE_OF_SUPPORTED_MCS_SET;
1509 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301510 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001511 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512
1513 if (pconfig->enable2x2) {
1514 for (value = 0; value < cfg->num_rf_chains; value++)
1515 mcs_set[value] =
1516 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1517
1518 status =
1519 sme_cfg_set_str(hdd_ctx->hHal,
1520 WNI_CFG_SUPPORTED_MCS_SET,
1521 mcs_set,
1522 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301523 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001524 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001525 }
1526 }
1527#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1528}
1529
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001530static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 struct wma_tgt_vht_cap *cfg)
1532{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301533 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534 uint32_t value = 0;
1535 struct hdd_config *pconfig = hdd_ctx->config;
1536 struct wiphy *wiphy = hdd_ctx->wiphy;
1537 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001538 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001539 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001540 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001541 uint32_t hw_rx_ldpc_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542
Dustin Brown5e06bd32016-10-04 12:49:10 -07001543 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001544 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001545 return;
1546 }
1547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 /* Get the current MPDU length */
1549 status =
1550 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1551 &value);
1552
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301553 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001554 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 value = 0;
1556 }
1557
1558 /*
1559 * VHT max MPDU length:
1560 * override if user configured value is too high
1561 * that the target cannot support
1562 */
1563 if (value > cfg->vht_max_mpdu) {
1564 status = sme_cfg_set_int(hdd_ctx->hHal,
1565 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1566 cfg->vht_max_mpdu);
1567
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001568 if (status == QDF_STATUS_E_FAILURE)
1569 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 }
1571
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001572 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1573 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1574
1575 if (pconfig->enable2x2)
1576 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1577
1578 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1579 QDF_STATUS_E_FAILURE) {
1580 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1581 }
1582
1583 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1584 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1585 if (pconfig->enable2x2)
1586 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1587
1588 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1589 QDF_STATUS_E_FAILURE) {
1590 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1591 }
1592
1593 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1594 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1595 if (pconfig->enable2x2)
1596 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1597
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001598 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001599 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1600
1601 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1602 QDF_STATUS_E_FAILURE) {
1603 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1604 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001606 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 &value);
1608
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301609 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001610 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 value = 0;
1612 }
1613
jiad4a7a33c2017-08-08 15:32:24 +08001614 /* Set HW RX LDPC capability */
1615 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1616 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 status = sme_cfg_set_int(hdd_ctx->hHal,
1618 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001619 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001621 if (status == QDF_STATUS_E_FAILURE)
1622 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 }
1624
1625 /* Get current GI 80 value */
1626 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1627 &value);
1628
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301629 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001630 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 value = 0;
1632 }
1633
1634 /* set the Guard interval 80MHz */
1635 if (value && !cfg->vht_short_gi_80) {
1636 status = sme_cfg_set_int(hdd_ctx->hHal,
1637 WNI_CFG_VHT_SHORT_GI_80MHZ,
1638 cfg->vht_short_gi_80);
1639
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001640 if (status == QDF_STATUS_E_FAILURE)
1641 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 }
1643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 /* Get VHT TX STBC cap */
1645 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1646
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301647 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001648 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 value = 0;
1650 }
1651
1652 /* VHT TX STBC cap */
1653 if (value && !cfg->vht_tx_stbc) {
1654 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1655 cfg->vht_tx_stbc);
1656
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001657 if (status == QDF_STATUS_E_FAILURE)
1658 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 }
1660
1661 /* Get VHT RX STBC cap */
1662 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1663
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301664 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001665 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 value = 0;
1667 }
1668
1669 /* VHT RX STBC cap */
1670 if (value && !cfg->vht_rx_stbc) {
1671 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1672 cfg->vht_rx_stbc);
1673
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001674 if (status == QDF_STATUS_E_FAILURE)
1675 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 }
1677
1678 /* Get VHT SU Beamformer cap */
1679 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1680 &value);
1681
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301682 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001683 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 value = 0;
1685 }
1686
1687 /* set VHT SU Beamformer cap */
1688 if (value && !cfg->vht_su_bformer) {
1689 status = sme_cfg_set_int(hdd_ctx->hHal,
1690 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1691 cfg->vht_su_bformer);
1692
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001693 if (status == QDF_STATUS_E_FAILURE)
1694 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695 }
1696
1697 /* check and update SU BEAMFORMEE capabality */
1698 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1699 pconfig->enableTxBF = cfg->vht_su_bformee;
1700
1701 status = sme_cfg_set_int(hdd_ctx->hHal,
1702 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1703 pconfig->enableTxBF);
1704
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001705 if (status == QDF_STATUS_E_FAILURE)
1706 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707
1708 /* Get VHT MU Beamformer cap */
1709 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1710 &value);
1711
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301712 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001713 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714 value = 0;
1715 }
1716
1717 /* set VHT MU Beamformer cap */
1718 if (value && !cfg->vht_mu_bformer) {
1719 status = sme_cfg_set_int(hdd_ctx->hHal,
1720 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1721 cfg->vht_mu_bformer);
1722
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001723 if (status == QDF_STATUS_E_FAILURE)
1724 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 }
1726
1727 /* Get VHT MU Beamformee cap */
1728 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1729 &value);
1730
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301731 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001732 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001733 value = 0;
1734 }
1735
1736 /* set VHT MU Beamformee cap */
1737 if (value && !cfg->vht_mu_bformee) {
1738 status = sme_cfg_set_int(hdd_ctx->hHal,
1739 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1740 cfg->vht_mu_bformee);
1741
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001742 if (status == QDF_STATUS_E_FAILURE)
1743 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744 }
1745
1746 /* Get VHT MAX AMPDU Len exp */
1747 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1748 &value);
1749
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301750 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001751 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752 value = 0;
1753 }
1754
1755 /*
1756 * VHT max AMPDU len exp:
1757 * override if user configured value is too high
1758 * that the target cannot support.
1759 * Even though Rome publish ampdu_len=7, it can
1760 * only support 4 because of some h/w bug.
1761 */
1762
1763 if (value > cfg->vht_max_ampdu_len_exp) {
1764 status = sme_cfg_set_int(hdd_ctx->hHal,
1765 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1766 cfg->vht_max_ampdu_len_exp);
1767
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001768 if (status == QDF_STATUS_E_FAILURE)
1769 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770 }
1771
1772 /* Get VHT TXOP PS CAP */
1773 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1774
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301775 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001776 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001777 value = 0;
1778 }
1779
1780 /* set VHT TXOP PS cap */
1781 if (value && !cfg->vht_txop_ps) {
1782 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1783 cfg->vht_txop_ps);
1784
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001785 if (status == QDF_STATUS_E_FAILURE)
1786 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001787 }
1788
1789 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1790 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1791 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1792 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1793 else
1794 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1795
1796
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001797 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1798 status = sme_cfg_set_int(hdd_ctx->hHal,
1799 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1800 VHT_CAP_160_AND_80P80_SUPP);
1801 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001802 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803 band_5g->vht_cap.cap |=
1804 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001805 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1806 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1807 status = sme_cfg_set_int(hdd_ctx->hHal,
1808 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1809 VHT_CAP_160_SUPP);
1810 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001811 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001812 band_5g->vht_cap.cap |=
1813 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001814 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1815 }
1816 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1817 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301818 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001819 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301820 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001821 &value);
1822 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301823 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001824 value = 0;
1825 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301826 /* set the Guard interval 160MHz */
1827 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001828 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301829 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1830 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001831
1832 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301833 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001834 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835
1836 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1837 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1838
1839 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1840 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1841 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1842 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1843
1844 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1845 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1846
1847 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1848 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1849 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1850 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1851 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1852 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1853
1854 band_5g->vht_cap.cap |=
1855 (cfg->vht_max_ampdu_len_exp <<
1856 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1857
1858 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1859 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1860 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1861 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1862 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1863 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1864 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1865 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1866
1867 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1868 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1869
1870}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001872/**
1873 * hdd_generate_macaddr_auto() - Auto-generate mac address
1874 * @hdd_ctx: Pointer to the HDD context
1875 *
1876 * Auto-generate mac address using device serial number.
1877 * Keep the first 3 bytes of OUI as before and replace
1878 * the last 3 bytes with the lower 3 bytes of serial number.
1879 *
1880 * Return: 0 for success
1881 * Non zero failure code for errors
1882 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001883static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001884{
1885 unsigned int serialno = 0;
1886 struct qdf_mac_addr mac_addr = {
1887 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1888 };
1889
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001890 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001891 if (serialno == 0)
1892 return -EINVAL;
1893
1894 serialno &= 0x00ffffff;
1895
1896 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1897 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1898 mac_addr.bytes[5] = serialno & 0xff;
1899
1900 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1901 return 0;
1902}
1903
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301904/**
1905 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1906 * configuration to cfg_ini in HDD
1907 * @hdd_ctx: Pointer to hdd_ctx
1908 * @cfg: target configuration
1909 *
1910 * Return: None
1911 */
1912#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001913static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301914 struct wma_tgt_cfg *cfg)
1915{
1916 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1917}
1918#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001919static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301920 struct wma_tgt_cfg *cfg)
1921{
1922}
1923#endif
1924
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301925static int hdd_update_green_ap_config(struct hdd_context *hdd_ctx)
1926{
1927 struct green_ap_user_cfg green_ap_cfg;
1928 struct hdd_config *cfg = hdd_ctx->config;
1929 QDF_STATUS status;
1930
1931 green_ap_cfg.host_enable_egap = cfg->enable_egap;
1932 green_ap_cfg.egap_inactivity_time = cfg->egap_inact_time;
1933 green_ap_cfg.egap_wait_time = cfg->egap_wait_time;
1934 green_ap_cfg.egap_feature_flags = cfg->egap_feature_flag;
1935
1936 status = ucfg_green_ap_update_user_config(hdd_ctx->hdd_pdev,
1937 &green_ap_cfg);
1938 if (status != QDF_STATUS_SUCCESS) {
1939 hdd_err("failed to update green ap user configuration");
1940 return -EINVAL;
1941 }
1942
1943 return 0;
1944}
1945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946void hdd_update_tgt_cfg(void *context, void *param)
1947{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001948 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001949 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 struct wma_tgt_cfg *cfg = param;
1951 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001952 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301953 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001954 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301955
Dustin Brownbd68fe12017-11-21 15:28:52 -08001956 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1957 if (ret) {
1958 hdd_err("Failed to create pdev; errno:%d", ret);
1959 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001960 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001961 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001962 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001963 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1964 hdd_err("dispatcher pdev open failed");
1965 QDF_BUG(0);
1966 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301967 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001968
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301969 ret = hdd_update_green_ap_config(hdd_ctx);
1970
Naveen Rawat64e477e2016-05-20 10:34:56 -07001971 if (cds_cfg) {
1972 if (hdd_ctx->config->enable_sub_20_channel_width !=
1973 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1974 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1975 cds_cfg->sub_20_channel_width =
1976 WLAN_SUB_20_CH_WIDTH_NONE;
1977 } else {
1978 cds_cfg->sub_20_channel_width =
1979 hdd_ctx->config->enable_sub_20_channel_width;
1980 }
1981 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982
1983 /* first store the INI band capability */
1984 temp_band_cap = hdd_ctx->config->nBandCapability;
1985
1986 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301987 hdd_ctx->is_fils_roaming_supported =
1988 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301990 hdd_ctx->config->is_11k_offload_supported =
1991 cfg->services.is_11k_offload_supported;
1992
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001993 /*
1994 * now overwrite the target band capability with INI
1995 * setting if INI setting is a subset
1996 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001998 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1999 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08002001 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
2002 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07002004 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 }
2006
Amar Singhal58b45ef2017-08-01 13:43:54 -07002007 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
2008
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302009 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010 hdd_ctx->reg.reg_domain = cfg->reg_domain;
2011 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
2012 }
2013
2014 /* This can be extended to other configurations like ht, vht cap... */
2015
Anurag Chouhanc5548422016-02-24 18:33:27 +05302016 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002018 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07002020 static struct qdf_mac_addr default_mac_addr = {
2021 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
2022 };
2023 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
2024 &default_mac_addr)) {
2025 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
2026 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
2027 MAC_ADDRESS_STR,
2028 MAC_ADDR_ARRAY(hdd_ctx->config->
2029 intfMacAddr[0].bytes));
2030 } else {
2031 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2032 MAC_ADDRESS_STR,
2033 MAC_ADDR_ARRAY(hdd_ctx->config->
2034 intfMacAddr[0].bytes));
2035 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002036 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037 }
2038
2039 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002040 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041
2042 hdd_ctx->max_intf_count = cfg->max_intf_count;
2043
Jeff Johnsonc875e242016-09-23 18:12:34 -07002044 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002045
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2047 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2048
2049 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002052 if (cfg->services.en_11ax) {
2053 hdd_info("11AX: 11ax is enabled - update HDD config");
2054 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2055 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002056
2057 hdd_update_vdev_nss(hdd_ctx);
2058
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302059 hdd_update_hw_dbs_capable(hdd_ctx);
2060
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002061 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002062 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002063 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002064 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002065
Nitesh Shahe50711f2017-04-26 16:30:45 +05302066 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2067 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2068 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002069 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002070 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002071
Rajeev Kumardd3bc602016-08-16 14:21:05 -07002072 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
2073 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302074 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302075 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302076
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302077 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002078 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2079 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302080 hdd_ctx->config->txBFCsnValue =
2081 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2082
Arif Hussainee10f902017-12-27 16:30:17 -08002083 status = sme_cfg_set_int(hdd_ctx->hHal,
2084 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2085 hdd_ctx->config->txBFCsnValue);
2086 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302087 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2088
2089
2090 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002091 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2092 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302093
2094 /*
2095 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2096 */
2097 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302098
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302099 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2100
Yue Macd359b72017-10-03 15:21:00 -07002101 /*
2102 * This needs to be done after HDD pdev is created and stored since
2103 * it will access the HDD pdev object lock.
2104 */
2105 hdd_runtime_suspend_context_init(hdd_ctx);
2106
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002107 /* Configure NAN datapath features */
2108 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002109 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002110 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002111 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2112 cfg->obss_detection_offloaded);
2113 if (QDF_IS_STATUS_ERROR(status))
2114 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002115
2116 status = sme_cfg_set_int(hdd_ctx->hHal,
2117 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2118 cfg->obss_color_collision_offloaded);
2119 if (QDF_IS_STATUS_ERROR(status))
2120 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121}
2122
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002123bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002124{
Jeff Johnson9d295242017-08-29 14:39:48 -07002125 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002126 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127
Jiachao Wuf610d912018-01-23 17:47:32 +08002128 if (!hdd_ctx) {
2129 hdd_info("Couldn't get hdd_ctx");
2130 return true;
2131 }
2132
2133 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002134 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002135 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302136 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002137 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138
Dustin Brown920397d2017-12-13 16:27:50 -08002139 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002140 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2141
2142 if ((QDF_SAP_MODE == adapter->device_mode ||
2143 QDF_P2P_GO_MODE == adapter->device_mode) &&
2144 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002145 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002146 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2147 true;
2148 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002149 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302150 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302152
2153 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002155
2156/**
2157 * hdd_is_valid_mac_address() - validate MAC address
2158 * @pMacAddr: Pointer to the input MAC address
2159 *
2160 * This function validates whether the given MAC address is valid or not
2161 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2162 * where X is the hexa decimal digit character and separated by ':'
2163 * This algorithm works even if MAC address is not separated by ':'
2164 *
2165 * This code checks given input string mac contains exactly 12 hexadecimal
2166 * digits and a separator colon : appears in the input string only after
2167 * an even number of hex digits.
2168 *
2169 * Return: 1 for valid and 0 for invalid
2170 */
2171bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2172{
2173 int xdigit = 0;
2174 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002176 while (*pMacAddr) {
2177 if (isxdigit(*pMacAddr)) {
2178 xdigit++;
2179 } else if (':' == *pMacAddr) {
2180 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2181 break;
2182
2183 ++separator;
2184 } else {
2185 /* Invalid MAC found */
2186 return 0;
2187 }
2188 ++pMacAddr;
2189 }
2190 return xdigit == 12 && (separator == 5 || separator == 0);
2191}
2192
2193/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302194 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2195 * @dev: Handle to struct net_device to be updated.
2196 *
2197 * Return: None
2198 */
2199static void hdd_mon_mode_ether_setup(struct net_device *dev)
2200{
2201 dev->header_ops = NULL;
2202 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2203 dev->hard_header_len = ETH_HLEN;
2204 dev->mtu = ETH_DATA_LEN;
2205 dev->addr_len = ETH_ALEN;
2206 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2207 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2208 dev->priv_flags |= IFF_TX_SKB_SHARING;
2209
2210 memset(dev->broadcast, 0xFF, ETH_ALEN);
2211}
2212
2213/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002214 * __hdd__mon_open() - HDD Open function
2215 * @dev: Pointer to net_device structure
2216 *
2217 * This is called in response to ifconfig up
2218 *
2219 * Return: 0 for success; non-zero for failure
2220 */
2221static int __hdd_mon_open(struct net_device *dev)
2222{
2223 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002224 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2225 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002226
Dustin Brownfdf17c12018-03-14 12:55:34 -07002227 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002228
2229 ret = wlan_hdd_validate_context(hdd_ctx);
2230 if (ret)
2231 return ret;
2232
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302233 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002234
2235 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2236 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2237 if (ret) {
2238 hdd_err("Failed to start WLAN modules return");
2239 return ret;
2240 }
2241 hdd_err("hdd_wlan_start_modules() successful !");
2242
2243 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2244 ret = hdd_start_adapter(adapter);
2245 if (ret) {
2246 hdd_err("Failed to start adapter :%d",
2247 adapter->device_mode);
2248 return ret;
2249 }
2250 hdd_err("hdd_start_adapters() successful !");
2251 }
2252 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2253 }
2254
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002255 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002256
2257 if (!ret)
2258 ret = hdd_enable_monitor_mode(dev);
2259
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002260 return ret;
2261}
2262
2263/**
2264 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2265 * @dev: Pointer to net_device structure
2266 *
2267 * This is called in response to ifconfig up
2268 *
2269 * Return: 0 for success; non-zero for failure
2270 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002271static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002272{
2273 int ret;
2274
2275 cds_ssr_protect(__func__);
2276 ret = __hdd_mon_open(dev);
2277 cds_ssr_unprotect(__func__);
2278
2279 return ret;
2280}
2281
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002282static QDF_STATUS
2283wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2284{
2285 struct policy_mgr_dual_mac_config cfg = {0};
2286 QDF_STATUS status;
2287 uint32_t channel_select_logic_conc;
2288 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2289
2290 if (!hdd_ctx) {
2291 hdd_err("HDD context is NULL");
2292 return QDF_STATUS_E_FAILURE;
2293 }
2294
2295
2296 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2297 return QDF_STATUS_SUCCESS;
2298
2299 cfg.scan_config = 0;
2300 cfg.fw_mode_config = 0;
2301 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2302
2303 channel_select_logic_conc = hdd_ctx->config->
2304 channel_select_logic_conc;
2305
2306 if (hdd_ctx->config->dual_mac_feature_disable !=
2307 DISABLE_DBS_CXN_AND_SCAN) {
2308 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2309 hdd_ctx->hdd_psoc, &cfg.scan_config,
2310 &cfg.fw_mode_config,
2311 hdd_ctx->config->dual_mac_feature_disable,
2312 channel_select_logic_conc);
2313
2314 if (status != QDF_STATUS_SUCCESS) {
2315 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2316 status);
2317 return status;
2318 }
2319 }
2320
2321 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2322 cfg.scan_config, cfg.fw_mode_config);
2323
2324 status = sme_soc_set_dual_mac_config(cfg);
2325 if (status != QDF_STATUS_SUCCESS) {
2326 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2327 return status;
2328 }
2329
2330 return QDF_STATUS_SUCCESS;
2331}
2332
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002333/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302334 * hdd_start_adapter() - Wrapper function for device specific adapter
2335 * @adapter: pointer to HDD adapter
2336 *
2337 * This function is called to start the device specific adapter for
2338 * the mode passed in the adapter's device_mode.
2339 *
2340 * Return: 0 for success; non-zero for failure
2341 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002342int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302343{
2344
2345 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002346 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302347
Dustin Brownfdf17c12018-03-14 12:55:34 -07002348 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002349 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302350
2351 switch (device_mode) {
2352 case QDF_P2P_CLIENT_MODE:
2353 case QDF_P2P_DEVICE_MODE:
2354 case QDF_OCB_MODE:
2355 case QDF_STA_MODE:
2356 case QDF_MONITOR_MODE:
2357 ret = hdd_start_station_adapter(adapter);
2358 if (ret)
2359 goto err_start_adapter;
2360 break;
2361 case QDF_P2P_GO_MODE:
2362 case QDF_SAP_MODE:
2363 ret = hdd_start_ap_adapter(adapter);
2364 if (ret)
2365 goto err_start_adapter;
2366 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302367 case QDF_IBSS_MODE:
2368 /*
2369 * For IBSS interface is initialized as part of
2370 * hdd_init_station_mode()
2371 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002372 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302373 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002374 /* vdevs are dynamically managed by firmware in FTM */
2375 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302376 default:
2377 hdd_err("Invalid session type %d", device_mode);
2378 QDF_ASSERT(0);
2379 goto err_start_adapter;
2380 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002381
Arun Khandavallifae92942016-08-01 13:31:08 +05302382 if (hdd_set_fw_params(adapter))
2383 hdd_err("Failed to set the FW params for the adapter!");
2384
2385 /*
2386 * Action frame registered in one adapter which will
2387 * applicable to all interfaces
2388 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302389 ret = wlan_hdd_cfg80211_register_frames(adapter);
2390 if (ret < 0) {
2391 hdd_err("Failed to register frames - ret %d", ret);
2392 goto err_start_adapter;
2393 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002394 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302395
Dustin Browndb2a8be2017-12-20 11:49:56 -08002396exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002397 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002398
Arun Khandavallifae92942016-08-01 13:31:08 +05302399 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002400
Arun Khandavallifae92942016-08-01 13:31:08 +05302401err_start_adapter:
2402 return -EINVAL;
2403}
2404
2405/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302406 * hdd_enable_power_management() - API to Enable Power Management
2407 *
2408 * API invokes Bus Interface Layer power management functionality
2409 *
2410 * Return: None
2411 */
2412static void hdd_enable_power_management(void)
2413{
2414 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2415
2416 if (!hif_ctx) {
2417 hdd_err("Bus Interface Context is Invalid");
2418 return;
2419 }
2420
2421 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2422}
2423
2424/**
2425 * hdd_disable_power_management() - API to disable Power Management
2426 *
2427 * API disable Bus Interface Layer Power management functionality
2428 *
2429 * Return: None
2430 */
2431static void hdd_disable_power_management(void)
2432{
2433 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2434
2435 if (!hif_ctx) {
2436 hdd_err("Bus Interface Context is Invalid");
2437 return;
2438 }
2439
2440 hif_disable_power_management(hif_ctx);
2441}
2442
2443/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302444 * hdd_update_hw_sw_info() - API to update the HW/SW information
2445 *
2446 * API to update the HW and SW information in the driver
2447 *
2448 * Return: None
2449 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002450static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302451{
2452 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002453 size_t target_hw_name_len;
2454 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302455
2456 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2457 if (!hif_sc) {
2458 hdd_err("HIF context is NULL");
2459 return;
2460 }
2461
2462 /*
2463 * target hw version/revision would only be retrieved after firmware
2464 * download
2465 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002466 hif_get_hw_info(hif_sc,
2467 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302468 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002469 &target_hw_name);
2470
2471 if (hdd_ctx->target_hw_name)
2472 qdf_mem_free(hdd_ctx->target_hw_name);
2473
2474 target_hw_name_len = strlen(target_hw_name) + 1;
2475 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2476 if (hdd_ctx->target_hw_name)
2477 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2478 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302479
2480 /* Get the wlan hw/fw version */
2481 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302482}
2483
2484/**
gbian62edd7e2017-03-07 13:12:13 +08002485 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2486 * @hdd_ctx: Pointer to hdd context
2487 *
2488 * Return: none
2489 */
2490static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002491hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002492{
2493 uint8_t num_entries = 0;
2494 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2495 uint8_t *tx_sched_wrr_ac;
2496 int i;
2497 cds_context_type *cds_ctx;
2498
2499 if (NULL == hdd_ctx)
2500 return;
2501
2502 if (NULL == hdd_ctx->config) {
2503 /* Do nothing if hdd_ctx is invalid */
2504 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2505 return;
2506 }
2507
2508 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2509
2510 if (!cds_ctx) {
2511 hdd_err("Invalid CDS Context");
2512 return;
2513 }
2514
2515 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2516 switch (i) {
2517 case OL_TX_WMM_AC_BE:
2518 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2519 break;
2520 case OL_TX_WMM_AC_BK:
2521 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2522 break;
2523 case OL_TX_WMM_AC_VI:
2524 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2525 break;
2526 case OL_TX_WMM_AC_VO:
2527 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2528 break;
2529 default:
2530 tx_sched_wrr_ac = NULL;
2531 break;
2532 }
2533
2534 hdd_string_to_u8_array(tx_sched_wrr_ac,
2535 tx_sched_wrr_param,
2536 &num_entries,
2537 sizeof(tx_sched_wrr_param));
2538
2539 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2540 cds_ctx->ac_specs[i].wrr_skip_weight =
2541 tx_sched_wrr_param[0];
2542 cds_ctx->ac_specs[i].credit_threshold =
2543 tx_sched_wrr_param[1];
2544 cds_ctx->ac_specs[i].send_limit =
2545 tx_sched_wrr_param[2];
2546 cds_ctx->ac_specs[i].credit_reserve =
2547 tx_sched_wrr_param[3];
2548 cds_ctx->ac_specs[i].discard_weight =
2549 tx_sched_wrr_param[4];
2550 }
2551
2552 num_entries = 0;
2553 }
2554}
2555
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002556#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002557static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2558 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2559{
Jeff Johnson9d295242017-08-29 14:39:48 -07002560 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002561 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002562
2563 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2564 if (!adapter) {
2565 hdd_err("Adapter is NULL");
2566 return PM_MAX_NUM_OF_MODE;
2567 }
2568
2569 return policy_mgr_convert_device_mode_to_qdf_type(
2570 adapter->device_mode);
2571}
2572
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002573static void hdd_register_policy_manager_callback(
2574 struct wlan_objmgr_psoc *psoc)
2575{
2576 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002577
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002578 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002579 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002580 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2581 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002582 hdd_cbacks.get_mode_for_non_connected_vdev =
2583 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302584 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002585
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002586 if (QDF_STATUS_SUCCESS !=
2587 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2588 hdd_err("HDD callback registration with policy manager failed");
2589 }
2590}
2591#else
2592static void hdd_register_policy_manager_callback(
2593 struct wlan_objmgr_psoc *psoc)
2594{
2595}
2596#endif
2597
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002598static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002599{
2600 struct nan_callbacks cb_obj = {0};
2601
2602 cb_obj.ndi_open = hdd_ndi_open;
2603 cb_obj.ndi_close = hdd_ndi_close;
2604 cb_obj.ndi_start = hdd_ndi_start;
2605 cb_obj.ndi_delete = hdd_ndi_delete;
2606 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2607 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2608
Naveen Rawat37f62c82017-03-26 22:24:43 -07002609 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2610 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002611 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002612
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002613 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2614}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002615
Dustin Brown26b3d042017-12-21 11:13:27 -08002616#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002617/**
2618 * hdd_check_for_leaks() - Perform runtime memory leak checks
2619 *
2620 * This API triggers runtime memory leak detection. This feature enforces the
2621 * policy that any memory allocated at runtime must also be released at runtime.
2622 *
2623 * Allocating memory at runtime and releasing it at unload is effectively a
2624 * memory leak for configurations which never unload (e.g. LONU, statically
2625 * compiled driver). Such memory leaks are NOT false positives, and must be
2626 * fixed.
2627 *
2628 * Return: None
2629 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002630static void hdd_check_for_leaks(void)
2631{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002632 /* DO NOT REMOVE these checks; for false positives, read above first */
2633
Dustin Brown677e0862017-10-10 16:30:09 -07002634 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002635 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002636 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002637}
2638
Dustin Brown26b3d042017-12-21 11:13:27 -08002639#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2640#else
2641static inline void hdd_check_for_leaks(void) {}
2642
2643#define hdd_debug_domain_set(domain)
2644#endif /* CONFIG_LEAK_DETECTION */
2645
gbian62edd7e2017-03-07 13:12:13 +08002646/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002647 * hdd_update_country_code - Update country code
2648 * @hdd_ctx: HDD context
2649 *
2650 * Update country code based on module parameter country_code
2651 *
2652 * Return: 0 on success and errno on failure
2653 */
2654static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2655{
2656 if (!country_code)
2657 return 0;
2658
2659 return hdd_reg_set_country(hdd_ctx, country_code);
2660}
2661
2662/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302663 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2664 * @hdd_ctx: HDD context
2665 * @adapter: HDD adapter
2666 * @reinit: flag to indicate from SSR or normal path
2667 *
2668 * This function maintains the driver state machine it will be invoked from
2669 * startup, reinit and change interface. Depending on the driver state shall
2670 * perform the opening of the modules.
2671 *
2672 * Return: 0 for success; non-zero for failure
2673 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002674int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2675 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302676 bool reinit)
2677{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002678 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302679 qdf_device_t qdf_dev;
2680 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302681 bool unint = false;
2682 void *hif_ctx;
2683
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002684 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302685
2686 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2687 if (!qdf_dev) {
2688 hdd_err("QDF Device Context is Invalid return");
2689 return -EINVAL;
2690 }
2691
Dustin Brown6f427922017-09-19 12:19:00 -07002692 hdd_set_idle_ps_config(hdd_ctx, false);
2693 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302694
Dustin Brown1fe30a82017-10-03 16:13:36 -07002695 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302696 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2697 mutex_unlock(&hdd_ctx->iface_change_lock);
2698 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002699 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302700 return 0;
2701 }
2702
Dustin Brown1fe30a82017-10-03 16:13:36 -07002703 hdd_ctx->start_modules_in_progress = true;
2704
Arun Khandavallifae92942016-08-01 13:31:08 +05302705 switch (hdd_ctx->driver_status) {
2706 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002707 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302708 unint = true;
2709 /* Fall through dont add break here */
2710 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002711 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2712
Dustin Brown26b3d042017-12-21 11:13:27 -08002713 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002714
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 if (!reinit && !unint) {
2716 ret = pld_power_on(qdf_dev->dev);
2717 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002718 hdd_err("Failed to Powerup the device; errno: %d",
2719 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302720 goto release_lock;
2721 }
2722 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002723
2724 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2725 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302726 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2727 qdf_dev->bus_type,
2728 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2729 HIF_ENABLE_TYPE_PROBE);
2730 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002731 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302732 goto power_down;
2733 }
2734
2735 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302736 if (!hif_ctx) {
2737 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002738 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302739 goto power_down;
2740 }
2741
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 status = ol_cds_init(qdf_dev, hif_ctx);
2743 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002744 hdd_err("No Memory to Create BMI Context; status: %d",
2745 status);
2746 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302747 goto hif_close;
2748 }
2749
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002750 ret = hdd_update_config(hdd_ctx);
2751 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002752 hdd_err("Failed to update configuration; errno: %d",
2753 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002754 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002755 }
2756
gbian62edd7e2017-03-07 13:12:13 +08002757 hdd_update_cds_ac_specs_params(hdd_ctx);
2758
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302759 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002760 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002761 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002762 ret = qdf_status_to_os_return(status);
2763 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302764 }
2765
Mukul Sharma9d797a02017-01-05 20:26:03 +05302766 /* initalize components configurations after psoc open */
2767 ret = hdd_update_components_config(hdd_ctx);
2768 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002769 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302770 ret);
2771 goto close;
2772 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002773 status = cds_dp_open(hdd_ctx->hdd_psoc);
2774 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002775 hdd_err("Failed to Open cds post open; status: %d",
2776 status);
2777 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002778 goto close;
2779 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302780
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002781 /*
2782 * NAN compoenet requires certian operations like, open adapter,
2783 * close adapter, etc. to be initiated by HDD, for those
2784 * register HDD callbacks with UMAC's NAN componenet.
2785 */
2786 hdd_nan_register_callbacks(hdd_ctx);
2787
Arun Khandavallifae92942016-08-01 13:31:08 +05302788 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2789
Jeff Johnson3a280122017-09-13 07:42:00 -07002790 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302791 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002792 hdd_err("Failed to pre-enable CDS; status: %d", status);
2793 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002794 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302795 }
2796
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002797 hdd_register_policy_manager_callback(
2798 hdd_ctx->hdd_psoc);
2799
Amar Singhal0928b192017-12-01 10:50:54 -08002800 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2801
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302802 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302803 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002804 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302805
Arun Khandavallifae92942016-08-01 13:31:08 +05302806 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002807 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302808 break;
2809 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302810
2811 if (reinit) {
Dustin Browndca39692017-11-09 15:30:25 -08002812 ret = hdd_ipa_uc_ssr_reinit(hdd_ctx);
2813 if (ret) {
2814 hdd_err("HDD IPA UC reinit failed; errno: %d",
2815 ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002816 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002817 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302818 }
2819
Arun Khandavallifae92942016-08-01 13:31:08 +05302820 /* Fall through dont add break here */
2821 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002822 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2823
Arun Khandavallifae92942016-08-01 13:31:08 +05302824 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002825 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002826 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002827 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302828 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302829 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2830 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002831 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302832 break;
2833 }
Dustin Browndca39692017-11-09 15:30:25 -08002834
2835 ret = hdd_configure_cds(hdd_ctx, adapter);
2836 if (ret) {
2837 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002838 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302839 }
Dustin Browndca39692017-11-09 15:30:25 -08002840
Komal Seelamf2136bb2016-09-28 18:30:44 +05302841 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002842
Arun Khandavallifae92942016-08-01 13:31:08 +05302843 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002844 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302845 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002846
Arun Khandavallifae92942016-08-01 13:31:08 +05302847 default:
2848 hdd_err("WLAN start invoked in wrong state! :%d\n",
2849 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002850 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302851 goto release_lock;
2852 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002853
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302854 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002855 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2856 ret = hdd_update_country_code(hdd_ctx);
2857 if (ret)
2858 hdd_err("Failed to update command line country code!");
2859 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302860 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002861
Dustin Browne74003f2018-03-14 12:51:58 -07002862 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002863
Arun Khandavallifae92942016-08-01 13:31:08 +05302864 return 0;
2865
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002866post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002867 cds_post_disable();
Amar Singhal410675c2018-01-10 12:14:21 -08002868 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Dustin Brownbd68fe12017-11-21 15:28:52 -08002869 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002870
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002871cds_txrx_free:
2872 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002873
Arun Khandavallifae92942016-08-01 13:31:08 +05302874close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002875 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002876 hdd_info("Wlan transition aborted (now CLOSED)");
2877
Jeff Johnsone4b14592017-09-13 14:23:33 -07002878 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302879
Dustin Brown28b17892017-10-10 13:29:38 -07002880deinit_config:
2881 cds_deinit_ini_config();
2882
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002883cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302884 ol_cds_free();
2885
2886hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002887 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2888 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302889power_down:
2890 if (!reinit && !unint)
2891 pld_power_off(qdf_dev->dev);
2892release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302893 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302894 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002895
2896 /* many adapter resources are not freed by design in SSR case */
2897 if (!reinit)
2898 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002899 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002900
Dustin Browne74003f2018-03-14 12:51:58 -07002901 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002902
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002903 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302904}
2905
Naveen Rawat910726a2017-03-06 11:42:51 -08002906#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002907static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002908{
2909 int ret = os_if_wifi_pos_register_nl();
2910
2911 if (ret)
2912 hdd_err("os_if_wifi_pos_register_nl failed");
2913
2914 return ret;
2915}
2916
2917static int hdd_deactivate_wifi_pos(void)
2918{
2919 int ret = os_if_wifi_pos_deregister_nl();
2920
2921 if (ret)
2922 hdd_err("os_if_wifi_pos_deregister_nl failed");
2923
2924 return ret;
2925}
2926
2927/**
2928 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2929 * @hdd_ctx: hdd context
2930 *
2931 * Return: status of operation
2932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002933static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002934{
2935 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2936 struct hdd_config *cfg = hdd_ctx->config;
2937
2938 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2939 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2940 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2941 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2942 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2943 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2944 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2945 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2946}
2947#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002948static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002949{
2950 return oem_activate_service(hdd_ctx);
2951}
2952
2953static int hdd_deactivate_wifi_pos(void)
2954{
2955 return 0;
2956}
2957
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002958static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002959{
2960}
2961#endif
2962
Arun Khandavallifae92942016-08-01 13:31:08 +05302963/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002964 * __hdd_open() - HDD Open function
2965 * @dev: Pointer to net_device structure
2966 *
2967 * This is called in response to ifconfig up
2968 *
2969 * Return: 0 for success; non-zero for failure
2970 */
2971static int __hdd_open(struct net_device *dev)
2972{
Jeff Johnson9d295242017-08-29 14:39:48 -07002973 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002974 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002975 int ret;
2976
Dustin Brownfdf17c12018-03-14 12:55:34 -07002977 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302978 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002979 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302981 /* Nothing to be done if device is unloading */
2982 if (cds_is_driver_unloading()) {
2983 hdd_err("Driver is unloading can not open the hdd");
2984 return -EBUSY;
2985 }
2986
Dustin Brown01847752017-10-25 13:56:27 -07002987 if (cds_is_driver_recovering()) {
2988 hdd_err("WLAN is currently recovering; Please try again.");
2989 return -EBUSY;
2990 }
2991
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302992 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2993 hdd_err("con_mode_handler is in progress; Please try again.");
2994 return -EBUSY;
2995 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302996
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302997 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302998 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2999
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303000 /*
3001 * This scenario can be hit in cases where in the wlan driver after
3002 * registering the netdevices and there is a failure in driver
3003 * initialization. So return error gracefully because the netdevices
3004 * will be de-registered as part of the load failure.
3005 */
3006
3007 if (!cds_is_driver_loaded()) {
3008 hdd_err("Failed to start the wlan driver!!");
3009 ret = -EIO;
3010 goto err_hdd_hdd_init_deinit_lock;
3011 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013
Arun Khandavallifae92942016-08-01 13:31:08 +05303014 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
3015 if (ret) {
3016 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303017 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303018 }
3019
3020
3021 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3022 ret = hdd_start_adapter(adapter);
3023 if (ret) {
3024 hdd_err("Failed to start adapter :%d",
3025 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303026 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303027 }
3028 }
3029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3031 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003032 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033 /* Enable TX queues only when we are connected */
3034 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303035 WLAN_START_ALL_NETIF_QUEUE,
3036 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037 }
3038
Naveen Rawat286def52016-09-23 15:38:02 -07003039 /* Enable carrier and transmit queues for NDI */
3040 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003041 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003042 wlan_hdd_netif_queue_control(adapter,
3043 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3044 WLAN_CONTROL_PATH);
3045 }
3046
Naveen Rawat910726a2017-03-06 11:42:51 -08003047 hdd_populate_wifi_pos_cfg(hdd_ctx);
3048
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303049err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303050 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303051 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003052 return ret;
3053}
3054
Arun Khandavallifae92942016-08-01 13:31:08 +05303055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056/**
3057 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3058 * @dev: Pointer to net_device structure
3059 *
3060 * This is called in response to ifconfig up
3061 *
3062 * Return: 0 for success; non-zero for failure
3063 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003064static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065{
3066 int ret;
3067
3068 cds_ssr_protect(__func__);
3069 ret = __hdd_open(dev);
3070 cds_ssr_unprotect(__func__);
3071
3072 return ret;
3073}
3074
3075/**
3076 * __hdd_stop() - HDD stop function
3077 * @dev: Pointer to net_device structure
3078 *
3079 * This is called in response to ifconfig down
3080 *
3081 * Return: 0 for success; non-zero for failure
3082 */
3083static int __hdd_stop(struct net_device *dev)
3084{
Jeff Johnson9d295242017-08-29 14:39:48 -07003085 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003086 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087 int ret;
3088
Dustin Brownfdf17c12018-03-14 12:55:34 -07003089 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003090
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303091 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003092 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003093
3094 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303095 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097
3098 /* Nothing to be done if the interface is not opened */
3099 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003100 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101 return -ENODEV;
3102 }
3103
3104 /* Make sure the interface is marked as closed */
3105 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303106
3107 hdd_debug("Disabling Auto Power save timer");
3108 sme_ps_disable_auto_ps_timer(
3109 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003110 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303111
3112 /*
3113 * Disable TX on the interface, after this hard_start_xmit() will not
3114 * be called on that interface
3115 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003116 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003117 hdd_device_mode_to_string(adapter->device_mode),
3118 adapter->device_mode);
3119
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303120 wlan_hdd_netif_queue_control(adapter,
3121 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3122 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123
3124 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003125 * NAN data interface is different in some sense. The traffic on NDI is
3126 * bursty in nature and depends on the need to transfer. The service
3127 * layer may down the interface after the usage and up again when
3128 * required. In some sense, the NDI is expected to be available
3129 * (like SAP) iface until NDI delete request is issued by the service
3130 * layer. Skip BSS termination and adapter deletion for NAN Data
3131 * interface (NDI).
3132 */
3133 if (WLAN_HDD_IS_NDI(adapter))
3134 return 0;
3135
3136 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 * The interface is marked as down for outside world (aka kernel)
3138 * But the driver is pretty much alive inside. The driver needs to
3139 * tear down the existing connection on the netdev (session)
3140 * cleanup the data pipes and wait until the control plane is stabilized
3141 * for this interface. The call also needs to wait until the above
3142 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003143 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 * That is intentional to be able to scan if it is a STA/P2P interface
3145 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003146 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003147
3148 /* DeInit the adapter. This ensures datapath cleanup as well */
3149 hdd_deinit_adapter(hdd_ctx, adapter, true);
3150
Arun Khandavallifae92942016-08-01 13:31:08 +05303151
3152 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303153 * Upon wifi turn off, DUT has to flush the scan results so if
3154 * this is the last cli iface, flush the scan database.
3155 */
3156 if (!hdd_is_cli_iface_up(hdd_ctx))
3157 sme_scan_flush_result(hdd_ctx->hHal);
3158
3159 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303160 * Find if any iface is up. If any iface is up then can't put device to
3161 * sleep/power save mode
3162 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303163 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003164 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003165 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3166 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303167 hdd_prevent_suspend_timeout(
3168 hdd_ctx->config->iface_change_wait_time,
3169 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303170 }
3171
Dustin Browne74003f2018-03-14 12:51:58 -07003172 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173 return 0;
3174}
3175
3176/**
3177 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3178 * @dev: pointer to net_device structure
3179 *
3180 * This is called in response to ifconfig down
3181 *
3182 * Return: 0 for success and error number for failure
3183 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003184static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185{
3186 int ret;
3187
3188 cds_ssr_protect(__func__);
3189 ret = __hdd_stop(dev);
3190 cds_ssr_unprotect(__func__);
3191
3192 return ret;
3193}
3194
3195/**
3196 * __hdd_uninit() - HDD uninit function
3197 * @dev: Pointer to net_device structure
3198 *
3199 * This is called during the netdev unregister to uninitialize all data
3200 * associated with the device
3201 *
3202 * Return: None
3203 */
3204static void __hdd_uninit(struct net_device *dev)
3205{
Jeff Johnson9d295242017-08-29 14:39:48 -07003206 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003207 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208
Dustin Brownfdf17c12018-03-14 12:55:34 -07003209 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210
3211 do {
3212 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003213 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214 break;
3215 }
3216
Jeff Johnson399c6272017-08-30 10:51:00 -07003217 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3218 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003219 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 break;
3221 }
3222
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003223 if (dev != adapter->dev)
3224 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225
Jeff Johnson399c6272017-08-30 10:51:00 -07003226 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227
3228 /* after uninit our adapter structure will no longer be valid */
3229 adapter->dev = NULL;
3230 adapter->magic = 0;
3231 } while (0);
3232
Dustin Browne74003f2018-03-14 12:51:58 -07003233 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234}
3235
3236/**
3237 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3238 * @dev: pointer to net_device structure
3239 *
3240 * This is called during the netdev unregister to uninitialize all data
3241 * associated with the device
3242 *
3243 * Return: none
3244 */
3245static void hdd_uninit(struct net_device *dev)
3246{
3247 cds_ssr_protect(__func__);
3248 __hdd_uninit(dev);
3249 cds_ssr_unprotect(__func__);
3250}
3251
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003252static int hdd_open_cesium_nl_sock(void)
3253{
3254#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3255 struct netlink_kernel_cfg cfg = {
3256 .groups = WLAN_NLINK_MCAST_GRP_ID,
3257 .input = NULL
3258 };
3259#endif
3260 int ret = 0;
3261
3262#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3263 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3264#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3265 THIS_MODULE,
3266#endif
3267 &cfg);
3268#else
3269 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3270 WLAN_NLINK_MCAST_GRP_ID,
3271 NULL, NULL, THIS_MODULE);
3272#endif
3273
3274 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003275 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003276 ret = -ECONNREFUSED;
3277 }
3278
3279 return ret;
3280}
3281
3282static void hdd_close_cesium_nl_sock(void)
3283{
3284 if (NULL != cesium_nl_srv_sock) {
3285 netlink_kernel_release(cesium_nl_srv_sock);
3286 cesium_nl_srv_sock = NULL;
3287 }
3288}
3289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003290/**
3291 * __hdd_set_mac_address() - set the user specified mac address
3292 * @dev: Pointer to the net device.
3293 * @addr: Pointer to the sockaddr.
3294 *
3295 * This function sets the user specified mac address using
3296 * the command ifconfig wlanX hw ether <mac adress>.
3297 *
3298 * Return: 0 for success, non zero for failure
3299 */
3300static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3301{
Jeff Johnson9d295242017-08-29 14:39:48 -07003302 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003303 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303305 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303307 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308
Dustin Brownfdf17c12018-03-14 12:55:34 -07003309 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303311 if (netif_running(dev)) {
3312 hdd_err("On iface up, set mac address change isn't supported");
3313 return -EBUSY;
3314 }
3315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3317 ret = wlan_hdd_validate_context(hdd_ctx);
3318 if (0 != ret)
3319 return ret;
3320
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303321 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3322
3323 if (qdf_is_macaddr_zero(&mac_addr)) {
3324 hdd_err("MAC is all zero");
3325 return -EINVAL;
3326 }
3327
3328 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3329 hdd_err("MAC is Broadcast");
3330 return -EINVAL;
3331 }
3332
3333 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3334 hdd_err("MAC is Multicast");
3335 return -EINVAL;
3336 }
3337
Jeff Johnson1e851a12017-10-28 14:36:12 -07003338 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3340
Dustin Browne74003f2018-03-14 12:51:58 -07003341 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303342 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003343}
3344
3345/**
3346 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3347 * function from SSR
3348 * @dev: pointer to net_device structure
3349 * @addr: Pointer to the sockaddr
3350 *
3351 * This function sets the user specified mac address using
3352 * the command ifconfig wlanX hw ether <mac adress>.
3353 *
3354 * Return: 0 for success.
3355 */
3356static int hdd_set_mac_address(struct net_device *dev, void *addr)
3357{
3358 int ret;
3359
3360 cds_ssr_protect(__func__);
3361 ret = __hdd_set_mac_address(dev, addr);
3362 cds_ssr_unprotect(__func__);
3363
3364 return ret;
3365}
3366
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003367uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368{
3369 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003370
Anurag Chouhan6d760662016-02-20 16:05:43 +05303371 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3373 break;
3374 }
3375
Anurag Chouhan6d760662016-02-20 16:05:43 +05303376 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377 return NULL;
3378
3379 hdd_ctx->config->intfAddrMask |= (1 << i);
3380 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3381}
3382
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003383void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3384 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385{
3386 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003387
Anurag Chouhan6d760662016-02-20 16:05:43 +05303388 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 if (!memcmp(releaseAddr,
3390 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3391 6)) {
3392 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3393 break;
3394 }
3395 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396}
3397
3398#ifdef WLAN_FEATURE_PACKET_FILTERING
3399/**
3400 * __hdd_set_multicast_list() - set the multicast address list
3401 * @dev: Pointer to the WLAN device.
3402 * @skb: Pointer to OS packet (sk_buff).
3403 *
3404 * This funciton sets the multicast address list.
3405 *
3406 * Return: None
3407 */
3408static void __hdd_set_multicast_list(struct net_device *dev)
3409{
Jeff Johnson9d295242017-08-29 14:39:48 -07003410 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411 int i = 0, status;
3412 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003413 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303414 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3415 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3416 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417
Dustin Brownfdf17c12018-03-14 12:55:34 -07003418 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303419 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303420 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303423 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303424 goto out;
3425
Dustin Brownc788acb2017-08-01 17:43:51 -07003426 status = hdd_validate_adapter(adapter);
3427 if (status)
3428 goto out;
3429
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303430 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3431 hdd_err("%s: Driver module is closed", __func__);
3432 return;
3433 }
3434
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303435 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3436 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003437 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303438 goto out;
3439 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303441 /* Delete already configured multicast address list */
3442 if (adapter->mc_addr_list.mc_cnt > 0) {
3443 hdd_info("clear previously configured MC address list");
3444 hdd_disable_and_flush_mc_addr_list(adapter,
3445 pmo_mc_list_change_notify);
3446 }
3447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003449 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303450 hdd_disable_and_flush_mc_addr_list(adapter,
3451 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 } else {
3453 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303454 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003455 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303456 pmo_ucfg_max_mc_addr_supported(psoc));
3457 hdd_disable_and_flush_mc_addr_list(adapter,
3458 pmo_mc_list_change_notify);
3459 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003462 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303463 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464 if (i == mc_count)
3465 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303466 memset(&(mc_list_request->mc_addr[i].bytes),
3467 0, ETH_ALEN);
3468 memcpy(&(mc_list_request->mc_addr[i].bytes),
3469 ha->addr, ETH_ALEN);
3470 hdd_info("mlist[%d] = %pM", i,
3471 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 i++;
3473 }
3474 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303475
3476 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003477 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303478 mc_list_request->count = mc_count;
3479 status = hdd_cache_mc_addr_list(mc_list_request);
3480 if (status == 0) {
3481 hdd_enable_mc_addr_filtering(adapter,
3482 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303484 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303486out:
3487 if (mc_list_request)
3488 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003489 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003490}
3491
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493/**
3494 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3495 * @dev: pointer to net_device
3496 *
3497 * Return: none
3498 */
3499static void hdd_set_multicast_list(struct net_device *dev)
3500{
3501 cds_ssr_protect(__func__);
3502 __hdd_set_multicast_list(dev);
3503 cds_ssr_unprotect(__func__);
3504}
3505#endif
3506
3507/**
3508 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3509 * @dev: Pointer to the WLAN device.
3510 * @skb: Pointer to OS packet (sk_buff).
3511 *
3512 * This function is registered with the Linux OS for network
3513 * core to decide which queue to use first.
3514 *
3515 * Return: ac, Queue Index/access category corresponding to UP in IP header
3516 */
3517static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3518#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3519 , void *accel_priv
3520#endif
3521#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3522 , select_queue_fallback_t fallback
3523#endif
3524)
3525{
3526 return hdd_wmm_select_queue(dev, skb);
3527}
3528
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003529static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 .ndo_open = hdd_open,
3531 .ndo_stop = hdd_stop,
3532 .ndo_uninit = hdd_uninit,
3533 .ndo_start_xmit = hdd_hard_start_xmit,
3534 .ndo_tx_timeout = hdd_tx_timeout,
3535 .ndo_get_stats = hdd_get_stats,
3536 .ndo_do_ioctl = hdd_ioctl,
3537 .ndo_set_mac_address = hdd_set_mac_address,
3538 .ndo_select_queue = hdd_select_queue,
3539#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541#endif
3542};
3543
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003544/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003545static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003546 .ndo_open = hdd_mon_open,
3547 .ndo_stop = hdd_stop,
3548 .ndo_get_stats = hdd_get_stats,
3549};
3550
3551/**
3552 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003553 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003554 * Return: None
3555 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003556void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003558 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003559 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003560 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003561 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003562}
3563
3564/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003565 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3566 * @hdd_ctx: global hdd context
3567 * @macAddr: mac address to assign to the interface
3568 * @name: User-visible name of the interface
3569 *
3570 * hdd adapter pointer would point to the netdev->priv space, this function
3571 * would retrive the pointer, and setup the hdd adapter configuration.
3572 *
3573 * Return: the pointer to hdd adapter, otherwise NULL
3574 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003575static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003577 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 const char *name)
3579{
Jeff Johnson5505db82017-11-02 21:19:23 -07003580 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003581 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003582 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303583 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 /*
3585 * cfg80211 initialization and registration....
3586 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003587 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003588#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3589 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003591 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3592 hdd_mon_mode_ether_setup : ether_setup),
3593 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594
Jeff Johnson5505db82017-11-02 21:19:23 -07003595 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596
3597 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003598 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599
Jeff Johnson9d295242017-08-29 14:39:48 -07003600 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003601 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303602 qdf_mem_set(sta_ctx->conn_info.staId,
3603 sizeof(sta_ctx->conn_info.staId),
3604 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003605 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003606 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003608 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303610 qdf_status = qdf_event_create(
3611 &adapter->qdf_session_open_event);
3612 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3613 hdd_err("Session open QDF event init failed!");
3614 free_netdev(adapter->dev);
3615 return NULL;
3616 }
3617
3618 qdf_status = qdf_event_create(
3619 &adapter->qdf_session_close_event);
3620 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3621 hdd_err("Session close QDF event init failed!");
3622 free_netdev(adapter->dev);
3623 return NULL;
3624 }
3625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303627 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 init_completion(&adapter->linkup_event_var);
3629 init_completion(&adapter->cancel_rem_on_chan_var);
3630 init_completion(&adapter->rem_on_chan_ready_event);
3631 init_completion(&adapter->sta_authorized_event);
3632 init_completion(&adapter->offchannel_tx_event);
3633 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003634 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 init_completion(&adapter->change_country_code);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303636 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637
3638 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003639 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003640 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003641 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003642
Jeff Johnson5505db82017-11-02 21:19:23 -07003643 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003645 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003647 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648
3649 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003650 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003652 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653
Jeff Johnson5505db82017-11-02 21:19:23 -07003654 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 hdd_set_station_ops(adapter->dev);
3657
Jeff Johnson5505db82017-11-02 21:19:23 -07003658 hdd_dev_setup_destructor(dev);
3659 dev->ieee80211_ptr = &adapter->wdev;
3660 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003662 adapter->wdev.netdev = dev;
3663 /* set dev's parent to underlying device */
3664 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 hdd_wmm_init(adapter);
3666 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303667 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 }
3669
3670 return adapter;
3671}
3672
Jeff Johnson9d295242017-08-29 14:39:48 -07003673static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003675 struct net_device *dev = adapter->dev;
3676 int ret;
3677
Dustin Brown491d54b2018-03-14 12:39:11 -07003678 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003680 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003681 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3682
3683 ret = dev_alloc_name(dev, dev->name);
3684 if (ret < 0) {
3685 hdd_err(
3686 "unable to get dev name: %s, err = 0x%x",
3687 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303688 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 }
3690 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003691
3692 ret = register_netdevice(dev);
3693 if (ret) {
3694 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3695 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303696 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 }
3698 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003699 ret = register_netdev(dev);
3700 if (ret) {
3701 hdd_err("register_netdev(%s) failed, err = 0x%x",
3702 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303703 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704 }
3705 }
3706 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3707
Dustin Browne74003f2018-03-14 12:51:58 -07003708 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003709
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303710 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003711}
3712
Krunal Sonib51eec72017-11-20 21:53:01 -08003713QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714{
Krunal Sonib51eec72017-11-20 21:53:01 -08003715 struct hdd_adapter *adapter;
3716 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003717
Krunal Sonib51eec72017-11-20 21:53:01 -08003718 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3719 if (!hdd_ctx) {
3720 hdd_err("Invalid HDD_CTX");
3721 return QDF_STATUS_E_FAILURE;
3722 }
3723
3724 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3725 if (NULL == adapter) {
3726 hdd_err("NULL adapter");
3727 return QDF_STATUS_E_INVAL;
3728 }
3729 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303730 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003731 hdd_debug("session %d opened", adapter->session_id);
3732
3733 return QDF_STATUS_SUCCESS;
3734}
3735
3736QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3737{
3738 struct hdd_adapter *adapter;
3739 struct hdd_context *hdd_ctx;
3740
3741 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3742 if (!hdd_ctx) {
3743 hdd_err("Invalid HDD_CTX");
3744 return QDF_STATUS_E_FAILURE;
3745 }
3746
3747 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003748 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003749 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303750 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 }
3752
3753 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003754 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303755 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 }
3757
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003758 /*
3759 * For NAN Data interface, the close session results in the final
3760 * indication to the userspace
3761 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003762 if (adapter->device_mode == QDF_NDI_MODE)
3763 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 /*
3768 * We can be blocked while waiting for scheduled work to be
3769 * flushed, and the adapter structure can potentially be freed, in
3770 * which case the magic will have been reset. So make sure the
3771 * magic is still good, and hence the adapter structure is still
3772 * valid, before signaling completion
3773 */
3774 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303775 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303777 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778}
3779
Jeff Johnson9d295242017-08-29 14:39:48 -07003780int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781{
Dustin Brownd28772b2017-03-17 14:16:07 -07003782 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783
Dustin Brownd28772b2017-03-17 14:16:07 -07003784 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003785 if (QDF_IS_STATUS_ERROR(status))
3786 return qdf_status_to_os_return(status);
3787
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003788 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003789 if (QDF_IS_STATUS_ERROR(status))
3790 return qdf_status_to_os_return(status);
3791
3792 if (wma_capability_enhanced_mcast_filter())
3793 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3794 else
3795 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003796
3797 return qdf_status_to_os_return(status);
3798}
3799
Jeff Johnson9d295242017-08-29 14:39:48 -07003800int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003801{
3802 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003803 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003804 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003805 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003806
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003807 vdev_id = adapter->session_id;
3808 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003809
3810 /* vdev created sanity check */
3811 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003812 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003813 return -EINVAL;
3814 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003815 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003816
Dustin Brownd28772b2017-03-17 14:16:07 -07003817 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303818 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003819 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003820 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003821 if (QDF_IS_STATUS_ERROR(status)) {
3822 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003823 errno = qdf_status_to_os_return(status);
3824 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003825 }
3826
3827 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303828 status = qdf_wait_for_event_completion(
3829 &adapter->qdf_session_close_event,
3830 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3831 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003832 if (adapter->device_mode == QDF_NDI_MODE)
3833 hdd_ndp_session_end_handler(adapter);
3834 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303835 adapter->session_id = HDD_SESSION_ID_INVALID;
3836 if (QDF_STATUS_E_TIMEOUT != status) {
3837 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003838 errno = -ETIMEDOUT;
3839 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303840 } else if (adapter->qdf_session_close_event.force_set) {
3841 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003842 errno = -EINVAL;
3843 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303844 } else {
3845 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003846 errno = -EINVAL;
3847 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303848 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003849 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003850
Yue Maf9782842017-05-08 12:49:49 -07003851release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003852 /*
3853 * In SSR or driver unloading case, directly exit may cause objects
3854 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003855 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003856 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003857 return errno;
3858
Sandeep Puligillaef415362017-08-30 16:37:13 -07003859 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003860 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003861 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003862 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003863 return errno;
3864 }
3865
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003866 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003867
3868 return 0;
3869}
3870
Krunal Sonib51eec72017-11-20 21:53:01 -08003871static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3872 struct sme_session_params *session_param,
3873 csr_roam_completeCallback callback,
3874 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003875{
Dustin Brownd28772b2017-03-17 14:16:07 -07003876 uint32_t type;
3877 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003878 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003879
3880 /* determine vdev (sub)type */
3881 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303882 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003883 hdd_err("failed to get vdev type: %d", status);
3884 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003886 session_param->sme_session_id = adapter->session_id;
3887 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3888 session_param->type_of_persona = type;
3889 session_param->subtype_of_persona = sub_type;
3890 session_param->session_open_cb = hdd_sme_open_session_callback;
3891 session_param->session_close_cb = hdd_sme_close_session_callback;
3892 session_param->callback = callback;
3893 session_param->callback_ctx = callback_ctx;
3894
3895 return 0;
3896}
3897
3898int hdd_vdev_create(struct hdd_adapter *adapter,
3899 csr_roam_completeCallback callback, void *ctx)
3900{
3901 QDF_STATUS status;
3902 int errno;
3903 struct hdd_context *hdd_ctx;
3904 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003905
3906 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003907
3908 /* do vdev create via objmgr */
3909 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003910 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003911 if (errno) {
3912 hdd_err("failed to create objmgr vdev: %d", errno);
3913 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003915
3916 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303917 status = qdf_event_reset(&adapter->qdf_session_open_event);
3918 if (QDF_STATUS_SUCCESS != status) {
3919 hdd_err("failed to reinit session open event");
3920 return -EINVAL;
3921 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003922 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3923 callback, ctx);
3924 if (errno) {
3925 hdd_err("failed to populating SME params");
3926 goto objmgr_vdev_destroy_procedure;
3927 }
3928
3929 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003930 if (QDF_IS_STATUS_ERROR(status)) {
3931 hdd_err("failed to open sme session: %d", status);
3932 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003933 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003934 }
3935
3936 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303937 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3938 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3939 if (QDF_STATUS_SUCCESS != status) {
3940 if (adapter->qdf_session_open_event.force_set) {
3941 /*
3942 * SSR/PDR has caused shutdown, which has forcefully
3943 * set the event. Return without the closing session.
3944 */
3945 adapter->session_id = HDD_SESSION_ID_INVALID;
3946 hdd_err("Session open event forcefully set");
3947 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303948 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003949
3950 if (QDF_STATUS_E_TIMEOUT == status)
3951 hdd_err("Session failed to open within timeout period");
3952 else
3953 hdd_err("Failed to wait for session open event(status-%d)",
3954 status);
3955 errno = -ETIMEDOUT;
3956 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3957 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003958 }
3959
3960 /* firmware ready for component communication, raise vdev_ready event */
3961 errno = hdd_vdev_ready(adapter);
3962 if (errno) {
3963 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003964 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003965 }
3966
Jeff Johnson1b780e42017-10-31 14:11:45 -07003967 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003968
3969 return 0;
3970
3971 /*
3972 * Due to legacy constraints, we need to destroy in the same order as
3973 * create. So, split error handling into 2 cases to accommodate.
3974 */
3975
Krunal Soni4a020c72017-10-30 20:58:40 -07003976objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003977 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003978
3979 return errno;
3980
Krunal Soni4a020c72017-10-30 20:58:40 -07003981hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003982 QDF_BUG(!hdd_vdev_destroy(adapter));
3983
3984 return errno;
3985}
3986
Jeff Johnson9d295242017-08-29 14:39:48 -07003987QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003988{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003989 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003990 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003991 QDF_STATUS status;
3992 int ret_val;
3993
Dustin Brownd28772b2017-03-17 14:16:07 -07003994 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3995 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3996 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003997 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07004000 status = hdd_register_wext(adapter->dev);
4001 if (QDF_IS_STATUS_ERROR(status)) {
4002 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 goto error_register_wext;
4004 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004005 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006
Jeff Johnsond377dce2017-10-04 10:32:42 -07004007 qdf_mem_set(sta_ctx->conn_info.staId,
4008 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304009
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004010 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004011 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304012 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004014 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 hdd_ctx->config->OperatingChannel;
4016
4017 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004018 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019
4020 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304021 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004022 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 status, status);
4024 goto error_init_txrx;
4025 }
4026
4027 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4028
4029 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304030 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004031 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 status, status);
4033 goto error_wmm_init;
4034 }
4035
4036 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4037
Jeff Johnson1b780e42017-10-31 14:11:45 -07004038 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 WMI_PDEV_PARAM_BURST_ENABLE,
4040 hdd_ctx->config->enableSifsBurst,
4041 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004042 if (ret_val)
4043 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304045 /*
4046 * In case of USB tethering, LRO is disabled. If SSR happened
4047 * during that time, then as part of SSR init, do not enable
4048 * the LRO again. Keep the LRO state same as before SSR.
4049 */
4050 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07004051 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304052
4053 /* rcpi info initialization */
4054 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4055
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304056 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058error_wmm_init:
4059 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4060 hdd_deinit_tx_rx(adapter);
4061error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004062 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07004064 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 return status;
4067}
4068
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304069/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004070 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304071 * @hdd_ctx: global hdd context
4072 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004073 * @rtnl_held: Used to indicate whether or not the caller is holding
4074 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304075 *
4076 * This function De-initializes the STA/P2P/OCB adapter.
4077 *
4078 * Return: None.
4079 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004080static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004081 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004082 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304083{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004084 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304085
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304086 if (adapter->dev) {
4087 if (rtnl_held)
4088 adapter->dev->wireless_handlers = NULL;
4089 else {
4090 rtnl_lock();
4091 adapter->dev->wireless_handlers = NULL;
4092 rtnl_unlock();
4093 }
4094 }
4095
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304096 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4097 hdd_deinit_tx_rx(adapter);
4098 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4099 }
4100
4101 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4102 hdd_wmm_adapter_close(adapter);
4103 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4104 }
4105
Krunal Sonib51eec72017-11-20 21:53:01 -08004106
Dustin Browne74003f2018-03-14 12:51:58 -07004107 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304108}
4109
Krunal Sonib51eec72017-11-20 21:53:01 -08004110void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4111 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 bool rtnl_held)
4113{
Dustin Brown491d54b2018-03-14 12:39:11 -07004114 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304115
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004117 case QDF_STA_MODE:
4118 case QDF_P2P_CLIENT_MODE:
4119 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004120 case QDF_IBSS_MODE:
4121 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004122 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004123 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124 break;
4125 }
4126
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004127 case QDF_SAP_MODE:
4128 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004130 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 break;
4132 }
4133
4134 default:
4135 break;
4136 }
4137
Dustin Browne74003f2018-03-14 12:51:58 -07004138 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139}
4140
Jeff Johnson9d295242017-08-29 14:39:48 -07004141static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004142 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143{
Jeff Johnson5505db82017-11-02 21:19:23 -07004144 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145
4146 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004147 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004149 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 return;
4151 }
4152
Rajeev Kumardca5f812016-02-04 17:28:06 -08004153 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304154
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 /*
4156 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4157 * the driver is almost closed and cannot handle either control
4158 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004159 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4160 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 * is not right. Setting this flag helps hdd_stop() to recognize that
4162 * the interface is closed and restricts any operations on that
4163 */
4164 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4165
4166 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004167 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004168 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004169 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004170 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 /*
4172 * Note that the adapter is no longer valid at this point
4173 * since the memory has been reclaimed
4174 */
4175 }
4176}
4177
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004178static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004179 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180{
Jeff Johnson9d295242017-08-29 14:39:48 -07004181 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004182
Dustin Brown920397d2017-12-13 16:27:50 -08004183 hdd_for_each_adapter(hdd_ctx, adapter) {
4184 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4185 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304186 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 }
Dustin Brown920397d2017-12-13 16:27:50 -08004189
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304190 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004192
Arun Khandavalli2358d522016-05-16 18:05:37 +05304193#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4194/**
4195 * hdd_set_fw_log_params() - Set log parameters to FW
4196 * @hdd_ctx: HDD Context
4197 * @adapter: HDD Adapter
4198 *
4199 * This function set the FW Debug log level based on the INI.
4200 *
4201 * Return: None
4202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004203static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004204 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304205{
4206 uint8_t count = 0, numentries = 0,
4207 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4208 uint32_t value = 0;
4209 int ret;
4210
Arun Khandavallifae92942016-08-01 13:31:08 +05304211 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4212 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004213 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304214 return;
4215 }
4216
Arun Khandavallifae92942016-08-01 13:31:08 +05304217 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304218 hdd_ctx->fw_log_settings.dl_type =
4219 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004220 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304221 WMI_DBGLOG_TYPE,
4222 hdd_ctx->config->enableFwLogType,
4223 DBG_CMD);
4224 if (ret != 0)
4225 hdd_err("Failed to enable FW log type ret %d",
4226 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304227
4228 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304229 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004230 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304231 WMI_DBGLOG_LOG_LEVEL,
4232 hdd_ctx->config->enableFwLogLevel,
4233 DBG_CMD);
4234 if (ret != 0)
4235 hdd_err("Failed to enable FW log level ret %d",
4236 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304237
4238 hdd_string_to_u8_array(
4239 hdd_ctx->config->enableFwModuleLogLevel,
4240 moduleloglevel,
4241 &numentries,
4242 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4243
4244 while (count < numentries) {
4245 /*
4246 * FW module log level input string looks like
4247 * below:
4248 * gFwDebugModuleLoglevel=<FW Module ID>,
4249 * <Log Level>,...
4250 * For example:
4251 * gFwDebugModuleLoglevel=
4252 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4253 * Above input string means :
4254 * For FW module ID 1 enable log level 0
4255 * For FW module ID 2 enable log level 1
4256 * For FW module ID 3 enable log level 2
4257 * For FW module ID 4 enable log level 3
4258 * For FW module ID 5 enable log level 4
4259 * For FW module ID 6 enable log level 5
4260 * For FW module ID 7 enable log level 6
4261 */
4262
Nishank Aggarwale239d962017-03-03 12:26:02 +05304263 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4264 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4265 hdd_err("Module id %d and dbglog level %d input length is more than max",
4266 moduleloglevel[count],
4267 moduleloglevel[count + 1]);
4268 return;
4269 }
4270
4271 value = moduleloglevel[count] << 16;
4272 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004273 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304274 WMI_DBGLOG_MOD_LOG_LEVEL,
4275 value, DBG_CMD);
4276 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304277 hdd_err("Failed to enable FW module log level %d ret %d",
4278 value, ret);
4279
4280 count += 2;
4281 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304282
Arun Khandavalli2358d522016-05-16 18:05:37 +05304283}
4284#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004285static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004286 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304287{
4288}
4289
4290#endif
4291
4292/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004293 * hdd_configure_chain_mask() - programs chain mask to firmware
4294 * @adapter: HDD adapter
4295 *
4296 * Return: 0 on success or errno on failure
4297 */
4298static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4299{
4300 int ret_val;
4301 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4302
4303 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4304 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4305 hdd_ctx->config->txchainmask1x1,
4306 hdd_ctx->config->rxchainmask1x1);
4307 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4308 hdd_ctx->config->dual_mac_feature_disable,
4309 hdd_ctx->config->tx_chain_mask_2g,
4310 hdd_ctx->config->rx_chain_mask_2g);
4311 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4312 hdd_ctx->config->tx_chain_mask_5g,
4313 hdd_ctx->config->rx_chain_mask_5g);
4314
4315 if (hdd_ctx->config->enable2x2) {
4316 hdd_info("2x2 enabled. skip chain mask programming");
4317 return 0;
4318 }
4319
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004320 if (hdd_ctx->config->dual_mac_feature_disable !=
4321 DISABLE_DBS_CXN_AND_SCAN) {
4322 hdd_info("DBS enabled(%d). skip chain mask programming",
4323 hdd_ctx->config->dual_mac_feature_disable);
4324 return 0;
4325 }
4326
Naveen Rawatdacb5032018-02-08 15:23:24 -08004327 if (hdd_ctx->lte_coex_ant_share) {
4328 hdd_info("lte ant sharing enabled. skip chainmask programming");
4329 return 0;
4330 }
4331
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004332 if (hdd_ctx->config->txchainmask1x1) {
4333 ret_val = sme_cli_set_command(adapter->session_id,
4334 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4335 hdd_ctx->config->txchainmask1x1,
4336 PDEV_CMD);
4337 if (ret_val)
4338 goto error;
4339 }
4340
4341 if (hdd_ctx->config->rxchainmask1x1) {
4342 ret_val = sme_cli_set_command(adapter->session_id,
4343 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4344 hdd_ctx->config->rxchainmask1x1,
4345 PDEV_CMD);
4346 if (ret_val)
4347 goto error;
4348 }
4349
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004350 if (hdd_ctx->config->txchainmask1x1 ||
4351 hdd_ctx->config->rxchainmask1x1) {
4352 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4353 return 0;
4354 }
4355
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004356 if (hdd_ctx->config->tx_chain_mask_2g) {
4357 ret_val = sme_cli_set_command(adapter->session_id,
4358 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4359 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4360 if (0 != ret_val)
4361 goto error;
4362 }
4363
4364 if (hdd_ctx->config->rx_chain_mask_2g) {
4365 ret_val = sme_cli_set_command(adapter->session_id,
4366 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4367 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4368 if (0 != ret_val)
4369 goto error;
4370 }
4371
4372 if (hdd_ctx->config->tx_chain_mask_5g) {
4373 ret_val = sme_cli_set_command(adapter->session_id,
4374 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4375 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4376 if (0 != ret_val)
4377 goto error;
4378 }
4379
4380 if (hdd_ctx->config->rx_chain_mask_5g) {
4381 ret_val = sme_cli_set_command(adapter->session_id,
4382 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4383 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4384 if (0 != ret_val)
4385 goto error;
4386 }
4387
4388 return 0;
4389
4390error:
4391 hdd_err("WMI PDEV set param failed %d", ret_val);
4392 return -EINVAL;
4393}
4394
4395/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304396 * hdd_set_fw_params() - Set parameters to firmware
4397 * @adapter: HDD adapter
4398 *
4399 * This function Sets various parameters to fw once the
4400 * adapter is started.
4401 *
4402 * Return: 0 on success or errno on failure
4403 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004404int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304405{
4406 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004407 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304408
Dustin Brownfdf17c12018-03-14 12:55:34 -07004409 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304410
4411 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4412 if (!hdd_ctx)
4413 return -EINVAL;
4414
Dustin Brown732ab9c2017-06-15 13:24:09 -07004415 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4416 hdd_debug("FTM Mode is active; nothing to do");
4417 return 0;
4418 }
4419
Jeff Johnson1b780e42017-10-31 14:11:45 -07004420 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304421 WMI_PDEV_PARAM_DTIM_SYNTH,
4422 hdd_ctx->config->enable_lprx, PDEV_CMD);
4423 if (ret) {
4424 hdd_err("Failed to set LPRx");
4425 goto error;
4426 }
4427
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304428
4429 ret = sme_cli_set_command(
4430 adapter->session_id,
4431 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4432 hdd_ctx->config->enable_dtim_selection_diversity,
4433 PDEV_CMD);
4434 if (ret) {
4435 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4436 goto error;
4437 }
4438
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304439 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004440 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304441 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4442 hdd_ctx->config->upper_brssi_thresh);
4443
Jeff Johnson1b780e42017-10-31 14:11:45 -07004444 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304445 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4446 hdd_ctx->config->lower_brssi_thresh);
4447
Jeff Johnson1b780e42017-10-31 14:11:45 -07004448 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304449 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4450 hdd_ctx->config->enable_dtim_1chrx);
4451 }
4452
Dustin Brown732ab9c2017-06-15 13:24:09 -07004453 if (hdd_ctx->config->enable2x2) {
4454 hdd_debug("configuring 2x2 mode fw params");
4455
Jeff Johnson1b780e42017-10-31 14:11:45 -07004456 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004457 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4458 hdd_ctx->config->enable_cck_tx_fir_override,
4459 PDEV_CMD);
4460 if (ret) {
4461 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4462 ret);
4463 goto error;
4464 }
4465 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304466#define HDD_DTIM_1CHAIN_RX_ID 0x5
4467#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004468 hdd_debug("configuring 1x1 mode fw params");
4469
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004470 /*
4471 * Disable DTIM 1 chain Rx when in 1x1,
4472 * we are passing two value
4473 * as param_id << 29 | param_value.
4474 * Below param_value = 0(disable)
4475 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004476 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004477 WMI_STA_SMPS_PARAM_CMDID,
4478 HDD_DTIM_1CHAIN_RX_ID <<
4479 HDD_SMPS_PARAM_VALUE_S,
4480 VDEV_CMD);
4481 if (ret) {
4482 hdd_err("DTIM 1 chain set failed %d", ret);
4483 goto error;
4484 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304485
Arun Khandavalli2358d522016-05-16 18:05:37 +05304486#undef HDD_DTIM_1CHAIN_RX_ID
4487#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004488
4489 if (hdd_configure_chain_mask(adapter))
4490 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004491 }
4492
Jeff Johnson1b780e42017-10-31 14:11:45 -07004493 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004494 WMI_PDEV_PARAM_HYST_EN,
4495 hdd_ctx->config->enableMemDeepSleep,
4496 PDEV_CMD);
4497 if (ret) {
4498 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4499 goto error;
4500 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304501
Jeff Johnson1b780e42017-10-31 14:11:45 -07004502 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004503 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4504 hdd_ctx->config->rts_profile,
4505 VDEV_CMD);
4506 if (ret) {
4507 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4508 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304509 }
4510
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004511 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4512
Jeff Johnson1b780e42017-10-31 14:11:45 -07004513 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004514 GEN_VDEV_PARAM_AMSDU,
4515 hdd_ctx->config->max_amsdu_num,
4516 GEN_CMD);
4517 if (ret != 0) {
4518 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4519 goto error;
4520 }
4521
Arun Khandavalli2358d522016-05-16 18:05:37 +05304522 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004523 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004524
Arun Khandavalli2358d522016-05-16 18:05:37 +05304525 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304526
Arun Khandavalli2358d522016-05-16 18:05:37 +05304527error:
4528 return -EINVAL;
4529}
4530
Ryan Hsu07495ea2016-01-21 15:25:39 -08004531/**
4532 * hdd_open_adapter() - open and setup the hdd adatper
4533 * @hdd_ctx: global hdd context
4534 * @session_type: type of the interface to be created
4535 * @iface_name: User-visible name of the interface
4536 * @macAddr: MAC address to assign to the interface
4537 * @name_assign_type: the name of assign type of the netdev
4538 * @rtnl_held: the rtnl lock hold flag
4539 *
4540 * This function open and setup the hdd adpater according to the device
4541 * type request, assign the name, the mac address assigned, and then prepared
4542 * the hdd related parameters, queue, lock and ready to start.
4543 *
4544 * Return: the pointer of hdd adapter, otherwise NULL.
4545 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004546struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004548 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004549 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550{
Jeff Johnson9d295242017-08-29 14:39:48 -07004551 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304552 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553
4554 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4555 /*
4556 * Max limit reached on the number of vdevs configured by the
4557 * host. Return error
4558 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304559 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4560 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 return NULL;
4562 }
4563
4564 if (macAddr == NULL) {
4565 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304566 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567 return NULL;
4568 }
4569 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304570 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304571 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4572 " already exists",
4573 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 return NULL;
4575 }
4576
4577 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004578 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579 /* Reset locally administered bit if the device mode is STA */
4580 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304581 hdd_info("locally administered bit reset in sta mode: "
4582 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004583 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004584 case QDF_P2P_CLIENT_MODE:
4585 case QDF_P2P_DEVICE_MODE:
4586 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004587 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304588 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004589 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4590 name_assign_type,
4591 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004592
4593 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304594 hdd_err("failed to allocate adapter for session %d",
4595 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004596 return NULL;
4597 }
4598
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004599 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004601 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304603 else if (QDF_MONITOR_MODE == session_type)
4604 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 else
4606 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4607
4608 adapter->device_mode = session_type;
4609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004610
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 /*
4612 * Workqueue which gets scheduled in IPv4 notification
4613 * callback
4614 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004615 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617
4618#ifdef WLAN_NS_OFFLOAD
4619 /*
4620 * Workqueue which gets scheduled in IPv6
4621 * notification callback.
4622 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004623 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624 hdd_ipv6_notifier_work_queue);
4625#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004626 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004627 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004628 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629
4630 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004631 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304633 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4634 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304635
Ravi Joshi1a292562017-05-18 16:28:54 -07004636 /* Initialize NAN Data Interface */
4637 if (QDF_NDI_MODE == session_type) {
4638 status = hdd_init_nan_data_mode(adapter);
4639 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004640 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004641 }
4642
4643 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004645 case QDF_P2P_GO_MODE:
4646 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004647 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4648 name_assign_type,
4649 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004651 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304652 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653 return NULL;
4654 }
4655
4656 adapter->wdev.iftype =
4657 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004658 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004659 NL80211_IFTYPE_P2P_GO;
4660 adapter->device_mode = session_type;
4661
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004662 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004663 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004665
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004666 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304668 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4669 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304670
4671 /*
4672 * Workqueue which gets scheduled in IPv4 notification
4673 * callback
4674 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004675 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304676 hdd_ipv4_notifier_work_queue);
4677
4678#ifdef WLAN_NS_OFFLOAD
4679 /*
4680 * Workqueue which gets scheduled in IPv6
4681 * notification callback.
4682 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004683 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304684 hdd_ipv6_notifier_work_queue);
4685#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304687 case QDF_FTM_MODE:
4688 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4689 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004690 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304691 if (NULL == adapter) {
4692 hdd_err("Failed to allocate adapter for FTM mode");
4693 return NULL;
4694 }
4695 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4696 adapter->device_mode = session_type;
4697 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004698 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004699 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004700
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304701 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004702 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304703 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304704 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4705 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304706 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004708 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304709 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710 return NULL;
4711 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712
hqueaa33ee2017-05-04 17:56:35 +08004713 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4714
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304715 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004717 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718 }
4719
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304720 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 if (NULL != adapter) {
4722 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4723 adapter = NULL;
4724 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726 return NULL;
4727 }
4728
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304729 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004730 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4731 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 /* Adapter successfully added. Increment the vdev count */
4734 hdd_ctx->current_intf_count++;
4735
Jeff Johnson5880d792016-08-15 13:32:30 -07004736 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 hdd_ctx->current_intf_count);
4738
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004739 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 }
4741
Rajeev Kumardca5f812016-02-04 17:28:06 -08004742 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004743 hdd_err("Interface %s wow debug_fs init failed",
4744 netdev_name(adapter->dev));
4745
4746 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4747 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748
4749 return adapter;
4750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004751err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004752 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304753 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754
4755 return NULL;
4756}
4757
Nirav Shaheb017be2018-02-15 11:20:58 +05304758#ifdef MSM_PLATFORM
4759static inline
4760void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4761{
4762 cancel_work_sync(&hdd_ctx->bus_bw_work);
4763}
4764#else
4765static inline
4766void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4767{
4768}
4769#endif
4770
Jeff Johnson9d295242017-08-29 14:39:48 -07004771QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004772 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004773{
Dustin Brown920397d2017-12-13 16:27:50 -08004774 /*
4775 * Here we are stopping global bus_bw timer & work per adapter.
4776 *
4777 * The reason is to fix one race condition between
4778 * bus bandwidth work and cleaning up an adapter.
4779 * Under some conditions, it is possible for the bus bandwidth
4780 * work to access a particularly destroyed adapter, leading to
4781 * use-after-free.
4782 */
4783 hdd_debug("wait for bus bw work to flush");
4784 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4785 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786
Dustin Brown920397d2017-12-13 16:27:50 -08004787 /* cleanup adapter */
4788 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4789 adapter->device_mode);
4790 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4791 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792
Dustin Brown920397d2017-12-13 16:27:50 -08004793 /* conditionally restart the bw timer */
4794 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795
Dustin Brown920397d2017-12-13 16:27:50 -08004796 /* Adapter removed. Decrement vdev count */
4797 if (hdd_ctx->current_intf_count != 0)
4798 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004799
Dustin Brown920397d2017-12-13 16:27:50 -08004800 /* Fw will take care incase of concurrency */
4801 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802}
4803
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004804/**
4805 * hdd_close_all_adapters - Close all open adapters
4806 * @hdd_ctx: Hdd context
4807 * rtnl_held: True if RTNL lock held
4808 *
4809 * Close all open adapters.
4810 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304811 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004812 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004813QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814{
Dustin Brown920397d2017-12-13 16:27:50 -08004815 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304816 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817
Dustin Brown491d54b2018-03-14 12:39:11 -07004818 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819
4820 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004821 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4822 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304823 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004824 adapter->mac_addr.bytes);
4825 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4826
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304827 /* Adapter removed. Decrement vdev count */
4828 if (hdd_ctx->current_intf_count != 0)
4829 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004830 }
Dustin Brown920397d2017-12-13 16:27:50 -08004831 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004832
Dustin Browne74003f2018-03-14 12:51:58 -07004833 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004834
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304835 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836}
4837
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004838void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304840 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004841 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004842
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004843 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004844 case QDF_STA_MODE:
4845 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004847 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004848 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004849 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 break;
4851 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004852 case QDF_SAP_MODE:
4853 case QDF_P2P_GO_MODE:
4854 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004856 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 break;
4858 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004859 case QDF_FTM_MODE:
4860 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861 default:
4862 /*
4863 * wlan_hdd_reset_prob_rspies should not have been called
4864 * for these kind of devices
4865 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004866 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004867 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 return;
4869 }
4870
Anurag Chouhanc5548422016-02-24 18:33:27 +05304871 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004872 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 updateIE.ieBufferlength = 0;
4874 updateIE.pAdditionIEBuffer = NULL;
4875 updateIE.append = true;
4876 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004877 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304879 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004880 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881 }
4882}
4883
Dustin Browndb2a8be2017-12-20 11:49:56 -08004884QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4885 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304887 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004888 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 union iwreq_data wrqu;
4890 tSirUpdateIE updateIE;
4891 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304892 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893
Dustin Brown491d54b2018-03-14 12:39:11 -07004894 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004896 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304897 wlan_hdd_netif_queue_control(adapter,
4898 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4899 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004900 /*
4901 * if this is the last active connection check & stop the
4902 * opportunistic timer first
4903 */
4904 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4905 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4906 policy_mgr_convert_device_mode_to_qdf_type(
4907 adapter->device_mode), NULL) == 1)) ||
4908 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4909 policy_mgr_check_and_stop_opportunistic_timer(
4910 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004912 case QDF_STA_MODE:
4913 case QDF_P2P_CLIENT_MODE:
4914 case QDF_IBSS_MODE:
4915 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004916 case QDF_NDI_MODE:
4917 if ((QDF_NDI_MODE == adapter->device_mode) ||
4918 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4920 hdd_is_connecting(
4921 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004922 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004923 roam_profile = hdd_roam_profile(adapter);
4924 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004925 if (QDF_NDI_MODE == adapter->device_mode)
4926 qdf_ret_status = sme_roam_disconnect(
4927 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004928 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004929 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004930 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004931 eCSR_BSS_TYPE_START_IBSS)
4932 qdf_ret_status = sme_roam_disconnect(
4933 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004934 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004935 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004936 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004937 qdf_ret_status =
4938 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004939 hdd_debug("Send disconnected event to userspace");
4940 wlan_hdd_cfg80211_indicate_disconnect(
4941 adapter->dev, true,
4942 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004943 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004944 qdf_ret_status = sme_roam_disconnect(
4945 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004946 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004947 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004948 /* success implies disconnect command got
4949 * queued up successfully
4950 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004951 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4952 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004953 rc = wait_for_completion_timeout(
4954 &adapter->disconnect_comp_var,
4955 msecs_to_jiffies
4956 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004957 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004958 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004959 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004960 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4961 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004962 memset(&wrqu, '\0', sizeof(wrqu));
4963 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4964 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4965 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4966 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304967 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004968 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004969
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304970 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304971 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972
4973#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004974 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004975#endif
4976
4977 hdd_deregister_tx_flow_control(adapter);
4978
4979#ifdef WLAN_NS_OFFLOAD
4980#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004981 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982#endif
4983#endif
4984
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304985 if (adapter->device_mode == QDF_STA_MODE)
4986 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4987 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004988
4989 if (wlan_hdd_try_disconnect(adapter)) {
4990 hdd_err("Error: Can't disconnect adapter");
4991 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08004992 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08004993
Himanshu Agarwalb229a142017-12-21 10:16:45 +05304994 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 break;
4996
Rajeev Kumar3b906202018-02-01 10:55:14 -08004997 case QDF_MONITOR_MODE:
4998 wlan_hdd_scan_abort(adapter);
4999 hdd_deregister_tx_flow_control(adapter);
5000 hdd_vdev_destroy(adapter);
5001 break;
5002
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005003 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005004 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305005 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305006 sap_config = &adapter->session.ap.sap_config;
5007 if (sap_config)
5008 wlansap_reset_sap_config_add_ie(sap_config,
5009 eUPDATE_IE_ALL);
Govind Singh1dab23b2017-08-12 13:31:00 +05305010 hdd_ipa_flush(hdd_ctx);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005011 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005012
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005013 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005014 if (QDF_SAP_MODE == adapter->device_mode) {
5015 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5016 cds_flush_delayed_work(
5017 &adapter->acs_pending_work);
5018 clear_bit(ACS_PENDING, &adapter->event_flags);
5019 }
5020 }
Krunal Soni22208392017-09-29 18:10:34 -07005021 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 /* Any softap specific cleanup here... */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005024 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005025 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5027
5028 hdd_deregister_tx_flow_control(adapter);
5029
Kapil Guptac1224bf2017-06-22 21:22:40 +05305030 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 mutex_lock(&hdd_ctx->sap_lock);
5032 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305033 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305034 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035
5036 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005037 status = wlansap_stop_bss(
5038 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305040 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005041 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305043 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305044 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305045 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305046 qdf_wait_for_event_completion(
5047 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005048 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049
Anurag Chouhance0dc992016-02-16 18:18:03 +05305050 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005051 hdd_err("failure waiting for wlansap_stop_bss %d",
5052 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053 }
5054 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005055 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 }
5057 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005058 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5059 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005060 adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305061 hdd_start_green_ap_state_mc(hdd_ctx,
5062 adapter->device_mode,
5063 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064
Anurag Chouhanc5548422016-02-24 18:33:27 +05305065 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005066 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005067 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 updateIE.ieBufferlength = 0;
5069 updateIE.pAdditionIEBuffer = NULL;
5070 updateIE.append = false;
5071 updateIE.notify = false;
5072 /* Probe bcn reset */
5073 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5074 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305075 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005076 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 }
5078 /* Assoc resp reset */
5079 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5080 &updateIE,
5081 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305082 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005083 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 }
5085 /* Reset WNI_CFG_PROBE_RSP Flags */
5086 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005088 qdf_mem_free(adapter->session.ap.beacon);
5089 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305090 /*
5091 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5092 */
5093 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5094 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5095
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305096#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005097 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305098#endif
5099
5100#ifdef WLAN_NS_OFFLOAD
5101#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005102 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305103#endif
5104#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005105
5106 hdd_vdev_destroy(adapter);
5107
Krunal Sonib51eec72017-11-20 21:53:01 -08005108 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005110 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005111 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005112 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005113 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005114 hdd_deregister_tx_flow_control(adapter);
5115 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 break;
5117 default:
5118 break;
5119 }
5120
Dustin Brown04348372017-12-14 16:13:39 -08005121 if (adapter->scan_info.default_scan_ies) {
5122 qdf_mem_free(adapter->scan_info.default_scan_ies);
5123 adapter->scan_info.default_scan_ies = NULL;
5124 }
5125
Dustin Browne74003f2018-03-14 12:51:58 -07005126 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005127
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305128 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005129}
5130
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305131/**
5132 * hdd_deinit_all_adapters - deinit all adapters
5133 * @hdd_ctx: HDD context
5134 * @rtnl_held: True if RTNL lock held
5135 *
5136 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005137void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305138{
Jeff Johnson9d295242017-08-29 14:39:48 -07005139 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305140
Dustin Brown491d54b2018-03-14 12:39:11 -07005141 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305142
Dustin Brown920397d2017-12-13 16:27:50 -08005143 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305144 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305145
Dustin Browne74003f2018-03-14 12:51:58 -07005146 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305147}
5148
Dustin Browndb2a8be2017-12-20 11:49:56 -08005149QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005150{
Jeff Johnson9d295242017-08-29 14:39:48 -07005151 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152
Dustin Brown491d54b2018-03-14 12:39:11 -07005153 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305155 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5156
Dustin Brown920397d2017-12-13 16:27:50 -08005157 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005158 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159
Dustin Browne74003f2018-03-14 12:51:58 -07005160 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305162 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163}
5164
Paul Zhang84fa9382017-11-10 21:18:21 +08005165static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5166 struct hdd_adapter *adapter)
5167{
5168 switch (adapter->device_mode) {
5169 case QDF_STA_MODE:
5170 case QDF_P2P_CLIENT_MODE:
5171 case QDF_IBSS_MODE:
5172 case QDF_P2P_DEVICE_MODE:
5173 case QDF_NDI_MODE:
5174 wlan_hdd_scan_abort(adapter);
5175 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5176 if (adapter->device_mode == QDF_STA_MODE)
5177 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5178 adapter->dev);
5179 break;
5180 case QDF_P2P_GO_MODE:
5181 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5182 break;
5183 case QDF_SAP_MODE:
5184 wlan_hdd_undo_acs(adapter);
5185 break;
5186 default:
5187 break;
5188 }
5189}
5190
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005191QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192{
Jeff Johnson9d295242017-08-29 14:39:48 -07005193 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005194 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005195 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005196 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197
Dustin Brown491d54b2018-03-14 12:39:11 -07005198 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305200 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5201
Dustin Brown920397d2017-12-13 16:27:50 -08005202 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005203 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5204 hdd_device_mode_to_string(adapter->device_mode),
5205 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305206
5207 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005208 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305209 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005210 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005211 adapter->session.station.hdd_reassoc_scenario = false;
5212 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305213
Arun Khandavallicc544b32017-01-30 19:52:16 +05305214 if (hdd_ctx->config->sap_internal_restart &&
5215 adapter->device_mode == QDF_SAP_MODE) {
5216 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305217 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305218 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005219 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005220 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005221 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005222 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5223 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305224 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305225 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005227 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228
Paul Zhang84fa9382017-11-10 21:18:21 +08005229 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230
5231 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005232 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005233 adapter->device_mode, adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305234 hdd_start_green_ap_state_mc(hdd_ctx, adapter->device_mode,
5235 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5237 hdd_wmm_adapter_close(adapter);
5238 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5239 }
5240
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305241 if (adapter->device_mode == QDF_STA_MODE)
5242 hdd_clear_fils_connection_info(adapter);
5243
Wu Gao3545e642017-07-14 19:24:41 +08005244 if (adapter->device_mode == QDF_SAP_MODE) {
5245 /*
5246 * If adapter is SAP, set session ID to invalid
5247 * since SAP session will be cleanup during SSR.
5248 */
Wu Gao36717432016-11-21 15:09:48 +08005249 wlansap_set_invalid_session(
5250 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5251
Wu Gao3545e642017-07-14 19:24:41 +08005252 wlansap_cleanup_cac_timer(
5253 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5254 }
5255
Yue Ma42654682018-01-11 16:55:24 -08005256 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005257 if (adapter->device_mode == QDF_STA_MODE ||
5258 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005259 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005260 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005261 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005262
5263 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5264 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005265 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5266 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5267 if (adapter->sta_info[sta_id].in_use) {
5268 hdd_debug("[SSR] deregister STA with ID %d",
5269 sta_id);
5270 hdd_softap_deregister_sta(adapter,
5271 sta_id);
5272 adapter->sta_info[sta_id].in_use = 0;
5273 }
5274 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005275 }
5276
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005277 hdd_softap_deinit_tx_rx(adapter);
5278
Yue Maf9782842017-05-08 12:49:49 -07005279 /* Destroy vdev which will be recreated during reinit. */
5280 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281 }
5282
Dustin Browne74003f2018-03-14 12:51:58 -07005283 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305285 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286}
5287
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005288bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305289{
Dustin Brown920397d2017-12-13 16:27:50 -08005290 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305291 bool close_modules = true;
5292
Arun Khandavalliba479c42017-07-26 21:29:40 +05305293 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5294 hdd_info("FTM mode, don't close the module");
5295 return false;
5296 }
5297
Dustin Brown920397d2017-12-13 16:27:50 -08005298 hdd_for_each_adapter(hdd_ctx, adapter) {
5299 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5300 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005301 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305302 close_modules = false;
5303 break;
5304 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305305 }
5306
5307 return close_modules;
5308}
5309
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305310bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305311{
5312 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5313 return true;
5314 else
5315 return false;
5316}
5317
Anurag Chouhanc4092922016-09-08 15:56:11 +05305318#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005319 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305320struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5321 struct ieee80211_channel *channel,
5322 const u8 *bssid, const u8 *ssid,
5323 size_t ssid_len)
5324{
5325 return cfg80211_get_bss(wiphy, channel, bssid,
5326 ssid, ssid_len,
5327 WLAN_CAPABILITY_ESS,
5328 WLAN_CAPABILITY_ESS);
5329}
5330#else
5331struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5332 struct ieee80211_channel *channel,
5333 const u8 *bssid, const u8 *ssid,
5334 size_t ssid_len)
5335{
5336 return cfg80211_get_bss(wiphy, channel, bssid,
5337 ssid, ssid_len,
5338 IEEE80211_BSS_TYPE_ESS,
5339 IEEE80211_PRIVACY_ANY);
5340}
5341#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305342
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305343#if defined CFG80211_CONNECT_BSS || \
5344 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305345#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305346 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305347/**
5348 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5349 * @timeout_reason: reason for connect timeout
5350 *
5351 * This function is used to convert host timeout
5352 * reason enum to kernel specific enum.
5353 *
5354 * Return: nl timeout enum
5355 */
5356static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5357 tSirResultCodes timeout_reason)
5358{
5359 switch (timeout_reason) {
5360 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5361 return NL80211_TIMEOUT_SCAN;
5362 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5363 return NL80211_TIMEOUT_AUTH;
5364 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5365 return NL80211_TIMEOUT_ASSOC;
5366 default:
5367 return NL80211_TIMEOUT_UNSPECIFIED;
5368 }
5369}
5370
5371/**
5372 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5373 * @dev: network device
5374 * @bssid: bssid to which we want to associate
5375 * @timeout_reason: reason for connect timeout
5376 *
5377 * This API is used to send connection timeout reason to supplicant
5378 *
5379 * Return: void
5380 */
5381static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5382 const u8 *bssid,
5383 tSirResultCodes timeout_reason)
5384{
5385 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005386
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305387 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5388
5389 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5390 nl_timeout_reason);
5391}
5392
5393/**
5394 * __hdd_connect_bss() - API to send connection status to supplicant
5395 * @dev: network device
5396 * @bssid: bssid to which we want to associate
5397 * @req_ie: Request Information Element
5398 * @req_ie_len: len of the req IE
5399 * @resp_ie: Response IE
5400 * @resp_ie_len: len of ht response IE
5401 * @status: status
5402 * @gfp: Kernel Flag
5403 * @timeout_reason: reason for connect timeout
5404 *
5405 * Return: void
5406 */
5407static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5408 struct cfg80211_bss *bss, const u8 *req_ie,
5409 size_t req_ie_len, const u8 *resp_ie,
5410 size_t resp_ie_len, int status, gfp_t gfp,
5411 tSirResultCodes timeout_reason)
5412{
5413 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005414
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305415 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5416
5417 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5418 resp_ie, resp_ie_len, status, gfp,
5419 nl_timeout_reason);
5420}
5421#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305422#if defined CFG80211_CONNECT_TIMEOUT || \
5423 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305424static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5425 const u8 *bssid,
5426 tSirResultCodes timeout_reason)
5427{
5428 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5429}
5430#endif
5431
5432static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5433 struct cfg80211_bss *bss, const u8 *req_ie,
5434 size_t req_ie_len, const u8 *resp_ie,
5435 size_t resp_ie_len, int status, gfp_t gfp,
5436 tSirResultCodes timeout_reason)
5437{
5438 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5439 resp_ie, resp_ie_len, status, gfp);
5440}
5441#endif
5442
Abhishek Singha84d3952016-09-13 13:45:05 +05305443/**
5444 * hdd_connect_bss() - API to send connection status to supplicant
5445 * @dev: network device
5446 * @bssid: bssid to which we want to associate
5447 * @req_ie: Request Information Element
5448 * @req_ie_len: len of the req IE
5449 * @resp_ie: Response IE
5450 * @resp_ie_len: len of ht response IE
5451 * @status: status
5452 * @gfp: Kernel Flag
5453 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305454 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305455 *
5456 * The API is a wrapper to send connection status to supplicant
5457 *
5458 * Return: Void
5459 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305460#if defined CFG80211_CONNECT_TIMEOUT || \
5461 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305462static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5463 struct cfg80211_bss *bss, const u8 *req_ie,
5464 size_t req_ie_len, const u8 *resp_ie,
5465 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305466 bool connect_timeout,
5467 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305468{
5469 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305470 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305471 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305472 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5473 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305474}
5475#else
5476static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5477 struct cfg80211_bss *bss, const u8 *req_ie,
5478 size_t req_ie_len, const u8 *resp_ie,
5479 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305480 bool connect_timeout,
5481 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305482{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305483 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5484 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305485}
5486#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305487
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305488#if defined(WLAN_FEATURE_FILS_SK)
5489#if defined(CFG80211_CONNECT_DONE) || \
5490 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5491#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5492 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305493/**
5494 * hdd_populate_fils_params() - Populate FILS keys to connect response
5495 * @fils_params: connect response to supplicant
5496 * @fils_kek: FILS kek
5497 * @fils_kek_len: FILS kek length
5498 * @pmk: FILS PMK
5499 * @pmk_len: FILS PMK length
5500 * @pmkid: PMKID
5501 * @fils_seq_num: FILS Seq number
5502 *
5503 * Return: None
5504 */
5505static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5506 *fils_params, const uint8_t *fils_kek,
5507 size_t fils_kek_len, const uint8_t *pmk,
5508 size_t pmk_len, const uint8_t *pmkid,
5509 uint16_t fils_seq_num)
5510{
5511 /* Increament seq number to be used for next FILS */
5512 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5513 fils_params->update_erp_next_seq_num = true;
5514 fils_params->fils_kek = fils_kek;
5515 fils_params->fils_kek_len = fils_kek_len;
5516 fils_params->pmk = pmk;
5517 fils_params->pmk_len = pmk_len;
5518 fils_params->pmkid = pmkid;
5519}
5520#else
5521static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5522 *fils_params, const uint8_t
5523 *fils_kek, size_t fils_kek_len,
5524 const uint8_t *pmk, size_t pmk_len,
5525 const uint8_t *pmkid,
5526 uint16_t fils_seq_num)
5527{ }
5528#endif
5529
Jeff Johnson172237b2017-11-07 15:32:59 -08005530void hdd_update_hlp_info(struct net_device *dev,
5531 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305532{
5533 struct sk_buff *skb;
5534 uint16_t skb_len;
5535 struct llc_snap_hdr_t *llc_hdr;
5536 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305537 uint8_t *hlp_data;
5538 uint16_t hlp_data_len;
5539 struct fils_join_rsp_params *roam_fils_params
5540 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305541 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5542
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305543 if (!roam_fils_params) {
5544 hdd_err("FILS Roam Param NULL");
5545 return;
5546 }
5547
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005548 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305549 hdd_err("FILS HLP Data NULL, len %d",
5550 roam_fils_params->hlp_data_len);
5551 return;
5552 }
5553
5554 hlp_data = roam_fils_params->hlp_data;
5555 hlp_data_len = roam_fils_params->hlp_data_len;
5556
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305557 /* Calculate skb length */
5558 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5559 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5560 if (skb == NULL) {
5561 hdd_err("HLP packet nbuf alloc fails");
5562 return;
5563 }
5564
5565 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5566 QDF_MAC_ADDR_SIZE);
5567 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5568 QDF_MAC_ADDR_SIZE);
5569
5570 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5571 if (IS_SNAP(llc_hdr)) {
5572 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5573 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5574 }
5575
5576 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5577
5578 /*
5579 * This HLP packet is formed from HLP info encapsulated
5580 * in assoc response frame which is AEAD encrypted.
5581 * Hence, this checksum validation can be set unnecessary.
5582 * i.e. network layer need not worry about checksum.
5583 */
5584 skb->ip_summed = CHECKSUM_UNNECESSARY;
5585
5586 status = hdd_rx_packet_cbk(padapter, skb);
5587 if (QDF_IS_STATUS_ERROR(status)) {
5588 hdd_err("Sending HLP packet fails");
5589 return;
5590 }
5591 hdd_debug("send HLP packet to netif successfully");
5592}
5593
5594/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305595 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5596 * @dev: network device
5597 * @bssid: bssid to which we want to associate
5598 * @bss: cfg80211 bss info
5599 * @roam_info: information about connected bss
5600 * @req_ie: Request Information Element
5601 * @req_ie_len: len of the req IE
5602 * @resp_ie: Response IE
5603 * @resp_ie_len: len of ht response IE
5604 * @status: status
5605 * @gfp: allocation flags
5606 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5607 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305608 *
5609 * This API is used as wrapper to send FILS key/sequence number
5610 * params etc. to supplicant in case of FILS connection
5611 *
5612 * Return: None
5613 */
5614static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005615 struct cfg80211_bss *bss,
5616 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305617 const u8 *req_ie, size_t req_ie_len,
5618 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005619 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305620 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305621{
5622 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305623 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5624 struct fils_join_rsp_params *roam_fils_params =
5625 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005626
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305627 qdf_mem_zero(&fils_params, sizeof(fils_params));
5628
5629 if (!roam_fils_params) {
5630 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5631 } else {
5632 fils_params.status = status;
5633 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005634 fils_params.timeout_reason =
5635 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305636 fils_params.req_ie = req_ie;
5637 fils_params.req_ie_len = req_ie_len;
5638 fils_params.resp_ie = resp_ie;
5639 fils_params.resp_ie_len = resp_ie_len;
5640 fils_params.bss = bss;
5641 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5642 roam_fils_params->kek_len,
5643 roam_fils_params->fils_pmk,
5644 roam_fils_params->fils_pmk_len,
5645 roam_fils_params->fils_pmkid,
5646 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305647 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305648 }
5649 hdd_debug("FILS indicate connect status %d seq no %d",
5650 fils_params.status,
5651 fils_params.fils_erp_next_seq_num);
5652
5653 cfg80211_connect_done(dev, &fils_params, gfp);
5654
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305655 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305656 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305657
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305658 /* Clear all the FILS key info */
5659 if (roam_fils_params && roam_fils_params->fils_pmk)
5660 qdf_mem_free(roam_fils_params->fils_pmk);
5661 if (roam_fils_params)
5662 qdf_mem_free(roam_fils_params);
5663 roam_info->fils_join_rsp = NULL;
5664}
5665#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005666static inline void
5667hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005668 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005669 const u8 *req_ie, size_t req_ie_len,
5670 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5671 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305672 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305673{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305674#endif
5675#endif
5676
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305677#if defined(WLAN_FEATURE_FILS_SK) && \
5678 (defined(CFG80211_CONNECT_DONE) || \
5679 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305680/**
5681 * hdd_fils_update_connect_results() - API to send fils connection status to
5682 * supplicant.
5683 * @dev: network device
5684 * @bssid: bssid to which we want to associate
5685 * @bss: cfg80211 bss info
5686 * @roam_info: information about connected bss
5687 * @req_ie: Request Information Element
5688 * @req_ie_len: len of the req IE
5689 * @resp_ie: Response IE
5690 * @resp_ie_len: len of ht response IE
5691 * @status: status
5692 * @gfp: allocation flags
5693 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5694 * @timeout_reason: reason for connect timeout
5695 *
5696 * The API is a wrapper to send connection status to supplicant
5697 *
5698 * Return: 0 if success else failure
5699 */
5700static int hdd_fils_update_connect_results(struct net_device *dev,
5701 const u8 *bssid,
5702 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005703 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305704 size_t req_ie_len, const u8 *resp_ie,
5705 size_t resp_ie_len, u16 status, gfp_t gfp,
5706 bool connect_timeout,
5707 tSirResultCodes timeout_reason)
5708{
Dustin Brown491d54b2018-03-14 12:39:11 -07005709 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305710 if (!roam_info || !roam_info->is_fils_connection)
5711 return -EINVAL;
5712
5713 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5714 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305715 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305716 return 0;
5717}
5718#else
5719static inline int hdd_fils_update_connect_results(struct net_device *dev,
5720 const u8 *bssid,
5721 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005722 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305723 size_t req_ie_len, const u8 *resp_ie,
5724 size_t resp_ie_len, u16 status, gfp_t gfp,
5725 bool connect_timeout,
5726 tSirResultCodes timeout_reason)
5727{
5728 return -EINVAL;
5729}
5730#endif
5731
Anurag Chouhanc4092922016-09-08 15:56:11 +05305732/**
5733 * hdd_connect_result() - API to send connection status to supplicant
5734 * @dev: network device
5735 * @bssid: bssid to which we want to associate
5736 * @roam_info: information about connected bss
5737 * @req_ie: Request Information Element
5738 * @req_ie_len: len of the req IE
5739 * @resp_ie: Response IE
5740 * @resp_ie_len: len of ht response IE
5741 * @status: status
5742 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305743 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305744 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305745 *
5746 * The API is a wrapper to send connection status to supplicant
5747 * and allow runtime suspend
5748 *
5749 * Return: Void
5750 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305751void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005752 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305753 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305754 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305755 bool connect_timeout,
5756 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305757{
Jeff Johnson9d295242017-08-29 14:39:48 -07005758 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305759 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005760 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305761
5762 if (WLAN_STATUS_SUCCESS == status) {
5763 struct ieee80211_channel *chan;
5764 int freq;
5765 int chan_no = roam_info->pBssDesc->channelId;
5766
5767 if (chan_no <= 14)
5768 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005769 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305770 else
5771 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005772 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305773
5774 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5775 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5776 roam_info->u.pConnectedProfile->SSID.ssId,
5777 roam_info->u.pConnectedProfile->SSID.length);
5778 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305779
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305780 if (hdd_fils_update_connect_results(dev, bssid, bss,
5781 roam_info, req_ie, req_ie_len, resp_ie,
5782 resp_ie_len, status, gfp, connect_timeout,
5783 timeout_reason) != 0) {
5784 hdd_connect_bss(dev, bssid, bss, req_ie,
5785 req_ie_len, resp_ie, resp_ie_len,
5786 status, gfp, connect_timeout, timeout_reason);
5787 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305788
Jingxiang Geb49aa302018-01-17 20:54:15 +08005789 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005790 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305791}
5792#else
5793void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005794 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305795 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305796 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305797 bool connect_timeout,
5798 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305799{
Jeff Johnson9d295242017-08-29 14:39:48 -07005800 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005801 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305802
Anurag Chouhanc4092922016-09-08 15:56:11 +05305803 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5804 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005805
Jingxiang Geb49aa302018-01-17 20:54:15 +08005806 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005807 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305808}
5809#endif
5810
5811
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005812QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005813{
Jeff Johnson9d295242017-08-29 14:39:48 -07005814 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005815#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005816 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005817#endif
5818 eConnectionState connState;
5819
Dustin Brown491d54b2018-03-14 12:39:11 -07005820 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005821
Dustin Brown920397d2017-12-13 16:27:50 -08005822 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305823 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005824 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305825
Yue Ma42654682018-01-11 16:55:24 -08005826 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5827 hdd_device_mode_to_string(adapter->device_mode),
5828 adapter->device_mode);
5829
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830 hdd_wmm_init(adapter);
5831
5832 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005833 case QDF_STA_MODE:
5834 case QDF_P2P_CLIENT_MODE:
5835 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005836
5837 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5838 ->conn_info.connState;
5839
Krunal Sonib51eec72017-11-20 21:53:01 -08005840 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005841 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005842 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005844 /* Indicate disconnect event to supplicant
5845 * if associated previously
5846 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005847 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005848 eConnectionState_IbssConnected == connState ||
5849 eConnectionState_NotConnected == connState ||
5850 eConnectionState_IbssDisconnected == connState ||
5851 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005853
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005854 memset(&wrqu, '\0', sizeof(wrqu));
5855 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5856 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5857 wireless_send_event(adapter->dev, SIOCGIWAP,
5858 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005859 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005860 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861
5862 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305863 wlan_hdd_cfg80211_indicate_disconnect(
5864 adapter->dev, false,
5865 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866 } else if (eConnectionState_Connecting == connState) {
5867 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005868 * Indicate connect failure to supplicant if we
5869 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305871 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305872 NULL, 0, NULL, 0,
5873 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005874 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875 }
5876
5877 hdd_register_tx_flow_control(adapter,
5878 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005879 hdd_tx_resume_cb,
5880 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005881
5882 break;
5883
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005884 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005885 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005886 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005888 break;
5889
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005890 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005892 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005893 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5894#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005895 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005896 /* event supplicant to restart */
5897 cfg80211_del_sta(adapter->dev,
5898 (const u8 *)&bcastMac.bytes[0],
5899 GFP_KERNEL);
5900#endif
5901 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305902 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005903 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305904 hdd_set_mon_rx_cb(adapter->dev);
5905 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5906 adapter->mon_bandwidth);
5907 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005908 default:
5909 break;
5910 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005911 /*
5912 * Action frame registered in one adapter which will
5913 * applicable to all interfaces
5914 */
5915 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005916 }
5917
Dustin Browne74003f2018-03-14 12:51:58 -07005918 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005919
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305920 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005921}
5922
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005923QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005924 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305926 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005927 qdf_list_node_t *node;
5928
5929 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005930
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005931 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005932 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005933 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005934
5935 if (QDF_IS_STATUS_ERROR(status))
5936 return status;
5937
5938 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5939
5940 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941}
5942
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005943QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005944 struct hdd_adapter *current_adapter,
5945 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305947 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005948 qdf_list_node_t *node;
5949
5950 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005951
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005952 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07005953 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08005954 &current_adapter->node,
5955 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005956 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005957
5958 if (QDF_IS_STATUS_ERROR(status))
5959 return status;
5960
5961 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5962
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963 return status;
5964}
5965
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005966QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005967 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305969 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005970
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005971 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005972 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005973 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005975 return status;
5976}
5977
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005978QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005979 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305981 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005982 qdf_list_node_t *node;
5983
5984 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005985
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005986 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005987 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08005988 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08005989
5990 if (QDF_IS_STATUS_ERROR(status))
5991 return status;
5992
5993 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
5994
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005995 return status;
5996}
5997
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005998QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005999 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006000{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306001 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006002
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006003 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006004 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006005 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007 return status;
6008}
6009
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006010QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006011 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006012{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306013 QDF_STATUS status;
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);
Dustin Brown920397d2017-12-13 16:27:50 -08006016 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006017 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006019 return status;
6020}
6021
Jeff Johnson9d295242017-08-29 14:39:48 -07006022struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006023 tSirMacAddr macAddr)
6024{
Jeff Johnson9d295242017-08-29 14:39:48 -07006025 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026
Dustin Brown920397d2017-12-13 16:27:50 -08006027 hdd_for_each_adapter(hdd_ctx, adapter) {
6028 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6029 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006031 }
6032
6033 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006034}
6035
Jeff Johnson9d295242017-08-29 14:39:48 -07006036struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037 uint32_t vdev_id)
6038{
Jeff Johnson9d295242017-08-29 14:39:48 -07006039 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006040
Dustin Brown920397d2017-12-13 16:27:50 -08006041 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006042 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006043 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 }
6045
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006046 return NULL;
6047}
6048
Abhishek Singh7996eb72015-12-30 17:24:02 +05306049/**
6050 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6051 * the sessionid
6052 * @hdd_ctx: hdd context.
6053 * @sme_session_id: sme session is for the adapter to get.
6054 *
6055 * This function is used to get the adapter with provided session id
6056 *
6057 * Return: adapter pointer if found
6058 *
6059 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006060struct hdd_adapter *
6061hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6062 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306063{
Jeff Johnson9d295242017-08-29 14:39:48 -07006064 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306065
Dustin Brown920397d2017-12-13 16:27:50 -08006066 hdd_for_each_adapter(hdd_ctx, adapter) {
6067 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306068 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306069 }
Dustin Brown920397d2017-12-13 16:27:50 -08006070
Abhishek Singh7996eb72015-12-30 17:24:02 +05306071 return NULL;
6072}
6073
Jeff Johnson9d295242017-08-29 14:39:48 -07006074struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006075 const char *iface_name)
6076{
Jeff Johnson9d295242017-08-29 14:39:48 -07006077 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006078
Dustin Brown920397d2017-12-13 16:27:50 -08006079 hdd_for_each_adapter(hdd_ctx, adapter) {
6080 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006081 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006082 }
Dustin Brown920397d2017-12-13 16:27:50 -08006083
Naveen Rawat4edb6822017-04-12 10:09:17 -07006084 return NULL;
6085}
6086
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006087/**
6088 * hdd_get_adapter() - to get adapter matching the mode
6089 * @hdd_ctx: hdd context
6090 * @mode: adapter mode
6091 *
6092 * This routine will return the pointer to adapter matching
6093 * with the passed mode.
6094 *
6095 * Return: pointer to adapter or null
6096 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006097struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006098 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099{
Jeff Johnson9d295242017-08-29 14:39:48 -07006100 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101
Dustin Brown920397d2017-12-13 16:27:50 -08006102 hdd_for_each_adapter(hdd_ctx, adapter) {
6103 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006104 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 }
6106
6107 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006108}
6109
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306110enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6111{
6112 struct hdd_context *hdd_ctx;
6113 struct hdd_adapter *adapter;
6114
6115 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6116 if (!hdd_ctx) {
6117 hdd_err("Invalid HDD context");
6118 return QDF_MAX_NO_OF_MODE;
6119 }
6120
6121 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6122 if (!adapter) {
6123 hdd_err("Invalid HDD adapter");
6124 return QDF_MAX_NO_OF_MODE;
6125 }
6126
6127 return adapter->device_mode;
6128}
6129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006130/**
6131 * hdd_get_operating_channel() - return operating channel of the device mode
6132 * @hdd_ctx: Pointer to the HDD context.
6133 * @mode: Device mode for which operating channel is required.
6134 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006135 * QDF_STA_MODE,
6136 * QDF_P2P_CLIENT_MODE,
6137 * QDF_SAP_MODE,
6138 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139 *
6140 * This API returns the operating channel of the requested device mode
6141 *
6142 * Return: channel number. "0" id the requested device is not found OR it is
6143 * not connected.
6144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006145uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006146 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147{
Jeff Johnson9d295242017-08-29 14:39:48 -07006148 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149 uint8_t operatingChannel = 0;
6150
Dustin Brown920397d2017-12-13 16:27:50 -08006151 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152 if (mode == adapter->device_mode) {
6153 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006154 case QDF_STA_MODE:
6155 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156 if (hdd_conn_is_connected
6157 (WLAN_HDD_GET_STATION_CTX_PTR
6158 (adapter))) {
6159 operatingChannel =
6160 (WLAN_HDD_GET_STATION_CTX_PTR
6161 (adapter))->conn_info.
6162 operationChannel;
6163 }
6164 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006165 case QDF_SAP_MODE:
6166 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 /* softap connection info */
6168 if (test_bit
6169 (SOFTAP_BSS_STARTED,
6170 &adapter->event_flags))
6171 operatingChannel =
6172 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006173 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006174 break;
6175 default:
6176 break;
6177 }
6178
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006179 /* Found the device of interest. break the loop */
6180 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006181 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006182 }
Dustin Brown920397d2017-12-13 16:27:50 -08006183
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006184 return operatingChannel;
6185}
6186
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006187static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006188 hdd_ctx)
6189{
Jeff Johnson9d295242017-08-29 14:39:48 -07006190 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006191
Dustin Brown491d54b2018-03-14 12:39:11 -07006192 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006193
Dustin Brown920397d2017-12-13 16:27:50 -08006194 hdd_for_each_adapter(hdd_ctx, adapter) {
6195 if (adapter->device_mode == QDF_STA_MODE ||
6196 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6197 adapter->device_mode == QDF_IBSS_MODE ||
6198 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6199 adapter->device_mode == QDF_SAP_MODE ||
6200 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 wlan_hdd_cfg80211_deregister_frames(adapter);
6202 hdd_unregister_wext(adapter->dev);
6203 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 }
6205
Dustin Browne74003f2018-03-14 12:51:58 -07006206 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006207
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306208 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209}
6210
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006211QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006212{
Jeff Johnson9d295242017-08-29 14:39:48 -07006213 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006214
Dustin Brown491d54b2018-03-14 12:39:11 -07006215 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216
Dustin Brown920397d2017-12-13 16:27:50 -08006217 hdd_for_each_adapter(hdd_ctx, adapter) {
6218 if (adapter->device_mode == QDF_STA_MODE ||
6219 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6220 adapter->device_mode == QDF_IBSS_MODE ||
6221 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6222 adapter->device_mode == QDF_SAP_MODE ||
6223 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006224 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006225 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306226 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228 }
6229
Dustin Browne74003f2018-03-14 12:51:58 -07006230 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306232 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233}
6234
Dustin Brownf27bce82016-11-03 12:52:27 -07006235/**
6236 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6237 * adapters
6238 * @hdd_ctx: The HDD context containing the adapters to operate on
6239 *
6240 * return: QDF_STATUS_SUCCESS
6241 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006242static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006243{
Jeff Johnson9d295242017-08-29 14:39:48 -07006244 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006245 int err;
6246
Dustin Brown491d54b2018-03-14 12:39:11 -07006247 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006248
Dustin Brown920397d2017-12-13 16:27:50 -08006249 hdd_for_each_adapter(hdd_ctx, adapter) {
6250 if (adapter->device_mode == QDF_STA_MODE ||
6251 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6252 adapter->device_mode == QDF_IBSS_MODE ||
6253 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6254 adapter->device_mode == QDF_SAP_MODE ||
6255 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006256 err = wlan_hdd_sched_scan_stop(adapter->dev);
6257 if (err)
6258 hdd_err("Unable to stop scheduled scan");
6259 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006260 }
6261
Dustin Browne74003f2018-03-14 12:51:58 -07006262 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006263
6264 return QDF_STATUS_SUCCESS;
6265}
6266
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267#ifdef WLAN_NS_OFFLOAD
6268/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006269 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 * @hdd_ctx: Pointer to hdd context
6271 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006272 * Unregister for IPv6 address change notifications.
6273 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274 * Return: None
6275 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006276static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277{
6278 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279}
6280
6281/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006282 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283 * @hdd_ctx: Pointer to hdd context
6284 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006285 * Register for IPv6 address change notifications.
6286 *
6287 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006289static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290{
6291 int ret;
6292
6293 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6294 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006295 if (ret) {
6296 hdd_err("Failed to register IPv6 notifier: %d", ret);
6297 goto out;
6298 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006300 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006301out:
6302 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006303}
6304#else
6305/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006306 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307 * @hdd_ctx: Pointer to hdd context
6308 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006309 * Unregister for IPv6 address change notifications.
6310 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006311 * Return: None
6312 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006313static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314{
6315}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006317/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006318 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006319 * @hdd_ctx: Pointer to hdd context
6320 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006321 * Register for IPv6 address change notifications.
6322 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323 * Return: None
6324 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006325static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006327 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006328}
6329#endif
6330
6331/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006332 * hdd_register_notifiers - Register netdev notifiers.
6333 * @hdd_ctx: HDD context
6334 *
6335 * Register netdev notifiers like IPv4 and IPv6.
6336 *
6337 * Return: 0 on success and errno on failure
6338 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006339static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006340{
6341 int ret;
6342
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006343 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6344 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306345 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006346
6347 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6348 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6349 if (ret) {
6350 hdd_err("Failed to register IPv4 notifier: %d", ret);
6351 goto unregister_ip6_notifier;
6352 }
6353
6354 return 0;
6355
6356unregister_ip6_notifier:
6357 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006358out:
6359 return ret;
6360
6361}
6362
6363/**
6364 * hdd_unregister_notifiers - Unregister netdev notifiers.
6365 * @hdd_ctx: HDD context
6366 *
6367 * Unregister netdev notifiers like IPv4 and IPv6.
6368 *
6369 * Return: None.
6370 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006371void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006372{
6373 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6374
6375 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006376}
6377
6378/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006379 * hdd_exit_netlink_services - Exit netlink services
6380 * @hdd_ctx: HDD context
6381 *
6382 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6383 * nl service.
6384 *
6385 * Return: None.
6386 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006387static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006388{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006389 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006390 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006391 ptt_sock_deactivate_svc();
6392
6393 nl_srv_exit();
6394}
6395
6396/**
6397 * hdd_init_netlink_services- Init netlink services
6398 * @hdd_ctx: HDD context
6399 *
6400 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6401 * nl service.
6402 *
6403 * Return: 0 on success and errno on failure.
6404 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006405static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006406{
6407 int ret;
6408
Ryan Hsuceddceb2016-04-28 10:20:14 -07006409 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006410 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006411 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006412 goto out;
6413 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006414 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006415
Naveen Rawat910726a2017-03-06 11:42:51 -08006416 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006417 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006418 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006419 goto err_nl_srv;
6420 }
6421
6422 ret = ptt_sock_activate_svc();
6423 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006424 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006425 goto err_nl_srv;
6426 }
6427
6428 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006429 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006430 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006431
6432 ret = cnss_diag_activate_service();
6433 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006434 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006435 goto err_close_cesium;
6436 }
6437
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006438 ret = spectral_scan_activate_service();
6439 if (ret) {
6440 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6441 goto err_close_cesium;
6442 }
6443
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006444 return 0;
6445
6446err_close_cesium:
6447 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006448 ptt_sock_deactivate_svc();
6449err_nl_srv:
6450 nl_srv_exit();
6451out:
6452 return ret;
6453}
6454
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006455/**
6456 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6457 * @hdd_ctx: HDD context.
6458 *
6459 * Destroy RX wakelock.
6460 *
6461 * Return: None.
6462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006463static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006464{
6465 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6466}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006467
6468/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006469 * hdd_rx_wake_lock_create() - Create RX wakelock
6470 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006471 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006472 * Create RX wakelock.
6473 *
6474 * Return: None.
6475 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006476static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006477{
6478 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6479}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006480
6481/**
Houston Hoffman160db392016-10-10 17:37:51 -07006482 * hdd_context_deinit() - Deinitialize HDD context
6483 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006484 *
Houston Hoffman160db392016-10-10 17:37:51 -07006485 * Deinitialize HDD context along with all the feature specific contexts but
6486 * do not free hdd context itself. Caller of this API is supposed to free
6487 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006488 *
Houston Hoffman160db392016-10-10 17:37:51 -07006489 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006490 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006491static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006492{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306493 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6494
Houston Hoffman160db392016-10-10 17:37:51 -07006495 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006496
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006497 hdd_sap_context_destroy(hdd_ctx);
6498
6499 hdd_rx_wake_lock_destroy(hdd_ctx);
6500
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006501 hdd_scan_context_destroy(hdd_ctx);
6502
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006503 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006504
Houston Hoffman160db392016-10-10 17:37:51 -07006505 return 0;
6506}
6507
6508/**
6509 * hdd_context_destroy() - Destroy HDD context
6510 * @hdd_ctx: HDD context to be destroyed.
6511 *
6512 * Free config and HDD context as well as destroy all the resources.
6513 *
6514 * Return: None
6515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006516static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006517{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006518 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306519
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306520 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6521
Houston Hoffman160db392016-10-10 17:37:51 -07006522 hdd_context_deinit(hdd_ctx);
6523
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306524 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006525 hdd_ctx->config = NULL;
6526
6527 wiphy_free(hdd_ctx->wiphy);
6528}
6529
6530/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306531 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6532 *
6533 * This function is used to destroy bug report lock
6534 *
6535 * Return: None
6536 */
6537static void wlan_destroy_bug_report_lock(void)
6538{
6539 p_cds_contextType p_cds_context;
6540
6541 p_cds_context = cds_get_global_context();
6542 if (!p_cds_context) {
6543 hdd_err("cds context is NULL");
6544 return;
6545 }
6546
6547 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6548}
6549
6550/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551 * hdd_wlan_exit() - HDD WLAN exit function
6552 * @hdd_ctx: Pointer to the HDD Context
6553 *
6554 * This is the driver exit point (invoked during rmmod)
6555 *
6556 * Return: None
6557 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006558static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006559{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306561 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562
Dustin Brown491d54b2018-03-14 12:39:11 -07006563 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006564
Dustin Brown6f427922017-09-19 12:19:00 -07006565 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05306566
6567 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568
Prashanth Bhattaab004382016-10-11 16:08:11 -07006569 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570
6571#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306572 if (QDF_TIMER_STATE_RUNNING ==
6573 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6574 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575 }
6576
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306577 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306578 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006579 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006581 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6582 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6583 hdd_ctx->last_acs_channel_list = NULL;
6584 hdd_ctx->num_of_channels = 0;
6585 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006587
Arun Khandavallifae92942016-08-01 13:31:08 +05306588 mutex_lock(&hdd_ctx->iface_change_lock);
6589 driver_status = hdd_ctx->driver_status;
6590 mutex_unlock(&hdd_ctx->iface_change_lock);
6591
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592 /*
6593 * Powersave Offload Case
6594 * Disable Idle Power Save Mode
6595 */
6596 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006597 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306598 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599
Arun Khandavallifae92942016-08-01 13:31:08 +05306600 if (driver_status != DRIVER_MODULES_CLOSED) {
6601 hdd_unregister_wext_all_adapters(hdd_ctx);
6602 /*
6603 * Cancel any outstanding scan requests. We are about to close
6604 * all of our adapters, but an adapter structure is what SME
6605 * passes back to our callback function. Hence if there
6606 * are any outstanding scan requests then there is a
6607 * race condition between when the adapter is closed and
6608 * when the callback is invoked. We try to resolve that
6609 * race condition here by canceling any outstanding scans
6610 * before we close the adapters.
6611 * Note that the scans may be cancelled in an asynchronous
6612 * manner, so ideally there needs to be some kind of
6613 * synchronization. Rather than introduce a new
6614 * synchronization here, we will utilize the fact that we are
6615 * about to Request Full Power, and since that is synchronized,
6616 * the expectation is that by the time Request Full Power has
6617 * completed, all scans will be cancelled
6618 */
6619 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006620 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006621 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006622 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006623 }
6624
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306625 unregister_netdevice_notifier(&hdd_netdev_notifier);
6626
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006627 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306628
Dustin Brown021cecd2017-12-11 13:56:43 -08006629 hdd_driver_memdump_deinit();
6630
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306631 qdf_nbuf_deinit_replenish_timer();
6632
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306633 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6634 hdd_info("Release wakelock for monitor mode!");
6635 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6636 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6637 }
6638
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306639 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6640 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6641 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6642
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643 /*
6644 * Close CDS
6645 * This frees pMac(HAL) context. There should not be any call
6646 * that requires pMac access after this.
6647 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006649 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
Dustin Brownd005ad82018-01-19 10:32:13 -08006651 hdd_close_all_adapters(hdd_ctx, false);
6652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653 hdd_ipa_cleanup(hdd_ctx);
6654
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306655 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306656 /*
6657 * If there is re_init failure wiphy would have already de-registered
6658 * check the wiphy status before un-registering again
6659 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306660 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306661 wiphy_unregister(wiphy);
6662 wlan_hdd_cfg80211_deinit(wiphy);
6663 hdd_lpass_notify_stop(hdd_ctx);
6664 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006665
Arun Khandavallifae92942016-08-01 13:31:08 +05306666 hdd_exit_netlink_services(hdd_ctx);
6667 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306668#ifdef FEATURE_WLAN_CH_AVOID
6669 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6670#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306671
Abhishek Singhe9068f12017-03-31 14:14:52 +05306672 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6673 if (driver_status)
6674 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006675
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006676 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677}
6678
6679void __hdd_wlan_exit(void)
6680{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006681 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682
Dustin Brown491d54b2018-03-14 12:39:11 -07006683 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684
Anurag Chouhan6d760662016-02-20 16:05:43 +05306685 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006687 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006688 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689 return;
6690 }
6691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 /* Do all the cleanup before deregistering the driver */
6693 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006694
Dustin Browne74003f2018-03-14 12:51:58 -07006695 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006696}
6697
6698#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006699/**
6700 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006702 *
6703 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6704 * Then new ACS request will do a fresh scan without reusing the cached
6705 * scan information.
6706 *
6707 * Return: void
6708 */
Tang Yingying523322d2017-01-17 23:28:43 +08006709static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006711 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006713 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006715 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6716 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6717 hdd_ctx->last_acs_channel_list = NULL;
6718 hdd_ctx->num_of_channels = 0;
6719 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006720
6721 if (!hdd_ctx->hHal)
6722 return;
6723 sme_scan_flush_result(hdd_ctx->hHal);
6724}
6725#endif
6726
6727#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006728int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6729 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730{
6731 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306732 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006733 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734
6735 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6736
6737 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306738 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306740
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006741 if (!hdd_ctx->hHal)
6742 return -EINVAL;
6743
Jeff Johnsone7672e72017-10-21 15:10:04 -07006744 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006745 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306746 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006747 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006748 return -EINVAL;
6749 }
6750
6751 return 0;
6752}
6753#endif
6754
6755/**
6756 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6757 * @state: state
6758 *
6759 * This function notifies FW with modem power status
6760 *
6761 * Return: 0 if successful, error number otherwise
6762 */
6763int hdd_wlan_notify_modem_power_state(int state)
6764{
6765 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306766 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006767 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768
Anurag Chouhan6d760662016-02-20 16:05:43 +05306769 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306771 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006772 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306773
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006774 if (!hdd_ctx->hHal)
6775 return -EINVAL;
6776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306777 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6778 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006779 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780 state);
6781 return -EINVAL;
6782 }
6783 return 0;
6784}
6785
6786/**
6787 *
6788 * hdd_post_cds_enable_config() - HDD post cds start config helper
6789 * @adapter - Pointer to the HDD
6790 *
6791 * Return: None
6792 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006793QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006794{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306795 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796
6797 /*
6798 * Send ready indication to the HDD. This will kick off the MAC
6799 * into a 'running' state and should kick off an initial scan.
6800 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306801 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6802 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006803 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6804 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306805 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006806 }
6807
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306808 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809}
6810
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306811struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6812{
6813 struct hdd_adapter *adapter;
6814
6815 hdd_for_each_adapter(hdd_ctx, adapter) {
6816 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6817 return adapter;
6818 }
6819
6820 return NULL;
6821}
6822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823/* wake lock APIs for HDD */
6824void hdd_prevent_suspend(uint32_t reason)
6825{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306826 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827}
6828
6829void hdd_allow_suspend(uint32_t reason)
6830{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306831 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006832}
6833
6834void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6835{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306836 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6837 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006838}
6839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006840/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006841QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006842{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006843
Amar Singhal6f8592b2017-04-26 14:31:58 -07006844 return sme_init_chan_list(hdd_ctx->hHal,
6845 hdd_ctx->reg.alpha2,
6846 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847}
6848
6849/**
6850 * hdd_is_5g_supported() - check if hardware supports 5GHz
6851 * @hdd_ctx: Pointer to the hdd context
6852 *
6853 * HDD function to know if hardware supports 5GHz
6854 *
6855 * Return: true if hardware supports 5GHz
6856 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006857bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006858{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006859 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006860 return true;
6861
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006862 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006863 return true;
6864 else
6865 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006866}
6867
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006868static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869{
6870 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006871 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872
6873 wiphy = hdd_ctx->wiphy;
6874
6875 /*
6876 * The channel information in
6877 * wiphy needs to be initialized before wiphy registration
6878 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006879 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6880 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006881 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006882 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883 }
6884
6885#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6886 wiphy->wowlan = &wowlan_support_reg_init;
6887#else
6888 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6889 WIPHY_WOWLAN_MAGIC_PKT |
6890 WIPHY_WOWLAN_DISCONNECT |
6891 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6892 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6893 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6894 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6895 WIPHY_WOWLAN_RFKILL_RELEASE;
6896
6897 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6898 WOW_MAX_FILTERS_PER_LIST);
6899 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6900 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6901#endif
6902
6903 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006904 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306905 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006906 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306907 return ret_val;
6908 }
6909
Amar Singhal2d812012018-02-03 15:06:47 +08006910 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911
Amar Singhale4f28ee2015-10-21 14:36:56 -07006912 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006913}
6914
Mohit Khannaca4173b2017-09-12 21:52:19 -07006915#ifdef MSM_PLATFORM
6916/**
6917 * hdd_display_periodic_stats() - Function to display periodic stats
6918 * @hdd_ctx - handle to hdd context
6919 * @bool data_in_interval - true, if data detected in bw time interval
6920 *
6921 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
6922 * Stats show up in wlan driver logs.
6923 *
6924 * Returns: None
6925 */
6926static inline
6927void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
6928 bool data_in_interval)
6929{
6930 static u32 counter;
6931 static bool data_in_time_period;
6932 ol_txrx_pdev_handle pdev;
6933
6934 if (hdd_ctx->config->periodic_stats_disp_time == 0)
6935 return;
6936
6937 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
6938 if (!pdev) {
6939 hdd_err("pdev is NULL");
6940 return;
6941 }
6942
6943 counter++;
6944 if (data_in_interval)
6945 data_in_time_period = data_in_interval;
6946
6947 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
6948 hdd_ctx->config->periodic_stats_disp_time * 1000) {
6949 if (data_in_time_period) {
6950 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
6951 CDP_TXRX_PATH_STATS,
6952 QDF_STATS_VERBOSITY_LEVEL_LOW);
6953 wlan_hdd_display_netif_queue_history
6954 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
6955 qdf_dp_trace_dump_stats();
6956 }
6957 counter = 0;
6958 data_in_time_period = false;
6959 }
6960}
6961
Ravi Joshie2331e82015-07-01 18:18:54 -07006962/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006963 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006964 * @hdd_ctx - handle to hdd context
6965 * @tx_packets - transmit packet count
6966 * @rx_packets - receive packet count
6967 *
6968 * The function controls the bus bandwidth and dynamic control of
6969 * tcp delayed ack configuration
6970 *
6971 * Returns: None
6972 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07006973
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006974static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07006975 const uint64_t tx_packets,
6976 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006977{
Mohit Khannaca4173b2017-09-12 21:52:19 -07006978 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006979 uint64_t temp_rx = 0;
6980 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006981 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006982 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006983 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006984 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006985 uint16_t index = 0;
6986 bool vote_level_change = false;
6987 bool rx_level_change = false;
6988 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989
Mohit Khannaca4173b2017-09-12 21:52:19 -07006990 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006991 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006992 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006993 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07006994 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006995 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006996 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006997 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007000 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7001 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007002 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007003 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007004 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05307005 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307006 if (hdd_ctx->hbw_requested) {
7007 pld_remove_pm_qos(hdd_ctx->parent_dev);
7008 hdd_ctx->hbw_requested = false;
7009 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307010 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007011 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007012 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307013 if (!hdd_ctx->hbw_requested) {
7014 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7015 hdd_ctx->hbw_requested = true;
7016 }
7017
Nirav Shah3bbfa512016-05-12 16:43:49 +05307018 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007019 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007020 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007021 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007022 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007023
Mohit Khannaf8f96822017-05-17 17:11:59 -07007024 qdf_dp_trace_throttle_live_mode(
7025 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7026
Mohit Khannae71e2262015-11-10 09:37:24 -08007027 /* fine-tuning parameters for RX Flows */
7028 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007031
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307032 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
7033 hdd_disable_lro_for_low_tput(hdd_ctx, true);
7034 else
7035 hdd_disable_lro_for_low_tput(hdd_ctx, false);
7036
Ravi Joshifed83572016-10-07 16:20:37 -07007037 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7038 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7039 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7040 next_rx_level = WLAN_SVC_TP_HIGH;
7041 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007042 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007043 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007044 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007045 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007048 struct wlan_rx_tp_data rx_tp_data = {0};
7049
Ravi Joshie2331e82015-07-01 18:18:54 -07007050 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051 next_rx_level, temp_rx);
7052 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007053 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007054 /* Send throughput indication only if it is enabled.
7055 * Disabling tcp_del_ack will revert the tcp stack behavior
7056 * to default delayed ack. Note that this will disable the
7057 * dynamic delayed ack mechanism across the system
7058 */
7059 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007060 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7061
Mohit Khanna6272fb682017-04-13 09:34:36 -07007062 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7063 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7064
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007065 rx_tp_data.level = next_rx_level;
7066 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7067 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7068 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069 }
7070
Mohit Khannae71e2262015-11-10 09:37:24 -08007071 /* fine-tuning parameters for TX Flows */
7072 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7073 hdd_ctx->prev_tx = tx_packets;
7074 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7075 next_tx_level = WLAN_SVC_TP_HIGH;
7076 else
7077 next_tx_level = WLAN_SVC_TP_LOW;
7078
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007079 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7080 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007081 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7082 next_tx_level, temp_tx);
7083 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007084 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307085 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7086 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007087 &next_tx_level,
7088 sizeof(next_tx_level));
7089 }
7090
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007091 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007092 if (vote_level_change || tx_level_change || rx_level_change) {
7093 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7094 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7095 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7096 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7097 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7098 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7099 hdd_ctx->hdd_txrx_hist_idx++;
7100 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7101 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007102
7103 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007104}
7105
7106#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307107static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007109 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307110 bus_bw_work);
Jeff Johnson9d295242017-08-29 14:39:48 -07007111 struct hdd_adapter *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307112 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307113 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7114 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307116 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117 bool connected = false;
7118 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7119
Prashanth Bhattaab004382016-10-11 16:08:11 -07007120 if (wlan_hdd_validate_context(hdd_ctx))
7121 return;
7122
Jeff Johnson214671b2017-10-30 19:45:23 -07007123 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007124 goto restart_timer;
7125
Dustin Brown920397d2017-12-13 16:27:50 -08007126 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307127 /*
7128 * Validate magic so we don't end up accessing
7129 * an invalid adapter.
7130 */
7131 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7132 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007134 if ((adapter->device_mode == QDF_STA_MODE ||
7135 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007136 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7137 != eConnectionState_Associated) {
7138
7139 continue;
7140 }
7141
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007142 if ((adapter->device_mode == QDF_SAP_MODE ||
7143 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007144 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007145
7146 continue;
7147 }
7148
7149 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7150 adapter->prev_tx_packets);
7151 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7152 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307153
7154 if (adapter->device_mode == QDF_SAP_MODE ||
7155 adapter->device_mode == QDF_P2P_GO_MODE ||
7156 adapter->device_mode == QDF_IBSS_MODE) {
7157
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007158 ret = cdp_get_intra_bss_fwd_pkts_count(
7159 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007160 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307161 &fwd_tx_packets, &fwd_rx_packets);
7162 if (ret == A_OK) {
7163 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7164 fwd_tx_packets,
7165 adapter->prev_fwd_tx_packets);
7166 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7167 fwd_tx_packets,
7168 adapter->prev_fwd_rx_packets);
7169 }
7170 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007171
7172 total_rx += adapter->stats.rx_packets;
7173 total_tx += adapter->stats.tx_packets;
7174
7175 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7176 adapter->prev_tx_packets = adapter->stats.tx_packets;
7177 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307178 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7179 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007180 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7181 connected = true;
7182 }
7183
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307184 /* add intra bss forwarded tx and rx packets */
7185 tx_packets += fwd_tx_packets_diff;
7186 rx_packets += fwd_rx_packets_diff;
7187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007188 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
7189 tx_packets += (uint64_t)ipa_tx_packets;
7190 rx_packets += (uint64_t)ipa_rx_packets;
7191
Yun Park2aa880c2017-08-22 10:58:10 -07007192 if (adapter) {
7193 adapter->stats.tx_packets += ipa_tx_packets;
7194 adapter->stats.rx_packets += ipa_rx_packets;
7195 }
7196
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007198 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007199 return;
7200 }
7201
Yuanyuan Liu13738502016-04-06 17:41:37 -07007202 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007203
7204 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
7205 hdd_ipa_uc_stat_request(adapter, 2);
7206
Jingxiang Gec64e1932017-08-22 14:38:59 +08007207restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007208 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007209 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007210 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307211 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007212 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007213 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007215
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307216/**
7217 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7218 * @arg: Argument of timer function
7219 *
7220 * Schedule a workqueue in this function where all the processing is done.
7221 *
7222 * Return: None.
7223 */
7224static void __hdd_bus_bw_cbk(void *arg)
7225{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007226 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307227
7228 if (wlan_hdd_validate_context(hdd_ctx))
7229 return;
7230
7231 schedule_work(&hdd_ctx->bus_bw_work);
7232}
7233
7234/**
7235 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7236 * @arg: Argument of timer function
7237 *
7238 * Return: None.
7239 */
7240static void hdd_bus_bw_cbk(void *arg)
7241{
7242 cds_ssr_protect(__func__);
7243 __hdd_bus_bw_cbk(arg);
7244 cds_ssr_unprotect(__func__);
7245}
7246
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007247int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007248{
7249 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307250 INIT_WORK(&hdd_ctx->bus_bw_work,
7251 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007252 hdd_ctx->bus_bw_timer_running = false;
7253 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307254 qdf_timer_init(NULL,
7255 &hdd_ctx->bus_bw_timer,
7256 hdd_bus_bw_cbk, (void *)hdd_ctx,
7257 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007258
7259 return 0;
7260}
7261
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007262void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007263{
Dustin Brownfce08d12017-01-17 16:29:38 -08007264 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007265 hdd_reset_tcp_delack(hdd_ctx);
7266
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007267 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307268 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307269 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007270 hdd_ctx->bus_bw_timer_running = false;
7271 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007272}
Lin Baic5c06882017-09-21 13:58:43 +08007273
7274void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7275{
7276 if (hdd_ctx)
7277 cancel_work_sync(&hdd_ctx->bus_bw_work);
7278}
jiadcdaf9bd2017-10-26 12:20:21 +08007279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280#endif
7281
7282/**
Nirav Shahed34b212016-04-25 10:59:16 +05307283 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7284 * @hdd_ctx: hdd context
7285 *
7286 * Return: 0 for success or error code
7287 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007288static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307289{
7290 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7291 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7292 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007293 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307294 return -ENOMEM;
7295 }
7296 return 0;
7297}
7298
7299/**
7300 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7301 * @hdd_ctx: hdd context
7302 *
7303 * Return: none
7304 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007305void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307306{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307307 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7308 return;
7309
7310 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7311 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307312}
7313
Nirav Shahda008342016-05-17 18:50:40 +05307314static uint8_t *convert_level_to_string(uint32_t level)
7315{
7316 switch (level) {
7317 /* initialize the wlan sub system */
7318 case WLAN_SVC_TP_NONE:
7319 return "NONE";
7320 case WLAN_SVC_TP_LOW:
7321 return "LOW";
7322 case WLAN_SVC_TP_MEDIUM:
7323 return "MED";
7324 case WLAN_SVC_TP_HIGH:
7325 return "HIGH";
7326 default:
7327 return "INVAL";
7328 }
7329}
7330
Nirav Shahed34b212016-04-25 10:59:16 +05307331
7332/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007333 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7334 * @hdd_ctx: hdd context
7335 *
7336 * Return: none
7337 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007338void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339{
7340 int i;
7341
7342#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007343 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307344 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007345 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346 hdd_ctx->config->busBandwidthHighThreshold,
7347 hdd_ctx->config->busBandwidthMediumThreshold,
7348 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007349 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307350 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007351 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007352 hdd_ctx->config->tcpDelackThresholdHigh,
7353 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007354 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307355 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007356#endif
7357
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007358 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307359 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7360
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007361 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007362
7363 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007364 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007365 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007366 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7367 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7368 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7369 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7370 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007371 hdd_ctx->hdd_txrx_hist[i].
7372 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007373 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007374 hdd_ctx->hdd_txrx_hist[i].
7375 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007376 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007377 hdd_ctx->hdd_txrx_hist[i].
7378 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007379 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007380}
7381
7382/**
7383 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7384 * @hdd_ctx: hdd context
7385 *
7386 * Return: none
7387 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007388void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007389{
7390 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307391 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7392 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007393}
7394
Mohit Khannaca4173b2017-09-12 21:52:19 -07007395/* length of the netif queue log needed per adapter */
7396#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7397
7398/**
7399 *
7400 * hdd_display_netif_queue_history_compact() - display compact netifq history
7401 * @hdd_ctx: hdd context
7402 *
7403 * Return: none
7404 */
7405static void
7406hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7407{
7408 int adapter_num = 0;
7409 int i;
7410 int bytes_written;
7411 u32 tbytes;
7412 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007413 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007414 char *comb_log_str;
7415 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007416 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007417
jiadbdefb252018-01-03 14:27:06 +08007418 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7419 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7420 if (!comb_log_str) {
7421 hdd_err("failed to alloc comb_log_str");
7422 return;
7423 }
7424
Mohit Khannaca4173b2017-09-12 21:52:19 -07007425 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007426
Dustin Brown920397d2017-12-13 16:27:50 -08007427 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007428 curr_time = qdf_system_ticks();
7429 total = curr_time - adapter->start_time;
7430 delta = curr_time - adapter->last_time;
7431
7432 if (adapter->pause_map) {
7433 pause = adapter->total_pause_time + delta;
7434 unpause = adapter->total_unpause_time;
7435 } else {
7436 unpause = adapter->total_unpause_time + delta;
7437 pause = adapter->total_pause_time;
7438 }
7439
7440 tbytes = 0;
7441 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7442 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7443 if (adapter->queue_oper_stats[i].pause_count == 0)
7444 continue;
7445 tbytes +=
7446 snprintf(
7447 &temp_str[tbytes],
7448 (tbytes >= sizeof(temp_str) ?
7449 0 : sizeof(temp_str) - tbytes),
7450 "%d(%d,%d) ",
7451 i,
7452 adapter->queue_oper_stats[i].
7453 pause_count,
7454 adapter->queue_oper_stats[i].
7455 unpause_count);
7456 }
7457 if (tbytes >= sizeof(temp_str))
7458 hdd_warn("log truncated");
7459
7460 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007461 bytes_written >= comb_log_str_size ? 0 :
7462 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007463 "[%d %d] (%d) %u/%ums %s|",
7464 adapter->session_id, adapter->device_mode,
7465 adapter->pause_map,
7466 qdf_system_ticks_to_msecs(pause),
7467 qdf_system_ticks_to_msecs(total),
7468 temp_str);
7469
Mohit Khannaca4173b2017-09-12 21:52:19 -07007470 adapter_num++;
7471 }
7472
7473 /* using QDF_TRACE to avoid printing function name */
7474 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7475 "STATS |%s", comb_log_str);
7476
jiadbdefb252018-01-03 14:27:06 +08007477 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007478 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007479
7480 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007481}
7482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007483/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007484 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007485 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007486 *
7487 * Return: none
7488 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007489void
7490wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7491 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492{
7493
Jeff Johnson9d295242017-08-29 14:39:48 -07007494 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307496 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497
Mohit Khannaca4173b2017-09-12 21:52:19 -07007498 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7499 hdd_display_netif_queue_history_compact(hdd_ctx);
7500 return;
7501 }
7502
Dustin Brown920397d2017-12-13 16:27:50 -08007503 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007504 hdd_debug("Netif queue operation statistics:");
7505 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007506 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007507 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307508 curr_time = qdf_system_ticks();
7509 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307510 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307511 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307512 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307513 unpause = adapter->total_unpause_time;
7514 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307515 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307516 pause = adapter->total_pause_time;
7517 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007518 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307519 qdf_system_ticks_to_msecs(total),
7520 qdf_system_ticks_to_msecs(pause),
7521 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007522 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007523
Nirav Shahda008342016-05-17 18:50:40 +05307524 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7525 qdf_time_t pause_delta = 0;
7526
7527 if (adapter->pause_map & (1 << i))
7528 pause_delta = delta;
7529
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007530 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007531 hdd_debug("%s: %d: %d: %ums",
7532 hdd_reason_type_to_string(i),
7533 adapter->queue_oper_stats[i].pause_count,
7534 adapter->queue_oper_stats[i].unpause_count,
7535 qdf_system_ticks_to_msecs(
7536 adapter->queue_oper_stats[i].total_pause_time +
7537 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538 }
7539
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007540 hdd_debug("Netif queue operation history:");
7541 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307542 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7543
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007544 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545
7546 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007547 /* using hdd_log to avoid printing function name */
7548 if (adapter->queue_oper_history[i].time == 0)
7549 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007550 hdd_debug("%d: %u: %s: %s: %x",
7551 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007553 hdd_action_type_to_string(
7554 adapter->queue_oper_history[i].netif_action),
7555 hdd_reason_type_to_string(
7556 adapter->queue_oper_history[i].netif_reason),
7557 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007558 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007559 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560}
7561
7562/**
7563 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7564 * @hdd_ctx: hdd context
7565 *
7566 * Return: none
7567 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007568void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569{
Jeff Johnson9d295242017-08-29 14:39:48 -07007570 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571
Dustin Brown920397d2017-12-13 16:27:50 -08007572 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307573 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307575 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007576 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307577 adapter->history_index = 0;
7578 adapter->start_time = adapter->last_time = qdf_system_ticks();
7579 adapter->total_pause_time = 0;
7580 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007581 }
7582}
7583
7584/**
7585 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7586 * @halHandle: Hal handle
7587 * @pContext: Pointer to the context
7588 * @sessionId: Session ID
7589 * @scanId: Scan ID
7590 * @status: Status
7591 *
7592 * This is the callback to be executed when 11d scan is completed to flush out
7593 * the scan results
7594 *
7595 * 11d scan is done during driver load and is a passive scan on all
7596 * channels supported by the device, 11d scans may find some APs on
7597 * frequencies which are forbidden to be used in the regulatory domain
7598 * the device is operating in. If these APs are notified to the supplicant
7599 * it may try to connect to these APs, thus flush out all the scan results
7600 * which are present in SME after 11d scan is done.
7601 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307602 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007603 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307604static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605 uint8_t sessionId, uint32_t scanId,
7606 eCsrScanStatus status)
7607{
Dustin Brown491d54b2018-03-14 12:39:11 -07007608 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007609
7610 sme_scan_flush_result(halHandle);
7611
Dustin Browne74003f2018-03-14 12:51:58 -07007612 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007613
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307614 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007615}
7616
7617#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7618/**
7619 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7620 * @hdd_ctx: hdd global context
7621 *
7622 * Return: none
7623 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007624static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007625{
7626 uint8_t i;
7627
7628 mutex_init(&hdd_ctx->op_ctx.op_lock);
7629 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7630 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7631 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7632 }
7633}
7634#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007635static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636{
7637}
7638#endif
7639
Yingying Tang95409972016-10-20 15:16:15 +08007640#ifdef WLAN_FEATURE_WOW_PULSE
7641/**
7642 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007643 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007644 * @enable: enable or disable this behaviour
7645 *
7646 * Return: int
7647 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007648static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007649{
7650 struct hdd_config *pcfg_ini = phddctx->config;
7651 struct wow_pulse_mode wow_pulse_set_info;
7652 QDF_STATUS status;
7653
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007654 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007655
7656 if (false == phddctx->config->wow_pulse_support)
7657 return 0;
7658
7659 /* prepare the request to send to SME */
7660 if (enable == true) {
7661 wow_pulse_set_info.wow_pulse_enable = true;
7662 wow_pulse_set_info.wow_pulse_pin =
7663 pcfg_ini->wow_pulse_pin;
7664 wow_pulse_set_info.wow_pulse_interval_low =
7665 pcfg_ini->wow_pulse_interval_low;
7666 wow_pulse_set_info.wow_pulse_interval_high =
7667 pcfg_ini->wow_pulse_interval_high;
7668 } else {
7669 wow_pulse_set_info.wow_pulse_enable = false;
7670 wow_pulse_set_info.wow_pulse_pin = 0;
7671 wow_pulse_set_info.wow_pulse_interval_low = 0;
7672 wow_pulse_set_info.wow_pulse_interval_high = 0;
7673 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007674 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007675 wow_pulse_set_info.wow_pulse_enable,
7676 wow_pulse_set_info.wow_pulse_pin,
7677 wow_pulse_set_info.wow_pulse_interval_low,
7678 wow_pulse_set_info.wow_pulse_interval_high);
7679
7680 status = sme_set_wow_pulse(&wow_pulse_set_info);
7681 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007682 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007683 return -EIO;
7684 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007685 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007686 return 0;
7687}
7688#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007689static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007690{
7691 return 0;
7692}
7693#endif
7694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007695#ifdef WLAN_FEATURE_FASTPATH
7696/**
7697 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7698 * @hdd_cfg: hdd config
7699 * @context: lower layer context
7700 *
7701 * Return: none
7702 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307703void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007704 void *context)
7705{
7706 if (hdd_cfg->fastpath_enable)
7707 hif_enable_fastpath(context);
7708}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007709#endif
7710
Yuanyuan Liu13738502016-04-06 17:41:37 -07007711#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007712/**
7713 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007714 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007715 * @level: thermal level
7716 *
7717 * Change IPA data path to SW path when the thermal throttle level greater
7718 * than 0, and restore the original data path when throttle level is 0
7719 *
7720 * Return: none
7721 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007722static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007723{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007724 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007726 /* Change IPA to SW path when throttle level greater than 0 */
7727 if (level > THROTTLE_LEVEL_0)
7728 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
7729 else
7730 /* restore original concurrency mode */
7731 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
7732}
7733
7734/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307735 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7736 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307737 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007738 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307739 * Get a safe channel to restart SAP. PCL already takes into account the
7740 * unsafe channels. So, the PCL is validated with the ACS range to provide
7741 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007742 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307743 * Return: Channel number to restart SAP in case of success. In case of any
7744 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007745 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307746static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007747 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007748{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307749 struct sir_pcl_list pcl;
7750 QDF_STATUS status;
7751 uint32_t i, j;
7752 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007753 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307754 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007755 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007756
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307757 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7758 if (!hdd_ctx) {
7759 hdd_err("invalid HDD context");
7760 return INVALID_CHANNEL_ID;
7761 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007762
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307763 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7764 if (!hal_handle) {
7765 hdd_err("invalid HAL handle");
7766 return INVALID_CHANNEL_ID;
7767 }
7768
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007769 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7770 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007771 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7772 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307773 if (QDF_IS_STATUS_ERROR(status)) {
7774 hdd_err("Get PCL failed");
7775 return INVALID_CHANNEL_ID;
7776 }
7777
Frank Liudc2cefb2017-06-21 15:38:18 +08007778 /*
7779 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7780 * channel is unsafe channel, the pcl may be empty, instead of return,
7781 * try to choose a safe channel from acs range.
7782 */
7783 if (!pcl.pcl_len)
7784 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307785
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007786 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007787 adapter->session.ap.sap_config.acs_cfg.start_ch,
7788 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307789
7790 /* PCL already takes unsafe channel into account */
7791 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007792 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307793 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007794 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307795 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007796 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007797 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307798 return pcl.pcl_list[i];
7799 }
7800 }
7801
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007802 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307803
7804 /* Try for safe channel from all valid channel */
7805 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007806 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7807 &pcl.pcl_len);
7808 if (ret) {
7809 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307810 return INVALID_CHANNEL_ID;
7811 }
7812
7813 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007814 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307815 found = false;
7816 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007817 if (pcl.pcl_list[i] ==
7818 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007819 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307820 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007821 break;
7822 }
7823 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307824
7825 if (found)
7826 continue;
7827
7828 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007829 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307830 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007831 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007832 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307833 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007834 }
7835 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307836
7837 return INVALID_CHANNEL_ID;
7838}
Nirav Shaheb017be2018-02-15 11:20:58 +05307839#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307840
7841/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007842 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307843 * @adapter: AP adapter
7844 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007845 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307846 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007847 * Moves the SAP interface by invoking the function which
7848 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307849 *
7850 * Return: None
7851 */
Min Liu2fef5792018-01-19 17:59:42 +08007852void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7853 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307854{
Jeff Johnson87251032017-08-29 13:31:11 -07007855 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307856 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007857 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307858
7859 if (!adapter) {
7860 hdd_err("invalid adapter");
7861 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007862 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307863
7864 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7865
7866 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7867 if (!hal_handle) {
7868 hdd_err("invalid HAL handle");
7869 return;
7870 }
7871
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007872 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7873
Jeff Johnson91df29d2017-10-27 19:29:50 -07007874 hdd_ap_ctx->sap_config.channel = channel;
7875 hdd_ap_ctx->sap_config.ch_params.ch_width =
7876 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307877
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007878 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007879 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307880
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007881 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007882 hdd_ap_ctx->sap_config.channel,
7883 hdd_ap_ctx->sap_config.sec_ch,
7884 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307885
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007886 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007887 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007888 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007889}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307890
Jeff Johnson9d295242017-08-29 14:39:48 -07007891int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307892{
7893 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307894 int status;
7895 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307896
7897 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7898
7899 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007900 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307901 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007902 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307903 }
7904 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007905 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307906 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307907 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007908 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307909 WLAN_VENDOR_ACS_WAIT_TIME);
7910 if (qdf_status != QDF_STATUS_SUCCESS) {
7911 hdd_err("failed to start external acs timer");
7912 return -ENOSPC;
7913 }
7914 /* Update config to application */
7915 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07007916 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307917
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307918 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307919}
7920
Nirav Shaheb017be2018-02-15 11:20:58 +05307921#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307922/**
7923 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
7924 * @hdd_ctx: hdd context pointer
7925 *
7926 * hdd_unsafe_channel_restart_sap check all unsafe channel list
7927 * and if ACS is enabled, driver will ask userspace to restart the
7928 * sap. User space on LTE coex indication restart driver.
7929 *
7930 * Return - none
7931 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007932void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05307933{
Dustin Brown920397d2017-12-13 16:27:50 -08007934 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307935 uint32_t i;
7936 bool found = false;
7937 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007938
Dustin Brown920397d2017-12-13 16:27:50 -08007939 hdd_for_each_adapter(hdd_ctxt, adapter) {
7940 if (!(adapter->device_mode == QDF_SAP_MODE &&
7941 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007942 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08007943 adapter->device_mode,
7944 adapter->session.ap.sap_config.
7945 acs_cfg.acs_mode);
7946 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307947 }
7948
7949 found = false;
7950 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08007951 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307952 hdd_ctxt->unsafe_channel_list[i]) {
7953 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007954 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08007955 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307956 break;
7957 }
7958 }
7959
7960 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007961 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08007962 adapter->session.ap.operating_channel);
7963 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307964 }
7965
Kapil Gupta8878ad92017-02-13 11:56:04 +05307966 if (hdd_ctxt->config->vendor_acs_support &&
7967 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08007968 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05307969 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08007970 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307971 } else
7972 restart_chan =
7973 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08007974 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307975 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007976 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307977 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007978 /*
7979 * SAP restart due to unsafe channel. While
7980 * restarting the SAP, make sure to clear
7981 * acs_channel, channel to reset to
7982 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307983 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007984 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307985 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08007986 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307987 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007988 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307989 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7990 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04007991 hdd_debug("driver to start sap: %d",
7992 hdd_ctxt->config->sap_internal_restart);
7993 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08007994 hdd_switch_sap_channel(adapter, restart_chan,
7995 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04007996 else
7997 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05307998 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05307999 }
8000}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308001
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008002/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008003 * hdd_init_channel_avoidance() - Initialize channel avoidance
8004 * @hdd_ctx: HDD global context
8005 *
8006 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008007 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008008 * down to the lower layers. Then subscribe to subsequent channel
8009 * avoidance events.
8010 *
8011 * Return: None
8012 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008013static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008014{
8015 uint16_t unsafe_channel_count;
8016 int index;
8017
Yuanyuan Liu13738502016-04-06 17:41:37 -07008018 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8019 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008020 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008021 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008022
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008023 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008024 hdd_ctx->unsafe_channel_count);
8025
Anurag Chouhan6d760662016-02-20 16:05:43 +05308026 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008027 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008028
8029 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008030 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008031 hdd_ctx->unsafe_channel_list[index]);
8032
8033 }
8034
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008035}
Dustin Brown676a2322017-08-15 13:16:13 -07008036
Jeff Johnson9d295242017-08-29 14:39:48 -07008037static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008038 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008039{
8040 uint8_t restart_chan;
8041
8042 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8043 if (!restart_chan) {
8044 hdd_alert("fail to restart SAP");
8045 return;
8046 }
8047
8048 /* SAP restart due to unsafe channel. While restarting
8049 * the SAP, make sure to clear acs_channel, channel to
8050 * reset to 0. Otherwise these settings will override
8051 * the ACS while restart.
8052 */
8053 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008054 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008055
8056 hdd_debug("sending coex indication");
8057
8058 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8059 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008060 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008061}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008062
8063int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8064 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8065{
8066 uint32_t size;
8067 uint16_t *unsafe_list;
8068 uint16_t chan_count;
8069
8070 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8071 return -EINVAL;
8072
8073 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8074 NUM_CHANNELS);
8075 if (chan_count) {
8076 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8077 unsafe_list = qdf_mem_malloc(size);
8078 if (!unsafe_list) {
8079 hdd_err("No memory for unsafe chan list size%d",
8080 size);
8081 return -ENOMEM;
8082 }
8083 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8084 } else {
8085 unsafe_list = NULL;
8086 }
8087
8088 *local_unsafe_list = unsafe_list;
8089 *local_unsafe_list_count = chan_count;
8090
8091 return 0;
8092}
8093
8094bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8095 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8096{
8097 int i, j;
8098
8099 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8100 return true;
8101 if (local_unsafe_list_count == 0)
8102 return false;
8103 for (i = 0; i < local_unsafe_list_count; i++) {
8104 for (j = 0; j < local_unsafe_list_count; j++)
8105 if (local_unsafe_list[i] ==
8106 hdd_ctx->unsafe_channel_list[j])
8107 break;
8108 if (j >= local_unsafe_list_count)
8109 break;
8110 }
8111 if (i >= local_unsafe_list_count) {
8112 hdd_info("unsafe chan list same");
8113 return false;
8114 }
8115
8116 return true;
8117}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008118#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008119static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008120{
8121}
Dustin Brown676a2322017-08-15 13:16:13 -07008122
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008123static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008124{
8125}
Dustin Brown676a2322017-08-15 13:16:13 -07008126
Jeff Johnson9d295242017-08-29 14:39:48 -07008127static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008128 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008129{
8130 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8131}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008132#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008133
8134/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008135 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8136 * user space
8137 * @frame_ind: Management frame data to be informed.
8138 *
8139 * This function is used to indicate management frame to
8140 * user space
8141 *
8142 * Return: None
8143 *
8144 */
8145void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8146{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008147 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008148 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008149 int i;
8150
Rajeev Kumard004abc2016-02-17 12:09:56 -08008151 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008152 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008153
8154 if (0 != wlan_hdd_validate_context(hdd_ctx))
8155 return;
8156
8157 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8158 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8159 adapter =
8160 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8161 if (adapter)
8162 break;
8163 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008164 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8165 hdd_for_each_adapter(hdd_ctx, adapter) {
8166 if ((NULL != adapter) &&
8167 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8168 __hdd_indicate_mgmt_frame(adapter,
8169 frame_ind->frame_len,
8170 frame_ind->frameBuf,
8171 frame_ind->frameType,
8172 frame_ind->rxChan,
8173 frame_ind->rxRssi);
8174 }
8175 }
8176 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008177 } else {
8178 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8179 frame_ind->sessionId);
8180 }
8181
8182 if ((NULL != adapter) &&
8183 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8184 __hdd_indicate_mgmt_frame(adapter,
8185 frame_ind->frame_len,
8186 frame_ind->frameBuf,
8187 frame_ind->frameType,
8188 frame_ind->rxChan,
8189 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008190}
8191
Kapil Gupta8878ad92017-02-13 11:56:04 +05308192void hdd_acs_response_timeout_handler(void *context)
8193{
8194 struct hdd_external_acs_timer_context *timer_context =
8195 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008196 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008197 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308198 uint8_t reason;
8199
Dustin Brown491d54b2018-03-14 12:39:11 -07008200 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308201 if (!timer_context) {
8202 hdd_err("invlaid timer context");
8203 return;
8204 }
8205 adapter = timer_context->adapter;
8206 reason = timer_context->reason;
8207
8208
8209 if ((!adapter) ||
8210 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8211 hdd_err("invalid adapter or adapter has invalid magic");
8212 return;
8213 }
8214 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8215 if (wlan_hdd_validate_context(hdd_ctx))
8216 return;
8217
8218 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8219 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8220 else
8221 return;
8222
8223 hdd_err("ACS timeout happened for %s reason %d",
8224 adapter->dev->name, reason);
8225 switch (reason) {
8226 /* SAP init case */
8227 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8228 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8229 false);
8230 wlan_hdd_cfg80211_start_acs(adapter);
8231 break;
8232 /* DFS detected on current channel */
8233 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8234 wlan_sap_update_next_channel(
8235 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8236 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008237 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308238 break;
8239 /* LTE coex event on current channel */
8240 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8241 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8242 break;
8243 default:
8244 hdd_info("invalid reason for timer invoke");
8245
8246 }
8247}
8248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008249/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008250 * hdd_override_ini_config - Override INI config
8251 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008252 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008253 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008254 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008255 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008256 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008257static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008258{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008259
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008260 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8261 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008262 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008263 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008264 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008265 if (0 == enable_11d || 1 == enable_11d) {
8266 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008267 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008268 }
Leo Chang11545d62016-10-17 14:53:50 -07008269
Yun Park45d35972018-03-02 09:57:54 -08008270 if (!hdd_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008271 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008272 hdd_debug("IpaConfig override to %d",
8273 hdd_ctx->config->IpaConfig);
8274 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308275
8276 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8277 !hdd_ctx->config->enable_bcast_probe_rsp) {
8278 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8279 hdd_ctx->config->rssi_assoc_reject_enabled,
8280 hdd_ctx->config->enable_bcast_probe_rsp);
8281 hdd_ctx->config->oce_sta_enabled = 0;
8282 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008283}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008284
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008285/**
8286 * hdd_set_trace_level_for_each - Set trace level for each INI config
8287 * @hdd_ctx - HDD context
8288 *
8289 * Set trace level for each module based on INI config.
8290 *
8291 * Return: None
8292 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008293static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008294{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308295 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8296 hdd_ctx->config->qdf_trace_enable_wdi);
8297 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8298 hdd_ctx->config->qdf_trace_enable_hdd);
8299 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8300 hdd_ctx->config->qdf_trace_enable_sme);
8301 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8302 hdd_ctx->config->qdf_trace_enable_pe);
8303 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8304 hdd_ctx->config->qdf_trace_enable_wma);
8305 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8306 hdd_ctx->config->qdf_trace_enable_sys);
8307 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8308 hdd_ctx->config->qdf_trace_enable_qdf);
8309 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8310 hdd_ctx->config->qdf_trace_enable_sap);
8311 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8312 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8313 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8314 hdd_ctx->config->qdf_trace_enable_bmi);
8315 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8316 hdd_ctx->config->qdf_trace_enable_cfg);
8317 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8318 hdd_ctx->config->qdf_trace_enable_epping);
8319 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8320 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8321 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008322 hdd_ctx->config->qdf_trace_enable_txrx);
8323 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8324 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308325 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8326 hdd_ctx->config->qdf_trace_enable_htc);
8327 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8328 hdd_ctx->config->qdf_trace_enable_hif);
8329 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8330 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8331 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8332 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008333 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8334 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008335 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8336 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008337 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8338 hdd_ctx->config->qdf_trace_enable_regulatory);
8339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008340 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008341}
8342
8343/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008344 * hdd_context_init() - Initialize HDD context
8345 * @hdd_ctx: HDD context.
8346 *
8347 * Initialize HDD context along with all the feature specific contexts.
8348 *
8349 * return: 0 on success and errno on failure.
8350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008351static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008352{
8353 int ret;
8354
8355 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8356 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8357
8358 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308359 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008360
8361 init_completion(&hdd_ctx->mc_sus_event_var);
8362 init_completion(&hdd_ctx->ready_to_suspend);
8363
8364 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308365 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008366 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308367
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008368 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008369
8370 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8371
8372 ret = hdd_scan_context_init(hdd_ctx);
8373 if (ret)
8374 goto list_destroy;
8375
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008376 hdd_rx_wake_lock_create(hdd_ctx);
8377
8378 ret = hdd_sap_context_init(hdd_ctx);
8379 if (ret)
8380 goto scan_destroy;
8381
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008382 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8383
8384 hdd_init_offloaded_packets_ctx(hdd_ctx);
8385
8386 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8387 hdd_ctx->config);
8388 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008389 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008390
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308391 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8392 "monitor_mode_wakelock");
8393
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008394 return 0;
8395
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008396sap_destroy:
8397 hdd_sap_context_destroy(hdd_ctx);
8398
8399scan_destroy:
8400 hdd_scan_context_destroy(hdd_ctx);
8401 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008402list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008403 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008404
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008405 return ret;
8406}
8407
8408/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308409 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8410 * @hdd_ctx: pointer to hdd context
8411 *
8412 * Return: status of initialization
8413 * 0 - success
8414 * negative value - failure
8415 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008416static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308417{
8418 int ret;
8419
8420 if (!hdd_ctx->config->probe_req_ie_whitelist)
8421 return 0;
8422
8423 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8424 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8425 hdd_ctx->config->probe_req_ie_whitelist = false;
8426 return -EINVAL;
8427 }
8428
8429 /* parse ini string probe req oui */
8430 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8431 if (ret) {
8432 hdd_err("parsing error: disable ie whitelisting");
8433 hdd_ctx->config->probe_req_ie_whitelist = false;
8434 }
8435
8436 return ret;
8437}
8438
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308439/**
8440 * hdd_iface_change_callback() - Function invoked when stop modules expires
8441 * @priv: pointer to hdd context
8442 *
8443 * This function is invoked when the timer waiting for the interface change
8444 * expires, it shall cut-down the power to wlan and stop all the modules.
8445 *
8446 * Return: void
8447 */
8448static void hdd_iface_change_callback(void *priv)
8449{
8450 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8451 int ret;
8452 int status = wlan_hdd_validate_context(hdd_ctx);
8453
8454 if (status)
8455 return;
8456
Dustin Brown491d54b2018-03-14 12:39:11 -07008457 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308458 hdd_debug("Interface change timer expired close the modules!");
8459 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8460 if (ret)
8461 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008462 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308463}
8464
Nirav Shaheb017be2018-02-15 11:20:58 +05308465#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8466static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8467{
8468 wlan_logging_set_log_to_console(hdd_ctx->config->
8469 wlan_logging_to_console);
8470 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8471}
8472#else
8473static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8474{ }
8475#endif
8476
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308477/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008478 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308479 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008480 *
8481 * Allocate and initialize HDD context. HDD context is allocated as part of
8482 * wiphy allocation and then context is initialized.
8483 *
8484 * Return: HDD context on success and ERR_PTR on failure
8485 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008486static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008487{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308488 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008489 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008490 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008491
Dustin Brown491d54b2018-03-14 12:39:11 -07008492 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008493
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008494 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008495 if (hdd_ctx == NULL) {
8496 ret = -ENOMEM;
8497 goto err_out;
8498 }
8499
Dustin Brown6f427922017-09-19 12:19:00 -07008500 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8501 hdd_iface_change_callback,
8502 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308503
8504 mutex_init(&hdd_ctx->iface_change_lock);
8505
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008506 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308507 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008508
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308509 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008510 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008511 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008512 ret = -ENOMEM;
8513 goto err_free_hdd_context;
8514 }
8515
8516 /* Read and parse the qcom_cfg.ini file */
8517 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308518 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308519 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008520 WLAN_INI_FILE);
8521 ret = -EINVAL;
8522 goto err_free_config;
8523 }
8524
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308525 ie_whitelist_attrs_init(hdd_ctx);
8526
Dustin Brown7f939932017-05-18 15:02:17 -07008527 hdd_debug("setting timer multiplier: %u",
8528 hdd_ctx->config->timer_multiplier);
8529 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8530
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008531
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308532 if (hdd_ctx->config->fhostNSOffload)
8533 hdd_ctx->ns_offload_enable = true;
8534
Abhishek Singh5ea86532016-04-27 14:10:53 +05308535 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8536
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008537 hdd_override_ini_config(hdd_ctx);
8538
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008539 ret = hdd_context_init(hdd_ctx);
8540
8541 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008542 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008543
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008544 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308545 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008546
Anurag Chouhan6d760662016-02-20 16:05:43 +05308547 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008548 goto skip_multicast_logging;
8549
8550 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8551
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008552 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8553 if (ret)
8554 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308555
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008556 ret = hdd_init_netlink_services(hdd_ctx);
8557 if (ret)
8558 goto err_deinit_txrx_histogram;
8559
Nirav Shaheb017be2018-02-15 11:20:58 +05308560 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308561
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008562skip_multicast_logging:
8563 hdd_set_trace_level_for_each(hdd_ctx);
8564
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008565 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8566
Dustin Browne74003f2018-03-14 12:51:58 -07008567 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008568
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008569 return hdd_ctx;
8570
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008571err_deinit_txrx_histogram:
8572 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8573
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008574err_deinit_hdd_context:
8575 hdd_context_deinit(hdd_ctx);
8576
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008577err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308578 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008579
8580err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308581 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008582 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008583
8584err_out:
8585 return ERR_PTR(ret);
8586}
8587
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008588#ifdef WLAN_OPEN_P2P_INTERFACE
8589/**
8590 * hdd_open_p2p_interface - Open P2P interface
8591 * @hdd_ctx: HDD context
8592 * @rtnl_held: True if RTNL lock held
8593 *
8594 * Open P2P interface during probe. This function called to open the P2P
8595 * interface at probe along with STA interface.
8596 *
8597 * Return: 0 on success and errno on failure
8598 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008599static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008600{
Jeff Johnson9d295242017-08-29 14:39:48 -07008601 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008602 uint8_t *p2p_dev_addr;
8603
8604 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8605 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008606 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008607 hdd_ctx->config->intfMacAddr[0].bytes,
8608 sizeof(tSirMacAddr));
8609
8610 /*
8611 * Generate the P2P Device Address. This consists of
8612 * the device's primary MAC address with the locally
8613 * administered bit set.
8614 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008615 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008616 } else {
8617 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8618 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008619 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008620 return -ENOSPC;
8621 }
8622
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008623 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8624 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008625 }
8626
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008627 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008628 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008629 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008630
8631 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008632 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008633 return -ENOSPC;
8634 }
8635
8636 return 0;
8637}
8638#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008639static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008640 bool rtnl_held)
8641{
8642 return 0;
8643}
8644#endif
8645
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008646static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008647{
Jeff Johnson9d295242017-08-29 14:39:48 -07008648 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008649 int ret = 0;
8650
8651 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8652 wlan_hdd_get_intf_addr(hdd_ctx),
8653 NET_NAME_UNKNOWN, rtnl_held);
8654 if (adapter == NULL) {
8655 hdd_err("Failed to open 802.11p interface");
8656 ret = -ENOSPC;
8657 }
8658
8659 return ret;
8660}
8661
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008662/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308663 * hdd_start_station_adapter()- Start the Station Adapter
8664 * @adapter: HDD adapter
8665 *
8666 * This function initializes the adapter for the station mode.
8667 *
8668 * Return: 0 on success or errno on failure.
8669 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008670int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308671{
8672 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008673 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308674
Dustin Brownfdf17c12018-03-14 12:55:34 -07008675 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008676 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8677 hdd_err("session is already opened, %d",
8678 adapter->session_id);
8679 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8680 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308681
Krunal Sonib51eec72017-11-20 21:53:01 -08008682 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8683 if (ret) {
8684 hdd_err("failed to create vdev: %d", ret);
8685 return ret;
8686 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308687 status = hdd_init_station_mode(adapter);
8688
8689 if (QDF_STATUS_SUCCESS != status) {
8690 hdd_err("Error Initializing station mode: %d", status);
8691 return qdf_status_to_os_return(status);
8692 }
8693
Arun Khandavallifae92942016-08-01 13:31:08 +05308694 hdd_register_tx_flow_control(adapter,
8695 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008696 hdd_tx_resume_cb,
8697 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308698
Dustin Browne74003f2018-03-14 12:51:58 -07008699 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308700 return 0;
8701}
8702
8703/**
8704 * hdd_start_ap_adapter()- Start AP Adapter
8705 * @adapter: HDD adapter
8706 *
8707 * This function initializes the adapter for the AP mode.
8708 *
8709 * Return: 0 on success errno on failure.
8710 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008711int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308712{
8713 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008714 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008715 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008716 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308717
Dustin Brown491d54b2018-03-14 12:39:11 -07008718 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308719
Krunal Sonib51eec72017-11-20 21:53:01 -08008720 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8721 hdd_err("session is already opened, %d",
8722 adapter->session_id);
8723 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8724 }
8725 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008726 * In SSR case no need to create new sap context.
8727 * Otherwise create sap context first and then create
8728 * vdev as while creating the vdev, driver needs to
8729 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008730 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008731 if (adapter->session.ap.sap_context) {
8732 is_ssr = true;
8733 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008734 hdd_err("sap creation failed");
8735 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8736 }
8737
8738 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8739 adapter->session.ap.sap_context);
8740 if (ret) {
8741 hdd_err("failed to create vdev, status:%d", ret);
8742 hdd_sap_destroy_ctx(adapter);
8743 return ret;
8744 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008745
8746 if (adapter->device_mode == QDF_SAP_MODE)
8747 sme_cli_set_command(adapter->session_id,
8748 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8749 (bool)(hdd_ctx->config->fine_time_meas_cap &
8750 WMI_FW_AP_RTT_RESPR),
8751 VDEV_CMD);
8752
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008753 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308754
8755 if (QDF_STATUS_SUCCESS != status) {
8756 hdd_err("Error Initializing the AP mode: %d", status);
8757 return qdf_status_to_os_return(status);
8758 }
8759
Arun Khandavallifae92942016-08-01 13:31:08 +05308760 hdd_register_tx_flow_control(adapter,
8761 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008762 hdd_softap_tx_resume_cb,
8763 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308764
Dustin Browne74003f2018-03-14 12:51:58 -07008765 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308766 return 0;
8767}
8768
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308769static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8770 bool rtnl_held)
8771{
8772 struct hdd_adapter *adapter;
8773
8774 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8775 hdd_ctx->config->enableConcurrentSTA,
8776 wlan_hdd_get_intf_addr(hdd_ctx),
8777 NET_NAME_UNKNOWN, rtnl_held);
8778
8779 if (!adapter)
8780 return -ENOSPC;
8781
8782 return 0;
8783}
8784
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308785/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008786 * hdd_open_interfaces - Open all required interfaces
8787 * hdd_ctx: HDD context
8788 * rtnl_held: True if RTNL lock is held
8789 *
8790 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8791 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008792 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008794static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008795{
Jeff Johnson9d295242017-08-29 14:39:48 -07008796 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008797 int ret;
8798
Ravi Joshia307f632017-07-17 23:41:41 -07008799 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008800 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8801 con_mode == QDF_GLOBAL_FTM_MODE) {
8802 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8803 QDF_MONITOR_MODE : QDF_FTM_MODE;
8804
8805 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8806 wlan_hdd_get_intf_addr(hdd_ctx),
8807 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008808 if (!adapter) {
8809 hdd_err("open adapter failed");
8810 return -ENOSPC;
8811 }
Lin Bai1c678482017-12-18 18:29:11 +08008812
Ravi Joshia307f632017-07-17 23:41:41 -07008813 return 0;
8814 }
8815
Jeff Johnson957bc272017-02-02 08:54:48 -08008816 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308817 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008818 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008819
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008820 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008821 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008822 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008823
8824 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008825 return -ENOSPC;
8826
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308827 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8828 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8829 if (ret)
8830 hdd_err("Cannot create concurrent STA interface");
8831 }
8832
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008833 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8834 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008835 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008836
8837 /* Open 802.11p Interface */
8838 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008839 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8840 if (ret)
8841 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008842 }
8843
Jeff Johnson957bc272017-02-02 08:54:48 -08008844 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008845
Jeff Johnson957bc272017-02-02 08:54:48 -08008846err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008847 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008848 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008849}
8850
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008851
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308852#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8853/**
8854 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8855 * @cds_cfg: CDS Configuration
8856 * @hdd_ctx: Pointer to hdd context
8857 *
8858 * Return: none
8859 */
8860static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8861 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008862 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308863{
8864 cds_cfg->tx_flow_stop_queue_th =
8865 hdd_ctx->config->TxFlowStopQueueThreshold;
8866 cds_cfg->tx_flow_start_queue_offset =
8867 hdd_ctx->config->TxFlowStartQueueOffset;
8868}
8869#else
8870static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8871 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008872 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308873{
8874}
8875#endif
8876
8877#ifdef FEATURE_WLAN_RA_FILTERING
8878/**
8879 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8880 * @cds_cfg: CDS Configuration
8881 * @hdd_ctx: Pointer to hdd context
8882 *
8883 * Return: none
8884 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308885static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008886 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308887{
8888 cds_cfg->ra_ratelimit_interval =
8889 hdd_ctx->config->RArateLimitInterval;
8890 cds_cfg->is_ra_ratelimit_enabled =
8891 hdd_ctx->config->IsRArateLimitEnabled;
8892}
8893#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308894static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008895 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308896{
8897}
8898#endif
8899
8900/**
8901 * hdd_update_cds_config() - API to update cds configuration parameters
8902 * @hdd_ctx: HDD Context
8903 *
8904 * Return: 0 for Success, errno on failure
8905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008906static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308907{
8908 struct cds_config_info *cds_cfg;
8909
8910 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8911 if (!cds_cfg) {
8912 hdd_err("failed to allocate cds config");
8913 return -ENOMEM;
8914 }
8915
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008916 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008917 if (!hdd_ctx->config->nMaxPsPoll ||
8918 !hdd_ctx->config->enablePowersaveOffload) {
8919 cds_cfg->powersave_offload_enabled =
8920 hdd_ctx->config->enablePowersaveOffload;
8921 } else {
8922 if ((hdd_ctx->config->enablePowersaveOffload ==
8923 PS_QPOWER_NODEEPSLEEP) ||
8924 (hdd_ctx->config->enablePowersaveOffload ==
8925 PS_LEGACY_NODEEPSLEEP))
8926 cds_cfg->powersave_offload_enabled =
8927 PS_LEGACY_NODEEPSLEEP;
8928 else
8929 cds_cfg->powersave_offload_enabled =
8930 PS_LEGACY_DEEPSLEEP;
8931 hdd_info("Qpower disabled in cds config, %d",
8932 cds_cfg->powersave_offload_enabled);
8933 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308934 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8935 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8936 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8937 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308938
8939 /*
8940 * Copy the DFS Phyerr Filtering Offload status.
8941 * This parameter reflects the value of the
8942 * dfs_phyerr_filter_offload flag as set in the ini.
8943 */
8944 cds_cfg->dfs_phyerr_filter_offload =
8945 hdd_ctx->config->fDfsPhyerrFilterOffload;
8946 if (hdd_ctx->config->ssdp)
8947 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8948
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05308949 cds_cfg->force_target_assert_enabled =
8950 hdd_ctx->config->crash_inject_enabled;
8951
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308952 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8953 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8954
8955 cds_cfg->ap_maxoffload_reorderbuffs =
8956 hdd_ctx->config->apMaxOffloadReorderBuffs;
8957
8958 cds_cfg->ap_disable_intrabss_fwd =
8959 hdd_ctx->config->apDisableIntraBssFwd;
8960
8961 cds_cfg->dfs_pri_multiplier =
8962 hdd_ctx->config->dfsRadarPriMultiplier;
8963 cds_cfg->reorder_offload =
8964 hdd_ctx->config->reorderOffloadSupport;
8965
8966 /* IPA micro controller data path offload resource config item */
8967 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008968 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8969 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008970 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008971 hdd_ctx->config->IpaUcTxBufCount);
8972 hdd_ctx->config->IpaUcTxBufCount =
8973 rounddown_pow_of_two(
8974 hdd_ctx->config->IpaUcTxBufCount);
8975 if (!hdd_ctx->config->IpaUcTxBufCount) {
8976 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308977 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008978 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008979 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008980 hdd_ctx->config->IpaUcTxBufCount);
8981 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308982 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8983 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008984 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8985 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008986 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008987 hdd_ctx->config->IpaUcRxIndRingCount);
8988 hdd_ctx->config->IpaUcRxIndRingCount =
8989 rounddown_pow_of_two(
8990 hdd_ctx->config->IpaUcRxIndRingCount);
8991 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8992 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308993 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008994 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008995 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008996 hdd_ctx->config->IpaUcRxIndRingCount);
8997 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308998 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008999 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309000 cds_cfg->uc_tx_partition_base =
9001 hdd_ctx->config->IpaUcTxPartitionBase;
9002 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9003
9004 cds_cfg->ip_tcp_udp_checksum_offload =
9005 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009006 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309007 cds_cfg->ce_classify_enabled =
9008 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009009 cds_cfg->bpf_packet_filter_enable =
9010 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309011 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9012 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9013 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009014 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009015 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009016 cds_cfg->max_msdus_per_rxinorderind =
9017 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009018 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009019 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309020 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9021 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309022 cds_cfg->auto_power_save_fail_mode =
9023 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309024
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309025 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009026 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009027 cds_cfg->delay_before_vdev_stop =
9028 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309029
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309030 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9031 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9032 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009033 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309034 cds_init_ini_config(cds_cfg);
9035 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309036
9037exit:
9038 qdf_mem_free(cds_cfg);
9039 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309040}
9041
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009042/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009043 * hdd_update_user_config() - API to update user configuration
9044 * parameters to obj mgr which are used by multiple components
9045 * @hdd_ctx: HDD Context
9046 *
9047 * Return: 0 for Success, errno on failure
9048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009049static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009050{
9051 struct wlan_objmgr_psoc_user_config *user_config;
9052
9053 user_config = qdf_mem_malloc(sizeof(*user_config));
9054 if (user_config == NULL) {
9055 hdd_alert("Failed to alloc memory for user_config!");
9056 return -ENOMEM;
9057 }
9058
9059 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9060 user_config->dual_mac_feature_disable =
9061 hdd_ctx->config->dual_mac_feature_disable;
9062 user_config->indoor_channel_support =
9063 hdd_ctx->config->indoor_channel_support;
9064 user_config->is_11d_support_enabled =
9065 hdd_ctx->config->Is11dSupportEnabled;
9066 user_config->is_11h_support_enabled =
9067 hdd_ctx->config->Is11hSupportEnabled;
9068 user_config->optimize_chan_avoid_event =
9069 hdd_ctx->config->goptimize_chan_avoid_event;
9070 user_config->skip_dfs_chnl_in_p2p_search =
9071 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009072 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009073 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9074
9075 qdf_mem_free(user_config);
9076 return 0;
9077}
9078
9079/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009080 * hdd_init_thermal_info - Initialize thermal level
9081 * @hdd_ctx: HDD context
9082 *
9083 * Initialize thermal level at SME layer and set the thermal level callback
9084 * which would be called when a configured thermal threshold is hit.
9085 *
9086 * Return: 0 on success and errno on failure
9087 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009088static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009089{
9090 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309091 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009092
9093 thermal_param.smeThermalMgmtEnabled =
9094 hdd_ctx->config->thermalMitigationEnable;
9095 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9096
Poddar, Siddarth83905022016-04-16 17:56:08 -07009097 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9098 hdd_ctx->config->throttle_dutycycle_level0;
9099 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9100 hdd_ctx->config->throttle_dutycycle_level1;
9101 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9102 hdd_ctx->config->throttle_dutycycle_level2;
9103 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9104 hdd_ctx->config->throttle_dutycycle_level3;
9105
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009106 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9107 hdd_ctx->config->thermalTempMinLevel0;
9108 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9109 hdd_ctx->config->thermalTempMaxLevel0;
9110 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9111 hdd_ctx->config->thermalTempMinLevel1;
9112 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9113 hdd_ctx->config->thermalTempMaxLevel1;
9114 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9115 hdd_ctx->config->thermalTempMinLevel2;
9116 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9117 hdd_ctx->config->thermalTempMaxLevel2;
9118 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9119 hdd_ctx->config->thermalTempMinLevel3;
9120 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9121 hdd_ctx->config->thermalTempMaxLevel3;
9122
9123 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9124
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309125 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309126 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009127
9128 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9129 hdd_set_thermal_level_cb);
9130
9131 return 0;
9132
9133}
9134
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009135#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9136/**
9137 * hdd_hold_rtnl_lock - Hold RTNL lock
9138 *
9139 * Hold RTNL lock
9140 *
9141 * Return: True if held and false otherwise
9142 */
9143static inline bool hdd_hold_rtnl_lock(void)
9144{
9145 rtnl_lock();
9146 return true;
9147}
9148
9149/**
9150 * hdd_release_rtnl_lock - Release RTNL lock
9151 *
9152 * Release RTNL lock
9153 *
9154 * Return: None
9155 */
9156static inline void hdd_release_rtnl_lock(void)
9157{
9158 rtnl_unlock();
9159}
9160#else
9161static inline bool hdd_hold_rtnl_lock(void) { return false; }
9162static inline void hdd_release_rtnl_lock(void) { }
9163#endif
9164
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009165#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009166
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309167/* MAX iwpriv command support */
9168#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309169#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309170#define MAX_PKTLOG_SIZE 16
9171
9172/**
9173 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9174 * @hdd_ctx: hdd context
9175 * @set_value2: pktlog buffer size value
9176 *
9177 *
9178 * Return: 0 for success or error.
9179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009180static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309181{
9182 struct sir_wifi_start_log start_log = { 0 };
9183 QDF_STATUS status;
9184
9185 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9186 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9187 start_log.ini_triggered = cds_is_packet_log_enabled();
9188 start_log.user_triggered = 1;
9189 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309190 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309191
9192 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9193 if (!QDF_IS_STATUS_SUCCESS(status)) {
9194 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009195 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309196 return -EINVAL;
9197 }
9198
9199 return 0;
9200}
9201
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009202/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309203 * hdd_pktlog_clear_buff() - clear pktlog buffer
9204 * @hdd_ctx: hdd context
9205 *
9206 * Return: 0 for success or error.
9207 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009208static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309209{
9210 struct sir_wifi_start_log start_log;
9211 QDF_STATUS status;
9212
9213 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9214 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9215 start_log.ini_triggered = cds_is_packet_log_enabled();
9216 start_log.user_triggered = 1;
9217 start_log.size = 0;
9218 start_log.is_pktlog_buff_clear = true;
9219
9220 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9221 if (!QDF_IS_STATUS_SUCCESS(status)) {
9222 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009223 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309224 return -EINVAL;
9225 }
9226
9227 return 0;
9228}
9229
9230
9231/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009232 * hdd_process_pktlog_command() - process pktlog command
9233 * @hdd_ctx: hdd context
9234 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309235 * @set_value2: pktlog buffer size value
9236 *
9237 * This function process pktlog command.
9238 * set_value2 only matters when set_value is 3 (set buff size)
9239 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009240 *
9241 * Return: 0 for success or error.
9242 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009243int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309244 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009245{
9246 int ret;
9247 bool enable;
9248 uint8_t user_triggered = 0;
9249
9250 ret = wlan_hdd_validate_context(hdd_ctx);
9251 if (0 != ret)
9252 return ret;
9253
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009254 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009255
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309256 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009257 hdd_err("invalid pktlog value %d", set_value);
9258 return -EINVAL;
9259 }
9260
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309261 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9262 if (set_value2 <= 0) {
9263 hdd_err("invalid pktlog size %d", set_value2);
9264 return -EINVAL;
9265 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9266 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9267 return -EINVAL;
9268 }
9269 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309270 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9271 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309272 }
9273
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009274 /*
9275 * set_value = 0 then disable packetlog
9276 * set_value = 1 enable packetlog forcefully
9277 * set_vlaue = 2 then disable packetlog if disabled through ini or
9278 * enable packetlog with AUTO type.
9279 */
9280 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9281 true : false;
9282
9283 if (1 == set_value) {
9284 enable = true;
9285 user_triggered = 1;
9286 }
9287
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309288 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009289}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009290
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009291/**
9292 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9293 * @hdd_ctx: HDD context
9294 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309295 * @user_triggered: triggered through iwpriv
9296 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009297 *
9298 * Return: 0 on success; error number otherwise
9299 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009300int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309301 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009302{
9303 struct sir_wifi_start_log start_log;
9304 QDF_STATUS status;
9305
9306 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9307 start_log.verbose_level =
9308 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009309 start_log.ini_triggered = cds_is_packet_log_enabled();
9310 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309311 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309312 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309313 /*
9314 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9315 * commands. Host uses this flag to decide whether to send pktlog
9316 * disable command to fw without sending pktlog enable command
9317 * previously. For eg, If vendor sends pktlog disable command without
9318 * sending pktlog enable command, then host discards the packet
9319 * but for iwpriv command, host will send it to fw.
9320 */
9321 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009322 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9323 if (!QDF_IS_STATUS_SUCCESS(status)) {
9324 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009325 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009326 return -EINVAL;
9327 }
9328
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309329 if (enable == true)
9330 hdd_ctx->is_pktlog_enabled = 1;
9331 else
9332 hdd_ctx->is_pktlog_enabled = 0;
9333
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009334 return 0;
9335}
9336#endif /* REMOVE_PKT_LOG */
9337
Komal Seelam92fff912016-03-24 11:51:41 +05309338/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009339 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9340 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309341 * @dev: Device Pointer
9342 * @num: Number of Valid Mac address
9343 *
9344 * Return: Pointer to MAC address buffer
9345 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009346static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9347 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309348{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009349 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309350}
Komal Seelam92fff912016-03-24 11:51:41 +05309351
9352/**
9353 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9354 * @hdd_ctx: HDD Context
9355 * @num: Number of random mac addresses needed
9356 *
9357 * Generate random addresses using bit manipulation on the base mac address
9358 *
9359 * Return: None
9360 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009361void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309362{
9363 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9364 uint32_t iter;
9365 struct hdd_config *ini = hdd_ctx->config;
9366 uint8_t *buf = NULL;
9367 uint8_t macaddr_b3, tmp_br3;
9368 uint8_t *src = ini->intfMacAddr[0].bytes;
9369
9370 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9371 buf = ini->intfMacAddr[iter].bytes;
9372 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9373 macaddr_b3 = buf[3];
9374 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9375 INTF_MACADDR_MASK;
9376 macaddr_b3 += tmp_br3;
9377 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9378 buf[0] |= 0x02;
9379 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009380 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309381 }
9382}
9383
9384/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009385 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309386 * @hdd_ctx: HDD Context
9387 *
9388 * API to get mac addresses from platform driver and update the driver
9389 * structures and configure FW with the base mac address.
9390 * Return: int
9391 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009392static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309393{
9394 uint32_t no_of_mac_addr, iter;
9395 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9396 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9397 uint8_t *addr, *buf;
9398 struct device *dev = hdd_ctx->parent_dev;
9399 struct hdd_config *ini = hdd_ctx->config;
9400 tSirMacAddr mac_addr;
9401 QDF_STATUS status;
9402
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009403 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309404
9405 if (no_of_mac_addr == 0 || !addr) {
9406 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9407 return -EINVAL;
9408 }
9409
9410 if (no_of_mac_addr > max_mac_addr)
9411 no_of_mac_addr = max_mac_addr;
9412
9413 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9414
9415 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9416 buf = ini->intfMacAddr[iter].bytes;
9417 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009418 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309419 }
9420
9421 status = sme_set_custom_mac_addr(mac_addr);
9422
9423 if (!QDF_IS_STATUS_SUCCESS(status))
9424 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009425
Komal Seelam92fff912016-03-24 11:51:41 +05309426 if (no_of_mac_addr < max_mac_addr)
9427 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9428 no_of_mac_addr);
9429 return 0;
9430}
9431
9432/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009433 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9434 * @hdd_ctx: HDD Context
9435 *
9436 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9437 * will generate its own MAC and update it to FW.
9438 *
9439 * Return: 0 for success
9440 * Non-zero error code for failure
9441 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009442static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009443{
9444 tSirMacAddr customMacAddr;
9445 QDF_STATUS status;
9446
9447 qdf_mem_copy(&customMacAddr,
9448 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9449 sizeof(tSirMacAddr));
9450 status = sme_set_custom_mac_addr(customMacAddr);
9451 if (!QDF_IS_STATUS_SUCCESS(status))
9452 return -EAGAIN;
9453 return 0;
9454}
9455
9456/**
Komal Seelam92fff912016-03-24 11:51:41 +05309457 * hdd_initialize_mac_address() - API to get wlan mac addresses
9458 * @hdd_ctx: HDD Context
9459 *
9460 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9461 * is provisioned with mac addresses, driver uses it, else it will use
9462 * wlan_mac.bin to update HW MAC addresses.
9463 *
9464 * Return: None
9465 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009466static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309467{
9468 QDF_STATUS status;
9469 int ret;
9470
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009471 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309472 if (ret == 0)
9473 return;
9474
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009475 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9476 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309477
9478 status = hdd_update_mac_config(hdd_ctx);
9479
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009480 if (QDF_IS_STATUS_SUCCESS(status))
9481 return;
9482
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009483 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9484 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009485
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009486 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009487 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009488 if (ret != 0) {
9489 hdd_err("MAC address out-of-sync, ret:%d", ret);
9490 QDF_ASSERT(ret);
9491 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009492 }
Komal Seelam92fff912016-03-24 11:51:41 +05309493}
9494
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009495static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009496{
9497 int vdev_id = 0;
9498 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9499 int value = hdd_ctx->config->smart_chainmask_enabled;
9500 int vpdev = PDEV_CMD;
9501 int ret;
9502
Naveen Rawat247a8682017-06-05 15:00:31 -07009503 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009504 if (ret)
9505 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9506
9507 return ret;
9508}
9509
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009510static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009511{
9512 int vdev_id = 0;
9513 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9514 int value = hdd_ctx->config->alternative_chainmask_enabled;
9515 int vpdev = PDEV_CMD;
9516 int ret;
9517
Naveen Rawat247a8682017-06-05 15:00:31 -07009518 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009519 if (ret)
9520 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9521 ret);
9522
9523 return ret;
9524}
9525
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009526static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009527{
9528 int vdev_id = 0;
9529 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9530 int value = hdd_ctx->config->ani_enabled;
9531 int vpdev = PDEV_CMD;
9532 int ret;
9533
Naveen Rawat247a8682017-06-05 15:00:31 -07009534 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009535 if (ret)
9536 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9537
9538 return ret;
9539}
9540
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009541/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009542 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9543 * @hdd_ctx: HDD context
9544 *
9545 * Pre configurations to be done at lower layer before calling cds enable.
9546 *
9547 * Return: 0 on success and errno on failure.
9548 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009549static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009550{
9551 int ret;
9552 QDF_STATUS status;
9553 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009554 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009555
Leo Changfdb45c32016-10-28 11:09:23 -07009556 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009557 /*
9558 * Set 802.11p config
9559 * TODO-OCB: This has been temporarily added here to ensure this
9560 * parameter is set in CSR when we init the channel list. This should
9561 * be removed once the 5.9 GHz channels are added to the regulatory
9562 * domain.
9563 */
9564 hdd_set_dot11p_config(hdd_ctx);
9565
9566 /*
9567 * Note that the cds_pre_enable() sequence triggers the cfg download.
9568 * The cfg download must occur before we update the SME config
9569 * since the SME config operation must access the cfg database
9570 */
9571 status = hdd_set_sme_config(hdd_ctx);
9572
9573 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009574 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009575 ret = qdf_status_to_os_return(status);
9576 goto out;
9577 }
9578
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009579 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9580 if (QDF_STATUS_SUCCESS != status) {
9581 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9582 ret = qdf_status_to_os_return(status);
9583 goto out;
9584 }
9585
Naveen Rawat247a8682017-06-05 15:00:31 -07009586 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009587 hdd_ctx->config->tx_chain_mask_1ss,
9588 PDEV_CMD);
9589 if (0 != ret) {
9590 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9591 goto out;
9592 }
9593
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009594 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9595 if (ret)
9596 goto out;
9597
9598 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9599 if (ret)
9600 goto out;
9601
Jeff Johnson12a744b2017-04-04 08:19:37 -07009602 ret = hdd_set_ani_enabled(hdd_ctx);
9603 if (ret)
9604 goto out;
9605
Naveen Rawat247a8682017-06-05 15:00:31 -07009606 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009607 hdd_ctx->config->arp_ac_category,
9608 PDEV_CMD);
9609 if (0 != ret) {
9610 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9611 hdd_ctx->config->arp_ac_category, ret);
9612 goto out;
9613 }
9614
Prashanth Bhatta07998752016-04-28 12:35:33 -07009615 status = hdd_set_sme_chan_list(hdd_ctx);
9616 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009617 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009618 ret = qdf_status_to_os_return(status);
9619 goto out;
9620 }
9621
9622 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009623 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009624 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009625 ret = -EINVAL;
9626 goto out;
9627 }
9628
Prashanth Bhatta07998752016-04-28 12:35:33 -07009629 /*
9630 * Set the MAC Address Currently this is used by HAL to add self sta.
9631 * Remove this once self sta is added as part of session open.
9632 */
9633 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9634 hdd_ctx->config->intfMacAddr[0].bytes,
9635 sizeof(hdd_ctx->config->intfMacAddr[0]));
9636
9637 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9638 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9639 hal_status, hal_status);
9640 ret = -EINVAL;
9641 goto out;
9642 }
9643
9644 hdd_init_channel_avoidance(hdd_ctx);
9645
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309646 /* update enable sap mandatory chan list */
9647 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9648 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009649out:
9650 return ret;
9651}
9652
9653/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009654 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9655 * @context_ptr - hdd context pointer
9656 * @event_ptr - event structure pointer
9657 *
9658 * This is the p2p listen offload stop event handler, it sends vendor
9659 * event back to supplicant to notify the stop reason.
9660 *
9661 * Return: None
9662 */
9663static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9664 void *event_ptr)
9665{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009666 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009667 struct sir_p2p_lo_event *evt = event_ptr;
9668 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009669 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009670
Dustin Brown491d54b2018-03-14 12:39:11 -07009671 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009672
9673 if (hdd_ctx == NULL) {
9674 hdd_err("Invalid HDD context pointer");
9675 return;
9676 }
9677
Peng Xu5c682812017-08-06 07:39:13 -07009678 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9679 if (!adapter) {
9680 hdd_err("Cannot find adapter by vdev_id = %d",
9681 evt->vdev_id);
9682 return;
9683 }
9684
Peng Xu8fdaa492016-06-22 10:20:47 -07009685 vendor_event =
9686 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009687 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009688 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9689 GFP_KERNEL);
9690
9691 if (!vendor_event) {
9692 hdd_err("cfg80211_vendor_event_alloc failed");
9693 return;
9694 }
9695
9696 if (nla_put_u32(vendor_event,
9697 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9698 evt->reason_code)) {
9699 hdd_err("nla put failed");
9700 kfree_skb(vendor_event);
9701 return;
9702 }
9703
9704 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009705 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9706 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009707}
9708
9709/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309710 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9711 * @hdd_ctx: HDD context
9712 *
9713 * This function sends the adaptive dwell time config configuration to the
9714 * firmware via WMA
9715 *
9716 * Return: 0 - success, < 0 - failure
9717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009718static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309719{
9720 QDF_STATUS status;
9721 struct adaptive_dwelltime_params dwelltime_params;
9722
9723 dwelltime_params.is_enabled =
9724 hdd_ctx->config->adaptive_dwell_mode_enabled;
9725 dwelltime_params.dwelltime_mode =
9726 hdd_ctx->config->global_adapt_dwelltime_mode;
9727 dwelltime_params.lpf_weight =
9728 hdd_ctx->config->adapt_dwell_lpf_weight;
9729 dwelltime_params.passive_mon_intval =
9730 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9731 dwelltime_params.wifi_act_threshold =
9732 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9733
9734 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9735 &dwelltime_params);
9736
9737 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9738 if (!QDF_IS_STATUS_SUCCESS(status)) {
9739 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9740 return -EAGAIN;
9741 }
9742 return 0;
9743}
9744
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009745int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309746{
9747 QDF_STATUS status;
9748 struct wmi_dbs_scan_sel_params dbs_scan_params;
9749 uint32_t i = 0;
9750 uint8_t count = 0, numentries = 0;
9751 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9752 * CDS_DBS_SCAN_CLIENTS_MAX];
9753
9754 /* check if DBS is enabled or supported */
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07009755 if (hdd_ctx->config->dual_mac_feature_disable ==
9756 DISABLE_DBS_CXN_AND_SCAN)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309757 return -EINVAL;
9758
9759 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9760 dbs_scan_config, &numentries,
9761 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9762 * CDS_DBS_SCAN_CLIENTS_MAX));
9763
9764 hdd_info("numentries %hu", numentries);
9765 if (!numentries) {
9766 hdd_info("Donot send scan_selection_config");
9767 return 0;
9768 }
9769
9770 /* hdd_set_fw_log_params */
9771 dbs_scan_params.num_clients = 0;
9772 while (count < (numentries - 2)) {
9773 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9774 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9775 dbs_scan_params.num_non_dbs_scans[i] =
9776 dbs_scan_config[count + 2];
9777 dbs_scan_params.num_clients++;
9778 hdd_debug("module:%d NDS:%d NNDS:%d",
9779 dbs_scan_params.module_id[i],
9780 dbs_scan_params.num_dbs_scans[i],
9781 dbs_scan_params.num_non_dbs_scans[i]);
9782 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9783 i++;
9784 }
9785
9786 dbs_scan_params.pdev_id = 0;
9787
9788 hdd_debug("clients:%d pdev:%d",
9789 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9790
9791 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9792 &dbs_scan_params);
9793 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9794 if (!QDF_IS_STATUS_SUCCESS(status)) {
9795 hdd_err("Failed to send DBS Scan selection configuration!");
9796 return -EAGAIN;
9797 }
9798 return 0;
9799}
9800
Arun Khandavallid4349a92016-07-25 11:10:43 +05309801#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9802/**
9803 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9804 * @hdd_ctx: HDD context
9805 *
9806 * Set auto shutdown callback to get indications from firmware to indicate
9807 * userspace to shutdown WLAN after a configured amount of inactivity.
9808 *
9809 * Return: 0 on success and errno on failure.
9810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009811static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309812{
9813 QDF_STATUS status;
9814
9815 if (!hdd_ctx->config->WlanAutoShutdown)
9816 return 0;
9817
9818 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9819 wlan_hdd_auto_shutdown_cb);
9820 if (status != QDF_STATUS_SUCCESS)
9821 hdd_err("Auto shutdown feature could not be enabled: %d",
9822 status);
9823
9824 return qdf_status_to_os_return(status);
9825}
9826#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009827static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309828{
9829 return 0;
9830}
9831#endif
9832
9833/**
9834 * hdd_features_init() - Init features
9835 * @hdd_ctx: HDD context
9836 * @adapter: Primary adapter context
9837 *
9838 * Initialize features and their feature context after WLAN firmware is up.
9839 *
9840 * Return: 0 on success and errno on failure.
9841 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009842static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309843{
9844 tSirTxPowerLimit hddtxlimit;
9845 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309846 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309847 int ret;
9848
Dustin Brown491d54b2018-03-14 12:39:11 -07009849 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309850
Arun Khandavallid4349a92016-07-25 11:10:43 +05309851 /* FW capabilities received, Set the Dot11 mode */
9852 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009853 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9854 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309855
Arun Khandavallid4349a92016-07-25 11:10:43 +05309856
9857 if (hdd_ctx->config->fIsImpsEnabled)
9858 hdd_set_idle_ps_config(hdd_ctx, true);
9859 else
9860 hdd_set_idle_ps_config(hdd_ctx, false);
9861
Poddar, Siddarth37033032017-10-11 15:47:40 +05309862 /* Send Enable/Disable data stall detection cmd to FW */
9863 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9864 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9865
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309866 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009867 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309868
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309869 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9870 hdd_warn("Error in setting Voltage Corner mode config to FW");
9871
Arun Khandavallid4349a92016-07-25 11:10:43 +05309872 if (hdd_lro_init(hdd_ctx))
9873 hdd_err("Unable to initialize LRO in fw");
9874
9875 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9876 hdd_err("Unable to send adaptive dwelltime setting to FW");
9877
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309878 if (hdd_dbs_scan_selection_init(hdd_ctx))
9879 hdd_err("Unable to send DBS scan selection setting to FW");
9880
Arun Khandavallid4349a92016-07-25 11:10:43 +05309881 ret = hdd_init_thermal_info(hdd_ctx);
9882 if (ret) {
9883 hdd_err("Error while initializing thermal information");
9884 goto deregister_frames;
9885 }
9886
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309887 /**
9888 * In case of SSR/PDR, if pktlog was enabled manually before
9889 * SSR/PDR, Then enabled it again automatically after Wlan
9890 * device up.
9891 */
9892 if (cds_is_driver_recovering()) {
9893 if (hdd_ctx->is_pktlog_enabled)
9894 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009895 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309896
Arun Khandavallid4349a92016-07-25 11:10:43 +05309897 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9898 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9899 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9900 if (!QDF_IS_STATUS_SUCCESS(status))
9901 hdd_err("Error setting txlimit in sme: %d", status);
9902
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009903 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309904
Arun Khandavallid4349a92016-07-25 11:10:43 +05309905 ret = hdd_register_cb(hdd_ctx);
9906 if (ret) {
9907 hdd_err("Failed to register HDD callbacks!");
9908 goto deregister_frames;
9909 }
9910
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309911 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9912 status = sme_enable_disable_chanavoidind_event(
9913 hdd_ctx->hHal, 0);
9914 if (!QDF_IS_STATUS_SUCCESS(status)) {
9915 hdd_err("Failed to disable Chan Avoidance Indication");
9916 goto deregister_cb;
9917 }
9918 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309919
Manjeet Singha9cae432017-02-28 11:58:22 +05309920 if (hdd_ctx->config->enable_5g_band_pref) {
9921 band_pref_params.rssi_boost_threshold_5g =
9922 hdd_ctx->config->rssi_boost_threshold_5g;
9923 band_pref_params.rssi_boost_factor_5g =
9924 hdd_ctx->config->rssi_boost_factor_5g;
9925 band_pref_params.max_rssi_boost_5g =
9926 hdd_ctx->config->max_rssi_boost_5g;
9927 band_pref_params.rssi_penalize_threshold_5g =
9928 hdd_ctx->config->rssi_penalize_threshold_5g;
9929 band_pref_params.rssi_penalize_factor_5g =
9930 hdd_ctx->config->rssi_penalize_factor_5g;
9931 band_pref_params.max_rssi_penalize_5g =
9932 hdd_ctx->config->max_rssi_penalize_5g;
9933 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9934 }
9935
Arun Khandavallid4349a92016-07-25 11:10:43 +05309936 /* register P2P Listen Offload event callback */
9937 if (wma_is_p2p_lo_capable())
9938 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9939 wlan_hdd_p2p_lo_event_callback);
9940
9941 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9942
9943 if (ret)
9944 goto deregister_cb;
9945
Dustin Brown11638b72018-01-25 17:37:25 +05309946 wlan_hdd_init_chan_info(hdd_ctx);
9947
Dustin Browne74003f2018-03-14 12:51:58 -07009948 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309949 return 0;
9950
9951deregister_cb:
9952 hdd_deregister_cb(hdd_ctx);
9953deregister_frames:
9954 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309955 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309956}
9957
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009958/**
9959 * hdd_features_deinit() - Deinit features
9960 * @hdd_ctx: HDD context
9961 *
9962 * De-Initialize features and their feature context.
9963 *
9964 * Return: none.
9965 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009966static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009967{
Dustin Brown11638b72018-01-25 17:37:25 +05309968 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009969 wlan_hdd_tsf_deinit(hdd_ctx);
9970}
9971
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309972/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009973 * hdd_register_bcn_cb() - register scan beacon callback
9974 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309975 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -07009976 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309977 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009978static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309979{
9980 QDF_STATUS status;
9981
9982 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9983 wlan_cfg80211_inform_bss_frame,
9984 SCAN_CB_TYPE_INFORM_BCN);
9985 if (!QDF_IS_STATUS_SUCCESS(status)) {
9986 hdd_err("failed with status code %08d [x%08x]",
9987 status, status);
9988 return status;
9989 }
9990
9991 return QDF_STATUS_SUCCESS;
9992}
Arun Khandavallid4349a92016-07-25 11:10:43 +05309993
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309994/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309995 * hdd_configure_cds() - Configure cds modules
9996 * @hdd_ctx: HDD context
9997 * @adapter: Primary adapter context
9998 *
9999 * Enable Cds modules after WLAN firmware is up.
10000 *
10001 * Return: 0 on success and errno on failure.
10002 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010003int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010004{
10005 int ret;
10006 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010007 int set_value;
10008 uint32_t num_abg_tx_chains = 0;
10009 uint32_t num_11b_tx_chains = 0;
10010 uint32_t num_11ag_tx_chains = 0;
Yun Parkff6a16a2017-09-26 16:38:18 -070010011 struct policy_mgr_dp_cbacks dp_cbs;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010012
10013 if (hdd_ctx->config->sifs_burst_duration) {
10014 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10015 hdd_ctx->config->sifs_burst_duration;
10016
10017 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10018 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10019 set_value, PDEV_CMD);
10020 }
10021
10022 if (hdd_ctx->config->is_force_1x1)
10023 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10024 1, PDEV_CMD);
10025 /* set chip power save failure detected callback */
10026 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10027 hdd_chip_pwr_save_fail_detected_cb);
10028
10029 if (hdd_ctx->config->max_mpdus_inampdu) {
10030 set_value = hdd_ctx->config->max_mpdus_inampdu;
10031 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10032 set_value, PDEV_CMD);
10033 }
10034
10035 if (hdd_ctx->config->enable_rts_sifsbursting) {
10036 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10037 sme_cli_set_command(0,
10038 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10039 set_value, PDEV_CMD);
10040 }
10041
10042 if (hdd_ctx->config->sap_get_peer_info) {
10043 set_value = hdd_ctx->config->sap_get_peer_info;
10044 sme_cli_set_command(0,
10045 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10046 set_value, PDEV_CMD);
10047 }
10048
10049 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10050 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10051 if (!hdd_ctx->config->enable2x2) {
10052 if (num_11b_tx_chains > 1)
10053 num_11b_tx_chains = 1;
10054 if (num_11ag_tx_chains > 1)
10055 num_11ag_tx_chains = 1;
10056 }
10057 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10058 num_11b_tx_chains);
10059 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10060 num_11ag_tx_chains);
10061 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10062 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010063
10064 ret = hdd_pre_enable_configure(hdd_ctx);
10065 if (ret) {
10066 hdd_err("Failed to pre-configure cds");
10067 goto out;
10068 }
10069
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010070 /* Always get latest IPA resources allocated from cds_open and configure
10071 * IPA module before configuring them to FW. Sequence required as crash
10072 * observed otherwise.
10073 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010074 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
10075 hdd_err("Failed to setup pipes");
10076 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010077 }
10078
Arun Khandavallifae92942016-08-01 13:31:08 +053010079 /*
10080 * Start CDS which starts up the SME/MAC/HAL modules and everything
10081 * else
10082 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010083 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010084
10085 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010086 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010087 goto out;
10088 }
10089
10090 status = hdd_post_cds_enable_config(hdd_ctx);
10091 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010092 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010093 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010094 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010095 status = hdd_register_bcn_cb(hdd_ctx);
10096 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010097 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010098 goto cds_disable;
10099 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010100
10101 ret = hdd_features_init(hdd_ctx, adapter);
10102 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010103 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010104
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010105 dp_cbs.hdd_disable_lro_in_concurrency = hdd_disable_lro_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010106 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010107 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10108 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010109 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010110 goto cds_disable;
10111 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010112 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10113 wlan_hdd_send_mode_change_event);
10114 if (!QDF_IS_STATUS_SUCCESS(status)) {
10115 hdd_debug("Failed to register mode change cb with Policy Manager");
10116 goto cds_disable;
10117 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010118
Himanshu Agarwalb229a142017-12-21 10:16:45 +053010119 if (ucfg_green_ap_enable_egap(hdd_ctx->hdd_pdev))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010120 hdd_debug("enhance green ap is not enabled");
10121
Nachiket Kukadedd302662017-07-13 17:31:44 +053010122 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10123 hdd_debug("Failed to set wow pulse");
10124
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010125 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10126 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010127 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10128 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10129
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010130
10131 if (hdd_ctx->config->enable_phy_reg_retention)
10132 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10133 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10134
Arun Khandavallifae92942016-08-01 13:31:08 +053010135 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010136
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010137cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010138 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010139
Arun Khandavallifae92942016-08-01 13:31:08 +053010140out:
10141 return -EINVAL;
10142}
10143
10144/**
10145 * hdd_deconfigure_cds() -De-Configure cds
10146 * @hdd_ctx: HDD context
10147 *
10148 * Deconfigure Cds modules before WLAN firmware is down.
10149 *
10150 * Return: 0 on success and errno on failure.
10151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010152static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010153{
10154 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010155 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010156
Dustin Brown491d54b2018-03-14 12:39:11 -070010157 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010158
10159 /* De-init features */
10160 hdd_features_deinit(hdd_ctx);
10161
Arun Khandavallifae92942016-08-01 13:31:08 +053010162 /* De-register the SME callbacks */
10163 hdd_deregister_cb(hdd_ctx);
10164
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010165 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10166 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10167 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10168 }
10169
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010170 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010171 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10172 hdd_err("Failed to Disable the CDS Modules! :%d",
10173 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010174 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010175 }
10176
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010177 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
10178 hdd_err("Failed to disconnect pipes");
10179 ret = -EINVAL;
10180 }
10181
Dustin Browne74003f2018-03-14 12:51:58 -070010182 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010183 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010184}
10185
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010186#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10187static void hdd_deregister_policy_manager_callback(
10188 struct wlan_objmgr_psoc *psoc)
10189{
10190 if (QDF_STATUS_SUCCESS !=
10191 policy_mgr_deregister_hdd_cb(psoc)) {
10192 hdd_err("HDD callback deregister with policy manager failed");
10193 }
10194}
10195#else
10196static void hdd_deregister_policy_manager_callback(
10197 struct wlan_objmgr_psoc *psoc)
10198{
10199}
10200#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010201
10202/**
10203 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10204 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010205 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010206 *
10207 * This function maintains the driver state machine it will be invoked from
10208 * exit, shutdown and con_mode change handler. Depending on the driver state
10209 * shall perform the stopping/closing of the modules.
10210 *
10211 * Return: 0 for success; non-zero for failure
10212 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010213int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010214{
10215 void *hif_ctx;
10216 qdf_device_t qdf_ctx;
10217 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010218 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010219 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010220 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10221 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010222 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010223 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010224
Dustin Brown491d54b2018-03-14 12:39:11 -070010225 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010226 hdd_alert("stop WLAN module: entering driver status=%d",
10227 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010228
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010229 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10230
Arun Khandavallifae92942016-08-01 13:31:08 +053010231 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10232 if (!qdf_ctx) {
10233 hdd_err("QDF device context NULL");
10234 return -EINVAL;
10235 }
10236
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010237 mutex_lock(&hdd_ctx->iface_change_lock);
10238 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010239 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010240
Dustin Brown70111822017-03-30 15:31:40 -070010241 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010242 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010243 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010244 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010245
10246 cds_print_external_threads();
10247
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010248 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010249 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010250 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10251 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010252 hdd_prevent_suspend_timeout(
10253 hdd_ctx->config->iface_change_wait_time,
10254 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010255 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010256 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010257 return 0;
10258 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010259 }
10260
Arun Khandavallifae92942016-08-01 13:31:08 +053010261 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10262
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010263 /* free user wowl patterns */
10264 hdd_free_user_wowl_ptrns();
10265
Arun Khandavallifae92942016-08-01 13:31:08 +053010266 switch (hdd_ctx->driver_status) {
10267 case DRIVER_MODULES_UNINITIALIZED:
10268 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010269 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010270 case DRIVER_MODULES_CLOSED:
10271 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010272 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010273 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010274 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10275
Komal Seelamf2136bb2016-09-28 18:30:44 +053010276 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010277 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010278 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010279 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010280 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010281 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010282 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010283
Arun Khandavallifae92942016-08-01 13:31:08 +053010284 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010285 hdd_info("Wlan transitioned (now OPENED)");
10286
10287 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010288 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010289 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010290 break;
10291 default:
10292 hdd_err("Trying to stop wlan in a wrong state: %d",
10293 hdd_ctx->driver_status);
10294 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010295 ret = -EINVAL;
10296 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010297 }
10298
Amar Singhal18081642018-01-26 16:04:13 -080010299 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010300 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010301
Rajeev Kumarbe021242017-02-16 16:12:23 -080010302 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010303 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10304 hdd_err("Failed to process post CDS disable Modules! :%d",
10305 qdf_status);
10306 ret = -EINVAL;
10307 QDF_ASSERT(0);
10308 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010309
psimhadeea0a12017-12-18 14:50:02 -080010310 hdd_runtime_suspend_context_deinit(hdd_ctx);
10311
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010312 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10313 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10314 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10315 ret = -EINVAL;
10316 QDF_ASSERT(0);
10317 }
10318
Jeff Johnsone4b14592017-09-13 14:23:33 -070010319 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010320 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010321 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010322 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010323 QDF_ASSERT(0);
10324 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010325
Amar Singhal410675c2018-01-10 12:14:21 -080010326 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010327 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10328 if (ret) {
10329 hdd_err("Failed to destroy pdev; errno:%d", ret);
10330 QDF_ASSERT(0);
10331 }
10332
10333 /*
10334 * Reset total mac phy during module stop such that during
10335 * next module start same psoc is used to populate new service
10336 * ready data
10337 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010338 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10339 if (tgt_hdl)
10340 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10341
Liangwei Dong50a64a72018-01-11 01:17:00 -050010342
Arun Khandavallifae92942016-08-01 13:31:08 +053010343 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10344 if (!hif_ctx) {
10345 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010346 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010347 }
10348
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010349 if (hdd_ctx->target_hw_name) {
10350 qdf_mem_free(hdd_ctx->target_hw_name);
10351 hdd_ctx->target_hw_name = NULL;
10352 }
10353
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010354 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010355
10356 ol_cds_free();
10357
Dustin Brown70111822017-03-30 15:31:40 -070010358 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010359 ret = pld_power_off(qdf_ctx->dev);
10360 if (ret)
10361 hdd_err("CNSS power down failed put device into Low power mode:%d",
10362 ret);
10363 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010364
Dustin Brown4bc0a622017-12-06 15:56:50 -080010365 /* many adapter resources are not freed by design in SSR case */
10366 if (!is_recovery_stop)
10367 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010368 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010369
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010370 /* Once the firmware sequence is completed reset this flag */
10371 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010372 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010373 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010374
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010375done:
10376 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010377 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010378 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010379 hdd_alert("stop WLAN module: exit driver status=%d",
10380 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010381
Dustin Browne74003f2018-03-14 12:51:58 -070010382 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010383
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010384 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010385}
10386
Arun Khandavallifae92942016-08-01 13:31:08 +053010387
10388/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010389 * hdd_state_info_dump() - prints state information of hdd layer
10390 * @buf: buffer pointer
10391 * @size: size of buffer to be filled
10392 *
10393 * This function is used to dump state information of hdd layer
10394 *
10395 * Return: None
10396 */
10397static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10398{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010399 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010400 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010401 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010402 uint16_t len = 0;
10403 char *buf = *buf_ptr;
10404
10405 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10406 if (!hdd_ctx) {
10407 hdd_err("Failed to get hdd context ");
10408 return;
10409 }
10410
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010411 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010412
10413 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010414 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010415 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010416 "\n is_scheduler_suspended %d",
10417 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010418
Dustin Brown920397d2017-12-13 16:27:50 -080010419 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010420 if (adapter->dev)
10421 len += scnprintf(buf + len, *size - len,
10422 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010423 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010424 "\n device_mode: %d", adapter->device_mode);
10425 switch (adapter->device_mode) {
10426 case QDF_STA_MODE:
10427 case QDF_P2P_CLIENT_MODE:
10428 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10429 len += scnprintf(buf + len, *size - len,
10430 "\n connState: %d",
10431 hdd_sta_ctx->conn_info.connState);
10432 break;
10433
10434 default:
10435 break;
10436 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010437 }
10438
10439 *size -= len;
10440 *buf_ptr += len;
10441}
10442
10443/**
10444 * hdd_register_debug_callback() - registration function for hdd layer
10445 * to print hdd state information
10446 *
10447 * Return: None
10448 */
10449static void hdd_register_debug_callback(void)
10450{
10451 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10452}
10453
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010454/*
10455 * wlan_init_bug_report_lock() - Initialize bug report lock
10456 *
10457 * This function is used to create bug report lock
10458 *
10459 * Return: None
10460 */
10461static void wlan_init_bug_report_lock(void)
10462{
10463 p_cds_contextType p_cds_context;
10464
10465 p_cds_context = cds_get_global_context();
10466 if (!p_cds_context) {
10467 hdd_err("cds context is NULL");
10468 return;
10469 }
10470
10471 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10472}
10473
Mohit Khannaf8f96822017-05-17 17:11:59 -070010474void hdd_dp_trace_init(struct hdd_config *config)
10475{
10476
10477 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10478 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10479 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10480 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10481 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10482 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10483 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010484 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010485
10486 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10487 &num_entries, sizeof(config_params));
10488
10489 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010490 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010491 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010492 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010493 else if (bw_compute_interval > 1000) {
10494 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10495 thresh_time_limit = 1;
10496 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010497 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10498
10499 switch (num_entries) {
10500 case 4:
10501 proto_bitmap = config_params[3];
10502 case 3:
10503 verbosity = config_params[2];
10504 case 2:
10505 thresh = config_params[1];
10506 case 1:
10507 live_mode = config_params[0];
10508 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010509 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010510 live_mode, thresh, thresh_time_limit,
10511 verbosity, proto_bitmap);
10512 };
10513
10514 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10515 verbosity, proto_bitmap);
10516
10517}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010518/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010519 * hdd_wlan_startup() - HDD init function
10520 * @dev: Pointer to the underlying device
10521 *
10522 * This is the driver startup code executed once a WLAN device has been detected
10523 *
10524 * Return: 0 for success, < 0 for failure
10525 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010526int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010527{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010528 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010529 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010530 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010531 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010532
Dustin Brown491d54b2018-03-14 12:39:11 -070010533 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010534
Arun Khandavallifae92942016-08-01 13:31:08 +053010535 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010536
10537 if (IS_ERR(hdd_ctx))
10538 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010539
Abhishek Singhe9068f12017-03-31 14:14:52 +053010540 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10541 DEFAULT_PSOC_ID);
10542 if (ret) {
10543 hdd_err("Psoc creation fails!");
10544 QDF_BUG(0);
10545 goto err_hdd_free_context;
10546 }
10547
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010548 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010549#ifdef FEATURE_WLAN_CH_AVOID
10550 mutex_init(&hdd_ctx->avoid_freq_lock);
10551#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010552
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010553 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010554 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010555
Dustin Brown021cecd2017-12-11 13:56:43 -080010556 hdd_driver_memdump_init();
10557
Jeff Johnson957bc272017-02-02 08:54:48 -080010558 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010559 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010560 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010561 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010562 }
10563
Yingying Tang80e15f32016-09-27 18:23:01 +080010564 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010565
Anurag Chouhan6d760662016-02-20 16:05:43 +053010566 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010567
10568 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010569 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010570 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010571 }
10572
Prashanth Bhatta07998752016-04-28 12:35:33 -070010573 ret = hdd_wiphy_init(hdd_ctx);
10574 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010575 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010576 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010577 }
10578
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010579 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010580 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010581
jiad195f7032018-01-31 15:18:09 +080010582 ret = hdd_ipa_init(hdd_ctx);
10583 if (ret == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010584 goto err_wiphy_unregister;
10585
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010586 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010587
Paul Zhangfb02f452017-12-22 11:58:43 +080010588 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10589 if (ret) {
10590 hdd_err("register_netdevice_notifier failed: %d", ret);
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010591 goto err_ipa_cleanup;
Paul Zhangfb02f452017-12-22 11:58:43 +080010592 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010593
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010594 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010595
Jeff Johnson957bc272017-02-02 08:54:48 -080010596 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10597 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010598 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010599 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010600 }
10601
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010602 hdd_release_rtnl_lock();
10603 rtnl_held = false;
10604
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010605 wlan_hdd_update_11n_mode(hdd_ctx->config);
10606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010607#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010608 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010609 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010610 hdd_skip_acs_scan_timer_handler,
10611 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010612 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010613 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010614 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010615#endif
10616
Prashanth Bhattaab004382016-10-11 16:08:11 -070010617 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010618
Jeff Johnson9afc5012016-09-23 13:56:27 -070010619 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010620
Nirav Shahbd36b062016-07-18 11:12:59 +053010621 if (hdd_ctx->rps)
10622 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010623
Paul Zhangfb02f452017-12-22 11:58:43 +080010624 ret = hdd_register_notifiers(hdd_ctx);
10625 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010626 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010627
Paul Zhangfb02f452017-12-22 11:58:43 +080010628 status = wlansap_global_init();
10629 if (QDF_IS_STATUS_ERROR(status)) {
10630 hdd_unregister_notifiers(hdd_ctx);
10631 goto err_close_adapters;
10632 }
10633
Arun Khandavallifae92942016-08-01 13:31:08 +053010634 if (hdd_ctx->config->fIsImpsEnabled)
10635 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010636 else
10637 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010638
Mukul Sharma07bd8752017-10-10 16:58:14 +053010639 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010640 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10641 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010642 hdd_prevent_suspend_timeout(
10643 hdd_ctx->config->iface_change_wait_time,
10644 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10645 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010646
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010647 goto success;
10648
Jeff Johnson957bc272017-02-02 08:54:48 -080010649err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010650 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010651
Jeff Johnson46bde382017-02-01 15:31:16 -080010652err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +053010653 if (rtnl_held)
10654 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010655
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010656 unregister_netdevice_notifier(&hdd_netdev_notifier);
10657
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010658err_ipa_cleanup:
Anurag Chouhance6a4052016-09-14 18:20:42 +053010659 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -080010660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010661err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010662 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010663
Arun Khandavallifae92942016-08-01 13:31:08 +053010664err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010665 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010666
Dustin Brown021cecd2017-12-11 13:56:43 -080010667err_memdump_deinit:
10668 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010669
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010670 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010671 hdd_exit_netlink_services(hdd_ctx);
10672
Dustin Brown20912462017-06-07 13:48:25 -070010673 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10674
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010675err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010676 if (cds_is_fw_down())
10677 hdd_err("Not setting the complete event as fw is down");
10678 else
10679 hdd_start_complete(ret);
10680
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010681 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010682 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010683 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010684
10685success:
Dustin Browne74003f2018-03-14 12:51:58 -070010686 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010687 return 0;
10688}
10689
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010690/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010691 * hdd_wlan_update_target_info() - update target type info
10692 * @hdd_ctx: HDD context
10693 * @context: hif context
10694 *
10695 * Update target info received from firmware in hdd context
10696 * Return:None
10697 */
10698
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010699void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010700{
10701 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10702
10703 if (!tgt_info) {
10704 hdd_err("Target info is Null");
10705 return;
10706 }
10707
10708 hdd_ctx->target_type = tgt_info->target_type;
10709}
10710
10711/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010712 * hdd_get_nud_stats_cb() - callback api to update the stats
10713 * received from the firmware
10714 * @data: pointer to adapter.
10715 * @rsp: pointer to data received from FW.
10716 *
10717 * This is called when wlan driver received response event for
10718 * get arp stats to firmware.
10719 *
10720 * Return: None
10721 */
10722static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10723{
10724 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10725 struct hdd_nud_stats_context *context;
10726 int status;
10727 struct hdd_adapter *adapter = NULL;
10728
Dustin Brown491d54b2018-03-14 12:39:11 -070010729 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010730
10731 if (!rsp) {
10732 hdd_err("data is null");
10733 return;
10734 }
10735
10736 status = wlan_hdd_validate_context(hdd_ctx);
10737 if (0 != status)
10738 return;
10739
10740 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10741 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10742 hdd_err("Invalid adapter or adapter has invalid magic");
10743 return;
10744 }
10745
Dustin Brown5e89ef82018-03-14 11:50:23 -070010746 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10747 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10748 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10749 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10750 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10751 rsp->out_of_order_arp_rsp_drop_cnt);
10752 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10753 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10754 hdd_info("rsp->ba_session_establishment_status :%x",
10755 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010756
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010757 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010758 adapter->dad |= rsp->dad_detected;
10759 adapter->con_status = rsp->connect_status;
10760
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010761 /* Flag true indicates connectivity check stats present. */
10762 if (rsp->connect_stats_present) {
10763 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10764 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10765 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10766 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10767 rsp->icmpv4_rsp_recvd;
10768 }
10769
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010770 spin_lock(&hdd_context_lock);
10771 context = &hdd_ctx->nud_stats_context;
10772 complete(&context->response_event);
10773 spin_unlock(&hdd_context_lock);
10774
Dustin Browne74003f2018-03-14 12:51:58 -070010775 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010776}
10777
10778/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010779 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010780 * @hdd_ctx: HDD context
10781 *
10782 * Register the HDD callbacks to CDS/SME.
10783 *
10784 * Return: 0 for success or Error code for failure
10785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010786int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010787{
10788 QDF_STATUS status;
10789 int ret = 0;
10790
Dustin Brown491d54b2018-03-14 12:39:11 -070010791 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010792
10793 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10794
10795 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10796 hdd_send_oem_data_rsp_msg);
10797
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010798 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10799 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010800 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10801 sme_nan_register_callback(hdd_ctx->hHal,
10802 wlan_hdd_cfg80211_nan_callback);
10803 sme_stats_ext_register_callback(hdd_ctx->hHal,
10804 wlan_hdd_cfg80211_stats_ext_callback);
10805
10806 sme_ext_scan_register_callback(hdd_ctx->hHal,
10807 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010808 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10809 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010810
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010811 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10812 hdd_rssi_threshold_breached);
10813
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010814 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10815
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010816 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10817 wlan_hdd_cfg80211_link_layer_stats_callback);
10818
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010819 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10820
Zhang Qianca38fb12016-12-23 11:10:48 +080010821 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10822 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10823
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010824 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10825 hdd_lost_link_info_cb);
10826 /* print error and not block the startup process */
10827 if (!QDF_IS_STATUS_SUCCESS(status))
10828 hdd_err("set lost link info callback failed");
10829
Poddar, Siddarth34872782017-08-10 14:08:51 +053010830 ret = hdd_register_data_stall_detect_cb();
10831 if (ret) {
10832 hdd_err("Register data stall detect detect callback failed.");
10833 return ret;
10834 }
10835
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010836 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10837
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010838 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010839 hdd_set_connection_in_progress,
10840 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010841
10842 status = sme_congestion_register_callback(hdd_ctx->hHal,
10843 hdd_update_cca_info_cb);
10844 if (!QDF_IS_STATUS_SUCCESS(status))
10845 hdd_err("set congestion callback failed");
10846
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010847 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10848 hdd_bt_activity_cb);
10849 if (!QDF_IS_STATUS_SUCCESS(status))
10850 hdd_err("set bt activity info callback failed");
10851
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010852 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10853 hdd_tx_queue_cb);
10854 if (!QDF_IS_STATUS_SUCCESS(status))
10855 hdd_err("Register tx queue callback failed");
10856
Dustin Browne74003f2018-03-14 12:51:58 -070010857 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010858
10859 return ret;
10860}
10861
10862/**
10863 * hdd_deregister_cb() - De-Register HDD callbacks.
10864 * @hdd_ctx: HDD context
10865 *
10866 * De-Register the HDD callbacks to CDS/SME.
10867 *
10868 * Return: void
10869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010870void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010871{
10872 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010873 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010874
Dustin Brown491d54b2018-03-14 12:39:11 -070010875 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010876
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010877 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010878 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10879 if (!QDF_IS_STATUS_SUCCESS(status))
10880 hdd_err("De-register of dcc stats callback failed: %d",
10881 status);
10882
10883 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010884 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10885
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010886 sme_stats_ext_register_callback(hdd_ctx->hHal,
10887 wlan_hdd_cfg80211_stats_ext_callback);
10888
10889 sme_nan_deregister_callback(hdd_ctx->hHal);
10890 status = sme_reset_tsfcb(hdd_ctx->hHal);
10891 if (!QDF_IS_STATUS_SUCCESS(status))
10892 hdd_err("Failed to de-register tsfcb the callback:%d",
10893 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010894
Poddar, Siddarth34872782017-08-10 14:08:51 +053010895 ret = hdd_deregister_data_stall_detect_cb();
10896 if (ret)
10897 hdd_err("Failed to de-register data stall detect event callback");
10898
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010899 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
10900 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
10901
Dustin Browne74003f2018-03-14 12:51:58 -070010902 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010903}
10904
10905/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010906 * hdd_softap_sta_deauth() - handle deauth req from HDD
10907 * @adapter: Pointer to the HDD
10908 * @enable: bool value
10909 *
10910 * This to take counter measure to handle deauth req from HDD
10911 *
10912 * Return: None
10913 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010914QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010915 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010916{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010917 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010918
Dustin Brown491d54b2018-03-14 12:39:11 -070010919 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010920
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010921 /* Ignore request to deauth bcmc station */
10922 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010923 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010924
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010925 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010926 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
10927 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010928
Dustin Browne74003f2018-03-14 12:51:58 -070010929 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010930 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010931}
10932
10933/**
10934 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
10935 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010936 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010937 *
10938 * This to take counter measure to handle deauth req from HDD
10939 *
10940 * Return: None
10941 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010942void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080010943 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010944{
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010945 struct sir_peer_sta_info peer_sta_info;
10946 struct hdd_station_info *stainfo;
Jeff Johnsone0847ba2018-03-01 12:34:50 -080010947
Dustin Brown491d54b2018-03-14 12:39:11 -070010948 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010949
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010950 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010951 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010952 return;
10953
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010954 wlan_hdd_get_peer_rssi(adapter, &pDelStaParams->peerMacAddr,
10955 &peer_sta_info);
10956 stainfo = hdd_get_stainfo(adapter->cache_sta_info,
10957 pDelStaParams->peerMacAddr);
10958 if (stainfo) {
10959 stainfo->rssi = peer_sta_info.info[0].rssi;
10960 stainfo->tx_rate = peer_sta_info.info[0].tx_rate;
10961 stainfo->rx_rate = peer_sta_info.info[0].rx_rate;
Jiachao Wuf610d912018-01-23 17:47:32 +080010962 stainfo->reason_code = pDelStaParams->reason_code;
Ashish Kumar Dhanotiya443d31f2017-10-13 12:41:19 +053010963 }
10964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010965 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053010966 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010967}
10968
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010969/**
10970 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
10971 * @hdd_ctx: HDD Context
10972 *
10973 * API to find if there is any STA or P2P-Client is connected
10974 *
10975 * Return: true if connected; false otherwise
10976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010977QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010978{
10979 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
10980}
10981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010982/**
10983 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
10984 * @adapter: HDD adapter pointer
10985 *
10986 * This function loop through each adapter and disable roaming on each STA
10987 * device mode except the input adapter.
10988 *
10989 * Note: On the input adapter roaming is not enabled yet hence no need to
10990 * disable.
10991 *
10992 * Return: None
10993 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010994void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010995{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010996 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070010997 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010998
10999 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011000 hdd_ctx->config->isRoamOffloadScanEnabled &&
11001 QDF_STA_MODE == adapter->device_mode &&
11002 policy_mgr_is_sta_active_connection_exists(
11003 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011004 hdd_debug("Connect received on STA session Id(%d)",
11005 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011006 /*
11007 * Loop through adapter and disable roaming for each STA device
11008 * mode except the input adapter.
11009 */
Dustin Brown920397d2017-12-13 16:27:50 -080011010 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011011 if (QDF_STA_MODE == adapterIdx->device_mode &&
11012 adapter->session_id != adapterIdx->session_id) {
11013 hdd_debug("Disable Roaming on session Id(%d)",
11014 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011015 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11016 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011017 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011018 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011019 }
11020 }
11021}
11022
11023/**
11024 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11025 * @adapter: HDD adapter pointer
11026 *
11027 * This function loop through each adapter and enable roaming on each STA
11028 * device mode except the input adapter.
11029 * Note: On the input adapter no need to enable roaming because link got
11030 * disconnected on this.
11031 *
11032 * Return: None
11033 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011034void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011035{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011036 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011037 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011038
11039 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011040 hdd_ctx->config->isRoamOffloadScanEnabled &&
11041 QDF_STA_MODE == adapter->device_mode &&
11042 policy_mgr_is_sta_active_connection_exists(
11043 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011044 hdd_debug("Disconnect received on STA session Id(%d)",
11045 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011046 /*
11047 * Loop through adapter and enable roaming for each STA device
11048 * mode except the input adapter.
11049 */
Dustin Brown920397d2017-12-13 16:27:50 -080011050 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011051 if (QDF_STA_MODE == adapterIdx->device_mode &&
11052 adapter->session_id != adapterIdx->session_id) {
11053 hdd_debug("Enabling Roaming on session Id(%d)",
11054 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011055 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11056 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011057 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011058 REASON_CONNECT);
11059 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011060 }
11061 }
11062}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011063
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011064/**
11065 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11066 * @skb: sk buffer pointer
11067 *
11068 * Sends the bcast message to SVC multicast group with generic nl socket
11069 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11070 *
11071 * Return: None
11072 */
11073static void nl_srv_bcast_svc(struct sk_buff *skb)
11074{
11075#ifdef CNSS_GENL
11076 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11077#else
11078 nl_srv_bcast(skb);
11079#endif
11080}
11081
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011082void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011083{
11084 struct sk_buff *skb;
11085 struct nlmsghdr *nlh;
11086 tAniMsgHdr *ani_hdr;
11087 void *nl_data = NULL;
11088 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011089 struct radio_index_tlv *radio_info;
11090 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011091
11092 if (in_interrupt() || irqs_disabled() || in_atomic())
11093 flags = GFP_ATOMIC;
11094
11095 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11096
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011097 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011098 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011099
11100 nlh = (struct nlmsghdr *)skb->data;
11101 nlh->nlmsg_pid = 0; /* from kernel */
11102 nlh->nlmsg_flags = 0;
11103 nlh->nlmsg_seq = 0;
11104 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11105
11106 ani_hdr = NLMSG_DATA(nlh);
11107 ani_hdr->type = type;
11108
11109 switch (type) {
11110 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011111 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011112 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011113 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011114 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011115 ani_hdr->length = 0;
11116 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011117 break;
11118 case WLAN_SVC_WLAN_STATUS_IND:
11119 case WLAN_SVC_WLAN_VERSION_IND:
11120 case WLAN_SVC_DFS_CAC_START_IND:
11121 case WLAN_SVC_DFS_CAC_END_IND:
11122 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11123 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11124 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011125 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011126 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011127 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128 ani_hdr->length = len;
11129 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11130 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11131 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011132 break;
11133
11134 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011135 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011136 type);
11137 kfree_skb(skb);
11138 return;
11139 }
11140
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011141 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011142 * Add radio index at the end of the svc event in TLV format
11143 * to maintain the backward compatibility with userspace
11144 * applications.
11145 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011146
11147 tlv_len = 0;
11148
11149 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11150 < WLAN_NL_MAX_PAYLOAD) {
11151 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11152 sizeof(*ani_hdr) + len);
11153 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11154 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11155 radio_info->radio = radio;
11156 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011157 hdd_debug("Added radio index tlv - radio index %d",
11158 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011159 }
11160
11161 nlh->nlmsg_len += tlv_len;
11162 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11163
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011164 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011165}
11166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011167#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11168void wlan_hdd_auto_shutdown_cb(void)
11169{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011170 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011171
11172 if (!hdd_ctx)
11173 return;
11174
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011175 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011176 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11177 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178}
11179
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011180void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011181{
Jeff Johnson9d295242017-08-29 14:39:48 -070011182 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011183 bool ap_connected = false, sta_connected = false;
11184 tHalHandle hal_handle;
11185
11186 hal_handle = hdd_ctx->hHal;
11187 if (hal_handle == NULL)
11188 return;
11189
11190 if (hdd_ctx->config->WlanAutoShutdown == 0)
11191 return;
11192
11193 if (enable == false) {
11194 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011195 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011196 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011197 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011198 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011199 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011200 return;
11201 }
11202
11203 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011204 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11205 hdd_for_each_adapter(hdd_ctx, adapter) {
11206 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011207 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11208 conn_info.connState ==
11209 eConnectionState_Associated) {
11210 sta_connected = true;
11211 break;
11212 }
11213 }
Dustin Brown920397d2017-12-13 16:27:50 -080011214
11215 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011216 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011217 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011218 ap_connected = true;
11219 break;
11220 }
11221 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011222 }
11223 }
11224
11225 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011226 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011227 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011228 }
Jeff Johnson68755312017-02-10 11:46:55 -080011229
11230 if (sme_set_auto_shutdown_timer(hal_handle,
11231 hdd_ctx->config->WlanAutoShutdown)
11232 != QDF_STATUS_SUCCESS)
11233 hdd_err("Failed to start wlan auto shutdown timer");
11234 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011235 hdd_info("Auto Shutdown timer for %d seconds enabled",
11236 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011237}
11238#endif
11239
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011240struct hdd_adapter *
11241hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11242 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011243{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011244 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011245 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011246
11247 con_sap_adapter = NULL;
11248
Dustin Brown920397d2017-12-13 16:27:50 -080011249 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011250 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11251 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011252 adapter != this_sap_adapter) {
11253 if (check_start_bss) {
11254 if (test_bit(SOFTAP_BSS_STARTED,
11255 &adapter->event_flags)) {
11256 con_sap_adapter = adapter;
11257 break;
11258 }
11259 } else {
11260 con_sap_adapter = adapter;
11261 break;
11262 }
11263 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011264 }
11265
11266 return con_sap_adapter;
11267}
11268
11269#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011270static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011271{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011272 return adapter->device_mode == QDF_STA_MODE ||
11273 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274}
11275
Jeff Johnson9d295242017-08-29 14:39:48 -070011276static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011277{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011278 return adapter->device_mode == QDF_SAP_MODE ||
11279 adapter->device_mode == QDF_P2P_GO_MODE;
11280}
11281
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011282static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011283{
Dustin Brown920397d2017-12-13 16:27:50 -080011284 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011285
Dustin Brown920397d2017-12-13 16:27:50 -080011286 hdd_for_each_adapter(hdd_ctx, adapter) {
11287 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011288 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11289 conn_info.connState == eConnectionState_Associated) {
11290 return true;
11291 }
11292
Dustin Brown920397d2017-12-13 16:27:50 -080011293 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011294 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011295 return true;
11296 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011297 }
11298
11299 return false;
11300}
11301
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011302static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011303{
11304 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011305
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011306 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011307 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011308 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011309
Dustin Brown5ec6b552017-03-31 12:11:40 -070011310 return is_running;
11311}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011312
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011313static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011314{
11315 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11316 hdd_ctx->bus_bw_timer_running = true;
11317 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11318 hdd_ctx->config->busBandwidthComputeInterval);
11319 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11320}
11321
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011322void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011323{
Dustin Brown491d54b2018-03-14 12:39:11 -070011324 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011325
11326 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11327 hdd_debug("Bandwidth compute timer already started");
11328 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329 }
11330
Dustin Brown5ec6b552017-03-31 12:11:40 -070011331 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11332
Dustin Browne74003f2018-03-14 12:51:58 -070011333 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011334}
11335
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011336void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011337{
Dustin Brown491d54b2018-03-14 12:39:11 -070011338 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011339
11340 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11341 hdd_debug("Bandwidth compute timer already started");
11342 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011343 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011344
11345 if (hdd_any_adapter_is_assoc(hdd_ctx))
11346 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11347
Dustin Browne74003f2018-03-14 12:51:58 -070011348 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011349}
11350
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011351static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011352{
11353 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
11354
11355 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11356 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11357 hdd_ctx->bus_bw_timer_running = false;
11358 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11359
11360 hdd_reset_tcp_delack(hdd_ctx);
11361}
11362
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011363void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011364{
Dustin Brown491d54b2018-03-14 12:39:11 -070011365 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011366
11367 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11368 hdd_debug("Bandwidth compute timer already stopped");
11369 return;
11370 }
11371
11372 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11373
Dustin Browne74003f2018-03-14 12:51:58 -070011374 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011375}
11376
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011377void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011378{
Dustin Brown491d54b2018-03-14 12:39:11 -070011379 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011380
11381 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11382 hdd_debug("Bandwidth compute timer already stopped");
11383 return;
11384 }
11385
11386 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11387 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11388
Dustin Browne74003f2018-03-14 12:51:58 -070011389 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011390}
11391#endif
11392
11393/**
11394 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11395 * and sta's operating channel.
11396 * @sta_adapter: Describe the first argument to foobar.
11397 * @ap_adapter: Describe the second argument to foobar.
11398 * @roam_profile: Roam profile of AP to which STA wants to connect.
11399 * @concurrent_chnl_same: If both SAP and STA channels are same then
11400 * set this flag to true else false.
11401 *
11402 * This function checks the sap's operating channel and sta's operating channel.
11403 * if both are same then it will return false else it will restart the sap in
11404 * sta's channel and return true.
11405 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011406 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011407 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011408QDF_STATUS
11409wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11410 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011411 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011412 tScanResultHandle *scan_cache,
11413 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414{
Jeff Johnson87251032017-08-29 13:31:11 -070011415 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011416 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011417 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011418 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011419 *concurrent_chnl_same = true;
11420
11421 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11422 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011423 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011424 scan_cache,
11425 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011426 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011427 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011428 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011429 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011430 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011431 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011432 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011433 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011434 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011435 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011436 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011437 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011438 }
11439 }
11440 } else {
11441 /*
11442 * Lets handle worst case scenario here, Scan cache lookup is
11443 * failed so we have to stop the SAP to avoid any channel
11444 * discrepancy between SAP's channel and STA's channel.
11445 * Return the status as failure so caller function could know
11446 * that scan look up is failed.
11447 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011448 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011449 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011450 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011451 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011452}
11453
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011454/**
11455 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11456 * @ap_adapter: SAP adapter
11457 *
11458 * This function will process the stopping of sap adapter.
11459 *
11460 * Return: None
11461 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011462void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011463{
Jeff Johnson87251032017-08-29 13:31:11 -070011464 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011465 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011466 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011467 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011468
11469 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011470 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011471 return;
11472 }
11473
11474 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11475 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011476 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011477 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011478
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011479 mutex_lock(&hdd_ctx->sap_lock);
11480 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011481 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011482 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011483 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011484 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011485 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011486 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011487 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011488 qdf_stop_bss_event,
11489 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011490 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011491 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011492 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011493 return;
11494 }
11495 }
11496 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011497 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11498 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011499 ap_adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011500 hdd_start_green_ap_state_mc(hdd_ctx, ap_adapter->device_mode,
11501 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011502 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011503 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011504 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011505 }
11506 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011507}
11508
11509/**
11510 * wlan_hdd_start_sap() - this function starts bss of SAP.
11511 * @ap_adapter: SAP adapter
11512 *
11513 * This function will process the starting of sap adapter.
11514 *
11515 * Return: None
11516 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011517void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011518{
Jeff Johnson87251032017-08-29 13:31:11 -070011519 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011520 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011521 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011522 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011523 tsap_Config_t *sap_config;
11524
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
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011530 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011531 hdd_err("SoftAp role has not been enabled");
11532 return;
11533 }
11534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011535 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11536 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11537 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011538 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011540 mutex_lock(&hdd_ctx->sap_lock);
11541 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11542 goto end;
11543
11544 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011545 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011546 goto end;
11547 }
11548
Wei Song2f76f642016-11-18 16:32:53 +080011549 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011550 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011551 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011552 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011553 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011554 goto end;
11555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011556 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011557 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011558 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011559 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011560 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011561 goto end;
11562 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011563 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011564 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011565 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011566 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011567 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11568 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011569 ap_adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011570 hdd_start_green_ap_state_mc(hdd_ctx, ap_adapter->device_mode,
11571 true);
11572 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011573 mutex_unlock(&hdd_ctx->sap_lock);
11574
11575 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011576end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011577 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011578 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011579 /* SAP context and beacon cleanup will happen during driver unload
11580 * in hdd_stop_adapter
11581 */
11582 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011584}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011585
11586/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011587 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11588 * mac scan config
11589 * @status: Status of set antenna mode
11590 *
11591 * Callback on setting the dual mac configuration
11592 *
11593 * Return: None
11594 */
11595void wlan_hdd_soc_set_antenna_mode_cb(
11596 enum set_antenna_mode_status status)
11597{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011598 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011599
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011600 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011601
11602 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11603 if (0 != wlan_hdd_validate_context(hdd_ctx))
11604 return;
11605
11606 /* Signal the completion of set dual mac config */
11607 complete(&hdd_ctx->set_antenna_mode_cmpl);
11608}
11609
11610/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011611 * hdd_get_fw_version() - Get FW version
11612 * @hdd_ctx: pointer to HDD context.
11613 * @major_spid: FW version - major spid.
11614 * @minor_spid: FW version - minor spid
11615 * @ssid: FW version - ssid
11616 * @crmid: FW version - crmid
11617 *
11618 * This function is called to get the firmware build version stored
11619 * as part of the HDD context
11620 *
11621 * Return: None
11622 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011623void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011624 uint32_t *major_spid, uint32_t *minor_spid,
11625 uint32_t *siid, uint32_t *crmid)
11626{
11627 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11628 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11629 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11630 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11631}
11632
11633#ifdef QCA_CONFIG_SMP
11634/**
11635 * wlan_hdd_get_cpu() - get cpu_index
11636 *
11637 * Return: cpu_index
11638 */
11639int wlan_hdd_get_cpu(void)
11640{
11641 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011642
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011643 put_cpu();
11644 return cpu_index;
11645}
11646#endif
11647
11648/**
11649 * hdd_get_fwpath() - get framework path
11650 *
11651 * This function is used to get the string written by
11652 * userspace to start the wlan driver
11653 *
11654 * Return: string
11655 */
11656const char *hdd_get_fwpath(void)
11657{
11658 return fwpath.string;
11659}
11660
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011661static int hdd_qdf_print_init(void)
11662{
11663 int qdf_print_idx;
11664 QDF_STATUS status;
11665
11666 status = qdf_print_setup();
11667 if (status != QDF_STATUS_SUCCESS) {
11668 pr_err("qdf_print_setup failed\n");
11669 return -EINVAL;
11670 }
11671
11672 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11673
11674 if (qdf_print_idx < 0) {
11675 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11676 qdf_print_idx);
11677 return -EINVAL;
11678 }
11679
11680 qdf_set_pidx(qdf_print_idx);
11681
11682 return 0;
11683}
11684
11685static void hdd_qdf_print_deinit(void)
11686{
11687 int qdf_print_idx;
11688
11689 qdf_print_idx = qdf_get_pidx();
11690 qdf_print_ctrl_cleanup(qdf_print_idx);
11691}
11692
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011693/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011694 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011695 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011696 * This function initilizes CDS global context with the help of cds_init. This
11697 * has to be the first function called after probe to get a valid global
11698 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011699 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011700 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011701 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011702int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011703{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011704 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011705 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011706
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011707 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011708 if (QDF_IS_STATUS_ERROR(status)) {
11709 hdd_err("Failed to allocate CDS context");
11710 ret = -ENOMEM;
11711 goto err_out;
11712 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011713
11714 wlan_init_bug_report_lock();
11715
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011716#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11717 wlan_logging_sock_init_svc();
11718#endif
11719
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011720 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11721 (void *)hdd_drv_ops_inactivity_handler, NULL,
11722 QDF_TIMER_TYPE_SW);
11723
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011724 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011725 hdd_qdf_print_init();
11726
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011727 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011728
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011729err_out:
11730 return ret;
11731}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011732
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011733/**
11734 * hdd_deinit() - Deinitialize Driver
11735 *
11736 * This function frees CDS global context with the help of cds_deinit. This
11737 * has to be the last function call in remove callback to free the global
11738 * context.
11739 */
11740void hdd_deinit(void)
11741{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011742 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011743
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011744 wlan_destroy_bug_report_lock();
11745 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011746
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011747 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011748#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11749 wlan_logging_sock_deinit_svc();
11750#endif
11751}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011752
Yue Ma6e7b1a02017-04-03 14:17:46 -070011753#ifdef QCA_WIFI_NAPIER_EMULATION
11754#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11755#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011756#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011757#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011758
Sachin Ahujadddd2632017-03-07 19:07:24 +053011759static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11760 struct file *file)
11761{
11762 return 0;
11763}
11764
11765static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11766 const char __user *user_buf,
11767 size_t count,
11768 loff_t *f_pos)
11769{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011770 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011771 static const char wlan_off_str[] = "OFF";
11772 static const char wlan_on_str[] = "ON";
11773 int ret;
11774 unsigned long rc;
11775
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011776 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011777 pr_err("Failed to read buffer\n");
11778 return -EINVAL;
11779 }
11780
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011781 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011782 pr_debug("Wifi turning off from UI\n");
11783 goto exit;
11784 }
11785
Sachin Ahuja16904db2017-12-13 19:56:57 +053011786 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11787 pr_info("Wifi Turning On from UI\n");
11788 }
11789
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011790 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011791 pr_err("Invalid value received from framework");
11792 goto exit;
11793 }
11794
11795 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011796 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011797 rc = wait_for_completion_timeout(&wlan_start_comp,
11798 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11799 if (!rc) {
11800 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11801 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011802 return ret;
11803 }
11804
11805 hdd_start_complete(0);
11806 }
11807
11808exit:
11809 return count;
11810}
11811
11812
11813const struct file_operations wlan_hdd_state_fops = {
11814 .owner = THIS_MODULE,
11815 .open = wlan_hdd_state_ctrl_param_open,
11816 .write = wlan_hdd_state_ctrl_param_write,
11817};
11818
11819static int wlan_hdd_state_ctrl_param_create(void)
11820{
11821 unsigned int wlan_hdd_state_major = 0;
11822 int ret;
11823 struct device *dev;
11824
11825 device = MKDEV(wlan_hdd_state_major, 0);
11826
11827 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11828 if (ret) {
11829 pr_err("Failed to register qcwlanstate");
11830 goto dev_alloc_err;
11831 }
11832 wlan_hdd_state_major = MAJOR(device);
11833
11834 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11835 if (IS_ERR(class)) {
11836 pr_err("wlan_hdd_state class_create error");
11837 goto class_err;
11838 }
11839
11840 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11841 if (IS_ERR(dev)) {
11842 pr_err("wlan_hdd_statedevice_create error");
11843 goto err_class_destroy;
11844 }
11845
11846 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11847 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11848 if (ret) {
11849 pr_err("Failed to add cdev error");
11850 goto cdev_add_err;
11851 }
11852
11853 pr_info("wlan_hdd_state %s major(%d) initialized",
11854 WLAN_MODULE_NAME, wlan_hdd_state_major);
11855
11856 return 0;
11857
11858cdev_add_err:
11859 device_destroy(class, device);
11860err_class_destroy:
11861 class_destroy(class);
11862class_err:
11863 unregister_chrdev_region(device, dev_num);
11864dev_alloc_err:
11865 return -ENODEV;
11866}
11867
11868static void wlan_hdd_state_ctrl_param_destroy(void)
11869{
11870 cdev_del(&wlan_hdd_state_cdev);
11871 device_destroy(class, device);
11872 class_destroy(class);
11873 unregister_chrdev_region(device, dev_num);
11874
11875 pr_info("Device node unregistered");
11876}
11877
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011878/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011879 * component_init - API to init cld component's
11880 *
11881 * Return: None
11882 */
11883static void component_init(void)
11884{
11885 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011886 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011887 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011888 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011889}
11890
11891/**
11892 * component_deinit - API to deinit cld component's
11893 *
11894 * Return: None
11895 */
11896static void component_deinit(void)
11897{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011898 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011899 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011900 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011901 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011902}
11903
11904void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11905{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011906 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011907 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011908}
11909
11910void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
11911{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011912 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080011913 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053011914}
11915
11916/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011917 * __hdd_module_init - Module init helper
11918 *
11919 * Module init helper function used by both module and static driver.
11920 *
11921 * Return: 0 for success, errno on failure
11922 */
11923static int __hdd_module_init(void)
11924{
11925 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011926
Dustin Brown96cd9632017-11-13 12:45:04 -080011927 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070011928 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080011929 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080011930 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011931
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011932 pld_init();
11933
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011934 ret = hdd_init();
11935 if (ret) {
11936 pr_err("hdd_init failed %x\n", ret);
11937 goto err_hdd_init;
11938 }
11939
Rajeev Kumar97767a02016-11-30 11:20:40 -080011940 dispatcher_init();
11941
Mukul Sharmad75a6672017-06-22 15:40:53 +053011942 /* Ensure to call post objmgr init */
11943 component_init();
11944
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011945 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011946
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011947 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011948
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011949 ret = wlan_hdd_register_driver();
11950 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070011951 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
11952 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011953 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011954 }
11955
Sachin Ahuja16904db2017-12-13 19:56:57 +053011956 ret = wlan_hdd_state_ctrl_param_create();
11957 if (ret) {
11958 pr_err("wlan_hdd_state_create:%x\n", ret);
11959 goto out;
11960 }
11961
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011962 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011963
11964 return 0;
11965out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011966 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080011967 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011968 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011969 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080011970
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011971err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070011972 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011973 return ret;
11974}
11975
11976/**
11977 * __hdd_module_exit - Module exit helper
11978 *
11979 * Module exit helper function used by both module and static driver.
11980 */
11981static void __hdd_module_exit(void)
11982{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053011983
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011984 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
11985 QWLAN_VERSIONSTR);
11986
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053011987 hdd_wait_for_recovery_completion();
11988
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011989 wlan_hdd_unregister_driver();
11990
Anurag Chouhana37b5b72016-02-21 14:53:42 +053011991 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011992
Mukul Sharmad75a6672017-06-22 15:40:53 +053011993 /* Ensure to call prior to objmgr deinit */
11994 component_deinit();
11995
Rajeev Kumar97767a02016-11-30 11:20:40 -080011996 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080011997
11998 hdd_sysfs_destroy_version_interface();
11999
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012000 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012001 pld_deinit();
12002
Sachin Ahujadddd2632017-03-07 19:07:24 +053012003 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012004}
12005
Arun Khandavallifae92942016-08-01 13:31:08 +053012006#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012007/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012008 * wlan_boot_cb() - Wlan boot callback
12009 * @kobj: object whose directory we're creating the link in.
12010 * @attr: attribute the user is interacting with
12011 * @buff: the buffer containing the user data
12012 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012013 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012014 * This callback is invoked when the fs is ready to start the
12015 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012016 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012017 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012018 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012019static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012020 struct kobj_attribute *attr,
12021 const char *buf,
12022 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012023{
Arun Khandavallifae92942016-08-01 13:31:08 +053012024
Arun Khandavallifae92942016-08-01 13:31:08 +053012025 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012026 pr_err("%s: wlan driver already initialized\n", __func__);
12027 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012028 }
12029
Arun Khandavallifae92942016-08-01 13:31:08 +053012030 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012031 pr_err("%s: wlan driver initialization failed\n", __func__);
12032 return -EIO;
12033 }
12034
12035 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012036
12037 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012038}
Arun Khandavallifae92942016-08-01 13:31:08 +053012039
12040/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012041 * hdd_sysfs_cleanup() - cleanup sysfs
12042 *
12043 * Return: None
12044 *
12045 */
12046static void hdd_sysfs_cleanup(void)
12047{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012048 /* remove from group */
12049 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12050 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12051 wlan_loader->attr_group);
12052
12053 /* unlink the object from parent */
12054 kobject_del(wlan_loader->boot_wlan_obj);
12055
12056 /* free the object */
12057 kobject_put(wlan_loader->boot_wlan_obj);
12058
12059 kfree(wlan_loader->attr_group);
12060 kfree(wlan_loader);
12061
12062 wlan_loader = NULL;
12063}
12064
12065/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012066 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12067 * ready
12068 *
12069 * This is creates the syfs entry boot_wlan. Which shall be invoked
12070 * when the filesystem is ready.
12071 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012072 * QDF API cannot be used here since this function is called even before
12073 * initializing WLAN driver.
12074 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012075 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012076 */
12077static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012078{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012079 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012080
12081 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012082 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012083 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012084
12085 wlan_loader->boot_wlan_obj = NULL;
12086 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12087 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012088 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012089 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012090
12091 wlan_loader->loaded_state = 0;
12092 wlan_loader->attr_group->attrs = attrs;
12093
12094 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12095 kernel_kobj);
12096 if (!wlan_loader->boot_wlan_obj) {
12097 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012098 goto error_return;
12099 }
12100
12101 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12102 wlan_loader->attr_group);
12103 if (ret) {
12104 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12105 goto error_return;
12106 }
12107
12108 return 0;
12109
12110error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012111 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012112
12113 return ret;
12114}
12115
12116/**
12117 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12118 *
12119 * Return: 0 on success or errno on failure
12120 */
12121static int wlan_deinit_sysfs(void)
12122{
Arun Khandavallifae92942016-08-01 13:31:08 +053012123 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012124 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012125 return -EINVAL;
12126 }
12127
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012128 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012129 return 0;
12130}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012131
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012132#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012133
12134#ifdef MODULE
12135/**
12136 * __hdd_module_init - Module init helper
12137 *
12138 * Module init helper function used by both module and static driver.
12139 *
12140 * Return: 0 for success, errno on failure
12141 */
12142static int hdd_module_init(void)
12143{
Arun Khandavallifae92942016-08-01 13:31:08 +053012144 if (__hdd_module_init()) {
12145 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012146 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012147 }
12148
Dustin Brownab482ac2017-06-09 17:00:44 -070012149 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012150}
12151#else
12152static int __init hdd_module_init(void)
12153{
12154 int ret = -EINVAL;
12155
12156 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012157 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012158 pr_err("Failed to create sysfs entry for loading wlan");
12159
12160 return ret;
12161}
12162#endif
12163
12164
12165#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012166/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012167 * hdd_module_exit() - Exit function
12168 *
12169 * This is the driver exit point (invoked when module is unloaded using rmmod)
12170 *
12171 * Return: None
12172 */
12173static void __exit hdd_module_exit(void)
12174{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012175 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012176}
Arun Khandavallifae92942016-08-01 13:31:08 +053012177#else
12178static void __exit hdd_module_exit(void)
12179{
12180 __hdd_module_exit();
12181 wlan_deinit_sysfs();
12182}
12183#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012184
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012185static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
12186{
12187 return param_set_copystring(kmessage, kp);
12188}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012189
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012190/**
12191 * is_con_mode_valid() check con mode is valid or not
12192 * @mode: global con mode
12193 *
12194 * Return: TRUE on success FALSE on failure
12195 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012196static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012197{
12198 switch (mode) {
12199 case QDF_GLOBAL_MONITOR_MODE:
12200 case QDF_GLOBAL_FTM_MODE:
12201 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012202 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012203 return true;
12204 default:
12205 return false;
12206 }
12207}
12208
12209/**
12210 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12211 * @mode: global con mode
12212 *
12213 * Return: adapter mode
12214 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012215static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012216 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012217{
12218
12219 switch (mode) {
12220 case QDF_GLOBAL_MISSION_MODE:
12221 return QDF_STA_MODE;
12222 case QDF_GLOBAL_MONITOR_MODE:
12223 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012224 case QDF_GLOBAL_EPPING_MODE:
12225 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012226 case QDF_GLOBAL_FTM_MODE:
12227 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012228 case QDF_GLOBAL_QVIT_MODE:
12229 return QDF_QVIT_MODE;
12230 default:
12231 return QDF_MAX_NO_OF_MODE;
12232 }
12233}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012234
Dustin Brown27cd9942017-09-27 16:11:44 -070012235static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012236 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012237{
12238 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12239 return;
12240
12241 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012242 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012243 hdd_info("Release wakelock for monitor mode!");
12244 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12245 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12246 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012247 case QDF_GLOBAL_FTM_MODE:
12248 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012249 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012250 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012251
Dustin Brown27cd9942017-09-27 16:11:44 -070012252 break;
12253 default:
12254 break;
12255 }
12256}
12257
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012258static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012259 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012260{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012261 int driver_status;
12262
12263 driver_status = hdd_ctx->driver_status;
12264
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012265 switch (curr_mode) {
12266 case QDF_GLOBAL_MISSION_MODE:
12267 case QDF_GLOBAL_MONITOR_MODE:
12268 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012269 hdd_deinit_all_adapters(hdd_ctx, false);
12270 hdd_close_all_adapters(hdd_ctx, false);
12271 break;
12272 case QDF_GLOBAL_EPPING_MODE:
12273 epping_disable();
12274 epping_close();
12275 break;
12276 default:
12277 return;
12278 }
12279}
12280
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012281static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012282 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012283{
Jeff Johnson9d295242017-08-29 14:39:48 -070012284 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012285 int ret = 0;
12286 bool rtnl_held;
12287 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12288 QDF_STATUS status;
12289
12290 if (!qdf_dev) {
12291 hdd_err("qdf device context is Null return!");
12292 return -EINVAL;
12293 }
12294
12295 rtnl_held = hdd_hold_rtnl_lock();
12296 switch (mode) {
12297 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012298 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12299 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012300 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012301 break;
12302 case QDF_GLOBAL_FTM_MODE:
12303 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12304 wlan_hdd_get_intf_addr(hdd_ctx),
12305 NET_NAME_UNKNOWN, rtnl_held);
12306 if (adapter == NULL)
12307 ret = -EINVAL;
12308 break;
12309 case QDF_GLOBAL_MONITOR_MODE:
12310 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12311 wlan_hdd_get_intf_addr(hdd_ctx),
12312 NET_NAME_UNKNOWN, rtnl_held);
12313 if (adapter == NULL)
12314 ret = -EINVAL;
12315 break;
12316 case QDF_GLOBAL_EPPING_MODE:
12317 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012318 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012319 hdd_err("Failed to open in eeping mode: %d", status);
12320 ret = -EINVAL;
12321 break;
12322 }
12323 ret = epping_enable(qdf_dev->dev);
12324 if (ret) {
12325 hdd_err("Failed to enable in epping mode : %d", ret);
12326 epping_close();
12327 }
12328 break;
12329 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012330 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012331 ret = -ENOTSUPP;
12332 break;
12333 }
12334 hdd_release_rtnl_lock();
12335 rtnl_held = false;
12336 return ret;
12337}
12338
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012339/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012340 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012341 * @kmessage: con mode name on which driver to be bring up
12342 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012343 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012344 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012345 * This function is invoked when user updates con mode using sys entry,
12346 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012347 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012348 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012349 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012350static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012351 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012352{
12353 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012354 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012355 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012356 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012357 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012358
Dustin Brownab6029b2017-05-24 13:04:19 -070012359 hdd_info("con_mode handler: %s", kmessage);
12360
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012361 ret = wlan_hdd_validate_context(hdd_ctx);
12362 if (ret)
12363 return ret;
12364
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012365 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012366 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012367
Dustin Brown20024e32018-01-03 12:34:58 -080012368 ret = kstrtoint(kmessage, 0, &new_con_mode);
12369 if (ret) {
12370 hdd_err("Failed to parse con_mode '%s'", kmessage);
12371 goto reset_flags;
12372 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012373 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012374
Dustin Brown20024e32018-01-03 12:34:58 -080012375 if (!is_con_mode_valid(new_con_mode)) {
12376 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012377 ret = -EINVAL;
12378 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012379 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012380
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012381 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012382 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012383 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012384 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012385 ret = 0;
12386 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012387 }
12388
Dustin Brown27cd9942017-09-27 16:11:44 -070012389 /* ensure adapters are stopped */
12390 hdd_stop_present_mode(hdd_ctx, curr_mode);
12391
Frank Liu6666f832018-01-04 10:06:05 +080012392 /* Cleanup present mode before switching to new mode */
12393 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12394
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012395 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012396 if (ret) {
12397 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012398 goto reset_flags;
12399 }
12400
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012401
Dustin Brown20024e32018-01-03 12:34:58 -080012402 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012403
Frank Liu6666f832018-01-04 10:06:05 +080012404 /*
12405 * Set ACTIVE domain before adapters created, otherwise check domain
12406 * match will fail when cleanup adapters.
12407 */
12408 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012409 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012410 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012411 if (ret) {
12412 hdd_err("Failed to register for new mode");
12413 goto reset_flags;
12414 }
12415
Dustin Brown20024e32018-01-03 12:34:58 -080012416 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012417 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12418 hdd_err("invalid adapter");
12419 ret = -EINVAL;
12420 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012421 }
12422
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012423 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012424 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012425 hdd_err("Failed to get adapter:%d", adapter_mode);
12426 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012427 }
12428
12429 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12430 if (ret) {
12431 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012432 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012433 }
12434
Dustin Brown20024e32018-01-03 12:34:58 -080012435 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012436 if (hdd_start_adapter(adapter)) {
12437 hdd_err("Failed to start %s adapter", kmessage);
12438 ret = -EINVAL;
12439 goto reset_flags;
12440 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012441
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012442 hdd_info("Acquire wakelock for monitor mode!");
12443 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12444 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12445 }
12446
Dustin Brown20024e32018-01-03 12:34:58 -080012447 /* con_mode is a global module parameter */
12448 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012449 hdd_info("Mode successfully changed to %s", kmessage);
12450 ret = 0;
12451
12452reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012453 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012454 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012455 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012456 return ret;
12457}
12458
12459
12460static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
12461{
12462 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012463 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012464
12465 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12466 ret = wlan_hdd_validate_context(hdd_ctx);
12467 if (ret)
12468 return ret;
12469
12470 cds_ssr_protect(__func__);
12471 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12472 cds_ssr_unprotect(__func__);
12473
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012474 return ret;
12475}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012476
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012477static int con_mode_handler_ftm(const char *kmessage,
12478 struct kernel_param *kp)
12479{
12480 int ret;
12481
12482 ret = param_set_int(kmessage, kp);
12483
12484 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12485 pr_err("Only FTM mode supported!");
12486 return -ENOTSUPP;
12487 }
12488
12489 hdd_set_conparam(con_mode_ftm);
12490 con_mode = con_mode_ftm;
12491
12492 return ret;
12493}
12494
Ravi Joshia307f632017-07-17 23:41:41 -070012495static int con_mode_handler_monitor(const char *kmessage,
12496 struct kernel_param *kp)
12497{
12498 int ret;
12499
12500 ret = param_set_int(kmessage, kp);
12501
12502 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12503 pr_err("Only Monitor mode supported!");
12504 return -ENOTSUPP;
12505 }
12506
12507 hdd_set_conparam(con_mode_monitor);
12508 con_mode = con_mode_monitor;
12509
12510 return ret;
12511}
12512
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012513/**
12514 * hdd_get_conparam() - driver exit point
12515 *
12516 * This is the driver exit point (invoked when module is unloaded using rmmod)
12517 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012518 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012519 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012520enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012521{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012522 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012523}
12524
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012525void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012526{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012527 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012528}
12529
Komal Seelamc11bb222016-01-27 18:57:10 +053012530/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012531 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12532 * @hdd_ctx: HDD context
12533 *
12534 * Cleans up the pre cac interface, if it exists
12535 *
12536 * Return: None
12537 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012538void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012539{
12540 uint8_t session_id;
12541 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012542 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012543
12544 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12545 if (QDF_IS_STATUS_ERROR(status)) {
12546 hdd_err("failed to get pre cac vdev id");
12547 return;
12548 }
12549
12550 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12551 if (!precac_adapter) {
12552 hdd_err("invalid pre cac adapater");
12553 return;
12554 }
12555
12556 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12557 wlan_hdd_sap_pre_cac_failure,
12558 (void *)precac_adapter);
12559 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12560
12561}
12562
12563/**
Komal Seelamec702b02016-02-24 18:42:16 +053012564 * hdd_update_ol_config - API to update ol configuration parameters
12565 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012566 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012567 * Return: void
12568 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012569static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012570{
Komal Seelamec702b02016-02-24 18:42:16 +053012571 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012572 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012573
Komal Seelamec702b02016-02-24 18:42:16 +053012574 if (!ol_ctx)
12575 return;
12576
12577 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12578 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12579 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12580 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012581 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012582
12583 ol_init_ini_config(ol_ctx, &cfg);
12584}
12585
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012586#ifdef FEATURE_RUNTIME_PM
12587/**
12588 * hdd_populate_runtime_cfg() - populate runtime configuration
12589 * @hdd_ctx: hdd context
12590 * @cfg: pointer to the configuration memory being populated
12591 *
12592 * Return: void
12593 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012594static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012595 struct hif_config_info *cfg)
12596{
12597 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12598 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12599}
12600#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012601static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012602 struct hif_config_info *cfg)
12603{
12604}
12605#endif
12606
Komal Seelamec702b02016-02-24 18:42:16 +053012607/**
12608 * hdd_update_hif_config - API to update HIF configuration parameters
12609 * @hdd_ctx: HDD Context
12610 *
12611 * Return: void
12612 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012613static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012614{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012615 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012616 struct hif_config_info cfg;
12617
12618 if (!scn)
12619 return;
12620
12621 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012622 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012623 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012624
12625 if (hdd_ctx->config->prevent_link_down)
12626 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012627}
12628
12629/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012630 * hdd_update_dp_config() - Propagate config parameters to Lithium
12631 * datapath
12632 * @hdd_ctx: HDD Context
12633 *
12634 * Return: 0 for success/errno for failure
12635 */
12636static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12637{
12638 struct cdp_config_params params;
12639 QDF_STATUS status;
12640
12641 params.tso_enable = hdd_ctx->config->tso_enable;
12642 params.lro_enable = hdd_ctx->config->lro_enable;
12643#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12644 params.tx_flow_stop_queue_threshold =
12645 hdd_ctx->config->TxFlowStopQueueThreshold;
12646 params.tx_flow_start_queue_offset =
12647 hdd_ctx->config->TxFlowStartQueueOffset;
12648#endif
12649 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12650 params.napi_enable = hdd_ctx->napi_enable;
12651 params.tcp_udp_checksumoffload =
12652 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12653
12654 status = cdp_update_config_parameters(
12655 cds_get_context(QDF_MODULE_ID_SOC),
12656 &params);
12657 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012658 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012659 return status;
12660 }
12661
12662 return 0;
12663}
12664
12665/**
Komal Seelamec702b02016-02-24 18:42:16 +053012666 * hdd_update_config() - Initialize driver per module ini parameters
12667 * @hdd_ctx: HDD Context
12668 *
12669 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012670 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012671 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012672int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012673{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012674 int ret;
12675
Komal Seelamec702b02016-02-24 18:42:16 +053012676 hdd_update_ol_config(hdd_ctx);
12677 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012678 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12679 ret = hdd_update_cds_config_ftm(hdd_ctx);
12680 else
12681 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012682 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012683
12684 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012685}
12686
Mukul Sharma9d797a02017-01-05 20:26:03 +053012687#ifdef FEATURE_WLAN_RA_FILTERING
12688/**
12689 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12690 * @psoc_cfg: pmo psoc Configuration
12691 * @hdd_ctx: Pointer to hdd context
12692 *
12693 * Return: none
12694 */
12695static inline void hdd_ra_populate_pmo_config(
12696 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012697 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012698{
12699 psoc_cfg->ra_ratelimit_interval =
12700 hdd_ctx->config->RArateLimitInterval;
12701 psoc_cfg->ra_ratelimit_enable =
12702 hdd_ctx->config->IsRArateLimitEnabled;
12703}
12704#else
12705static inline void hdd_ra_populate_pmo_config(
12706 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012707 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012708{
12709}
12710#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012711
Mukul Sharma9d797a02017-01-05 20:26:03 +053012712/**
12713 * hdd_update_pmo_config - API to update pmo configuration parameters
12714 * @hdd_ctx: HDD context
12715 *
12716 * Return: void
12717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012718static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012719{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012720 struct pmo_psoc_cfg psoc_cfg;
12721 QDF_STATUS status;
12722
12723 /*
12724 * Value of hdd_ctx->wowEnable can be,
12725 * 0 - Disable both magic pattern match and pattern byte match.
12726 * 1 - Enable magic pattern match on all interfaces.
12727 * 2 - Enable pattern byte match on all interfaces.
12728 * 3 - Enable both magic patter and pattern byte match on
12729 * all interfaces.
12730 */
12731 psoc_cfg.magic_ptrn_enable =
12732 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12733 psoc_cfg.ptrn_match_enable_all_vdev =
12734 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012735 psoc_cfg.ptrn_id_per_vdev =
12736 wma_is_service_enabled(wmi_service_unified_wow_capability);
12737 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012738 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012739 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012740 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012741 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012742 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012743 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12744 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012745 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012746 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012747 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012748 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12749 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12750 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012751 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012752 psoc_cfg.auto_power_save_fail_mode =
12753 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012754
12755 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012756 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12757 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012758
Dustin Brownb9987af2018-03-01 17:15:11 -080012759 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12760 if (QDF_IS_STATUS_ERROR(status))
12761 hdd_err("failed pmo psoc configuration; status:%d", status);
12762
12763 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012764}
12765
Abhishek Singhb20db962017-03-03 21:28:46 +053012766#ifdef FEATURE_WLAN_SCAN_PNO
12767static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12768 struct hdd_config *cfg)
12769{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012770 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12771
Abhishek Singhb20db962017-03-03 21:28:46 +053012772 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12773 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12774 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12775 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12776 pno_cfg->channel_prediction_full_scan =
12777 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012778 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12779 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12780 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12781 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012782}
12783#else
12784static inline void
12785hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012786 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012787{
Abhishek Singhb20db962017-03-03 21:28:46 +053012788}
12789#endif
12790
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012791void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12792 struct hdd_config *cfg)
12793{
12794 uint8_t i = 0;
12795
12796 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12797 if (!ie_whitelist->white_list)
12798 return;
12799
12800 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12801 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12802 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12803 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12804 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12805 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12806 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12807 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12808
12809 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12810 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12811 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12812}
12813
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012814uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12815{
12816 uint8_t i, score;
12817
12818 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12819 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12820 if (score > MAX_INDEX_SCORE)
12821 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12822 MAX_INDEX_SCORE, i);
12823 }
12824
12825 return per_index_score;
12826}
12827
12828/**
12829 * hdd_update_score_config - API to update candidate scoring related params
12830 * configuration parameters
12831 * @score_config: score config to update
12832 * @cfg: config params
12833 *
12834 * Return: 0 if success else err
12835 */
12836static void hdd_update_score_config(
12837 struct scoring_config *score_config, struct hdd_config *cfg)
12838{
12839 int total_weight;
12840
12841 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12842 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12843 score_config->weight_cfg.vht_caps_weightage =
12844 cfg->vht_caps_weightage;
12845 score_config->weight_cfg.he_caps_weightage =
12846 cfg->he_caps_weightage;
12847 score_config->weight_cfg.chan_width_weightage =
12848 cfg->chan_width_weightage;
12849 score_config->weight_cfg.chan_band_weightage =
12850 cfg->chan_band_weightage;
12851 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12852 score_config->weight_cfg.beamforming_cap_weightage =
12853 cfg->beamforming_cap_weightage;
12854 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12855 score_config->weight_cfg.channel_congestion_weightage =
12856 cfg->channel_congestion_weightage;
12857 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12858
12859 total_weight = score_config->weight_cfg.rssi_weightage +
12860 score_config->weight_cfg.ht_caps_weightage +
12861 score_config->weight_cfg.vht_caps_weightage +
12862 score_config->weight_cfg.he_caps_weightage +
12863 score_config->weight_cfg.chan_width_weightage +
12864 score_config->weight_cfg.chan_band_weightage +
12865 score_config->weight_cfg.nss_weightage +
12866 score_config->weight_cfg.beamforming_cap_weightage +
12867 score_config->weight_cfg.pcl_weightage +
12868 score_config->weight_cfg.channel_congestion_weightage +
12869 score_config->weight_cfg.oce_wan_weightage;
12870
12871 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12872 hdd_err("total weight is greater than %d fallback to default values",
12873 BEST_CANDIDATE_MAX_WEIGHT);
12874
12875 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12876 score_config->weight_cfg.ht_caps_weightage =
12877 HT_CAPABILITY_WEIGHTAGE;
12878 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12879 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12880 score_config->weight_cfg.chan_width_weightage =
12881 CHAN_WIDTH_WEIGHTAGE;
12882 score_config->weight_cfg.chan_band_weightage =
12883 CHAN_BAND_WEIGHTAGE;
12884 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12885 score_config->weight_cfg.beamforming_cap_weightage =
12886 BEAMFORMING_CAP_WEIGHTAGE;
12887 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12888 score_config->weight_cfg.channel_congestion_weightage =
12889 CHANNEL_CONGESTION_WEIGHTAGE;
12890 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12891 }
12892
12893 score_config->bandwidth_weight_per_index =
12894 hdd_limit_max_per_index_score(
12895 cfg->bandwidth_weight_per_index);
12896 score_config->nss_weight_per_index =
12897 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
12898 score_config->band_weight_per_index =
12899 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
12900
12901 score_config->rssi_score.best_rssi_threshold =
12902 cfg->best_rssi_threshold;
12903 score_config->rssi_score.good_rssi_threshold =
12904 cfg->good_rssi_threshold;
12905 score_config->rssi_score.bad_rssi_threshold =
12906 cfg->bad_rssi_threshold;
12907 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
12908 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
12909 score_config->rssi_score.good_rssi_bucket_size =
12910 cfg->good_rssi_bucket_size;
12911 score_config->rssi_score.bad_rssi_bucket_size =
12912 cfg->bad_rssi_bucket_size;
12913 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
12914 cfg->rssi_pref_5g_rssi_thresh;
12915
12916 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
12917 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
12918 hdd_limit_max_per_index_score(
12919 cfg->esp_qbss_score_slots3_to_0);
12920 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
12921 hdd_limit_max_per_index_score(
12922 cfg->esp_qbss_score_slots7_to_4);
12923 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
12924 hdd_limit_max_per_index_score(
12925 cfg->esp_qbss_score_slots11_to_8);
12926 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
12927 hdd_limit_max_per_index_score(
12928 cfg->esp_qbss_score_slots15_to_12);
12929
12930 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
12931 score_config->oce_wan_scoring.score_pcnt3_to_0 =
12932 hdd_limit_max_per_index_score(
12933 cfg->oce_wan_score_slots3_to_0);
12934 score_config->oce_wan_scoring.score_pcnt7_to_4 =
12935 hdd_limit_max_per_index_score(
12936 cfg->oce_wan_score_slots7_to_4);
12937 score_config->oce_wan_scoring.score_pcnt11_to_8 =
12938 hdd_limit_max_per_index_score(
12939 cfg->oce_wan_score_slots11_to_8);
12940 score_config->oce_wan_scoring.score_pcnt15_to_12 =
12941 hdd_limit_max_per_index_score(
12942 cfg->oce_wan_score_slots15_to_12);
12943
12944
12945 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
12946 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
12947 score_config->nss = cfg->enable2x2 ? 2 : 1;
12948
12949 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
12950 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
12951 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
12952 score_config->he_cap = 1;
12953
12954 if (score_config->he_cap ||
12955 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
12956 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
12957 score_config->vht_cap = 1;
12958
12959 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
12960 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
12961 score_config->ht_cap = 1;
12962
12963 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
12964 score_config->vht_24G_cap = 1;
12965
12966 if (cfg->enableTxBF)
12967 score_config->beamformee_cap = 1;
12968
12969}
12970
Abhishek Singh257a9482017-03-06 16:52:39 +053012971/**
bings81fe50a2017-11-27 14:33:26 +080012972 * hdd_update_dfs_config() - API to update dfs configuration parameters.
12973 * @hdd_ctx: HDD context
12974 *
12975 * Return: 0 if success else err
12976 */
12977static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
12978{
12979 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
12980 struct hdd_config *cfg = hdd_ctx->config;
12981 struct dfs_user_config dfs_cfg;
12982 QDF_STATUS status;
12983
12984 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
12985 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
12986 if (QDF_IS_STATUS_ERROR(status)) {
12987 hdd_err("failed dfs psoc configuration");
12988 return -EINVAL;
12989 }
12990
12991 return 0;
12992}
12993
12994/**
Abhishek Singh257a9482017-03-06 16:52:39 +053012995 * hdd_update_scan_config - API to update scan configuration parameters
12996 * @hdd_ctx: HDD context
12997 *
12998 * Return: 0 if success else err
12999 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013000static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013001{
13002 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13003 struct scan_user_cfg scan_cfg;
13004 struct hdd_config *cfg = hdd_ctx->config;
13005 QDF_STATUS status;
13006
13007 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13008 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13009 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13010 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13011 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13012 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13013 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013014 /* convert to ms */
13015 scan_cfg.scan_cache_aging_time =
13016 cfg->scanAgingTimeout * 1000;
13017 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13018 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13019 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13020 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013021 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013022 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013023 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13024 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013025 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013026 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013027 scan_cfg.sta_miracast_mcc_rest_time =
13028 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013029
Abhishek Singhb20db962017-03-03 21:28:46 +053013030 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013031 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013032 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013033
Abhishek Singh257a9482017-03-06 16:52:39 +053013034 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13035 if (status != QDF_STATUS_SUCCESS) {
13036 hdd_err("failed pmo psoc configuration");
13037 return -EINVAL;
13038 }
13039
13040 return 0;
13041}
Abhishek Singh257a9482017-03-06 16:52:39 +053013042
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013043int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013044{
13045 int ret;
13046
13047 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013048 if (ret)
13049 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013050
Abhishek Singh257a9482017-03-06 16:52:39 +053013051 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013052 if (ret)
13053 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013054
Frank Liud4b2fa02017-03-29 11:46:48 +080013055 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013056 if (ret)
13057 return ret;
13058
13059 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013060 if (ret)
13061 return ret;
13062
13063 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013064
13065 return ret;
13066}
13067
Agrawal Ashish65634612016-08-18 13:24:32 +053013068/**
13069 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13070 * @mode : cfg80211 DFS mode
13071 *
13072 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13073 */
13074enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13075{
13076 switch (mode) {
13077 case DFS_MODE_ENABLE:
13078 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013079 case DFS_MODE_DISABLE:
13080 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013081 case DFS_MODE_DEPRIORITIZE:
13082 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013083 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013084 hdd_debug("ACS dfs mode is NONE");
13085 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013086 }
13087}
13088
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013089/**
13090 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13091 * @hddctx: pointer to hdd context
13092 * @set_value: enable/disable
13093 *
13094 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13095 * Host(even though it is duplicate). When Host send vendor command
13096 * disable,FW doesn't perform any action. Whenever any change in
13097 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13098 *
13099 * return - 0 on success, appropriate error values on failure.
13100 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013101int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013102{
13103 QDF_STATUS status;
13104
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013105 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013106 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013107
13108 if (!hddctx->config->goptimize_chan_avoid_event) {
13109 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13110 return -EINVAL;
13111 }
13112
13113 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13114 if (!QDF_IS_STATUS_SUCCESS(status)) {
13115 hdd_err("Failed to send chan avoid command to SME");
13116 return -EINVAL;
13117 }
13118 return 0;
13119}
Agrawal Ashish65634612016-08-18 13:24:32 +053013120
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013121/**
13122 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13123 * @value: value to set
13124 *
13125 * This function will set the passed value to roaming in progress flag.
13126 *
13127 * Return: None
13128 */
13129void hdd_set_roaming_in_progress(bool value)
13130{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013131 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013132
13133 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13134 if (!hdd_ctx) {
13135 hdd_err("HDD context is NULL");
13136 return;
13137 }
13138
13139 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013140 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013141}
13142
13143/**
13144 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013145 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013146 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013147 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013148 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013149bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013150{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013151 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013152 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013153
13154 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13155 if (!hdd_ctx) {
13156 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013157 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013158 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013159 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13160 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013161 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13162 hdd_ctx->roaming_in_progress);
13163
13164 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013165}
13166
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013167/**
13168 * hdd_is_connection_in_progress() - check if connection is in
13169 * progress
13170 * @session_id: session id
13171 * @reason: scan reject reason
13172 *
13173 * Go through each adapter and check if Connection is in progress
13174 *
13175 * Return: true if connection is in progress else false
13176 */
13177bool hdd_is_connection_in_progress(uint8_t *session_id,
13178 enum scan_reject_states *reason)
13179{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013180 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013181 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013182 uint8_t sta_id = 0;
13183 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013184 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013185
13186 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13187 if (!hdd_ctx) {
13188 hdd_err("HDD context is NULL");
13189 return false;
13190 }
13191
Dustin Brown920397d2017-12-13 16:27:50 -080013192 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013193 hdd_info("Adapter with device mode %s(%d) exists",
13194 hdd_device_mode_to_string(adapter->device_mode),
13195 adapter->device_mode);
13196 if (((QDF_STA_MODE == adapter->device_mode)
13197 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13198 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13199 && (eConnectionState_Connecting ==
13200 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13201 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013202 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013203 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013204 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013205 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013206 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013207 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013208 }
13209 return true;
13210 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013211 /*
13212 * sme_neighbor_middle_of_roaming is for LFR2
13213 * hdd_is_roaming_in_progress is for LFR3
13214 */
13215 if (((QDF_STA_MODE == adapter->device_mode) &&
13216 sme_neighbor_middle_of_roaming(
13217 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013218 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013219 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013220 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013221 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013222 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013223 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013224 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013225 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013226 }
13227 return true;
13228 }
13229 if ((QDF_STA_MODE == adapter->device_mode) ||
13230 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13231 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13232 hdd_sta_ctx =
13233 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13234 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013235 hdd_sta_ctx->conn_info.connState)
13236 && sme_is_sta_key_exchange_in_progress(
13237 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013238 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013239 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013240 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013241 " is in middle of WPS/EAPOL exchange.",
13242 MAC_ADDR_ARRAY(sta_mac));
13243 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013244 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013245 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013246 }
13247 return true;
13248 }
13249 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13250 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13251 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13252 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013253 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013254 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013255 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013256 continue;
13257
13258 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013259 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013260 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013261 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013262 " of SAP/GO is in middle of WPS/EAPOL exchange",
13263 MAC_ADDR_ARRAY(sta_mac));
13264 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013265 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013266 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013267 }
13268 return true;
13269 }
13270 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013271 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013272 return true;
13273 }
13274 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013275 }
Dustin Brown920397d2017-12-13 16:27:50 -080013276
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013277 return false;
13278}
13279
13280/**
13281 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013282 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013283 *
13284 * Return: None
13285 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013286void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013287{
Jeff Johnson87251032017-08-29 13:31:11 -070013288 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013289 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013290 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013291 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013292 tsap_Config_t *sap_config;
13293 void *sap_ctx;
13294
13295 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013296 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013297 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013298
13299 mutex_lock(&hdd_ctx->sap_lock);
13300 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13301 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013302 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13303 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13304 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13305 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013306 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013307 qdf_stop_bss_event,
13308 SME_CMD_TIMEOUT_VALUE);
13309
13310 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013311 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013312 goto end;
13313 }
13314 }
13315 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013316 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013317 ap_adapter->device_mode, ap_adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013318 hdd_start_green_ap_state_mc(hdd_ctx, ap_adapter->device_mode,
13319 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013320 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013321
13322 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013323 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013324 wlansap_reset_sap_config_add_ie(sap_config,
13325 eUPDATE_IE_ALL);
13326 goto end;
13327 }
13328
13329 qdf_event_reset(&hostapd_state->qdf_event);
13330 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13331 sap_config,
13332 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013333 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013334 wlansap_reset_sap_config_add_ie(sap_config,
13335 eUPDATE_IE_ALL);
13336 goto end;
13337 }
13338
Jeff Johnson6867ec32017-09-29 20:30:20 -070013339 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013340 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013341 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013342 SME_CMD_TIMEOUT_VALUE);
13343 wlansap_reset_sap_config_add_ie(sap_config,
13344 eUPDATE_IE_ALL);
13345 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013346 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013347 goto end;
13348 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013349 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013350 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013351 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013352 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13353 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013354 ap_adapter->session_id);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013355 hdd_start_green_ap_state_mc(hdd_ctx,
13356 ap_adapter->device_mode,
13357 true);
13358 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013359 }
13360end:
13361 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013362}
13363
13364/**
13365 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13366 * with non dfs acs
13367 *
13368 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13369 *
13370 * Return: None
13371 */
13372void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13373{
Jeff Johnson9d295242017-08-29 14:39:48 -070013374 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013375 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013376 cds_context_type *cds_ctx;
13377
13378 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13379 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013380 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013381 return;
13382 }
13383
13384 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13385 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013386 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013387 return;
13388 }
13389
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013390 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13391 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013392 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013393 return;
13394 }
13395
13396 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013397 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13398 &ap_adapter->event_flags) &&
13399 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013400 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013401
Jeff Johnson6867ec32017-09-29 20:30:20 -070013402 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013403 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013404 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013405 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013406 acs_cfg.acs_mode = true;
13407
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013408 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013409 }
13410}
13411
13412/**
13413 * hdd_set_connection_in_progress() - to set the connection in
13414 * progress flag
13415 * @value: value to set
13416 *
13417 * This function will set the passed value to connection in progress flag.
13418 * If value is previously being set to true then no need to set it again.
13419 *
13420 * Return: true if value is being set correctly and false otherwise.
13421 */
13422bool hdd_set_connection_in_progress(bool value)
13423{
13424 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013425 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013426
13427 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13428 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013429 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013430 return false;
13431 }
13432
13433 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13434 /*
13435 * if the value is set to true previously and if someone is
13436 * trying to make it true again then it could be some race
13437 * condition being triggered. Avoid this situation by returning
13438 * false
13439 */
13440 if (hdd_ctx->connection_in_progress && value)
13441 status = false;
13442 else
13443 hdd_ctx->connection_in_progress = value;
13444 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13445 return status;
13446}
13447
Jeff Johnson9d295242017-08-29 14:39:48 -070013448int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013449{
13450 if (!adapter) {
13451 hdd_err("Invalid adapter");
13452 return -EINVAL;
13453 }
13454 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013455 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013456 WMA_VDEV_MCC_SET_TIME_QUOTA,
13457 set_value, VDEV_CMD);
13458 return 0;
13459
13460}
13461
Jeff Johnson9d295242017-08-29 14:39:48 -070013462int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013463{
13464 if (!adapter) {
13465 hdd_err("Invalid adapter");
13466 return -EINVAL;
13467 }
13468
13469 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013470 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013471 WMA_VDEV_MCC_SET_TIME_LATENCY,
13472 set_value, VDEV_CMD);
13473 return 0;
13474}
13475
Jeff Johnson9d295242017-08-29 14:39:48 -070013476struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013477 *psoc, uint8_t vdev_id)
13478{
Jeff Johnson9d295242017-08-29 14:39:48 -070013479 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013480 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013481
13482 /*
13483 * Currently PSOC is not being used. But this logic will
13484 * change once we have the converged implementation of
13485 * HDD context per PSOC in place. This would break if
13486 * multiple vdev objects reuse the vdev id.
13487 */
13488 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13489 if (!adapter)
13490 hdd_err("Get adapter by vdev id failed");
13491
13492 return adapter;
13493}
13494
Jeff Johnson9d295242017-08-29 14:39:48 -070013495int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013496 int8_t *rssi, int8_t *snr)
13497{
13498 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013499 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013500
Jeff Johnson025618c2018-03-18 14:41:00 -070013501 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013502 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013503 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013504 if (QDF_STATUS_SUCCESS != status) {
13505 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13506 return -EINVAL;
13507 }
13508
13509 return 0;
13510}
13511
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013512/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013513 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13514 * @adapter - HDD adapter
13515 * @tos - type of service
13516 * @status - status of the traffic
13517 *
13518 * Return: 0 on success and non zero value on failure
13519 */
13520
13521int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13522 bool is_tos_active)
13523{
13524 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013525 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013526 uint32_t max_off_chan_time = 0;
13527 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013528 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013529 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013530
13531 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13532 ret = wlan_hdd_validate_context(hdd_ctx);
13533
13534 if (ret < 0) {
13535 hdd_err("failed to set limit off chan params");
13536 return ret;
13537 }
13538
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013539 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13540
13541 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013542 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013543 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013544 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013545
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013546 if (adapter->active_ac) {
13547 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013548 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013549 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13550 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13551 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013552 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013553 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013554 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13555 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13556 PM_LATENCY);
13557 } else {
13558 /*ignore this command if only BE/BK is active */
13559 is_tos_active = false;
13560 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13561 hdd_ctx->config->conc_system_pref);
13562 }
13563 } else {
13564 /* No active tos */
13565 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13566 hdd_ctx->config->conc_system_pref);
13567 }
13568
Jeff Johnson1b780e42017-10-31 14:11:45 -070013569 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013570 is_tos_active, max_off_chan_time,
13571 hdd_ctx->config->nRestTimeConc, true);
13572 if (!QDF_IS_STATUS_SUCCESS(status)) {
13573 hdd_err("failed to set limit off chan params");
13574 ret = -EINVAL;
13575 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013576
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013577 return ret;
13578}
13579
13580/**
13581 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13582 * @adapter - HDD adapter
13583 *
13584 * Return: 0 on success and non zero value on failure
13585 */
13586int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13587{
13588 struct hdd_context *hdd_ctx;
13589 int ret;
13590 QDF_STATUS status;
13591 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13592
13593 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13594 ret = wlan_hdd_validate_context(hdd_ctx);
13595 if (ret < 0)
13596 return ret;
13597
13598 /* set the system preferece to default */
13599 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13600 hdd_ctx->config->conc_system_pref);
13601
13602 /* clear the bitmap */
13603 adapter->active_ac = 0;
13604
13605 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013606 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013607
Jeff Johnson1b780e42017-10-31 14:11:45 -070013608 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013609 false, 0, 0, false);
13610 if (!QDF_IS_STATUS_SUCCESS(status)) {
13611 hdd_err("failed to reset limit off chan params");
13612 ret = -EINVAL;
13613 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013614
13615 return ret;
13616}
13617
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013618/**
13619 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13620 * @drv_op: Enum indicating driver op
13621 *
13622 * Return: none
13623 */
13624void hdd_start_driver_ops_timer(int drv_op)
13625{
13626 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13627 switch (drv_op) {
13628 case eHDD_DRV_OP_PROBE:
13629 memcpy(drv_ops_string, "probe", sizeof("probe"));
13630 break;
13631 case eHDD_DRV_OP_REMOVE:
13632 memcpy(drv_ops_string, "remove", sizeof("remove"));
13633 break;
13634 case eHDD_DRV_OP_SHUTDOWN:
13635 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13636 break;
13637 case eHDD_DRV_OP_REINIT:
13638 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13639 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013640 case eHDD_DRV_OP_IFF_UP:
13641 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13642 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013643 }
13644
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013645 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013646 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13647 HDD_OPS_INACTIVITY_TIMEOUT);
13648}
13649
13650/**
13651 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13652 *
13653 * Return: none
13654 */
13655void hdd_stop_driver_ops_timer(void)
13656{
13657 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13658}
13659
13660/**
13661 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13662 * inactivity timer
13663 *
13664 * Return: None
13665 */
13666void hdd_drv_ops_inactivity_handler(void)
13667{
13668 hdd_err("%s: %d Sec timer expired while in .%s",
13669 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13670
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013671 if (hdd_drv_ops_task) {
13672 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13673 qdf_print_thread_trace(hdd_drv_ops_task);
13674 } else {
13675 hdd_err("hdd_drv_ops_task is null");
13676 }
13677
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013678 /* Driver shutdown is stuck, no recovery possible at this point */
13679 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13680 sizeof("shutdown")))
13681 QDF_BUG(0);
13682
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013683 if (cds_is_fw_down()) {
13684 hdd_err("FW is down");
13685 return;
13686 }
13687
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013688 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013689 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013690 else
13691 QDF_BUG(0);
13692}
13693
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013694void hdd_pld_ipa_uc_shutdown_pipes(void)
13695{
13696 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13697
13698 if (!hdd_ctx)
13699 return;
13700
13701 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
13702}
13703
Yun Parkff6a16a2017-09-26 16:38:18 -070013704/**
13705 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13706 * @struct hdd_context *hdd_ctx
13707 * @struct hdd_adapter *padapter
13708 * @bool enble
13709 *
13710 * Return: none
13711 */
13712void hdd_set_rx_mode_rps(bool enable)
13713{
13714 struct cds_config_info *cds_cfg = cds_get_ini_config();
13715 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13716 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13717
13718 if (adapter && hdd_ctx &&
13719 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13720 if (enable && !cds_cfg->rps_enabled)
13721 hdd_send_rps_ind(adapter);
13722 else if (!enable && cds_cfg->rps_enabled)
13723 hdd_send_rps_disable_ind(adapter);
13724 }
13725}
13726
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013727bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13728{
13729 struct hdd_adapter *adapter = NULL;
13730
13731 hdd_for_each_adapter(hdd_ctx, adapter) {
13732 if ((adapter->device_mode == QDF_STA_MODE ||
13733 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13734 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13735 &adapter->event_flags)){
13736 return true;
13737 }
13738 }
13739
13740 return false;
13741}
13742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013743/* Register the module init/exit functions */
13744module_init(hdd_module_init);
13745module_exit(hdd_module_exit);
13746
13747MODULE_LICENSE("Dual BSD/GPL");
13748MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13749MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013751module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
13752 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013753
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013754module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
13755 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13756
Ravi Joshia307f632017-07-17 23:41:41 -070013757module_param_call(con_mode_monitor, con_mode_handler_monitor, param_get_int,
13758 &con_mode_monitor, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013760module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
13761 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13762
13763module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13764
13765module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13766
13767module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);