blob: 157a3e7cefeb6752ea5fadb853f695c8a3f9fdc0 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnsond9f08602016-12-02 11:31:30 -08002 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_main.c
30 *
31 * WLAN Host Device Driver implementation
32 *
33 */
34
35/* Include Files */
36#include <wlan_hdd_includes.h>
37#include <cds_api.h>
38#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053039#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include <linux/etherdevice.h>
41#include <linux/firmware.h>
42#include <wlan_hdd_tx_rx.h>
43#include <wni_api.h>
44#include <wlan_hdd_cfg.h>
45#include <wlan_ptt_sock_svc.h>
46#include <dbglog_host.h>
47#include <wlan_logging_sock_svc.h>
48#include <wlan_hdd_wowl.h>
49#include <wlan_hdd_misc.h>
50#include <wlan_hdd_wext.h>
51#include "wlan_hdd_trace.h"
52#include "wlan_hdd_ioctl.h"
53#include "wlan_hdd_ftm.h"
54#include "wlan_hdd_power.h"
55#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070056#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080057#include "wlan_hdd_request_manager.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053058#include "qdf_types.h"
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +053059#include "qdf_trace.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062
63#include <net/addrconf.h>
64#include <linux/wireless.h>
65#include <net/cfg80211.h>
66#include <linux/inetdevice.h>
67#include <net/addrconf.h>
68#include "wlan_hdd_cfg80211.h"
69#include "wlan_hdd_ext_scan.h"
70#include "wlan_hdd_p2p.h"
71#include <linux/rtnetlink.h>
72#include "sap_api.h"
73#include <linux/semaphore.h>
74#include <linux/ctype.h>
75#include <linux/compat.h>
76#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
81#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Dhanashri Atreb08959a2016-03-01 17:28:03 -080087#include "cdp_txrx_flow_ctrl_v2.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#endif /* FEATURE_WLAN_CH_AVOID */
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
95#include "wlan_hdd_memdump.h"
96
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_green_ap.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530103#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700104#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700105#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530106#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700107#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530108#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800109#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530111#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800112#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800113#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530114#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530115#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800116#include "os_if_wifi_pos.h"
117#include "wifi_pos_api.h"
118#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800119#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700120#include "os_if_nan.h"
121#include "nan_public_structs.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800122
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530123#ifdef CNSS_GENL
124#include <net/cnss_nl.h>
125#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800126#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800128#ifdef MODULE
129#define WLAN_MODULE_NAME module_name(THIS_MODULE)
130#else
131#define WLAN_MODULE_NAME "wlan"
132#endif
133
134#ifdef TIMER_MANAGER
135#define TIMER_MANAGER_STR " +TIMER_MANAGER"
136#else
137#define TIMER_MANAGER_STR ""
138#endif
139
140#ifdef MEMORY_DEBUG
141#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
142#else
143#define MEMORY_DEBUG_STR ""
144#endif
145
Sachin Ahujadddd2632017-03-07 19:07:24 +0530146int wlan_start_ret_val;
147static DECLARE_COMPLETION(wlan_start_comp);
148static unsigned int dev_num = 1;
149static struct cdev wlan_hdd_state_cdev;
150static struct class *class;
151static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530152#ifndef MODULE
153static struct gwlan_loader *wlan_loader;
154static ssize_t wlan_boot_cb(struct kobject *kobj,
155 struct kobj_attribute *attr,
156 const char *buf, size_t count);
157struct gwlan_loader {
158 bool loaded_state;
159 struct kobject *boot_wlan_obj;
160 struct attribute_group *attr_group;
161};
162
163static struct kobj_attribute wlan_boot_attribute =
164 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
165
166static struct attribute *attrs[] = {
167 &wlan_boot_attribute.attr,
168 NULL,
169};
170
171#define MODULE_INITIALIZED 1
172#endif
173
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174/* the Android framework expects this param even though we don't use it */
175#define BUF_LEN 20
176static char fwpath_buffer[BUF_LEN];
177static struct kparam_string fwpath = {
178 .string = fwpath_buffer,
179 .maxlen = BUF_LEN,
180};
181
182static char *country_code;
183static int enable_11d = -1;
184static int enable_dfs_chan_scan = -1;
185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800186/*
187 * spinlock for synchronizing asynchronous request/response
188 * (full description of use in wlan_hdd_main.h)
189 */
190DEFINE_SPINLOCK(hdd_context_lock);
191
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800192#define WLAN_NLINK_CESIUM 30
193
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530194static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800195
196#define WOW_MAX_FILTER_LISTS 1
197#define WOW_MAX_FILTERS_PER_LIST 4
198#define WOW_MIN_PATTERN_SIZE 6
199#define WOW_MAX_PATTERN_SIZE 64
200
201#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
202static const struct wiphy_wowlan_support wowlan_support_reg_init = {
203 .flags = WIPHY_WOWLAN_ANY |
204 WIPHY_WOWLAN_MAGIC_PKT |
205 WIPHY_WOWLAN_DISCONNECT |
206 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
207 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
208 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
209 WIPHY_WOWLAN_4WAY_HANDSHAKE |
210 WIPHY_WOWLAN_RFKILL_RELEASE,
211 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
212 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
213 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
214};
215#endif
216
217/* internal function declaration */
218
219struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700221static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800222#endif
223
Sachin Ahujadddd2632017-03-07 19:07:24 +0530224void hdd_start_complete(int ret)
225{
226 wlan_start_ret_val = ret;
227
228 complete(&wlan_start_comp);
229}
230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530232 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
233 * @hdd_ctx: pointer to hdd_context_t
234 *
235 * Return: none
236 */
Jeff Johnson590e2012016-10-05 16:16:24 -0700237static void hdd_set_rps_cpu_mask(hdd_context_t *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530238{
239 hdd_adapter_t *adapter;
240 hdd_adapter_list_node_t *adapter_node, *next;
241 QDF_STATUS status = QDF_STATUS_SUCCESS;
242
243 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
244 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
245 adapter = adapter_node->pAdapter;
246 if (NULL != adapter)
247 hdd_send_rps_ind(adapter);
248 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
249 adapter_node = next;
250 }
251}
252
253/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800254 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
255 * @vdev_id: vdev_id
256 * @action: action type
257 * @reason: reason type
258 *
259 * Return: none
260 */
261void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
262 enum netif_action_type action, enum netif_reason_type reason)
263{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530264 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800265 hdd_adapter_t *adapter;
266
267 if (!hdd_ctx) {
268 hdd_err("hdd ctx is NULL");
269 return;
270 }
271 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
272
273 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800274}
275
276/*
277 * Store WLAN driver version info in a global variable such that crash debugger
278 * can extract it from driver debug symbol and crashdump for post processing
279 */
280uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
281
282/**
283 * hdd_device_mode_to_string() - return string conversion of device mode
284 * @device_mode: device mode
285 *
286 * This utility function helps log string conversion of device mode.
287 *
288 * Return: string conversion of device mode, if match found;
289 * "Unknown" otherwise.
290 */
291const char *hdd_device_mode_to_string(uint8_t device_mode)
292{
293 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800294 CASE_RETURN_STRING(QDF_STA_MODE);
295 CASE_RETURN_STRING(QDF_SAP_MODE);
296 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
297 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
298 CASE_RETURN_STRING(QDF_FTM_MODE);
299 CASE_RETURN_STRING(QDF_IBSS_MODE);
300 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
301 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700302 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800303 default:
304 return "Unknown";
305 }
306}
307
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530308/**
309 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
310 * @adapter: HDD adapter
311 * @chan_number: Channel number
312 * @chan_bw: Bandwidth
313 *
314 * Checks if the given bandwidth is valid for the given channel number.
315 *
316 * Return: 0 for success, non-zero for failure
317 */
318int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
319 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800320 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530321{
322 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
323 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
324 bool found = false;
325 tHalHandle hal;
326
327 hal = WLAN_HDD_GET_HAL_CTX(adapter);
328 if (!hal) {
329 hdd_err("Invalid HAL context");
330 return -EINVAL;
331 }
332
333 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
334 hdd_err("No valid channel list");
335 return -EOPNOTSUPP;
336 }
337
338 for (i = 0; i < len; i++) {
339 if (chan[i] == chan_number) {
340 found = true;
341 break;
342 }
343 }
344
345 if (found == false) {
346 hdd_err("Channel not in driver's valid channel list");
347 return -EOPNOTSUPP;
348 }
349
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700350 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
351 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530352 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
353 return -EINVAL;
354 }
355
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700356 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530357 if (chan_bw == CH_WIDTH_80MHZ) {
358 hdd_err("BW80 not possible in 2.4GHz band");
359 return -EINVAL;
360 }
361 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
362 (chan_bw != CH_WIDTH_MAX)) {
363 hdd_err("Only BW20 possible on channel 14");
364 return -EINVAL;
365 }
366 }
367
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700368 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530369 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
370 (chan_bw != CH_WIDTH_MAX)) {
371 hdd_err("Only BW20 possible on channel 165");
372 return -EINVAL;
373 }
374 }
375
376 return 0;
377}
378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379static int __hdd_netdev_notifier_call(struct notifier_block *nb,
380 unsigned long state, void *data)
381{
382#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
383 struct netdev_notifier_info *dev_notif_info = data;
384 struct net_device *dev = dev_notif_info->dev;
385#else
386 struct net_device *dev = data;
387#endif
388 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
389 hdd_context_t *hdd_ctx;
390
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800391 ENTER_DEV(dev);
392
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800393 /* Make sure that this callback corresponds to our device. */
394 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
395 return NOTIFY_DONE;
396
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530397 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800398 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700399 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800400 return NOTIFY_DONE;
401 }
402
403 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700404 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800405 return NOTIFY_DONE;
406 }
407
408 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
409 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800410 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530411 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800412 return NOTIFY_DONE;
413 }
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800414 if (cds_is_driver_recovering())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800415 return NOTIFY_DONE;
416
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800417 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800418 dev->name, state);
419
420 switch (state) {
421 case NETDEV_REGISTER:
422 break;
423
424 case NETDEV_UNREGISTER:
425 break;
426
427 case NETDEV_UP:
428 sme_ch_avoid_update_req(hdd_ctx->hHal);
429 break;
430
431 case NETDEV_DOWN:
432 break;
433
434 case NETDEV_CHANGE:
435 if (true == adapter->isLinkUpSvcNeeded)
436 complete(&adapter->linkup_event_var);
437 break;
438
439 case NETDEV_GOING_DOWN:
440 if (adapter->scan_info.mScanPending != false) {
441 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800443 INIT_COMPLETION(adapter->scan_info.
444 abortscan_event_var);
445 hdd_abort_mac_scan(adapter->pHddCtx,
446 adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530447 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448 eCSR_SCAN_ABORT_DEFAULT);
449 rc = wait_for_completion_timeout(
450 &adapter->scan_info.abortscan_event_var,
451 msecs_to_jiffies(WLAN_WAIT_TIME_ABORTSCAN));
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700452 if (!rc)
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700453 hdd_err("Timeout occurred while waiting for abortscan");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800454 } else {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800455 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800456 }
457 break;
458
459 default:
460 break;
461 }
462
463 return NOTIFY_DONE;
464}
465
466/**
467 * hdd_netdev_notifier_call() - netdev notifier callback function
468 * @nb: pointer to notifier block
469 * @state: state
470 * @ndev: ndev pointer
471 *
472 * Return: 0 on success, error number otherwise.
473 */
474static int hdd_netdev_notifier_call(struct notifier_block *nb,
475 unsigned long state,
476 void *ndev)
477{
478 int ret;
479
480 cds_ssr_protect(__func__);
481 ret = __hdd_netdev_notifier_call(nb, state, ndev);
482 cds_ssr_unprotect(__func__);
483
484 return ret;
485}
486
487struct notifier_block hdd_netdev_notifier = {
488 .notifier_call = hdd_netdev_notifier_call,
489};
490
491/* variable to hold the insmod parameters */
492static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800493
494/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800495static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530497/**
498 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
499 * @ch_width: NL channel width
500 *
501 * Converts the NL channel width to the driver's internal representation
502 *
503 * Return: Converted channel width. In case of non matching NL channel width,
504 * CH_WIDTH_MAX will be returned.
505 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800506enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530507{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800508 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700509
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800510 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530511 switch (ch_width) {
512 case NL80211_CHAN_WIDTH_20_NOHT:
513 case NL80211_CHAN_WIDTH_20:
514 return CH_WIDTH_20MHZ;
515 case NL80211_CHAN_WIDTH_40:
516 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530517 case NL80211_CHAN_WIDTH_80:
518 return CH_WIDTH_80MHZ;
519 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800520 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
521 return CH_WIDTH_80P80MHZ;
522 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
523 return CH_WIDTH_160MHZ;
524 else
525 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530526 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800527 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
528 return CH_WIDTH_160MHZ;
529 else
530 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530531 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800532 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530533 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800534 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530535 default:
536 hdd_err("Invalid channel width %d, setting to default",
537 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800538 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530539 }
540}
541
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530542/* wlan_hdd_find_opclass() - Find operating class for a channel
543 * @hal: handler to HAL
544 * @channel: channel id
545 * @bw_offset: bandwidth offset
546 *
547 * Function invokes sme api to find the operating class
548 *
549 * Return: operating class
550 */
551uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
552 uint8_t bw_offset)
553{
554 uint8_t opclass = 0;
555
556 sme_get_opclass(hal, channel, bw_offset, &opclass);
557 return opclass;
558}
559
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530561 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530562 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 * @bitmask: Bitmask of log levels to be enabled
564 *
565 * Called immediately after the cfg.ini is read in order to configure
566 * the desired trace levels.
567 *
568 * Return: None
569 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530570int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800571{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530572 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530573 int qdf_print_idx = -1;
574 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575 /*
576 * if the bitmask is the default value, then a bitmask was not
577 * specified in cfg.ini, so leave the logging level alone (it
578 * will remain at the "compiled in" default value)
579 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700580 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530581 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530583 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530585 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530586 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530587 QDF_TRACE_LEVEL_NONE, 0);
588
589 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530590 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530592 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800593 while (0 != bitmask) {
594 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530595 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530596 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530597 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530598 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800599 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 level++;
602 bitmask >>= 1;
603 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530604 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605}
606
607/**
608 * wlan_hdd_validate_context() - check the HDD context
609 * @hdd_ctx: HDD context pointer
610 *
611 * Return: 0 if the context is valid. Error code otherwise
612 */
613int wlan_hdd_validate_context(hdd_context_t *hdd_ctx)
614{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800615 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530616 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617 return -ENODEV;
618 }
619
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800620 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800621 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530622 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 return -EAGAIN;
624 }
625
Rajeev Kumarfec3dbe2016-01-19 15:23:52 -0800626 if (cds_is_load_or_unload_in_progress()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800627 hdd_debug("%pS Unloading/Loading in Progress. Ignore!!!: 0x%x",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530628 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800629 return -EAGAIN;
630 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530631
632 if (hdd_ctx->start_modules_in_progress ||
633 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800634 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530635 (void *)_RET_IP_);
636 return -EAGAIN;
637 }
638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 return 0;
640}
641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642/**
643 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
644 * @hdd_adapter_t Hdd adapter.
645 *
646 * This function sets the IBSS power save config parameters to WMA
647 * which will send it to firmware if FW supports IBSS power save
648 * before vdev start.
649 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530650 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651 * on failure.
652 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530653QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800654{
655 int ret;
656 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
657
658 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700659 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530660 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 }
662
663 ret = wma_cli_set_command(adapter->sessionId,
664 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
665 hdd_ctx->config->ibssATIMWinSize,
666 VDEV_CMD);
667 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700668 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530669 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800670 }
671
672 ret = wma_cli_set_command(adapter->sessionId,
673 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
674 hdd_ctx->config->isIbssPowerSaveAllowed,
675 VDEV_CMD);
676 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700677 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
678 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530679 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680 }
681
682 ret = wma_cli_set_command(adapter->sessionId,
683 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
684 hdd_ctx->config->
685 isIbssPowerCollapseAllowed, VDEV_CMD);
686 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700687 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
688 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530689 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690 }
691
692 ret = wma_cli_set_command(adapter->sessionId,
693 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
694 hdd_ctx->config->isIbssAwakeOnTxRx,
695 VDEV_CMD);
696 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700697 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530698 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800699 }
700
701 ret = wma_cli_set_command(adapter->sessionId,
702 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
703 hdd_ctx->config->ibssInactivityCount,
704 VDEV_CMD);
705 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700706 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530707 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708 }
709
710 ret = wma_cli_set_command(adapter->sessionId,
711 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
712 hdd_ctx->config->ibssTxSpEndInactivityTime,
713 VDEV_CMD);
714 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700715 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
716 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530717 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800718 }
719
720 ret = wma_cli_set_command(adapter->sessionId,
721 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
722 hdd_ctx->config->ibssPsWarmupTime,
723 VDEV_CMD);
724 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700725 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
726 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530727 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 }
729
730 ret = wma_cli_set_command(adapter->sessionId,
731 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
732 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
733 VDEV_CMD);
734 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700735 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
736 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530737 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 }
739
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530740 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741}
742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743#define INTF_MACADDR_MASK 0x7
744
745/**
746 * hdd_update_macaddr() - update mac address
747 * @config: hdd configuration
748 * @hw_macaddr: mac address
749 *
750 * Mac address for multiple virtual interface is found as following
751 * i) The mac address of the first interface is just the actual hw mac address.
752 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
753 * define the mac address for the remaining interfaces and locally
754 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
755 * supported virtual interfaces, right now this is 0x07 (meaning 8
756 * interface).
757 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
758 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
759 *
760 * Return: None
761 */
762void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530763 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764{
765 int8_t i;
766 uint8_t macaddr_b3, tmp_br3;
767
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530768 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530769 QDF_MAC_ADDR_SIZE);
770 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530771 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530772 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 macaddr_b3 = config->intfMacAddr[i].bytes[3];
774 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
775 INTF_MACADDR_MASK;
776 macaddr_b3 += tmp_br3;
777
778 /* XOR-ing bit-24 of the mac address. This will give enough
779 * mac address range before collision
780 */
781 macaddr_b3 ^= (1 << 7);
782
783 /* Set locally administered bit */
784 config->intfMacAddr[i].bytes[0] |= 0x02;
785 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800786 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 MAC_ADDRESS_STR, i,
788 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
789 }
790}
791
792static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
793 struct wma_tgt_services *cfg)
794{
795 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796
797 /* Set up UAPSD */
798 config->apUapsdEnabled &= cfg->uapsd;
799
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800800 /* 11AX mode support */
801 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
802 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
803 config->dot11Mode = eHDD_DOT11_MODE_11ac;
804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805 /* 11AC mode support */
806 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
807 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
808 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809
810 /* ARP offload: override user setting if invalid */
811 config->fhostArpOffload &= cfg->arp_offload;
812
813#ifdef FEATURE_WLAN_SCAN_PNO
814 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800815 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816 if (cfg->pno_offload)
817 config->PnoOffload = true;
818#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819#ifdef FEATURE_WLAN_TDLS
820 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530821 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
822 cfg->en_tdls_offchan;
823 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
824 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700825 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700827 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830#ifdef WLAN_FEATURE_ROAM_OFFLOAD
831 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
832#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700833 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834
835}
836
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700837/**
838 * hdd_update_vdev_nss() - sets the vdev nss
839 * @hdd_ctx: HDD context
840 *
841 * Sets the Nss per vdev type based on INI
842 *
843 * Return: None
844 */
845static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
846{
847 struct hdd_config *cfg_ini = hdd_ctx->config;
848 uint8_t max_supp_nss = 1;
849
Naveen Rawat10b1c152017-01-18 11:16:06 -0800850 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700851 max_supp_nss = 2;
852
853 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
854 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
855
856 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
857 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
858}
859
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530860/**
861 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
862 * @hdd_ctx: HDD context
863 *
864 * Sets the DBS capability as per INI and firmware capability
865 *
866 * Return: None
867 */
868static void hdd_update_hw_dbs_capable(hdd_context_t *hdd_ctx)
869{
870 struct hdd_config *cfg_ini = hdd_ctx->config;
871 uint8_t hw_dbs_capable = 0;
872
873 if ((!cfg_ini->dual_mac_feature_disable)
Archana Ramachandran62886ce2017-03-24 14:46:32 -0700874 && policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530875 hw_dbs_capable = 1;
876
877 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
878}
879
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
881 struct wma_tgt_ht_cap *cfg)
882{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530883 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 uint32_t value, val32;
885 uint16_t val16;
886 struct hdd_config *pconfig = hdd_ctx->config;
887 tSirMacHTCapabilityInfo *phtCapInfo;
888 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
889 uint8_t enable_tx_stbc;
890
891 /* check and update RX STBC */
892 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
893 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
894
895 /* get the MPDU density */
896 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
897
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530898 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700899 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900 value = 0;
901 }
902
903 /*
904 * MPDU density:
905 * override user's setting if value is larger
906 * than the one supported by target
907 */
908 if (value > cfg->mpdu_density) {
909 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
910 cfg->mpdu_density);
911
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530912 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800913 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 }
915
916 /* get the HT capability info */
917 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530918 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700919 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 return;
921 }
922 val16 = (uint16_t) val32;
923 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
924
925 /* Set the LDPC capability */
926 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
927
928 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
929 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
930
931 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
932 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
933
934 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
935 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
936
937 enable_tx_stbc = pconfig->enableTxSTBC;
938
939 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
940 pconfig->enable2x2 = 1;
941 } else {
942 pconfig->enable2x2 = 0;
943 enable_tx_stbc = 0;
944
945 /* 1x1 */
946 /* Update Rx Highest Long GI data Rate */
947 if (sme_cfg_set_int(hdd_ctx->hHal,
948 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700949 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530950 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700951 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 }
953
954 /* Update Tx Highest Long GI data Rate */
955 if (sme_cfg_set_int
956 (hdd_ctx->hHal,
957 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700958 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530959 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700960 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 }
962 }
963 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
964 enable_tx_stbc = 0;
965 phtCapInfo->txSTBC = enable_tx_stbc;
966
967 val32 = val16;
968 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530969 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800970 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
972 value = SIZE_OF_SUPPORTED_MCS_SET;
973 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530974 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800975 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976
977 if (pconfig->enable2x2) {
978 for (value = 0; value < cfg->num_rf_chains; value++)
979 mcs_set[value] =
980 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
981
982 status =
983 sme_cfg_set_str(hdd_ctx->hHal,
984 WNI_CFG_SUPPORTED_MCS_SET,
985 mcs_set,
986 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530987 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800988 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 }
990 }
991#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
992}
993
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
995 struct wma_tgt_vht_cap *cfg)
996{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530997 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 uint32_t value = 0;
999 struct hdd_config *pconfig = hdd_ctx->config;
1000 struct wiphy *wiphy = hdd_ctx->wiphy;
1001 struct ieee80211_supported_band *band_5g =
Dustin Browna30892e2016-10-12 17:28:36 -07001002 wiphy->bands[NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001003 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001004 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001005
Dustin Brown5e06bd32016-10-04 12:49:10 -07001006 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001007 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001008 return;
1009 }
1010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 /* Get the current MPDU length */
1012 status =
1013 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1014 &value);
1015
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301016 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001017 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 value = 0;
1019 }
1020
1021 /*
1022 * VHT max MPDU length:
1023 * override if user configured value is too high
1024 * that the target cannot support
1025 */
1026 if (value > cfg->vht_max_mpdu) {
1027 status = sme_cfg_set_int(hdd_ctx->hHal,
1028 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1029 cfg->vht_max_mpdu);
1030
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001031 if (status == QDF_STATUS_E_FAILURE)
1032 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 }
1034
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001035 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1036 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1037
1038 if (pconfig->enable2x2)
1039 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1040
1041 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1042 QDF_STATUS_E_FAILURE) {
1043 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1044 }
1045
1046 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1047 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1048 if (pconfig->enable2x2)
1049 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1050
1051 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1052 QDF_STATUS_E_FAILURE) {
1053 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1054 }
1055
1056 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1057 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1058 if (pconfig->enable2x2)
1059 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1060
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001061 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001062 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1063
1064 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1065 QDF_STATUS_E_FAILURE) {
1066 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1067 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001069 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 &value);
1071
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301072 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001073 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 value = 0;
1075 }
1076
1077 /* Set the LDPC capability */
1078 if (value && !cfg->vht_rx_ldpc) {
1079 status = sme_cfg_set_int(hdd_ctx->hHal,
1080 WNI_CFG_VHT_LDPC_CODING_CAP,
1081 cfg->vht_rx_ldpc);
1082
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001083 if (status == QDF_STATUS_E_FAILURE)
1084 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 }
1086
1087 /* Get current GI 80 value */
1088 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1089 &value);
1090
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301091 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001092 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 value = 0;
1094 }
1095
1096 /* set the Guard interval 80MHz */
1097 if (value && !cfg->vht_short_gi_80) {
1098 status = sme_cfg_set_int(hdd_ctx->hHal,
1099 WNI_CFG_VHT_SHORT_GI_80MHZ,
1100 cfg->vht_short_gi_80);
1101
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001102 if (status == QDF_STATUS_E_FAILURE)
1103 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104 }
1105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106 /* Get VHT TX STBC cap */
1107 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1108
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301109 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001110 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 value = 0;
1112 }
1113
1114 /* VHT TX STBC cap */
1115 if (value && !cfg->vht_tx_stbc) {
1116 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1117 cfg->vht_tx_stbc);
1118
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001119 if (status == QDF_STATUS_E_FAILURE)
1120 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001121 }
1122
1123 /* Get VHT RX STBC cap */
1124 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1125
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301126 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001127 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 value = 0;
1129 }
1130
1131 /* VHT RX STBC cap */
1132 if (value && !cfg->vht_rx_stbc) {
1133 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1134 cfg->vht_rx_stbc);
1135
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001136 if (status == QDF_STATUS_E_FAILURE)
1137 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 }
1139
1140 /* Get VHT SU Beamformer cap */
1141 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1142 &value);
1143
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301144 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001145 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 value = 0;
1147 }
1148
1149 /* set VHT SU Beamformer cap */
1150 if (value && !cfg->vht_su_bformer) {
1151 status = sme_cfg_set_int(hdd_ctx->hHal,
1152 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1153 cfg->vht_su_bformer);
1154
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001155 if (status == QDF_STATUS_E_FAILURE)
1156 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 }
1158
1159 /* check and update SU BEAMFORMEE capabality */
1160 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1161 pconfig->enableTxBF = cfg->vht_su_bformee;
1162
1163 status = sme_cfg_set_int(hdd_ctx->hHal,
1164 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1165 pconfig->enableTxBF);
1166
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001167 if (status == QDF_STATUS_E_FAILURE)
1168 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169
1170 /* Get VHT MU Beamformer cap */
1171 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1172 &value);
1173
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301174 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001175 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 value = 0;
1177 }
1178
1179 /* set VHT MU Beamformer cap */
1180 if (value && !cfg->vht_mu_bformer) {
1181 status = sme_cfg_set_int(hdd_ctx->hHal,
1182 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1183 cfg->vht_mu_bformer);
1184
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001185 if (status == QDF_STATUS_E_FAILURE)
1186 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 }
1188
1189 /* Get VHT MU Beamformee cap */
1190 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1191 &value);
1192
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301193 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001194 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195 value = 0;
1196 }
1197
1198 /* set VHT MU Beamformee cap */
1199 if (value && !cfg->vht_mu_bformee) {
1200 status = sme_cfg_set_int(hdd_ctx->hHal,
1201 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1202 cfg->vht_mu_bformee);
1203
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001204 if (status == QDF_STATUS_E_FAILURE)
1205 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 }
1207
1208 /* Get VHT MAX AMPDU Len exp */
1209 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1210 &value);
1211
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301212 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001213 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 value = 0;
1215 }
1216
1217 /*
1218 * VHT max AMPDU len exp:
1219 * override if user configured value is too high
1220 * that the target cannot support.
1221 * Even though Rome publish ampdu_len=7, it can
1222 * only support 4 because of some h/w bug.
1223 */
1224
1225 if (value > cfg->vht_max_ampdu_len_exp) {
1226 status = sme_cfg_set_int(hdd_ctx->hHal,
1227 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1228 cfg->vht_max_ampdu_len_exp);
1229
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001230 if (status == QDF_STATUS_E_FAILURE)
1231 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 }
1233
1234 /* Get VHT TXOP PS CAP */
1235 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1236
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301237 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001238 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 value = 0;
1240 }
1241
1242 /* set VHT TXOP PS cap */
1243 if (value && !cfg->vht_txop_ps) {
1244 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1245 cfg->vht_txop_ps);
1246
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001247 if (status == QDF_STATUS_E_FAILURE)
1248 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 }
1250
1251 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1252 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1253 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1254 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1255 else
1256 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1257
1258
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001259 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1260 status = sme_cfg_set_int(hdd_ctx->hHal,
1261 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1262 VHT_CAP_160_AND_80P80_SUPP);
1263 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001264 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 band_5g->vht_cap.cap |=
1266 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001267 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1268 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1269 status = sme_cfg_set_int(hdd_ctx->hHal,
1270 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1271 VHT_CAP_160_SUPP);
1272 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001273 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 band_5g->vht_cap.cap |=
1275 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001276 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1277 }
1278 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1279 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301280 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001281 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301282 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001283 &value);
1284 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301285 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001286 value = 0;
1287 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301288 /* set the Guard interval 160MHz */
1289 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001290 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301291 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1292 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001293
1294 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301295 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001296 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297
1298 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1299 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1300
1301 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1302 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1303 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1304 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1305
1306 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1307 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1308
1309 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1310 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1311 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1312 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1313 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1314 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1315
1316 band_5g->vht_cap.cap |=
1317 (cfg->vht_max_ampdu_len_exp <<
1318 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1319
1320 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1321 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1322 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1323 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1324 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1325 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1326 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1327 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1328
1329 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1330 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1331
1332}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001333
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001334/**
1335 * hdd_generate_macaddr_auto() - Auto-generate mac address
1336 * @hdd_ctx: Pointer to the HDD context
1337 *
1338 * Auto-generate mac address using device serial number.
1339 * Keep the first 3 bytes of OUI as before and replace
1340 * the last 3 bytes with the lower 3 bytes of serial number.
1341 *
1342 * Return: 0 for success
1343 * Non zero failure code for errors
1344 */
1345static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1346{
1347 unsigned int serialno = 0;
1348 struct qdf_mac_addr mac_addr = {
1349 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1350 };
1351
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001352 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001353 if (serialno == 0)
1354 return -EINVAL;
1355
1356 serialno &= 0x00ffffff;
1357
1358 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1359 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1360 mac_addr.bytes[5] = serialno & 0xff;
1361
1362 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1363 return 0;
1364}
1365
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301366/**
1367 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1368 * configuration to cfg_ini in HDD
1369 * @hdd_ctx: Pointer to hdd_ctx
1370 * @cfg: target configuration
1371 *
1372 * Return: None
1373 */
1374#ifdef FEATURE_WLAN_RA_FILTERING
1375static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1376 struct wma_tgt_cfg *cfg)
1377{
1378 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1379}
1380#else
1381static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1382 struct wma_tgt_cfg *cfg)
1383{
1384}
1385#endif
1386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387void hdd_update_tgt_cfg(void *context, void *param)
1388{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001389 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1391 struct wma_tgt_cfg *cfg = param;
1392 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001393 struct cds_config_info *cds_cfg = cds_get_ini_config();
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301394
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001395 /* Reuse same pdev for module stop and start */
1396 if ((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
1397 (!cds_is_driver_loading())) {
1398 hdd_err("Reuse pdev for module start/stop");
1399 } else {
1400 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1401 if (ret) {
1402 hdd_err("pdev creation fails!");
1403 QDF_BUG(0);
1404 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301405 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001406
Naveen Rawat64e477e2016-05-20 10:34:56 -07001407 if (cds_cfg) {
1408 if (hdd_ctx->config->enable_sub_20_channel_width !=
1409 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1410 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1411 cds_cfg->sub_20_channel_width =
1412 WLAN_SUB_20_CH_WIDTH_NONE;
1413 } else {
1414 cds_cfg->sub_20_channel_width =
1415 hdd_ctx->config->enable_sub_20_channel_width;
1416 }
1417 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418
1419 /* first store the INI band capability */
1420 temp_band_cap = hdd_ctx->config->nBandCapability;
1421
1422 hdd_ctx->config->nBandCapability = cfg->band_cap;
1423
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001424 /*
1425 * now overwrite the target band capability with INI
1426 * setting if INI setting is a subset
1427 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428
1429 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1430 (temp_band_cap != eCSR_BAND_ALL))
1431 hdd_ctx->config->nBandCapability = temp_band_cap;
1432 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1433 (temp_band_cap != eCSR_BAND_ALL) &&
1434 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001435 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 }
1437
Prashanth Bhatta9e143052015-12-04 11:56:47 -08001438 if (!cds_is_driver_recovering()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1440 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1441 }
1442
1443 /* This can be extended to other configurations like ht, vht cap... */
1444
Anurag Chouhanc5548422016-02-24 18:33:27 +05301445 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001447 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001449 static struct qdf_mac_addr default_mac_addr = {
1450 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1451 };
1452 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1453 &default_mac_addr)) {
1454 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1455 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1456 MAC_ADDRESS_STR,
1457 MAC_ADDR_ARRAY(hdd_ctx->config->
1458 intfMacAddr[0].bytes));
1459 } else {
1460 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1461 MAC_ADDRESS_STR,
1462 MAC_ADDR_ARRAY(hdd_ctx->config->
1463 intfMacAddr[0].bytes));
1464 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001465 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 }
1467
1468 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001469 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470
1471 hdd_ctx->max_intf_count = cfg->max_intf_count;
1472
Jeff Johnsonc875e242016-09-23 18:12:34 -07001473 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001474 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1477 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1478
1479 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001482 if (cfg->services.en_11ax) {
1483 hdd_info("11AX: 11ax is enabled - update HDD config");
1484 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1485 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001486
1487 hdd_update_vdev_nss(hdd_ctx);
1488
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301489 hdd_update_hw_dbs_capable(hdd_ctx);
1490
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001491 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001492 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001493 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001494 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001495
1496 hdd_ctx->current_antenna_mode =
1497 (hdd_ctx->config->enable2x2 == 0x01) ?
1498 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001499 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001500 hdd_ctx->current_antenna_mode);
1501
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001502 hdd_debug("Target BPF %d Host BPF %d",
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001503 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable);
1504 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1505 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301506 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301507
Arun Khandavallid454d422016-08-17 12:47:05 +05301508 /*
1509 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1510 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1511 * configure the STA mode wow pattern.
1512 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301513 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301514 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301515
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301516 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1517
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001518 /* Configure NAN datapath features */
1519 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001520 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521}
1522
1523/**
1524 * hdd_dfs_indicate_radar() - handle radar detection on current SAP channel
1525 * @context: HDD context pointer
1526 * @param: HDD radar indication pointer
1527 *
Sandeep Puligillaa8d4eec2016-06-30 15:13:11 -07001528 * This function is invoked in atomic context when a radar
1529 * is found on the SAP current operating channel and Data Tx
1530 * from netif has to be stopped to honor the DFS regulations.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001531 * Actions: Stop the netif Tx queues,Indicate Radar present
1532 * in HDD context for future usage.
1533 *
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301534 * Return: true to allow radar indication to host else false
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301536bool hdd_dfs_indicate_radar(void *context, void *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537{
1538 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1539 struct wma_dfs_radar_ind *hdd_radar_event =
1540 (struct wma_dfs_radar_ind *)param;
1541 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1542 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301543 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301544 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301546 if (!hdd_ctx || !hdd_radar_event ||
1547 hdd_ctx->config->disableDFSChSwitch)
1548 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549
1550 if (true == hdd_radar_event->dfs_radar_status) {
Arif Hussain2a7c1f32016-07-18 14:24:36 -07001551 if (qdf_atomic_inc_return(&hdd_ctx->dfs_radar_found) > 1) {
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301552 /*
1553 * Application already triggered channel switch
1554 * on current channel, so return here.
1555 */
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301556 return false;
1557 }
1558
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301560 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 adapter = adapterNode->pAdapter;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301562 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1563 if ((QDF_SAP_MODE == adapter->device_mode ||
1564 QDF_P2P_GO_MODE == adapter->device_mode) &&
1565 (CHANNEL_STATE_DFS ==
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001566 wlan_reg_get_channel_state(hdd_ctx->hdd_pdev,
1567 ap_ctx->operatingChannel))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 WLAN_HDD_GET_AP_CTX_PTR(adapter)->
1569 dfs_cac_block_tx = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001570 hdd_debug("tx blocked for session:%d",
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301571 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 }
1573
1574 status = hdd_get_next_adapter(hdd_ctx,
1575 adapterNode,
1576 &pNext);
1577 adapterNode = pNext;
1578 }
1579 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301580
1581 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583
1584/**
1585 * hdd_is_valid_mac_address() - validate MAC address
1586 * @pMacAddr: Pointer to the input MAC address
1587 *
1588 * This function validates whether the given MAC address is valid or not
1589 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1590 * where X is the hexa decimal digit character and separated by ':'
1591 * This algorithm works even if MAC address is not separated by ':'
1592 *
1593 * This code checks given input string mac contains exactly 12 hexadecimal
1594 * digits and a separator colon : appears in the input string only after
1595 * an even number of hex digits.
1596 *
1597 * Return: 1 for valid and 0 for invalid
1598 */
1599bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1600{
1601 int xdigit = 0;
1602 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 while (*pMacAddr) {
1605 if (isxdigit(*pMacAddr)) {
1606 xdigit++;
1607 } else if (':' == *pMacAddr) {
1608 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1609 break;
1610
1611 ++separator;
1612 } else {
1613 /* Invalid MAC found */
1614 return 0;
1615 }
1616 ++pMacAddr;
1617 }
1618 return xdigit == 12 && (separator == 5 || separator == 0);
1619}
1620
1621/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301622 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1623 * @dev: Handle to struct net_device to be updated.
1624 *
1625 * Return: None
1626 */
1627static void hdd_mon_mode_ether_setup(struct net_device *dev)
1628{
1629 dev->header_ops = NULL;
1630 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1631 dev->hard_header_len = ETH_HLEN;
1632 dev->mtu = ETH_DATA_LEN;
1633 dev->addr_len = ETH_ALEN;
1634 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1635 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1636 dev->priv_flags |= IFF_TX_SKB_SHARING;
1637
1638 memset(dev->broadcast, 0xFF, ETH_ALEN);
1639}
1640
1641/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001642 * __hdd__mon_open() - HDD Open function
1643 * @dev: Pointer to net_device structure
1644 *
1645 * This is called in response to ifconfig up
1646 *
1647 * Return: 0 for success; non-zero for failure
1648 */
1649static int __hdd_mon_open(struct net_device *dev)
1650{
1651 int ret;
1652
1653 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301654 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001655 ret = hdd_set_mon_rx_cb(dev);
1656 return ret;
1657}
1658
1659/**
1660 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1661 * @dev: Pointer to net_device structure
1662 *
1663 * This is called in response to ifconfig up
1664 *
1665 * Return: 0 for success; non-zero for failure
1666 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001667static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001668{
1669 int ret;
1670
1671 cds_ssr_protect(__func__);
1672 ret = __hdd_mon_open(dev);
1673 cds_ssr_unprotect(__func__);
1674
1675 return ret;
1676}
1677
1678/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301679 * hdd_start_adapter() - Wrapper function for device specific adapter
1680 * @adapter: pointer to HDD adapter
1681 *
1682 * This function is called to start the device specific adapter for
1683 * the mode passed in the adapter's device_mode.
1684 *
1685 * Return: 0 for success; non-zero for failure
1686 */
1687int hdd_start_adapter(hdd_adapter_t *adapter)
1688{
1689
1690 int ret;
1691 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1692
1693 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001694 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301695
1696 switch (device_mode) {
1697 case QDF_P2P_CLIENT_MODE:
1698 case QDF_P2P_DEVICE_MODE:
1699 case QDF_OCB_MODE:
1700 case QDF_STA_MODE:
1701 case QDF_MONITOR_MODE:
1702 ret = hdd_start_station_adapter(adapter);
1703 if (ret)
1704 goto err_start_adapter;
1705 break;
1706 case QDF_P2P_GO_MODE:
1707 case QDF_SAP_MODE:
1708 ret = hdd_start_ap_adapter(adapter);
1709 if (ret)
1710 goto err_start_adapter;
1711 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301712 case QDF_IBSS_MODE:
1713 /*
1714 * For IBSS interface is initialized as part of
1715 * hdd_init_station_mode()
1716 */
1717 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301718 case QDF_FTM_MODE:
1719 ret = hdd_start_ftm_adapter(adapter);
1720 if (ret)
1721 goto err_start_adapter;
1722 break;
1723 default:
1724 hdd_err("Invalid session type %d", device_mode);
1725 QDF_ASSERT(0);
1726 goto err_start_adapter;
1727 }
1728 if (hdd_set_fw_params(adapter))
1729 hdd_err("Failed to set the FW params for the adapter!");
1730
1731 /*
1732 * Action frame registered in one adapter which will
1733 * applicable to all interfaces
1734 */
1735 wlan_hdd_cfg80211_register_frames(adapter);
1736 EXIT();
1737 return 0;
1738err_start_adapter:
1739 return -EINVAL;
1740}
1741
1742/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301743 * hdd_enable_power_management() - API to Enable Power Management
1744 *
1745 * API invokes Bus Interface Layer power management functionality
1746 *
1747 * Return: None
1748 */
1749static void hdd_enable_power_management(void)
1750{
1751 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1752
1753 if (!hif_ctx) {
1754 hdd_err("Bus Interface Context is Invalid");
1755 return;
1756 }
1757
1758 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1759}
1760
1761/**
1762 * hdd_disable_power_management() - API to disable Power Management
1763 *
1764 * API disable Bus Interface Layer Power management functionality
1765 *
1766 * Return: None
1767 */
1768static void hdd_disable_power_management(void)
1769{
1770 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1771
1772 if (!hif_ctx) {
1773 hdd_err("Bus Interface Context is Invalid");
1774 return;
1775 }
1776
1777 hif_disable_power_management(hif_ctx);
1778}
1779
1780/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301781 * hdd_update_hw_sw_info() - API to update the HW/SW information
1782 *
1783 * API to update the HW and SW information in the driver
1784 *
1785 * Return: None
1786 */
1787static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1788{
1789 void *hif_sc;
1790
1791 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1792 if (!hif_sc) {
1793 hdd_err("HIF context is NULL");
1794 return;
1795 }
1796
1797 /*
1798 * target hw version/revision would only be retrieved after firmware
1799 * download
1800 */
1801 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
1802 &hdd_ctx->target_hw_revision,
1803 &hdd_ctx->target_hw_name);
1804
1805 /* Get the wlan hw/fw version */
1806 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
1807
1808 return;
1809}
1810
1811/**
gbian62edd7e2017-03-07 13:12:13 +08001812 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1813 * @hdd_ctx: Pointer to hdd context
1814 *
1815 * Return: none
1816 */
1817static void
1818hdd_update_cds_ac_specs_params(hdd_context_t *hdd_ctx)
1819{
1820 uint8_t num_entries = 0;
1821 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
1822 uint8_t *tx_sched_wrr_ac;
1823 int i;
1824 cds_context_type *cds_ctx;
1825
1826 if (NULL == hdd_ctx)
1827 return;
1828
1829 if (NULL == hdd_ctx->config) {
1830 /* Do nothing if hdd_ctx is invalid */
1831 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
1832 return;
1833 }
1834
1835 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1836
1837 if (!cds_ctx) {
1838 hdd_err("Invalid CDS Context");
1839 return;
1840 }
1841
1842 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
1843 switch (i) {
1844 case OL_TX_WMM_AC_BE:
1845 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
1846 break;
1847 case OL_TX_WMM_AC_BK:
1848 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
1849 break;
1850 case OL_TX_WMM_AC_VI:
1851 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
1852 break;
1853 case OL_TX_WMM_AC_VO:
1854 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
1855 break;
1856 default:
1857 tx_sched_wrr_ac = NULL;
1858 break;
1859 }
1860
1861 hdd_string_to_u8_array(tx_sched_wrr_ac,
1862 tx_sched_wrr_param,
1863 &num_entries,
1864 sizeof(tx_sched_wrr_param));
1865
1866 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
1867 cds_ctx->ac_specs[i].wrr_skip_weight =
1868 tx_sched_wrr_param[0];
1869 cds_ctx->ac_specs[i].credit_threshold =
1870 tx_sched_wrr_param[1];
1871 cds_ctx->ac_specs[i].send_limit =
1872 tx_sched_wrr_param[2];
1873 cds_ctx->ac_specs[i].credit_reserve =
1874 tx_sched_wrr_param[3];
1875 cds_ctx->ac_specs[i].discard_weight =
1876 tx_sched_wrr_param[4];
1877 }
1878
1879 num_entries = 0;
1880 }
1881}
1882
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07001883#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07001884static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
1885 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
1886{
1887 hdd_adapter_t *adapter = NULL;
1888 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1889
1890 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
1891 if (!adapter) {
1892 hdd_err("Adapter is NULL");
1893 return PM_MAX_NUM_OF_MODE;
1894 }
1895
1896 return policy_mgr_convert_device_mode_to_qdf_type(
1897 adapter->device_mode);
1898}
1899
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07001900static void hdd_register_policy_manager_callback(
1901 struct wlan_objmgr_psoc *psoc)
1902{
1903 struct policy_mgr_hdd_cbacks hdd_cbacks;
1904 hdd_cbacks.sap_restart_chan_switch_cb =
1905 sap_restart_chan_switch_cb;
1906 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
1907 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07001908 hdd_cbacks.get_mode_for_non_connected_vdev =
1909 wlan_hdd_get_mode_for_non_connected_vdev;
1910
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07001911 if (QDF_STATUS_SUCCESS !=
1912 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
1913 hdd_err("HDD callback registration with policy manager failed");
1914 }
1915}
1916#else
1917static void hdd_register_policy_manager_callback(
1918 struct wlan_objmgr_psoc *psoc)
1919{
1920}
1921#endif
1922
Naveen Rawatcb5c5402017-03-22 10:12:19 -07001923#ifdef WLAN_FEATURE_NAN_CONVERGENCE
1924static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
1925{
1926 struct nan_callbacks cb_obj = {0};
1927
1928 cb_obj.ndi_open = hdd_ndi_open;
1929 cb_obj.ndi_close = hdd_ndi_close;
1930 cb_obj.ndi_start = hdd_ndi_start;
1931 cb_obj.ndi_delete = hdd_ndi_delete;
1932 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
1933 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
1934
Naveen Rawat37f62c82017-03-26 22:24:43 -07001935 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
1936 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07001937 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07001938
Naveen Rawatcb5c5402017-03-22 10:12:19 -07001939 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
1940}
1941#else
1942static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
1943{
1944}
1945#endif
1946
gbian62edd7e2017-03-07 13:12:13 +08001947/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301948 * hdd_wlan_start_modules() - Single driver state machine for starting modules
1949 * @hdd_ctx: HDD context
1950 * @adapter: HDD adapter
1951 * @reinit: flag to indicate from SSR or normal path
1952 *
1953 * This function maintains the driver state machine it will be invoked from
1954 * startup, reinit and change interface. Depending on the driver state shall
1955 * perform the opening of the modules.
1956 *
1957 * Return: 0 for success; non-zero for failure
1958 */
1959int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
1960 bool reinit)
1961{
1962 int ret;
1963 qdf_device_t qdf_dev;
1964 QDF_STATUS status;
1965 p_cds_contextType p_cds_context;
1966 bool unint = false;
1967 void *hif_ctx;
1968
1969 ENTER();
1970
1971 p_cds_context = cds_get_global_context();
1972 if (!p_cds_context) {
1973 hdd_err("Global Context is NULL");
1974 QDF_ASSERT(0);
1975 return -EINVAL;
1976 }
1977
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001978 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05301979 hdd_ctx->driver_status, reinit);
1980
1981 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
1982 if (!qdf_dev) {
1983 hdd_err("QDF Device Context is Invalid return");
1984 return -EINVAL;
1985 }
1986
1987 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301988 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05301989
1990 if (QDF_TIMER_STATE_RUNNING ==
1991 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
1992
1993 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001994 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05301995 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
1996 }
1997
1998 switch (hdd_ctx->driver_status) {
1999 case DRIVER_MODULES_UNINITIALIZED:
2000 unint = true;
2001 /* Fall through dont add break here */
2002 case DRIVER_MODULES_CLOSED:
2003 if (!reinit && !unint) {
2004 ret = pld_power_on(qdf_dev->dev);
2005 if (ret) {
2006 hdd_err("Failed to Powerup the device: %d", ret);
2007 goto release_lock;
2008 }
2009 }
2010 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2011 qdf_dev->bus_type,
2012 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2013 HIF_ENABLE_TYPE_PROBE);
2014 if (ret) {
2015 hdd_err("Failed to open hif: %d", ret);
2016 goto power_down;
2017 }
2018
2019 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302020 if (!hif_ctx) {
2021 hdd_err("hif context is null!!");
2022 goto power_down;
2023 }
2024
Arun Khandavallifae92942016-08-01 13:31:08 +05302025 status = ol_cds_init(qdf_dev, hif_ctx);
2026 if (status != QDF_STATUS_SUCCESS) {
2027 hdd_err("No Memory to Create BMI Context :%d", status);
2028 goto hif_close;
2029 }
2030
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002031 ret = hdd_update_config(hdd_ctx);
2032 if (ret) {
2033 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302034 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002035 }
2036
gbian62edd7e2017-03-07 13:12:13 +08002037 hdd_update_cds_ac_specs_params(hdd_ctx);
2038
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302039 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302040 if (!QDF_IS_STATUS_SUCCESS(status)) {
2041 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302042 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302043 }
2044
Mukul Sharma9d797a02017-01-05 20:26:03 +05302045 /* initalize components configurations after psoc open */
2046 ret = hdd_update_components_config(hdd_ctx);
2047 if (ret) {
2048 hdd_err("Failed to update components configs :%d",
2049 ret);
2050 goto close;
2051 }
2052
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002053 /*
2054 * NAN compoenet requires certian operations like, open adapter,
2055 * close adapter, etc. to be initiated by HDD, for those
2056 * register HDD callbacks with UMAC's NAN componenet.
2057 */
2058 hdd_nan_register_callbacks(hdd_ctx);
2059
Arun Khandavallifae92942016-08-01 13:31:08 +05302060 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2061
2062 status = cds_pre_enable(hdd_ctx->pcds_context);
2063 if (!QDF_IS_STATUS_SUCCESS(status)) {
2064 hdd_err("Failed to pre-enable CDS: %d", status);
2065 goto close;
2066 }
2067
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002068 hdd_register_policy_manager_callback(
2069 hdd_ctx->hdd_psoc);
2070
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302071 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302072 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302073
Arun Khandavallifae92942016-08-01 13:31:08 +05302074 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2075 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2076 hdd_ftm_mc_process_msg);
2077 break;
2078 }
2079 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002080 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302081 break;
2082 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302083
2084 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002085 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2086 hdd_err("HDD IPA UC reinit failed");
2087 goto close;
2088 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302089 }
2090
Arun Khandavallifae92942016-08-01 13:31:08 +05302091 /* Fall through dont add break here */
2092 case DRIVER_MODULES_OPENED:
2093 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002094 hdd_err("adapter is Null");
Arun Khandavallifae92942016-08-01 13:31:08 +05302095 goto close;
2096 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302097 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2098 hdd_err("in ftm mode, no need to configure cds modules");
2099 break;
2100 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302101 if (hdd_configure_cds(hdd_ctx, adapter)) {
2102 hdd_err("Failed to Enable cds modules");
2103 goto close;
2104 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302105 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302106 hdd_info("Driver Modules Successfully Enabled");
2107 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2108 break;
2109 case DRIVER_MODULES_ENABLED:
2110 hdd_info("Driver modules already Enabled");
2111 break;
2112 default:
2113 hdd_err("WLAN start invoked in wrong state! :%d\n",
2114 hdd_ctx->driver_status);
2115 goto release_lock;
2116 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302117 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302118 mutex_unlock(&hdd_ctx->iface_change_lock);
2119 EXIT();
2120 return 0;
2121
2122close:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302123 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302124
2125ol_cds_free:
2126 ol_cds_free();
2127
2128hif_close:
2129 hdd_hif_close(p_cds_context->pHIFContext);
2130power_down:
2131 if (!reinit && !unint)
2132 pld_power_off(qdf_dev->dev);
2133release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302134 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302135 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302136 EXIT();
Arun Khandavallifae92942016-08-01 13:31:08 +05302137 return -EINVAL;
2138}
2139
Naveen Rawat910726a2017-03-06 11:42:51 -08002140#ifdef WIFI_POS_CONVERGED
2141static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2142{
2143 int ret = os_if_wifi_pos_register_nl();
2144
2145 if (ret)
2146 hdd_err("os_if_wifi_pos_register_nl failed");
2147
2148 return ret;
2149}
2150
2151static int hdd_deactivate_wifi_pos(void)
2152{
2153 int ret = os_if_wifi_pos_deregister_nl();
2154
2155 if (ret)
2156 hdd_err("os_if_wifi_pos_deregister_nl failed");
2157
2158 return ret;
2159}
2160
2161/**
2162 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2163 * @hdd_ctx: hdd context
2164 *
2165 * Return: status of operation
2166 */
2167static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2168{
2169 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2170 struct hdd_config *cfg = hdd_ctx->config;
2171
2172 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2173 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2174 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2175 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2176 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2177 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2178 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2179 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2180}
2181#else
2182static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2183{
2184 return oem_activate_service(hdd_ctx);
2185}
2186
2187static int hdd_deactivate_wifi_pos(void)
2188{
2189 return 0;
2190}
2191
2192static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2193{
2194}
2195#endif
2196
Arun Khandavallifae92942016-08-01 13:31:08 +05302197/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002198 * __hdd_open() - HDD Open function
2199 * @dev: Pointer to net_device structure
2200 *
2201 * This is called in response to ifconfig up
2202 *
2203 * Return: 0 for success; non-zero for failure
2204 */
2205static int __hdd_open(struct net_device *dev)
2206{
2207 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2208 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2209 int ret;
2210
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002211 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302212 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302213 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002214
2215 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302216 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002217 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002219
Arun Khandavallifae92942016-08-01 13:31:08 +05302220 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2221 if (ret) {
2222 hdd_err("Failed to start WLAN modules return");
2223 return -ret;
2224 }
2225
2226
2227 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2228 ret = hdd_start_adapter(adapter);
2229 if (ret) {
2230 hdd_err("Failed to start adapter :%d",
2231 adapter->device_mode);
2232 return ret;
2233 }
2234 }
2235
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002236 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2237 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Arun Khandavallifae92942016-08-01 13:31:08 +05302238 hdd_info("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002239 /* Enable TX queues only when we are connected */
2240 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302241 WLAN_START_ALL_NETIF_QUEUE,
2242 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243 }
2244
Naveen Rawat286def52016-09-23 15:38:02 -07002245 /* Enable carrier and transmit queues for NDI */
2246 if (WLAN_HDD_IS_NDI(adapter)) {
2247 hdd_notice("Enabling Tx Queues");
2248 wlan_hdd_netif_queue_control(adapter,
2249 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2250 WLAN_CONTROL_PATH);
2251 }
2252
Naveen Rawat910726a2017-03-06 11:42:51 -08002253 hdd_populate_wifi_pos_cfg(hdd_ctx);
2254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 return ret;
2256}
2257
Arun Khandavallifae92942016-08-01 13:31:08 +05302258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259/**
2260 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2261 * @dev: Pointer to net_device structure
2262 *
2263 * This is called in response to ifconfig up
2264 *
2265 * Return: 0 for success; non-zero for failure
2266 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002267static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268{
2269 int ret;
2270
2271 cds_ssr_protect(__func__);
2272 ret = __hdd_open(dev);
2273 cds_ssr_unprotect(__func__);
2274
2275 return ret;
2276}
2277
2278/**
2279 * __hdd_stop() - HDD stop function
2280 * @dev: Pointer to net_device structure
2281 *
2282 * This is called in response to ifconfig down
2283 *
2284 * Return: 0 for success; non-zero for failure
2285 */
2286static int __hdd_stop(struct net_device *dev)
2287{
2288 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2289 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2290 int ret;
2291
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002292 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302294 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002295 adapter->sessionId, adapter->device_mode));
2296
2297 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302298 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002300
2301 /* Nothing to be done if the interface is not opened */
2302 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002303 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002304 return -ENODEV;
2305 }
2306
2307 /* Make sure the interface is marked as closed */
2308 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Jeff Johnson1346fab2016-08-15 13:09:42 -07002309 hdd_notice("Disabling OS Tx queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310
2311 /*
2312 * Disable TX on the interface, after this hard_start_xmit() will not
2313 * be called on that interface
2314 */
Jeff Johnson1346fab2016-08-15 13:09:42 -07002315 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302316 wlan_hdd_netif_queue_control(adapter,
2317 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2318 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319
2320 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002321 * NAN data interface is different in some sense. The traffic on NDI is
2322 * bursty in nature and depends on the need to transfer. The service
2323 * layer may down the interface after the usage and up again when
2324 * required. In some sense, the NDI is expected to be available
2325 * (like SAP) iface until NDI delete request is issued by the service
2326 * layer. Skip BSS termination and adapter deletion for NAN Data
2327 * interface (NDI).
2328 */
2329 if (WLAN_HDD_IS_NDI(adapter))
2330 return 0;
2331
2332 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002333 * The interface is marked as down for outside world (aka kernel)
2334 * But the driver is pretty much alive inside. The driver needs to
2335 * tear down the existing connection on the netdev (session)
2336 * cleanup the data pipes and wait until the control plane is stabilized
2337 * for this interface. The call also needs to wait until the above
2338 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002339 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002340 * That is intentional to be able to scan if it is a STA/P2P interface
2341 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002343
2344 /* DeInit the adapter. This ensures datapath cleanup as well */
2345 hdd_deinit_adapter(hdd_ctx, adapter, true);
2346
Arun Khandavallifae92942016-08-01 13:31:08 +05302347
2348 /*
2349 * Find if any iface is up. If any iface is up then can't put device to
2350 * sleep/power save mode
2351 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302352 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002353 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302354 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
2355 hdd_ctx->config->iface_change_wait_time
2356 * 50000);
2357 }
2358
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002359 EXIT();
2360 return 0;
2361}
2362
2363/**
2364 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2365 * @dev: pointer to net_device structure
2366 *
2367 * This is called in response to ifconfig down
2368 *
2369 * Return: 0 for success and error number for failure
2370 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002371static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002372{
2373 int ret;
2374
2375 cds_ssr_protect(__func__);
2376 ret = __hdd_stop(dev);
2377 cds_ssr_unprotect(__func__);
2378
2379 return ret;
2380}
2381
2382/**
2383 * __hdd_uninit() - HDD uninit function
2384 * @dev: Pointer to net_device structure
2385 *
2386 * This is called during the netdev unregister to uninitialize all data
2387 * associated with the device
2388 *
2389 * Return: None
2390 */
2391static void __hdd_uninit(struct net_device *dev)
2392{
2393 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2394
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002395 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002396
2397 do {
2398 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002399 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002400 break;
2401 }
2402
2403 if (NULL == adapter->pHddCtx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002404 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002405 break;
2406 }
2407
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002408 if (dev != adapter->dev)
2409 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410
2411 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2412
2413 /* after uninit our adapter structure will no longer be valid */
2414 adapter->dev = NULL;
2415 adapter->magic = 0;
2416 } while (0);
2417
2418 EXIT();
2419}
2420
2421/**
2422 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2423 * @dev: pointer to net_device structure
2424 *
2425 * This is called during the netdev unregister to uninitialize all data
2426 * associated with the device
2427 *
2428 * Return: none
2429 */
2430static void hdd_uninit(struct net_device *dev)
2431{
2432 cds_ssr_protect(__func__);
2433 __hdd_uninit(dev);
2434 cds_ssr_unprotect(__func__);
2435}
2436
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002437static int hdd_open_cesium_nl_sock(void)
2438{
2439#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2440 struct netlink_kernel_cfg cfg = {
2441 .groups = WLAN_NLINK_MCAST_GRP_ID,
2442 .input = NULL
2443 };
2444#endif
2445 int ret = 0;
2446
2447#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2448 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2449#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2450 THIS_MODULE,
2451#endif
2452 &cfg);
2453#else
2454 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2455 WLAN_NLINK_MCAST_GRP_ID,
2456 NULL, NULL, THIS_MODULE);
2457#endif
2458
2459 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002460 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002461 ret = -ECONNREFUSED;
2462 }
2463
2464 return ret;
2465}
2466
2467static void hdd_close_cesium_nl_sock(void)
2468{
2469 if (NULL != cesium_nl_srv_sock) {
2470 netlink_kernel_release(cesium_nl_srv_sock);
2471 cesium_nl_srv_sock = NULL;
2472 }
2473}
2474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002475/**
2476 * __hdd_set_mac_address() - set the user specified mac address
2477 * @dev: Pointer to the net device.
2478 * @addr: Pointer to the sockaddr.
2479 *
2480 * This function sets the user specified mac address using
2481 * the command ifconfig wlanX hw ether <mac adress>.
2482 *
2483 * Return: 0 for success, non zero for failure
2484 */
2485static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2486{
2487 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2488 hdd_context_t *hdd_ctx;
2489 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302490 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 int ret;
2492
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002493 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002494
2495 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2496 ret = wlan_hdd_validate_context(hdd_ctx);
2497 if (0 != ret)
2498 return ret;
2499
2500 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2501 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2502
2503 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302504 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002505}
2506
2507/**
2508 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2509 * function from SSR
2510 * @dev: pointer to net_device structure
2511 * @addr: Pointer to the sockaddr
2512 *
2513 * This function sets the user specified mac address using
2514 * the command ifconfig wlanX hw ether <mac adress>.
2515 *
2516 * Return: 0 for success.
2517 */
2518static int hdd_set_mac_address(struct net_device *dev, void *addr)
2519{
2520 int ret;
2521
2522 cds_ssr_protect(__func__);
2523 ret = __hdd_set_mac_address(dev, addr);
2524 cds_ssr_unprotect(__func__);
2525
2526 return ret;
2527}
2528
2529uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2530{
2531 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002532
Anurag Chouhan6d760662016-02-20 16:05:43 +05302533 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002534 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2535 break;
2536 }
2537
Anurag Chouhan6d760662016-02-20 16:05:43 +05302538 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002539 return NULL;
2540
2541 hdd_ctx->config->intfAddrMask |= (1 << i);
2542 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2543}
2544
2545void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2546{
2547 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002548
Anurag Chouhan6d760662016-02-20 16:05:43 +05302549 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002550 if (!memcmp(releaseAddr,
2551 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2552 6)) {
2553 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2554 break;
2555 }
2556 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557}
2558
2559#ifdef WLAN_FEATURE_PACKET_FILTERING
2560/**
2561 * __hdd_set_multicast_list() - set the multicast address list
2562 * @dev: Pointer to the WLAN device.
2563 * @skb: Pointer to OS packet (sk_buff).
2564 *
2565 * This funciton sets the multicast address list.
2566 *
2567 * Return: None
2568 */
2569static void __hdd_set_multicast_list(struct net_device *dev)
2570{
2571 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572 int i = 0, status;
2573 struct netdev_hw_addr *ha;
2574 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302575 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2576 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2577 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002579 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302580 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302581 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302582
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302584 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302585 goto out;
2586
2587 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2588 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002589 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302590 goto out;
2591 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002592
2593 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002594 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302595 hdd_disable_and_flush_mc_addr_list(adapter,
2596 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597 } else {
2598 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302599 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002600 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302601 pmo_ucfg_max_mc_addr_supported(psoc));
2602 hdd_disable_and_flush_mc_addr_list(adapter,
2603 pmo_mc_list_change_notify);
2604 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002606 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002607 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302608 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 if (i == mc_count)
2610 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302611 memset(&(mc_list_request->mc_addr[i].bytes),
2612 0, ETH_ALEN);
2613 memcpy(&(mc_list_request->mc_addr[i].bytes),
2614 ha->addr, ETH_ALEN);
2615 hdd_info("mlist[%d] = %pM", i,
2616 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 i++;
2618 }
2619 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302620
2621 mc_list_request->psoc = psoc;
2622 mc_list_request->vdev_id = adapter->sessionId;
2623 mc_list_request->count = mc_count;
2624 status = hdd_cache_mc_addr_list(mc_list_request);
2625 if (status == 0) {
2626 hdd_enable_mc_addr_filtering(adapter,
2627 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302629 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002630 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302631out:
2632 if (mc_list_request)
2633 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302634 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635}
2636
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638/**
2639 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2640 * @dev: pointer to net_device
2641 *
2642 * Return: none
2643 */
2644static void hdd_set_multicast_list(struct net_device *dev)
2645{
2646 cds_ssr_protect(__func__);
2647 __hdd_set_multicast_list(dev);
2648 cds_ssr_unprotect(__func__);
2649}
2650#endif
2651
2652/**
2653 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2654 * @dev: Pointer to the WLAN device.
2655 * @skb: Pointer to OS packet (sk_buff).
2656 *
2657 * This function is registered with the Linux OS for network
2658 * core to decide which queue to use first.
2659 *
2660 * Return: ac, Queue Index/access category corresponding to UP in IP header
2661 */
2662static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2663#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2664 , void *accel_priv
2665#endif
2666#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2667 , select_queue_fallback_t fallback
2668#endif
2669)
2670{
2671 return hdd_wmm_select_queue(dev, skb);
2672}
2673
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002674static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675 .ndo_open = hdd_open,
2676 .ndo_stop = hdd_stop,
2677 .ndo_uninit = hdd_uninit,
2678 .ndo_start_xmit = hdd_hard_start_xmit,
2679 .ndo_tx_timeout = hdd_tx_timeout,
2680 .ndo_get_stats = hdd_get_stats,
2681 .ndo_do_ioctl = hdd_ioctl,
2682 .ndo_set_mac_address = hdd_set_mac_address,
2683 .ndo_select_queue = hdd_select_queue,
2684#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686#endif
2687};
2688
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002689/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002690static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002691 .ndo_open = hdd_mon_open,
2692 .ndo_stop = hdd_stop,
2693 .ndo_get_stats = hdd_get_stats,
2694};
2695
2696/**
2697 * hdd_set_station_ops() - update net_device ops for monitor mode
2698 * @pWlanDev: Handle to struct net_device to be updated.
2699 * Return: None
2700 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701void hdd_set_station_ops(struct net_device *pWlanDev)
2702{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002703 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2704 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2705 else
2706 pWlanDev->netdev_ops = &wlan_drv_ops;
2707}
2708
Komal Seelama89be8d2016-09-29 11:09:26 +05302709#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302710/**
2711 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2712 * @hdd_ctx: HDD context
2713 *
2714 * Return: None
2715 */
2716static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2717{
2718 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2719
2720 ctx->scan = qdf_runtime_lock_init("scan");
Komal Seelamaa75f262016-09-29 12:32:13 +05302721 ctx->roc = qdf_runtime_lock_init("roc");
Komal Seelam81cb1662016-09-29 12:39:08 +05302722 ctx->dfs = qdf_runtime_lock_init("dfs");
Komal Seelam8634b772016-09-29 12:12:24 +05302723}
2724
2725/**
2726 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2727 * @hdd_ctx: HDD Context
2728 *
2729 * Return: None
2730 */
2731static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2732{
2733 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2734
2735 qdf_runtime_lock_deinit(ctx->scan);
2736 ctx->scan = NULL;
Komal Seelamaa75f262016-09-29 12:32:13 +05302737 qdf_runtime_lock_deinit(ctx->roc);
2738 ctx->roc = NULL;
Komal Seelam81cb1662016-09-29 12:39:08 +05302739 qdf_runtime_lock_deinit(ctx->dfs);
2740 ctx->dfs = NULL;
Komal Seelam8634b772016-09-29 12:12:24 +05302741}
2742
Komal Seelama89be8d2016-09-29 11:09:26 +05302743static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2744{
2745 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2746
2747 ctx->connect = qdf_runtime_lock_init("connect");
2748}
2749
2750static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2751{
2752 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2753
2754 qdf_runtime_lock_deinit(ctx->connect);
2755 ctx->connect = NULL;
2756}
2757#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302758static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2759static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302760static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2761static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2762#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002763/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002764 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2765 * @hdd_ctx: global hdd context
2766 * @macAddr: mac address to assign to the interface
2767 * @name: User-visible name of the interface
2768 *
2769 * hdd adapter pointer would point to the netdev->priv space, this function
2770 * would retrive the pointer, and setup the hdd adapter configuration.
2771 *
2772 * Return: the pointer to hdd adapter, otherwise NULL
2773 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2775 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002776 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777 const char *name)
2778{
2779 struct net_device *pWlanDev = NULL;
2780 hdd_adapter_t *adapter = NULL;
2781 /*
2782 * cfg80211 initialization and registration....
2783 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002784 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2785#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2786 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002788 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2789 hdd_mon_mode_ether_setup : ether_setup),
2790 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791
2792 if (pWlanDev != NULL) {
2793
2794 /* Save the pointer to the net_device in the HDD adapter */
2795 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2796
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302797 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002798
2799 adapter->dev = pWlanDev;
2800 adapter->pHddCtx = hdd_ctx;
2801 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302802 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803
2804 init_completion(&adapter->session_open_comp_var);
2805 init_completion(&adapter->session_close_comp_var);
2806 init_completion(&adapter->disconnect_comp_var);
2807 init_completion(&adapter->linkup_event_var);
2808 init_completion(&adapter->cancel_rem_on_chan_var);
2809 init_completion(&adapter->rem_on_chan_ready_event);
2810 init_completion(&adapter->sta_authorized_event);
2811 init_completion(&adapter->offchannel_tx_event);
2812 init_completion(&adapter->tx_action_cnf_event);
2813#ifdef FEATURE_WLAN_TDLS
2814 init_completion(&adapter->tdls_add_station_comp);
2815 init_completion(&adapter->tdls_del_station_comp);
2816 init_completion(&adapter->tdls_mgmt_comp);
2817 init_completion(&adapter->tdls_link_establish_req_comp);
2818#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002819 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820 init_completion(&adapter->change_country_code);
2821
2822
2823 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05302824 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002825
2826 adapter->offloads_configured = false;
2827 adapter->isLinkUpSvcNeeded = false;
2828 adapter->higherDtimTransition = true;
2829 /* Init the net_device structure */
2830 strlcpy(pWlanDev->name, name, IFNAMSIZ);
2831
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302832 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302834 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002835 sizeof(tSirMacAddr));
2836 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837
2838 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
2839 pWlanDev->features |=
2840 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2841 pWlanDev->features |= NETIF_F_RXCSUM;
2842
Dhanashri Atre83d373d2015-07-28 16:45:59 -07002843 hdd_set_tso_flags(hdd_ctx, pWlanDev);
2844
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845 hdd_set_station_ops(adapter->dev);
2846
2847 pWlanDev->destructor = free_netdev;
2848 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08002849 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850 adapter->wdev.wiphy = hdd_ctx->wiphy;
2851 adapter->wdev.netdev = pWlanDev;
2852 /* set pWlanDev's parent to underlying device */
2853 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
2854 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05302855 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002856 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05302857 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858 }
2859
2860 return adapter;
2861}
2862
Jeff Johnson590e2012016-10-05 16:16:24 -07002863static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter,
2864 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002865{
2866 struct net_device *pWlanDev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08002868 if (rtnl_held) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869 if (strnchr(pWlanDev->name, strlen(pWlanDev->name), '%')) {
2870 if (dev_alloc_name(pWlanDev, pWlanDev->name) < 0) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002871 hdd_err("Failed:dev_alloc_name");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002873 }
2874 }
2875 if (register_netdevice(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002876 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302877 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 }
2879 } else {
2880 if (register_netdev(pWlanDev)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002881 hdd_err("Failed:register_netdev");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302882 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883 }
2884 }
2885 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
2886
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302887 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888}
2889
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002890QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891{
2892 hdd_adapter_t *adapter = pContext;
2893
2894 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002895 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302896 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 }
2898
2899 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002900 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302901 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902 }
2903
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002904 /*
2905 * For NAN Data interface, the close session results in the final
2906 * indication to the userspace
2907 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07002908 if (adapter->device_mode == QDF_NDI_MODE)
2909 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07002910
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
2912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913 /*
2914 * We can be blocked while waiting for scheduled work to be
2915 * flushed, and the adapter structure can potentially be freed, in
2916 * which case the magic will have been reset. So make sure the
2917 * magic is still good, and hence the adapter structure is still
2918 * valid, before signaling completion
2919 */
2920 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
2921 complete(&adapter->session_close_comp_var);
2922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302923 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002924}
2925
Krunal Soni8c37e322016-02-03 16:08:37 -08002926/**
2927 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
2928 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08002929 *
2930 * This routine will check the mode of adapter and if it is required then it
2931 * will initialize the TDLS operations
2932 *
2933 * Return: QDF_STATUS
2934 */
2935#ifdef FEATURE_WLAN_TDLS
Dustin Brownd28772b2017-03-17 14:16:07 -07002936static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08002937{
Dustin Brownd28772b2017-03-17 14:16:07 -07002938 if (adapter->device_mode == QDF_IBSS_MODE)
2939 return QDF_STATUS_SUCCESS;
2940
2941 if (wlan_hdd_tdls_init(adapter)) {
2942 hdd_err("wlan_hdd_tdls_init failed");
2943 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08002944 }
Dustin Brownd28772b2017-03-17 14:16:07 -07002945 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
2946
Krunal Soni8c37e322016-02-03 16:08:37 -08002947 return QDF_STATUS_SUCCESS;
2948}
2949#else
Dustin Brownd28772b2017-03-17 14:16:07 -07002950static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08002951{
2952 return QDF_STATUS_SUCCESS;
2953}
2954#endif
2955
Dustin Brownd28772b2017-03-17 14:16:07 -07002956int hdd_vdev_ready(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002957{
Dustin Brownd28772b2017-03-17 14:16:07 -07002958 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002959
Dustin Brownd28772b2017-03-17 14:16:07 -07002960 status = pmo_vdev_ready(adapter->hdd_vdev);
2961
2962 return qdf_status_to_os_return(status);
2963}
2964
2965int hdd_vdev_destroy(hdd_adapter_t *adapter)
2966{
2967 QDF_STATUS status;
2968 int errno;
2969 hdd_context_t *hdd_ctx;
2970 unsigned long rc;
2971
2972 hdd_info("destroying vdev %d", adapter->sessionId);
2973
2974 /* vdev created sanity check */
2975 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2976 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
2977 return -EINVAL;
2978 }
2979
Dustin Brown0d2eeae2017-03-24 15:21:32 -07002980 /* do vdev logical destroy via objmgr */
2981 errno = hdd_objmgr_destroy_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07002982 if (errno) {
2983 hdd_err("failed to destroy objmgr vdev: %d", errno);
2984 return errno;
2985 }
2986
2987 /* close sme session (destroy vdev in firmware via legacy API) */
2988 INIT_COMPLETION(adapter->session_close_comp_var);
2989 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2990 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
2991 hdd_sme_close_session_callback, adapter);
2992 if (QDF_IS_STATUS_ERROR(status)) {
2993 hdd_err("failed to close sme session: %d", status);
2994 return qdf_status_to_os_return(status);
2995 }
2996
2997 /* block on a completion variable until sme session is closed */
2998 rc = wait_for_completion_timeout(
2999 &adapter->session_close_comp_var,
3000 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3001 if (!rc) {
3002 hdd_err("timed out waiting for close sme session: %ld", rc);
3003 if (adapter->device_mode == QDF_NDI_MODE)
3004 hdd_ndp_session_end_handler(adapter);
3005 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3006 return -ETIMEDOUT;
3007 }
3008
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003009 /* now that sme session is closed, allow physical vdev destroy */
3010 errno = hdd_objmgr_release_vdev(adapter);
3011 if (errno) {
3012 hdd_err("failed to release objmgr vdev: %d", errno);
3013 return errno;
3014 }
3015
Dustin Brownd28772b2017-03-17 14:16:07 -07003016 hdd_info("vdev destroyed successfully");
3017
3018 return 0;
3019}
3020
3021int hdd_vdev_create(hdd_adapter_t *adapter)
3022{
3023 QDF_STATUS status;
3024 int errno;
3025 hdd_context_t *hdd_ctx;
3026 uint32_t type;
3027 uint32_t sub_type;
3028 unsigned long rc;
3029
3030 hdd_info("creating new vdev");
3031
3032 /* determine vdev (sub)type */
3033 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303034 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003035 hdd_err("failed to get vdev type: %d", status);
3036 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003038
3039 /* do vdev create via objmgr */
3040 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003041 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003042 if (errno) {
3043 hdd_err("failed to create objmgr vdev: %d", errno);
3044 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003046
3047 /* Open a SME session (prepare vdev in firmware via legacy API) */
3048 INIT_COMPLETION(adapter->session_open_comp_var);
3049 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3050 (uint8_t *)&adapter->macAddressCurrent,
3051 adapter->sessionId, type, sub_type);
3052 if (QDF_IS_STATUS_ERROR(status)) {
3053 hdd_err("failed to open sme session: %d", status);
3054 errno = qdf_status_to_os_return(status);
3055 goto objmgr_vdev_destroy;
3056 }
3057
3058 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059 rc = wait_for_completion_timeout(
3060 &adapter->session_open_comp_var,
3061 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3062 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003063 hdd_err("timed out waiting for open sme session: %ld", rc);
3064 errno = -ETIMEDOUT;
3065 goto objmgr_vdev_destroy;
3066 }
3067
3068 /* firmware ready for component communication, raise vdev_ready event */
3069 errno = hdd_vdev_ready(adapter);
3070 if (errno) {
3071 hdd_err("failed to dispatch vdev ready event: %d", errno);
3072 goto hdd_vdev_destroy;
3073 }
3074
3075 hdd_info("vdev %d created successfully", adapter->sessionId);
3076
3077 return 0;
3078
3079 /*
3080 * Due to legacy constraints, we need to destroy in the same order as
3081 * create. So, split error handling into 2 cases to accommodate.
3082 */
3083
3084objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003085 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003086
3087 return errno;
3088
3089hdd_vdev_destroy:
3090 QDF_BUG(!hdd_vdev_destroy(adapter));
3091
3092 return errno;
3093}
3094
3095QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
3096{
3097 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
3098 hdd_context_t *hdd_ctx;
3099 QDF_STATUS status;
3100 int ret_val;
3101
3102 ret_val = hdd_vdev_create(adapter);
3103 if (ret_val) {
3104 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303105 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 }
3107
Dustin Brownd28772b2017-03-17 14:16:07 -07003108 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3109 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3110 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003111 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003114 status = hdd_register_wext(adapter->dev);
3115 if (QDF_IS_STATUS_ERROR(status)) {
3116 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117 goto error_register_wext;
3118 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003119
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 /* Set the Connection State to Not Connected */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003121 hdd_debug("Set HDD connState to eConnectionState_NotConnected");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 pHddStaCtx->conn_info.connState = eConnectionState_NotConnected;
3123
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003124 /* set fast roaming capability in sme session */
3125 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3126 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 /* Set the default operation channel */
3128 pHddStaCtx->conn_info.operationChannel =
3129 hdd_ctx->config->OperatingChannel;
3130
3131 /* Make the default Auth Type as OPEN */
3132 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3133
3134 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303135 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003136 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 status, status);
3138 goto error_init_txrx;
3139 }
3140
3141 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3142
3143 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303144 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003145 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 status, status);
3147 goto error_wmm_init;
3148 }
3149
3150 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3151
3152 ret_val = wma_cli_set_command(adapter->sessionId,
3153 WMI_PDEV_PARAM_BURST_ENABLE,
3154 hdd_ctx->config->enableSifsBurst,
3155 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003156 if (ret_val)
3157 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158
Dustin Brownd28772b2017-03-17 14:16:07 -07003159 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003160 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05303163 status = hdd_lro_enable(hdd_ctx, adapter);
3164 if (status != QDF_STATUS_SUCCESS)
3165 goto error_lro_enable;
3166
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303167 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05303169error_lro_enable:
3170 wlan_hdd_tdls_exit(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171error_tdls_init:
3172 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3173 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174error_wmm_init:
3175 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3176 hdd_deinit_tx_rx(adapter);
3177error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003178 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003180 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 return status;
3183}
3184
3185void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
3186{
3187 hdd_cfg80211_state_t *cfgState;
3188
3189 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3190
3191 if (NULL != cfgState->buf) {
3192 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 rc = wait_for_completion_timeout(
3195 &adapter->tx_action_cnf_event,
3196 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3197 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003198 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303199 /*
3200 * Inform tx status as FAILURE to upper layer and free
3201 * cfgState->buf
3202 */
3203 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 }
3205 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206}
3207
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303208/**
3209 * hdd_station_adapter_deinit() - De-initialize the station adapter
3210 * @hdd_ctx: global hdd context
3211 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003212 * @rtnl_held: Used to indicate whether or not the caller is holding
3213 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303214 *
3215 * This function De-initializes the STA/P2P/OCB adapter.
3216 *
3217 * Return: None.
3218 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003219static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
3220 hdd_adapter_t *adapter,
3221 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303222{
3223 ENTER_DEV(adapter->dev);
3224
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303225 if (adapter->dev) {
3226 if (rtnl_held)
3227 adapter->dev->wireless_handlers = NULL;
3228 else {
3229 rtnl_lock();
3230 adapter->dev->wireless_handlers = NULL;
3231 rtnl_unlock();
3232 }
3233 }
3234
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303235 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3236 hdd_deinit_tx_rx(adapter);
3237 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3238 }
3239
3240 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3241 hdd_wmm_adapter_close(adapter);
3242 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3243 }
3244
3245 hdd_cleanup_actionframe(hdd_ctx, adapter);
3246 wlan_hdd_tdls_exit(adapter);
3247
3248 EXIT();
3249}
3250
3251/**
3252 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3253 * @hdd_ctx: global hdd context
3254 * @adapter: HDD adapter
3255 * @rtnl_held: the rtnl lock hold flag
3256 * This function De-initializes the AP/P2PGo adapter.
3257 *
3258 * Return: None.
3259 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003260static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
3261 hdd_adapter_t *adapter,
3262 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303263{
3264 ENTER_DEV(adapter->dev);
3265
3266 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3267 hdd_wmm_adapter_close(adapter);
3268 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3269 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003270 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303271
3272 hdd_cleanup_actionframe(hdd_ctx, adapter);
3273
3274 hdd_unregister_hostapd(adapter, rtnl_held);
3275
3276 EXIT();
3277}
3278
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003279void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3280 bool rtnl_held)
3281{
3282 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303283
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003285 case QDF_STA_MODE:
3286 case QDF_P2P_CLIENT_MODE:
3287 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303289 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003290 break;
3291 }
3292
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003293 case QDF_SAP_MODE:
3294 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295 {
3296
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303297 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298 break;
3299 }
3300
3301 default:
3302 break;
3303 }
3304
3305 EXIT();
3306}
3307
Jeff Johnson590e2012016-10-05 16:16:24 -07003308static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3309 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310{
3311 struct net_device *pWlanDev = NULL;
3312
3313 if (adapter)
3314 pWlanDev = adapter->dev;
3315 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003316 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003317 return;
3318 }
3319
Rajeev Kumardca5f812016-02-04 17:28:06 -08003320 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303321
3322 if (adapter->scan_info.default_scan_ies) {
3323 qdf_mem_free(adapter->scan_info.default_scan_ies);
3324 adapter->scan_info.default_scan_ies = NULL;
3325 }
3326
Komal Seelama89be8d2016-09-29 11:09:26 +05303327 hdd_adapter_runtime_suspend_denit(adapter);
3328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329 /*
3330 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3331 * the driver is almost closed and cannot handle either control
3332 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003333 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3334 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335 * is not right. Setting this flag helps hdd_stop() to recognize that
3336 * the interface is closed and restricts any operations on that
3337 */
3338 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3339
3340 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003341 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003343 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 /*
3346 * Note that the adapter is no longer valid at this point
3347 * since the memory has been reclaimed
3348 */
3349 }
3350}
3351
Jeff Johnson590e2012016-10-05 16:16:24 -07003352static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3353 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354{
3355 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3356 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303357 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003358
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303360 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 adapter = adapterNode->pAdapter;
3362 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303363 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303365 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 }
3367 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3368 adapterNode = pNext;
3369 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303370 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003372
Arun Khandavalli2358d522016-05-16 18:05:37 +05303373#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3374/**
3375 * hdd_set_fw_log_params() - Set log parameters to FW
3376 * @hdd_ctx: HDD Context
3377 * @adapter: HDD Adapter
3378 *
3379 * This function set the FW Debug log level based on the INI.
3380 *
3381 * Return: None
3382 */
3383static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3384 hdd_adapter_t *adapter)
3385{
3386 uint8_t count = 0, numentries = 0,
3387 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3388 uint32_t value = 0;
3389 int ret;
3390
Arun Khandavallifae92942016-08-01 13:31:08 +05303391 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3392 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003393 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303394 return;
3395 }
3396
Arun Khandavallifae92942016-08-01 13:31:08 +05303397 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303398 hdd_ctx->fw_log_settings.dl_type =
3399 hdd_ctx->config->enableFwLogType;
3400 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303401 WMI_DBGLOG_TYPE,
3402 hdd_ctx->config->enableFwLogType,
3403 DBG_CMD);
3404 if (ret != 0)
3405 hdd_err("Failed to enable FW log type ret %d",
3406 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303407
3408 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303409 hdd_ctx->config->enableFwLogLevel;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303410 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303411 WMI_DBGLOG_LOG_LEVEL,
3412 hdd_ctx->config->enableFwLogLevel,
3413 DBG_CMD);
3414 if (ret != 0)
3415 hdd_err("Failed to enable FW log level ret %d",
3416 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303417
3418 hdd_string_to_u8_array(
3419 hdd_ctx->config->enableFwModuleLogLevel,
3420 moduleloglevel,
3421 &numentries,
3422 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3423
3424 while (count < numentries) {
3425 /*
3426 * FW module log level input string looks like
3427 * below:
3428 * gFwDebugModuleLoglevel=<FW Module ID>,
3429 * <Log Level>,...
3430 * For example:
3431 * gFwDebugModuleLoglevel=
3432 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3433 * Above input string means :
3434 * For FW module ID 1 enable log level 0
3435 * For FW module ID 2 enable log level 1
3436 * For FW module ID 3 enable log level 2
3437 * For FW module ID 4 enable log level 3
3438 * For FW module ID 5 enable log level 4
3439 * For FW module ID 6 enable log level 5
3440 * For FW module ID 7 enable log level 6
3441 */
3442
Nishank Aggarwale239d962017-03-03 12:26:02 +05303443 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3444 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3445 hdd_err("Module id %d and dbglog level %d input length is more than max",
3446 moduleloglevel[count],
3447 moduleloglevel[count + 1]);
3448 return;
3449 }
3450
3451 value = moduleloglevel[count] << 16;
3452 value |= moduleloglevel[count + 1];
Arun Khandavalli2358d522016-05-16 18:05:37 +05303453 ret = wma_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303454 WMI_DBGLOG_MOD_LOG_LEVEL,
3455 value, DBG_CMD);
3456 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303457 hdd_err("Failed to enable FW module log level %d ret %d",
3458 value, ret);
3459
3460 count += 2;
3461 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303462
Arun Khandavalli2358d522016-05-16 18:05:37 +05303463}
3464#else
3465static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3466 hdd_adapter_t *adapter)
3467{
3468}
3469
3470#endif
3471
3472/**
3473 * hdd_set_fw_params() - Set parameters to firmware
3474 * @adapter: HDD adapter
3475 *
3476 * This function Sets various parameters to fw once the
3477 * adapter is started.
3478 *
3479 * Return: 0 on success or errno on failure
3480 */
3481int hdd_set_fw_params(hdd_adapter_t *adapter)
3482{
3483 int ret;
3484 hdd_context_t *hdd_ctx;
3485
3486 ENTER_DEV(adapter->dev);
3487
3488 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3489 if (!hdd_ctx)
3490 return -EINVAL;
3491
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003492 if ((cds_get_conparam() != QDF_GLOBAL_FTM_MODE) &&
Arun Khandavallifae92942016-08-01 13:31:08 +05303493 (!hdd_ctx->config->enable2x2)) {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303494#define HDD_DTIM_1CHAIN_RX_ID 0x5
3495#define HDD_SMPS_PARAM_VALUE_S 29
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003496 /*
3497 * Disable DTIM 1 chain Rx when in 1x1,
3498 * we are passing two value
3499 * as param_id << 29 | param_value.
3500 * Below param_value = 0(disable)
3501 */
3502 ret = wma_cli_set_command(adapter->sessionId,
3503 WMI_STA_SMPS_PARAM_CMDID,
3504 HDD_DTIM_1CHAIN_RX_ID <<
3505 HDD_SMPS_PARAM_VALUE_S,
3506 VDEV_CMD);
3507 if (ret) {
3508 hdd_err("DTIM 1 chain set failed %d", ret);
3509 goto error;
3510 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303511
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003512 ret = wma_cli_set_command(adapter->sessionId,
3513 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3514 hdd_ctx->config->txchainmask1x1,
3515 PDEV_CMD);
3516 if (ret) {
3517 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3518 ret);
3519 goto error;
3520 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303521
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003522 ret = wma_cli_set_command(adapter->sessionId,
3523 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3524 hdd_ctx->config->rxchainmask1x1,
3525 PDEV_CMD);
3526 if (ret) {
3527 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3528 ret);
3529 goto error;
3530 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303531#undef HDD_DTIM_1CHAIN_RX_ID
3532#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003533 } else {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003534 hdd_debug("FTM Mode or 2x2 mode - Do not set 1x1 params");
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003535 }
3536
Arun Khandavallifae92942016-08-01 13:31:08 +05303537 if (QDF_GLOBAL_FTM_MODE != cds_get_conparam()) {
3538 ret = wma_cli_set_command(adapter->sessionId,
3539 WMI_PDEV_PARAM_HYST_EN,
3540 hdd_ctx->config->enableMemDeepSleep,
3541 PDEV_CMD);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303542
Arun Khandavallifae92942016-08-01 13:31:08 +05303543 if (ret) {
3544 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d",
3545 ret);
3546 goto error;
3547 }
Rajeev Kumar Sirasanagandla2dab3ec2016-10-18 16:10:15 +05303548
3549 ret = wma_cli_set_command(adapter->sessionId,
3550 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3551 hdd_ctx->config->rts_profile,
3552 VDEV_CMD);
3553 if (ret) {
3554 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3555 goto error;
3556 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303557 }
3558
3559 hdd_set_fw_log_params(hdd_ctx, adapter);
3560
3561 EXIT();
3562 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303563
Arun Khandavalli2358d522016-05-16 18:05:37 +05303564error:
3565 return -EINVAL;
3566}
3567
Ryan Hsu07495ea2016-01-21 15:25:39 -08003568/**
3569 * hdd_open_adapter() - open and setup the hdd adatper
3570 * @hdd_ctx: global hdd context
3571 * @session_type: type of the interface to be created
3572 * @iface_name: User-visible name of the interface
3573 * @macAddr: MAC address to assign to the interface
3574 * @name_assign_type: the name of assign type of the netdev
3575 * @rtnl_held: the rtnl lock hold flag
3576 *
3577 * This function open and setup the hdd adpater according to the device
3578 * type request, assign the name, the mac address assigned, and then prepared
3579 * the hdd related parameters, queue, lock and ready to start.
3580 *
3581 * Return: the pointer of hdd adapter, otherwise NULL.
3582 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3584 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003585 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003586 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587{
3588 hdd_adapter_t *adapter = NULL;
3589 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303590 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08003593 hdd_info("%s interface created. iftype: %d", iface_name, session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594
3595 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3596 /*
3597 * Max limit reached on the number of vdevs configured by the
3598 * host. Return error
3599 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303600 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3601 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 return NULL;
3603 }
3604
3605 if (macAddr == NULL) {
3606 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303607 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608 return NULL;
3609 }
3610 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303611 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303612 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3613 " already exists",
3614 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615 return NULL;
3616 }
3617
3618 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003619 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 /* Reset locally administered bit if the device mode is STA */
3621 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3622 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003623 case QDF_P2P_CLIENT_MODE:
3624 case QDF_P2P_DEVICE_MODE:
3625 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003626 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303627 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003628 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3629 name_assign_type,
3630 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631
3632 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303633 hdd_err("failed to allocate adapter for session %d",
3634 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 return NULL;
3636 }
3637
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003638 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003640 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303642 else if (QDF_MONITOR_MODE == session_type)
3643 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 else
3645 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3646
3647 adapter->device_mode = session_type;
3648
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303649 if (QDF_NDI_MODE == session_type) {
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003650 status = hdd_init_nan_data_mode(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303651 if (QDF_STATUS_SUCCESS != status)
3652 goto err_free_netdev;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303653 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 /*
3656 * Workqueue which gets scheduled in IPv4 notification
3657 * callback
3658 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3660 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661
3662#ifdef WLAN_NS_OFFLOAD
3663 /*
3664 * Workqueue which gets scheduled in IPv6
3665 * notification callback.
3666 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3668 hdd_ipv6_notifier_work_queue);
3669#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303671 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303673 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 }
3675
3676 /* Stop the Interface TX queue. */
Arun Khandavallifae92942016-08-01 13:31:08 +05303677 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303679 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3680 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 break;
Arun Khandavallifae92942016-08-01 13:31:08 +05303682
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003684 case QDF_P2P_GO_MODE:
3685 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003686 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3687 name_assign_type,
3688 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003690 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303691 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 return NULL;
3693 }
3694
3695 adapter->wdev.iftype =
3696 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003697 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698 NL80211_IFTYPE_P2P_GO;
3699 adapter->device_mode = session_type;
3700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 status = hdd_register_hostapd(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303702 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3704 goto err_free_netdev;
3705 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303706 hdd_info("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303708 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3709 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303711 case QDF_FTM_MODE:
3712 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3713 name_assign_type,
3714 "wlan0");
3715 if (NULL == adapter) {
3716 hdd_err("Failed to allocate adapter for FTM mode");
3717 return NULL;
3718 }
3719 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3720 adapter->device_mode = session_type;
3721 status = hdd_register_interface(adapter, rtnl_held);
3722 if (QDF_STATUS_SUCCESS != status) {
3723 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3724 goto err_free_netdev;
3725 }
3726 /* Stop the Interface TX queue. */
3727 hdd_info("Disabling queues");
3728 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303729 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3730 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303731 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003732 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003733 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303734 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735 return NULL;
3736 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737
3738 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3739 mutex_init(&cfgState->remain_on_chan_ctx_lock);
3740
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303741 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 /* Add it to the hdd's session list. */
3743 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303744 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303746 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747 } else {
3748 pHddAdapterNode->pAdapter = adapter;
3749 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
3750 }
3751 }
3752
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303753 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754 if (NULL != adapter) {
3755 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
3756 adapter = NULL;
3757 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003758 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303759 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 return NULL;
3762 }
3763
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303764 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08003765 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
3766 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767
3768 /* Initialize the WoWL service */
3769 if (!hdd_init_wowl(adapter)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003770 hdd_err("hdd_init_wowl failed");
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303771 goto err_close_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772 }
3773
3774 /* Adapter successfully added. Increment the vdev count */
3775 hdd_ctx->current_intf_count++;
3776
Jeff Johnson5880d792016-08-15 13:32:30 -07003777 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 hdd_ctx->current_intf_count);
3779
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08003780 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781 }
3782
Rajeev Kumardca5f812016-02-04 17:28:06 -08003783 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
3784 hdd_err("Interface %s wow debug_fs init failed", iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785
3786 return adapter;
3787
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303788err_close_adapter:
3789 hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003790err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303792 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003793
3794 return NULL;
3795}
3796
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303797QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003798 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799{
3800 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303801 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802
3803 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303804 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003805 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 status);
3807 return status;
3808 }
3809
3810 while (pCurrent->pAdapter != adapter) {
3811 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303812 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 break;
3814
3815 pCurrent = pNext;
3816 }
3817 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303818 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003819 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07003820 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05303821 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07003822
3823 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08003824 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
3825 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303828 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 adapterNode = NULL;
3830
Dustin Brown5ec6b552017-03-31 12:11:40 -07003831 /* conditionally restart the bw timer */
3832 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
3833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834 /* Adapter removed. Decrement vdev count */
3835 if (hdd_ctx->current_intf_count != 0)
3836 hdd_ctx->current_intf_count--;
3837
3838 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303839 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303841
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303842 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843}
3844
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003845/**
3846 * hdd_close_all_adapters - Close all open adapters
3847 * @hdd_ctx: Hdd context
3848 * rtnl_held: True if RTNL lock held
3849 *
3850 * Close all open adapters.
3851 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303852 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003853 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303854QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855{
3856 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303857 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858
3859 ENTER();
3860
3861 do {
3862 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303863 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303864 wlan_hdd_release_intf_addr(hdd_ctx,
3865 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003866 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003867 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303868 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303869 /* Adapter removed. Decrement vdev count */
3870 if (hdd_ctx->current_intf_count != 0)
3871 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303873 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874
3875 EXIT();
3876
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303877 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878}
3879
3880void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
3881{
Anurag Chouhan6d760662016-02-20 16:05:43 +05303882 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003884
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003886 case QDF_STA_MODE:
3887 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888 {
3889 hdd_station_ctx_t *pHddStaCtx =
3890 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003891 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 break;
3893 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003894 case QDF_SAP_MODE:
3895 case QDF_P2P_GO_MODE:
3896 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08003898 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 break;
3900 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003901 case QDF_FTM_MODE:
3902 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 default:
3904 /*
3905 * wlan_hdd_reset_prob_rspies should not have been called
3906 * for these kind of devices
3907 */
Jeff Johnson5880d792016-08-15 13:32:30 -07003908 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 pHostapdAdapter->device_mode);
3910 return;
3911 }
3912
Anurag Chouhanc5548422016-02-24 18:33:27 +05303913 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 updateIE.smeSessionId = pHostapdAdapter->sessionId;
3915 updateIE.ieBufferlength = 0;
3916 updateIE.pAdditionIEBuffer = NULL;
3917 updateIE.append = true;
3918 updateIE.notify = false;
3919 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
3920 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303921 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003922 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 }
3924}
3925
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303926QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927 const bool bCloseSession)
3928{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303929 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
3931 union iwreq_data wrqu;
3932 tSirUpdateIE updateIE;
3933 unsigned long rc;
Sachin Ahuja988fd102016-09-15 17:16:25 +05303934 hdd_scaninfo_t *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935
3936 ENTER();
3937
Sachin Ahuja988fd102016-09-15 17:16:25 +05303938 scan_info = &adapter->scan_info;
Jeff Johnson5880d792016-08-15 13:32:30 -07003939 hdd_notice("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303940 wlan_hdd_netif_queue_control(adapter,
3941 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3942 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003944 case QDF_STA_MODE:
3945 case QDF_P2P_CLIENT_MODE:
3946 case QDF_IBSS_MODE:
3947 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003948 case QDF_NDI_MODE:
3949 if ((QDF_NDI_MODE == adapter->device_mode) ||
3950 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
3952 hdd_is_connecting(
3953 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003954 INIT_COMPLETION(adapter->disconnect_comp_var);
3955 /*
3956 * For NDI do not use pWextState from sta_ctx, if needed
3957 * extract from ndi_ctx.
3958 */
3959 if (QDF_NDI_MODE == adapter->device_mode)
3960 qdf_ret_status = sme_roam_disconnect(
3961 hdd_ctx->hHal,
3962 adapter->sessionId,
3963 eCSR_DISCONNECT_REASON_NDI_DELETE);
3964 else if (pWextState->roamProfile.BSSType ==
3965 eCSR_BSS_TYPE_START_IBSS)
3966 qdf_ret_status = sme_roam_disconnect(
3967 hdd_ctx->hHal,
3968 adapter->sessionId,
3969 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003971 qdf_ret_status = sme_roam_disconnect(
3972 hdd_ctx->hHal,
3973 adapter->sessionId,
3974 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003975 /* success implies disconnect command got
3976 * queued up successfully
3977 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303978 if (qdf_ret_status == QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 rc = wait_for_completion_timeout(
3980 &adapter->disconnect_comp_var,
3981 msecs_to_jiffies
3982 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003983 if (!rc)
3984 hdd_warn("wait on disconnect_comp_var failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003986 hdd_err("failed to post disconnect event to SME");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 }
3988 memset(&wrqu, '\0', sizeof(wrqu));
3989 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3990 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3991 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
3992 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05303993 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003994 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05303995 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003996
Himanshu Agarwal3d95b902016-08-24 16:27:03 +05303997 hdd_lro_disable(hdd_ctx, adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05303998 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999
4000#ifdef WLAN_OPEN_SOURCE
4001 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4002#endif
4003
4004 hdd_deregister_tx_flow_control(adapter);
4005
4006#ifdef WLAN_NS_OFFLOAD
4007#ifdef WLAN_OPEN_SOURCE
4008 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4009#endif
4010#endif
4011
4012 /*
4013 * It is possible that the caller of this function does not
4014 * wish to close the session
4015 */
Krunal Soni985b8132017-02-10 18:49:08 -08004016 if (true == bCloseSession) {
4017 if (0 != wlan_hdd_try_disconnect(adapter)) {
4018 hdd_err("Error: Can't disconnect adapter");
4019 return QDF_STATUS_E_FAILURE;
4020 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004021 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004022 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 break;
4024
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004025 case QDF_SAP_MODE:
4026 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004028 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4030
4031 hdd_deregister_tx_flow_control(adapter);
4032
4033 mutex_lock(&hdd_ctx->sap_lock);
4034 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304035 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304036 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
4038 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 status = wlansap_stop_bss(
4040 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304042 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 hdd_hostapd_state_t *hostapd_state =
4044 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304045 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304046 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304047 qdf_status =
4048 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004049 qdf_stop_bss_event,
4050 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051
Anurag Chouhance0dc992016-02-16 18:18:03 +05304052 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004053 hdd_err("failure waiting for wlansap_stop_bss %d",
4054 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055 }
4056 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004057 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 }
4059 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004060 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4061 adapter->device_mode,
4062 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063
Anurag Chouhanc5548422016-02-24 18:33:27 +05304064 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004065 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 updateIE.smeSessionId = adapter->sessionId;
4067 updateIE.ieBufferlength = 0;
4068 updateIE.pAdditionIEBuffer = NULL;
4069 updateIE.append = false;
4070 updateIE.notify = false;
4071 /* Probe bcn reset */
4072 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4073 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304074 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004075 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 }
4077 /* Assoc resp reset */
4078 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4079 &updateIE,
4080 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304081 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004082 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 }
4084 /* Reset WNI_CFG_PROBE_RSP Flags */
4085 wlan_hdd_reset_prob_rspies(adapter);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304086 qdf_mem_free(adapter->sessionCtx.ap.beacon);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 adapter->sessionCtx.ap.beacon = NULL;
4088 }
Peng Xu66162de2016-02-11 17:01:20 -08004089 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004090 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004091 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004093 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004094 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004095 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004096 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 break;
4098 default:
4099 break;
4100 }
4101
4102 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304103 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104}
4105
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304106/**
4107 * hdd_deinit_all_adapters - deinit all adapters
4108 * @hdd_ctx: HDD context
4109 * @rtnl_held: True if RTNL lock held
4110 *
4111 */
4112void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
4113{
4114 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4115 QDF_STATUS status;
4116 hdd_adapter_t *adapter;
4117
4118 ENTER();
4119
4120 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4121
4122 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4123 adapter = adapter_node->pAdapter;
4124 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4125 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4126 adapter_node = next;
4127 }
4128
4129 EXIT();
4130}
4131
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304132QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133{
4134 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304135 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004136 hdd_adapter_t *adapter;
4137
4138 ENTER();
4139
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304140 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4143
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304144 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 adapter = adapterNode->pAdapter;
4146 hdd_stop_adapter(hdd_ctx, adapter, true);
4147 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4148 adapterNode = pNext;
4149 }
4150
4151 EXIT();
4152
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304153 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154}
4155
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304156QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157{
4158 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304159 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 hdd_adapter_t *adapter;
4161
4162 ENTER();
4163
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304164 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4167
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304168 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 adapter = adapterNode->pAdapter;
Jeff Johnson5880d792016-08-15 13:32:30 -07004170 hdd_notice("Disabling queues");
Arun Khandavallicc544b32017-01-30 19:52:16 +05304171 if (hdd_ctx->config->sap_internal_restart &&
4172 adapter->device_mode == QDF_SAP_MODE) {
4173 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304174 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304175 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004176 if (test_bit(SOFTAP_BSS_STARTED,
4177 &adapter->event_flags)) {
4178 hdd_sap_indicate_disconnect_for_sta(adapter);
4179 hdd_cleanup_actionframe(hdd_ctx, adapter);
4180 hdd_sap_destroy_events(adapter);
4181 }
4182 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4183 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304184 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304185 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004187 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188
4189 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4190
4191 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004192 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4193 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4195 hdd_wmm_adapter_close(adapter);
4196 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4197 }
4198
Wu Gao36717432016-11-21 15:09:48 +08004199 /*
4200 * If adapter is SAP, set session ID to invalid since SAP
4201 * session will be cleanup during SSR.
4202 */
4203 if (adapter->device_mode == QDF_SAP_MODE)
4204 wlansap_set_invalid_session(
4205 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4208 adapterNode = pNext;
4209 }
4210
4211 EXIT();
4212
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304213 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214}
4215
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304216bool hdd_check_for_opened_interfaces(hdd_context_t *hdd_ctx)
4217{
4218 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4219 QDF_STATUS status;
4220 bool close_modules = true;
4221
4222 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4223 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4224 if (test_bit(DEVICE_IFACE_OPENED,
4225 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004226 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304227 close_modules = false;
4228 break;
4229 }
4230 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4231 adapter_node = next;
4232 }
4233
4234 return close_modules;
4235}
4236
Arun Khandavallifae92942016-08-01 13:31:08 +05304237/**
4238 * hdd_is_interface_up()- Checkfor interface up before ssr
4239 * @hdd_ctx: HDD context
4240 *
4241 * check if there are any wlan interfaces before SSR accordingly start
4242 * the interface.
4243 *
4244 * Return: 0 if interface was opened else false
4245 */
4246static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4247{
4248 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4249 return true;
4250 else
4251 return false;
4252}
4253
Anurag Chouhanc4092922016-09-08 15:56:11 +05304254#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
Abhishek Singhb5e38ef2017-01-02 12:09:34 +05304255 && !defined(WITH_BACKPORTS)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304256struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4257 struct ieee80211_channel *channel,
4258 const u8 *bssid, const u8 *ssid,
4259 size_t ssid_len)
4260{
4261 return cfg80211_get_bss(wiphy, channel, bssid,
4262 ssid, ssid_len,
4263 WLAN_CAPABILITY_ESS,
4264 WLAN_CAPABILITY_ESS);
4265}
4266#else
4267struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4268 struct ieee80211_channel *channel,
4269 const u8 *bssid, const u8 *ssid,
4270 size_t ssid_len)
4271{
4272 return cfg80211_get_bss(wiphy, channel, bssid,
4273 ssid, ssid_len,
4274 IEEE80211_BSS_TYPE_ESS,
4275 IEEE80211_PRIVACY_ANY);
4276}
4277#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304278
Abhishek Singha84d3952016-09-13 13:45:05 +05304279#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304280#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4281 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4282/**
4283 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4284 * @timeout_reason: reason for connect timeout
4285 *
4286 * This function is used to convert host timeout
4287 * reason enum to kernel specific enum.
4288 *
4289 * Return: nl timeout enum
4290 */
4291static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4292 tSirResultCodes timeout_reason)
4293{
4294 switch (timeout_reason) {
4295 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4296 return NL80211_TIMEOUT_SCAN;
4297 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4298 return NL80211_TIMEOUT_AUTH;
4299 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4300 return NL80211_TIMEOUT_ASSOC;
4301 default:
4302 return NL80211_TIMEOUT_UNSPECIFIED;
4303 }
4304}
4305
4306/**
4307 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4308 * @dev: network device
4309 * @bssid: bssid to which we want to associate
4310 * @timeout_reason: reason for connect timeout
4311 *
4312 * This API is used to send connection timeout reason to supplicant
4313 *
4314 * Return: void
4315 */
4316static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4317 const u8 *bssid,
4318 tSirResultCodes timeout_reason)
4319{
4320 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004321
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304322 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4323
4324 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4325 nl_timeout_reason);
4326}
4327
4328/**
4329 * __hdd_connect_bss() - API to send connection status to supplicant
4330 * @dev: network device
4331 * @bssid: bssid to which we want to associate
4332 * @req_ie: Request Information Element
4333 * @req_ie_len: len of the req IE
4334 * @resp_ie: Response IE
4335 * @resp_ie_len: len of ht response IE
4336 * @status: status
4337 * @gfp: Kernel Flag
4338 * @timeout_reason: reason for connect timeout
4339 *
4340 * Return: void
4341 */
4342static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4343 struct cfg80211_bss *bss, const u8 *req_ie,
4344 size_t req_ie_len, const u8 *resp_ie,
4345 size_t resp_ie_len, int status, gfp_t gfp,
4346 tSirResultCodes timeout_reason)
4347{
4348 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004349
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304350 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4351
4352 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4353 resp_ie, resp_ie_len, status, gfp,
4354 nl_timeout_reason);
4355}
4356#else
4357#if defined CFG80211_CONNECT_TIMEOUT
4358static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4359 const u8 *bssid,
4360 tSirResultCodes timeout_reason)
4361{
4362 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4363}
4364#endif
4365
4366static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4367 struct cfg80211_bss *bss, const u8 *req_ie,
4368 size_t req_ie_len, const u8 *resp_ie,
4369 size_t resp_ie_len, int status, gfp_t gfp,
4370 tSirResultCodes timeout_reason)
4371{
4372 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4373 resp_ie, resp_ie_len, status, gfp);
4374}
4375#endif
4376
Abhishek Singha84d3952016-09-13 13:45:05 +05304377/**
4378 * hdd_connect_bss() - API to send connection status to supplicant
4379 * @dev: network device
4380 * @bssid: bssid to which we want to associate
4381 * @req_ie: Request Information Element
4382 * @req_ie_len: len of the req IE
4383 * @resp_ie: Response IE
4384 * @resp_ie_len: len of ht response IE
4385 * @status: status
4386 * @gfp: Kernel Flag
4387 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304388 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304389 *
4390 * The API is a wrapper to send connection status to supplicant
4391 *
4392 * Return: Void
4393 */
4394#if defined CFG80211_CONNECT_TIMEOUT
4395static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4396 struct cfg80211_bss *bss, const u8 *req_ie,
4397 size_t req_ie_len, const u8 *resp_ie,
4398 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304399 bool connect_timeout,
4400 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304401{
4402 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304403 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304404 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304405 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4406 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304407}
4408#else
4409static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4410 struct cfg80211_bss *bss, const u8 *req_ie,
4411 size_t req_ie_len, const u8 *resp_ie,
4412 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304413 bool connect_timeout,
4414 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304415{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304416 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4417 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304418}
4419#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304420
4421/**
4422 * hdd_connect_result() - API to send connection status to supplicant
4423 * @dev: network device
4424 * @bssid: bssid to which we want to associate
4425 * @roam_info: information about connected bss
4426 * @req_ie: Request Information Element
4427 * @req_ie_len: len of the req IE
4428 * @resp_ie: Response IE
4429 * @resp_ie_len: len of ht response IE
4430 * @status: status
4431 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304432 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304433 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304434 *
4435 * The API is a wrapper to send connection status to supplicant
4436 * and allow runtime suspend
4437 *
4438 * Return: Void
4439 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304440void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4441 tCsrRoamInfo *roam_info, const u8 *req_ie,
4442 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304443 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304444 bool connect_timeout,
4445 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304446{
4447 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4448 struct cfg80211_bss *bss = NULL;
4449
4450 if (WLAN_STATUS_SUCCESS == status) {
4451 struct ieee80211_channel *chan;
4452 int freq;
4453 int chan_no = roam_info->pBssDesc->channelId;
4454
4455 if (chan_no <= 14)
4456 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004457 NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304458 else
4459 freq = ieee80211_channel_to_frequency(chan_no,
Dustin Browna30892e2016-10-12 17:28:36 -07004460 NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304461
4462 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4463 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4464 roam_info->u.pConnectedProfile->SSID.ssId,
4465 roam_info->u.pConnectedProfile->SSID.length);
4466 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304467
Abhishek Singha84d3952016-09-13 13:45:05 +05304468 hdd_connect_bss(dev, bssid, bss, req_ie,
4469 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304470 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304471
4472 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304473}
4474#else
4475void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4476 tCsrRoamInfo *roam_info, const u8 *req_ie,
4477 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304478 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304479 bool connect_timeout,
4480 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304481{
Komal Seelama89be8d2016-09-29 11:09:26 +05304482 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4483
Anurag Chouhanc4092922016-09-08 15:56:11 +05304484 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4485 resp_ie, resp_ie_len, status, gfp);
Komal Seelama89be8d2016-09-29 11:09:26 +05304486 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304487}
4488#endif
4489
4490
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304491QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004492{
4493 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304494 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 hdd_adapter_t *adapter;
4496#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304497 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498#endif
4499 eConnectionState connState;
4500
4501 ENTER();
4502
4503 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304504 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004505 adapter = adapterNode->pAdapter;
4506
Arun Khandavallifae92942016-08-01 13:31:08 +05304507 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304508 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004510 hdd_wmm_init(adapter);
4511
4512 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004513 case QDF_STA_MODE:
4514 case QDF_P2P_CLIENT_MODE:
4515 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516
4517 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4518 ->conn_info.connState;
4519
4520 hdd_init_station_mode(adapter);
4521 /* Open the gates for HDD to receive Wext commands */
4522 adapter->isLinkUpSvcNeeded = false;
4523 adapter->scan_info.mScanPending = false;
4524
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004525 /* Indicate disconnect event to supplicant
4526 * if associated previously
4527 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004529 eConnectionState_IbssConnected == connState ||
4530 eConnectionState_NotConnected == connState ||
4531 eConnectionState_IbssDisconnected == connState ||
4532 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 memset(&wrqu, '\0', sizeof(wrqu));
4536 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4537 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4538 wireless_send_event(adapter->dev, SIOCGIWAP,
4539 &wrqu, NULL);
4540 adapter->sessionCtx.station.
4541 hdd_ReassocScenario = false;
4542
4543 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304544 wlan_hdd_cfg80211_indicate_disconnect(
4545 adapter->dev, false,
4546 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 } else if (eConnectionState_Connecting == connState) {
4548 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004549 * Indicate connect failure to supplicant if we
4550 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304552 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304553 NULL, 0, NULL, 0,
4554 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004555 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556 }
4557
4558 hdd_register_tx_flow_control(adapter,
4559 hdd_tx_resume_timer_expired_handler,
4560 hdd_tx_resume_cb);
4561
4562 break;
4563
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004564 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004565 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05304566 hdd_init_ap_mode(adapter, true);
4567
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 break;
4569
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004570 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004572 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4574#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004575 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004576 /* event supplicant to restart */
4577 cfg80211_del_sta(adapter->dev,
4578 (const u8 *)&bcastMac.bytes[0],
4579 GFP_KERNEL);
4580#endif
4581 break;
4582
4583 default:
4584 break;
4585 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304586get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004587 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4588 adapterNode = pNext;
4589 }
4590
4591 EXIT();
4592
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304593 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004594}
4595
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304596QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597 hdd_adapter_list_node_t **padapterNode)
4598{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304599 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004600
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004601 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304602 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4603 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004604 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 return status;
4606}
4607
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304608QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004609 hdd_adapter_list_node_t *adapterNode,
4610 hdd_adapter_list_node_t **pNextAdapterNode)
4611{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304612 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004613
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004614 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304615 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4616 (qdf_list_node_t *) adapterNode,
4617 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004619 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620 return status;
4621}
4622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304623QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624 hdd_adapter_list_node_t *adapterNode)
4625{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304626 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004627
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004628 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304629 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004631 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632 return status;
4633}
4634
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304635QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004636 hdd_adapter_list_node_t **padapterNode)
4637{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304638 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004639
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004640 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304641 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4642 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004643 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 return status;
4645}
4646
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304647QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 hdd_adapter_list_node_t *adapterNode)
4649{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304650 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004651
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004652 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304653 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4654 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004655 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656 return status;
4657}
4658
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304659QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660 hdd_adapter_list_node_t *adapterNode)
4661{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304662 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004663
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004664 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304665 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4666 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004667 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668 return status;
4669}
4670
4671hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4672 tSirMacAddr macAddr)
4673{
4674 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4675 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304676 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677
4678 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4679
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304680 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004681 adapter = adapterNode->pAdapter;
4682
4683 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304684 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004685 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4689 adapterNode = pNext;
4690 }
4691
4692 return NULL;
4693
4694}
4695
4696hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
4697 uint32_t vdev_id)
4698{
4699 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4700 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304701 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004702
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304703 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304705 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004706 adapter = adapterNode->pAdapter;
4707
4708 if (adapter->sessionId == vdev_id)
4709 return adapter;
4710
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304711 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4713 adapterNode = pNext;
4714 }
4715
Jeff Johnson5880d792016-08-15 13:32:30 -07004716 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717
4718 return NULL;
4719}
4720
Abhishek Singh7996eb72015-12-30 17:24:02 +05304721/**
4722 * hdd_get_adapter_by_sme_session_id() - Return adapter with
4723 * the sessionid
4724 * @hdd_ctx: hdd context.
4725 * @sme_session_id: sme session is for the adapter to get.
4726 *
4727 * This function is used to get the adapter with provided session id
4728 *
4729 * Return: adapter pointer if found
4730 *
4731 */
4732hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
4733 uint32_t sme_session_id)
4734{
4735 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4736 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304737 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05304738
4739
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304740 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05304741
4742 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304743 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05304744 adapter = adapter_node->pAdapter;
4745
4746 if (adapter &&
4747 adapter->sessionId == sme_session_id)
4748 return adapter;
4749
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304750 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05304751 hdd_get_next_adapter(hdd_ctx,
4752 adapter_node, &next);
4753 adapter_node = next;
4754 }
4755 return NULL;
4756}
4757
Naveen Rawat4edb6822017-04-12 10:09:17 -07004758hdd_adapter_t *hdd_get_adapter_by_iface_name(hdd_context_t *hdd_ctx,
4759 const char *iface_name)
4760{
4761 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4762 hdd_adapter_t *adapter;
4763 QDF_STATUS qdf_status;
4764
4765 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4766
4767 while ((NULL != adapter_node) &&
4768 (QDF_STATUS_SUCCESS == qdf_status)) {
4769 adapter = adapter_node->pAdapter;
4770
4771 if (adapter &&
4772 !qdf_str_cmp(adapter->dev->name, iface_name))
4773 return adapter;
4774
4775 qdf_status =
4776 hdd_get_next_adapter(hdd_ctx,
4777 adapter_node, &next);
4778 adapter_node = next;
4779 }
4780 return NULL;
4781}
4782
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004783/**
4784 * hdd_get_adapter() - to get adapter matching the mode
4785 * @hdd_ctx: hdd context
4786 * @mode: adapter mode
4787 *
4788 * This routine will return the pointer to adapter matching
4789 * with the passed mode.
4790 *
4791 * Return: pointer to adapter or null
4792 */
4793hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
4794 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795{
4796 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4797 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304798 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799
4800 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4801
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304802 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 adapter = adapterNode->pAdapter;
4804
4805 if (adapter && (mode == adapter->device_mode))
4806 return adapter;
4807
4808 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4809 adapterNode = pNext;
4810 }
4811
4812 return NULL;
4813
4814}
4815
4816/**
4817 * hdd_get_operating_channel() - return operating channel of the device mode
4818 * @hdd_ctx: Pointer to the HDD context.
4819 * @mode: Device mode for which operating channel is required.
4820 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004821 * QDF_STA_MODE,
4822 * QDF_P2P_CLIENT_MODE,
4823 * QDF_SAP_MODE,
4824 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 *
4826 * This API returns the operating channel of the requested device mode
4827 *
4828 * Return: channel number. "0" id the requested device is not found OR it is
4829 * not connected.
4830 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004831uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
4832 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833{
4834 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304835 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836 hdd_adapter_t *adapter;
4837 uint8_t operatingChannel = 0;
4838
4839 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4840
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304841 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 adapter = adapterNode->pAdapter;
4843
4844 if (mode == adapter->device_mode) {
4845 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004846 case QDF_STA_MODE:
4847 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848 if (hdd_conn_is_connected
4849 (WLAN_HDD_GET_STATION_CTX_PTR
4850 (adapter))) {
4851 operatingChannel =
4852 (WLAN_HDD_GET_STATION_CTX_PTR
4853 (adapter))->conn_info.
4854 operationChannel;
4855 }
4856 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004857 case QDF_SAP_MODE:
4858 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004859 /* softap connection info */
4860 if (test_bit
4861 (SOFTAP_BSS_STARTED,
4862 &adapter->event_flags))
4863 operatingChannel =
4864 (WLAN_HDD_GET_AP_CTX_PTR
4865 (adapter))->operatingChannel;
4866 break;
4867 default:
4868 break;
4869 }
4870
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004871 /* Found the device of interest. break the loop */
4872 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 }
4874
4875 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4876 adapterNode = pNext;
4877 }
4878 return operatingChannel;
4879}
4880
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304881static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004882 hdd_ctx)
4883{
4884 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304885 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886 hdd_adapter_t *adapter;
4887
4888 ENTER();
4889
4890 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4891
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304892 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004894 if ((adapter->device_mode == QDF_STA_MODE) ||
4895 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4896 (adapter->device_mode == QDF_IBSS_MODE) ||
4897 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4898 (adapter->device_mode == QDF_SAP_MODE) ||
4899 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 wlan_hdd_cfg80211_deregister_frames(adapter);
4901 hdd_unregister_wext(adapter->dev);
4902 }
4903 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4904 adapterNode = pNext;
4905 }
4906
4907 EXIT();
4908
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304909 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910}
4911
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304912QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004913{
4914 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304915 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004916 hdd_adapter_t *adapter;
4917
4918 ENTER();
4919
4920 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304922 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004924 if ((adapter->device_mode == QDF_STA_MODE) ||
4925 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4926 (adapter->device_mode == QDF_IBSS_MODE) ||
4927 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4928 (adapter->device_mode == QDF_SAP_MODE) ||
4929 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004930 hdd_abort_mac_scan(hdd_ctx, adapter->sessionId,
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +05304931 INVALID_SCAN_ID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932 eCSR_SCAN_ABORT_DEFAULT);
4933 }
4934 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4935 adapterNode = pNext;
4936 }
4937
4938 EXIT();
4939
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304940 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004941}
4942
Dustin Brownf27bce82016-11-03 12:52:27 -07004943/**
4944 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
4945 * adapters
4946 * @hdd_ctx: The HDD context containing the adapters to operate on
4947 *
4948 * return: QDF_STATUS_SUCCESS
4949 */
4950static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
4951{
4952 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
4953 QDF_STATUS status;
4954 hdd_adapter_t *adapter;
4955 int err;
4956
4957 ENTER();
4958
4959 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4960
4961 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4962 adapter = adapter_node->pAdapter;
4963 if ((adapter->device_mode == QDF_STA_MODE) ||
4964 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
4965 (adapter->device_mode == QDF_IBSS_MODE) ||
4966 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
4967 (adapter->device_mode == QDF_SAP_MODE) ||
4968 (adapter->device_mode == QDF_P2P_GO_MODE)) {
4969 err = wlan_hdd_sched_scan_stop(adapter->dev);
4970 if (err)
4971 hdd_err("Unable to stop scheduled scan");
4972 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004973 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
4974 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07004975 adapter_node = next_node;
4976 }
4977
4978 EXIT();
4979
4980 return QDF_STATUS_SUCCESS;
4981}
4982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983#ifdef WLAN_NS_OFFLOAD
4984/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004985 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 * @hdd_ctx: Pointer to hdd context
4987 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004988 * Unregister for IPv6 address change notifications.
4989 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990 * Return: None
4991 */
4992static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
4993{
4994 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995}
4996
4997/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07004998 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999 * @hdd_ctx: Pointer to hdd context
5000 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005001 * Register for IPv6 address change notifications.
5002 *
5003 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005005static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006{
5007 int ret;
5008
5009 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5010 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005011 if (ret) {
5012 hdd_err("Failed to register IPv6 notifier: %d", ret);
5013 goto out;
5014 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005016 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005017out:
5018 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019}
5020#else
5021/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005022 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 * @hdd_ctx: Pointer to hdd context
5024 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005025 * Unregister for IPv6 address change notifications.
5026 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005027 * Return: None
5028 */
5029static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5030{
5031}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005032
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005034 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035 * @hdd_ctx: Pointer to hdd context
5036 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005037 * Register for IPv6 address change notifications.
5038 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039 * Return: None
5040 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005041static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005043 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044}
5045#endif
5046
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305047#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
5048/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005049 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305050 * @hdd_ctx: HDD context
5051 *
5052 * Activates the logging service
5053 *
5054 * Return: Zero in case of success, negative value otherwise
5055 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005056static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305057{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005058 int ret;
5059 struct hdd_config *config = hdd_ctx->config;
5060
5061 if (!config->wlanLoggingEnable)
5062 return 0;
5063
Srinivas Girigowda8187e792017-03-03 11:50:59 -08005064 ret = wlan_logging_sock_activate_svc(config->wlanLoggingToConsole,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005065 config->wlanLoggingNumBuf);
5066 if (ret)
5067 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
5068 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305069}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005070
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305071/**
5072 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
5073 * @hdd_ctx: HDD context
5074 *
5075 * Deactivates the logging service
5076 *
5077 * Return: 0 on deactivating the logging service
5078 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005079static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305080{
5081 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
5082 return wlan_logging_sock_deactivate_svc();
5083
5084 return 0;
5085}
5086#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005087static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305088{
5089 return 0;
5090}
5091
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005092static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305093{
5094 return 0;
5095}
5096#endif
5097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005099 * hdd_register_notifiers - Register netdev notifiers.
5100 * @hdd_ctx: HDD context
5101 *
5102 * Register netdev notifiers like IPv4 and IPv6.
5103 *
5104 * Return: 0 on success and errno on failure
5105 */
5106static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
5107{
5108 int ret;
5109
5110 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5111 if (ret) {
5112 hdd_err("register_netdevice_notifier failed: %d", ret);
5113 goto out;
5114 }
5115
5116 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5117 if (ret)
5118 goto unregister_notifier;
5119
5120 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5121 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5122 if (ret) {
5123 hdd_err("Failed to register IPv4 notifier: %d", ret);
5124 goto unregister_ip6_notifier;
5125 }
5126
5127 return 0;
5128
5129unregister_ip6_notifier:
5130 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5131unregister_notifier:
5132 unregister_netdevice_notifier(&hdd_netdev_notifier);
5133out:
5134 return ret;
5135
5136}
5137
5138/**
5139 * hdd_unregister_notifiers - Unregister netdev notifiers.
5140 * @hdd_ctx: HDD context
5141 *
5142 * Unregister netdev notifiers like IPv4 and IPv6.
5143 *
5144 * Return: None.
5145 */
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305146void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005147{
5148 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5149
5150 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5151
5152 unregister_netdevice_notifier(&hdd_netdev_notifier);
5153}
5154
5155/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005156 * hdd_exit_netlink_services - Exit netlink services
5157 * @hdd_ctx: HDD context
5158 *
5159 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5160 * nl service.
5161 *
5162 * Return: None.
5163 */
5164static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
5165{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005166 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005167 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005168 ptt_sock_deactivate_svc();
5169
5170 nl_srv_exit();
5171}
5172
5173/**
5174 * hdd_init_netlink_services- Init netlink services
5175 * @hdd_ctx: HDD context
5176 *
5177 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5178 * nl service.
5179 *
5180 * Return: 0 on success and errno on failure.
5181 */
5182static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
5183{
5184 int ret;
5185
Ryan Hsuceddceb2016-04-28 10:20:14 -07005186 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005187 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005188 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005189 goto out;
5190 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005191 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005192
Naveen Rawat910726a2017-03-06 11:42:51 -08005193 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005194 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005195 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005196 goto err_nl_srv;
5197 }
5198
5199 ret = ptt_sock_activate_svc();
5200 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005201 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005202 goto err_nl_srv;
5203 }
5204
5205 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005206 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005207 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005208
5209 ret = cnss_diag_activate_service();
5210 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005211 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005212 goto err_close_cesium;
5213 }
5214
5215 return 0;
5216
5217err_close_cesium:
5218 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005219 ptt_sock_deactivate_svc();
5220err_nl_srv:
5221 nl_srv_exit();
5222out:
5223 return ret;
5224}
5225
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005226/**
5227 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5228 * @hdd_ctx: HDD context.
5229 *
5230 * Destroy RX wakelock.
5231 *
5232 * Return: None.
5233 */
5234static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
5235{
5236 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5237}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005238
5239/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005240 * hdd_rx_wake_lock_create() - Create RX wakelock
5241 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005242 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005243 * Create RX wakelock.
5244 *
5245 * Return: None.
5246 */
5247static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
5248{
5249 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5250}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005251
5252/**
5253 * hdd_roc_context_init() - Init ROC context
5254 * @hdd_ctx: HDD context.
5255 *
5256 * Initialize ROC context.
5257 *
5258 * Return: 0 on success and errno on failure.
5259 */
5260static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
5261{
5262 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5263 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5264
5265 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5266
5267 return 0;
5268}
5269
5270/**
5271 * hdd_roc_context_destroy() - Destroy ROC context
5272 * @hdd_ctx: HDD context.
5273 *
5274 * Destroy roc list and flush the pending roc work.
5275 *
5276 * Return: None.
5277 */
5278static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
5279{
5280 flush_delayed_work(&hdd_ctx->roc_req_work);
5281 qdf_list_destroy(&hdd_ctx->hdd_roc_req_q);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005282 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005283}
5284
5285/**
Houston Hoffman160db392016-10-10 17:37:51 -07005286 * hdd_context_deinit() - Deinitialize HDD context
5287 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005288 *
Houston Hoffman160db392016-10-10 17:37:51 -07005289 * Deinitialize HDD context along with all the feature specific contexts but
5290 * do not free hdd context itself. Caller of this API is supposed to free
5291 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005292 *
Houston Hoffman160db392016-10-10 17:37:51 -07005293 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005294 */
Houston Hoffman160db392016-10-10 17:37:51 -07005295static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005296{
Houston Hoffman160db392016-10-10 17:37:51 -07005297 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005298
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005299 hdd_roc_context_destroy(hdd_ctx);
5300
5301 hdd_sap_context_destroy(hdd_ctx);
5302
5303 hdd_rx_wake_lock_destroy(hdd_ctx);
5304
5305 hdd_tdls_context_destroy(hdd_ctx);
5306
5307 hdd_scan_context_destroy(hdd_ctx);
5308
5309 qdf_list_destroy(&hdd_ctx->hddAdapters);
5310
Houston Hoffman160db392016-10-10 17:37:51 -07005311 return 0;
5312}
5313
5314/**
5315 * hdd_context_destroy() - Destroy HDD context
5316 * @hdd_ctx: HDD context to be destroyed.
5317 *
5318 * Free config and HDD context as well as destroy all the resources.
5319 *
5320 * Return: None
5321 */
5322static void hdd_context_destroy(hdd_context_t *hdd_ctx)
5323{
5324 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
5325 hdd_logging_sock_deactivate_svc(hdd_ctx);
5326
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305327 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5328
Houston Hoffman160db392016-10-10 17:37:51 -07005329 hdd_context_deinit(hdd_ctx);
5330
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305331 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005332 hdd_ctx->config = NULL;
5333
5334 wiphy_free(hdd_ctx->wiphy);
5335}
5336
5337/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005338 * hdd_wlan_exit() - HDD WLAN exit function
5339 * @hdd_ctx: Pointer to the HDD Context
5340 *
5341 * This is the driver exit point (invoked during rmmod)
5342 *
5343 * Return: None
5344 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005345static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346{
5347 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305348 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305350 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351
5352 ENTER();
5353
Arun Khandavallifae92942016-08-01 13:31:08 +05305354 if (QDF_TIMER_STATE_RUNNING ==
5355 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005356 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305357 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 }
5359
Arun Khandavallifae92942016-08-01 13:31:08 +05305360 if (!QDF_IS_STATUS_SUCCESS
5361 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5362 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005363
Arun Khandavallifae92942016-08-01 13:31:08 +05305364
5365 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005366
Nitesh Shah61c10d92016-10-19 19:29:15 +05305367 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5368
Prashanth Bhattaab004382016-10-11 16:08:11 -07005369 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370
5371#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305372 if (QDF_TIMER_STATE_RUNNING ==
5373 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5374 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375 }
5376
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305377 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305378 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005379 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005381 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5382 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5383 hdd_ctx->last_acs_channel_list = NULL;
5384 hdd_ctx->num_of_channels = 0;
5385 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005386#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387
Arun Khandavallifae92942016-08-01 13:31:08 +05305388 mutex_lock(&hdd_ctx->iface_change_lock);
5389 driver_status = hdd_ctx->driver_status;
5390 mutex_unlock(&hdd_ctx->iface_change_lock);
5391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 /*
5393 * Powersave Offload Case
5394 * Disable Idle Power Save Mode
5395 */
5396 hdd_set_idle_ps_config(hdd_ctx, false);
5397
Arun Khandavallifae92942016-08-01 13:31:08 +05305398 if (driver_status != DRIVER_MODULES_CLOSED) {
5399 hdd_unregister_wext_all_adapters(hdd_ctx);
5400 /*
5401 * Cancel any outstanding scan requests. We are about to close
5402 * all of our adapters, but an adapter structure is what SME
5403 * passes back to our callback function. Hence if there
5404 * are any outstanding scan requests then there is a
5405 * race condition between when the adapter is closed and
5406 * when the callback is invoked. We try to resolve that
5407 * race condition here by canceling any outstanding scans
5408 * before we close the adapters.
5409 * Note that the scans may be cancelled in an asynchronous
5410 * manner, so ideally there needs to be some kind of
5411 * synchronization. Rather than introduce a new
5412 * synchronization here, we will utilize the fact that we are
5413 * about to Request Full Power, and since that is synchronized,
5414 * the expectation is that by the time Request Full Power has
5415 * completed, all scans will be cancelled
5416 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005417 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305418 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005419 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305420 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421 }
5422
5423 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305424 * Close the scheduler before calling cds_close to make sure
5425 * no thread is scheduled after the each module close is
5426 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305428 qdf_status = cds_sched_close(p_cds_context);
5429 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005430 hdd_err("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305431 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005433
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005434 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305435
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305436 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5437 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5438 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5439
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440 /*
5441 * Close CDS
5442 * This frees pMac(HAL) context. There should not be any call
5443 * that requires pMac access after this.
5444 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005445
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005446 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005447 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005448
Komal Seelam8634b772016-09-29 12:12:24 +05305449 hdd_runtime_suspend_context_deinit(hdd_ctx);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005450 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005451
5452 hdd_ipa_cleanup(hdd_ctx);
5453
5454 /* Free up RoC request queue and flush workqueue */
5455 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005456
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305457 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305458 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305459 /*
5460 * If there is re_init failure wiphy would have already de-registered
5461 * check the wiphy status before un-registering again
5462 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305463 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305464 wiphy_unregister(wiphy);
5465 wlan_hdd_cfg80211_deinit(wiphy);
5466 hdd_lpass_notify_stop(hdd_ctx);
5467 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005468
Arun Khandavallifae92942016-08-01 13:31:08 +05305469 hdd_exit_netlink_services(hdd_ctx);
5470 mutex_destroy(&hdd_ctx->iface_change_lock);
Abhishek Singhe9068f12017-03-31 14:14:52 +05305471
5472 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5473 if (driver_status)
5474 hdd_err("Pdev delete failed");
5475
5476 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
5477 if (driver_status)
5478 hdd_err("Psoc delete failed");
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005479 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480}
5481
5482void __hdd_wlan_exit(void)
5483{
5484 hdd_context_t *hdd_ctx;
5485
5486 ENTER();
5487
Anurag Chouhan6d760662016-02-20 16:05:43 +05305488 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005489 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005490 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005491 EXIT();
5492 return;
5493 }
5494
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005495 /* Check IPA HW Pipe shutdown */
5496 hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
5497
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005498 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305499 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005501 /* Do all the cleanup before deregistering the driver */
5502 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504 EXIT();
5505}
5506
5507#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005508/**
5509 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5510 * @data: pointer to hdd_context_t
5511 *
5512 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5513 * Then new ACS request will do a fresh scan without reusing the cached
5514 * scan information.
5515 *
5516 * Return: void
5517 */
Tang Yingying523322d2017-01-17 23:28:43 +08005518static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519{
5520 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5521
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005522 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005523 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005524 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5525 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5526 hdd_ctx->last_acs_channel_list = NULL;
5527 hdd_ctx->num_of_channels = 0;
5528 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529
5530 if (!hdd_ctx->hHal)
5531 return;
5532 sme_scan_flush_result(hdd_ctx->hHal);
5533}
5534#endif
5535
5536#ifdef QCA_HT_2040_COEX
5537/**
5538 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5539 * @adapter: pointer to adapter
5540 * @staId: station id
5541 * @macAddrSTA: station MAC address
5542 * @channel_type: channel type
5543 *
5544 * This function notifies FW with HT20/HT40 mode
5545 *
5546 * Return: 0 if successful, error number otherwise
5547 */
5548int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305549 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005550{
5551 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305552 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553 hdd_context_t *hdd_ctx = NULL;
5554
5555 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5556
5557 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305558 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305560
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561 if (!hdd_ctx->hHal)
5562 return -EINVAL;
5563
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305564 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305566 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005567 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005568 return -EINVAL;
5569 }
5570
5571 return 0;
5572}
5573#endif
5574
5575/**
5576 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5577 * @state: state
5578 *
5579 * This function notifies FW with modem power status
5580 *
5581 * Return: 0 if successful, error number otherwise
5582 */
5583int hdd_wlan_notify_modem_power_state(int state)
5584{
5585 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305586 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587 hdd_context_t *hdd_ctx;
5588
Anurag Chouhan6d760662016-02-20 16:05:43 +05305589 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005590 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305591 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005592 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005594 if (!hdd_ctx->hHal)
5595 return -EINVAL;
5596
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305597 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5598 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005599 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005600 state);
5601 return -EINVAL;
5602 }
5603 return 0;
5604}
5605
5606/**
5607 *
5608 * hdd_post_cds_enable_config() - HDD post cds start config helper
5609 * @adapter - Pointer to the HDD
5610 *
5611 * Return: None
5612 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305613QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305615 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616
5617 /*
5618 * Send ready indication to the HDD. This will kick off the MAC
5619 * into a 'running' state and should kick off an initial scan.
5620 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305621 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5622 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005623 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5624 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305625 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626 }
5627
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305628 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629}
5630
5631/* wake lock APIs for HDD */
5632void hdd_prevent_suspend(uint32_t reason)
5633{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305634 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635}
5636
5637void hdd_allow_suspend(uint32_t reason)
5638{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305639 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640}
5641
5642void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
5643{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05305644 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
5645 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646}
5647
5648/**
5649 * hdd_exchange_version_and_caps() - exchange version and capability with target
5650 * @hdd_ctx: Pointer to HDD context
5651 *
5652 * This is the HDD function to exchange version and capability information
5653 * between Host and Target
5654 *
5655 * This function gets reported version of FW.
5656 * It also finds the version of target headers used to compile the host;
5657 * It compares the above two and prints a warning if they are different;
5658 * It gets the SW and HW version string;
5659 * Finally, it exchanges capabilities between host and target i.e. host
5660 * and target exchange a msg indicating the features they support through a
5661 * bitmap
5662 *
5663 * Return: None
5664 */
5665void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
5666{
5667
5668 tSirVersionType versionCompiled;
5669 tSirVersionType versionReported;
5670 tSirVersionString versionString;
5671 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305672 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673
5674 memset(&versionCompiled, 0, sizeof(versionCompiled));
5675 memset(&versionReported, 0, sizeof(versionReported));
5676
5677 /* retrieve and display WCNSS version information */
5678 do {
5679
5680 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
5681 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305682 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005683 hdd_err("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 break;
5685 }
5686
5687 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
5688 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305689 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005690 hdd_err("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 break;
5692 }
5693
5694 if ((versionCompiled.major != versionReported.major) ||
5695 (versionCompiled.minor != versionReported.minor) ||
5696 (versionCompiled.version != versionReported.version) ||
5697 (versionCompiled.revision != versionReported.revision)) {
5698 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
5699 "Host expected %u.%u.%u.%u\n",
5700 WLAN_MODULE_NAME,
5701 (int)versionReported.major,
5702 (int)versionReported.minor,
5703 (int)versionReported.version,
5704 (int)versionReported.revision,
5705 (int)versionCompiled.major,
5706 (int)versionCompiled.minor,
5707 (int)versionCompiled.version,
5708 (int)versionCompiled.revision);
5709 } else {
5710 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
5711 WLAN_MODULE_NAME,
5712 (int)versionReported.major,
5713 (int)versionReported.minor,
5714 (int)versionReported.version,
5715 (int)versionReported.revision);
5716 }
5717
5718 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
5719 versionString,
5720 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305721 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005722 hdd_err("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005723 break;
5724 }
5725
5726 pr_info("%s: WCNSS software version %s\n",
5727 WLAN_MODULE_NAME, versionString);
5728
5729 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
5730 versionString,
5731 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305732 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005733 hdd_err("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734 break;
5735 }
5736
5737 pr_info("%s: WCNSS hardware version %s\n",
5738 WLAN_MODULE_NAME, versionString);
5739
5740 /*
5741 * 1.Check if FW version is greater than 0.1.1.0. Only then
5742 * send host-FW capability exchange message
5743 * 2.Host-FW capability exchange message is only present on
5744 * target 1.1 so send the message only if it the target is 1.1
5745 * minor numbers for different target branches:
5746 * 0 -> (1.0)Mainline Build
5747 * 1 -> (1.1)Mainline Build
5748 * 2->(1.04) Stability Build
5749 */
5750 if (((versionReported.major > 0) || (versionReported.minor > 1)
5751 || ((versionReported.minor >= 1)
5752 && (versionReported.version >= 1)))
5753 && ((versionReported.major == 1)
5754 && (versionReported.minor >= 1)))
5755 fwFeatCapsMsgSupported = 1;
5756
5757 if (fwFeatCapsMsgSupported) {
5758 /*
5759 * Indicate if IBSS heartbeat monitoring needs to be
5760 * offloaded
5761 */
5762 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
5763 sme_disable_feature_capablity
5764 (IBSS_HEARTBEAT_OFFLOAD);
5765 }
5766
5767 sme_feature_caps_exchange(hdd_ctx->hHal);
5768 }
5769
5770 } while (0);
5771
5772}
5773
5774/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305775QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776{
Amar Singhal5cccafe2017-02-15 12:42:58 -08005777
5778 if (hdd_ctx->reg_offload)
5779 return sme_init_chan_list(hdd_ctx->hHal,
5780 hdd_ctx->reg.alpha2,
5781 0);
5782 else
5783 return sme_init_chan_list(hdd_ctx->hHal,
5784 hdd_ctx->reg.alpha2,
5785 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786}
5787
5788/**
5789 * hdd_is_5g_supported() - check if hardware supports 5GHz
5790 * @hdd_ctx: Pointer to the hdd context
5791 *
5792 * HDD function to know if hardware supports 5GHz
5793 *
5794 * Return: true if hardware supports 5GHz
5795 */
5796bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
5797{
zdingf54169a2016-10-12 17:08:45 +08005798 if (!hdd_ctx || !hdd_ctx->config)
5799 return true;
5800
5801 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
5802 return true;
5803 else
5804 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805}
5806
Amar Singhale4f28ee2015-10-21 14:36:56 -07005807static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005808{
5809 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07005810 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811
5812 wiphy = hdd_ctx->wiphy;
5813
5814 /*
5815 * The channel information in
5816 * wiphy needs to be initialized before wiphy registration
5817 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005818 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
5819 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005820 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07005821 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005822 }
5823
5824#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
5825 wiphy->wowlan = &wowlan_support_reg_init;
5826#else
5827 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
5828 WIPHY_WOWLAN_MAGIC_PKT |
5829 WIPHY_WOWLAN_DISCONNECT |
5830 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
5831 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
5832 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
5833 WIPHY_WOWLAN_4WAY_HANDSHAKE |
5834 WIPHY_WOWLAN_RFKILL_RELEASE;
5835
5836 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
5837 WOW_MAX_FILTERS_PER_LIST);
5838 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
5839 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
5840#endif
5841
5842 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07005843 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05305844 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07005845 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05305846 return ret_val;
5847 }
5848
Amar Singhal5cccafe2017-02-15 12:42:58 -08005849 if (!hdd_ctx->reg_offload)
5850 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005851
Amar Singhale4f28ee2015-10-21 14:36:56 -07005852 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005853}
5854
Ravi Joshie2331e82015-07-01 18:18:54 -07005855/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07005856 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07005857 * @hdd_ctx - handle to hdd context
5858 * @tx_packets - transmit packet count
5859 * @rx_packets - receive packet count
5860 *
5861 * The function controls the bus bandwidth and dynamic control of
5862 * tcp delayed ack configuration
5863 *
5864 * Returns: None
5865 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005866#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07005867static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
5868 const uint64_t tx_packets,
5869 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005871 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08005872 uint64_t temp_rx = 0;
5873 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005874 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08005875 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08005876 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005877 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08005878 uint16_t index = 0;
5879 bool vote_level_change = false;
5880 bool rx_level_change = false;
5881 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005882
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005883 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005884 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005885 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005886 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07005887 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07005888 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07005889 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07005890 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005893 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
5894 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005895 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08005896 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07005897 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05305898 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05305899 if (hdd_ctx->hbw_requested) {
5900 pld_remove_pm_qos(hdd_ctx->parent_dev);
5901 hdd_ctx->hbw_requested = false;
5902 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05305903 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005904 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305905 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05305906 if (!hdd_ctx->hbw_requested) {
5907 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
5908 hdd_ctx->hbw_requested = true;
5909 }
5910
Nirav Shah3bbfa512016-05-12 16:43:49 +05305911 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005912 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05305913 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07005914 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915 }
Mohit Khannae71e2262015-11-10 09:37:24 -08005916
5917 /* fine-tuning parameters for RX Flows */
5918 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
5919
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08005921
Ravi Joshifed83572016-10-07 16:20:37 -07005922 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
5923 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
5924 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
5925 next_rx_level = WLAN_SVC_TP_HIGH;
5926 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07005927 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07005928 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08005929 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07005930 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005932 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07005933 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 next_rx_level, temp_rx);
5935 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08005936 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07005937 /* Send throughput indication only if it is enabled.
5938 * Disabling tcp_del_ack will revert the tcp stack behavior
5939 * to default delayed ack. Note that this will disable the
5940 * dynamic delayed ack mechanism across the system
5941 */
5942 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305943 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5944 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 &next_rx_level,
5946 sizeof(next_rx_level));
5947 }
5948
Mohit Khannae71e2262015-11-10 09:37:24 -08005949 /* fine-tuning parameters for TX Flows */
5950 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
5951 hdd_ctx->prev_tx = tx_packets;
5952 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
5953 next_tx_level = WLAN_SVC_TP_HIGH;
5954 else
5955 next_tx_level = WLAN_SVC_TP_LOW;
5956
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005957 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08005958 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
5959 next_tx_level, temp_tx);
5960 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08005961 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05305962 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
5963 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08005964 &next_tx_level,
5965 sizeof(next_tx_level));
5966 }
5967
Mohit Khannaafff9fb2016-11-16 20:22:03 -08005968 index = hdd_ctx->hdd_txrx_hist_idx;
5969
5970 if (vote_level_change || tx_level_change || rx_level_change) {
5971 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
5972 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
5973 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
5974 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
5975 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
5976 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
5977 hdd_ctx->hdd_txrx_hist_idx++;
5978 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
5979 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005980}
5981
5982#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305983static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005984{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05305985 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
5986 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005987 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305988 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05305989 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
5990 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005991 uint64_t total_tx = 0, total_rx = 0;
5992 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305993 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05305994 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005995 bool connected = false;
5996 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
5997
Prashanth Bhattaab004382016-10-11 16:08:11 -07005998 if (wlan_hdd_validate_context(hdd_ctx))
5999 return;
6000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006001 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306002 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006003 status =
6004 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6005
6006 if (adapterNode->pAdapter == NULL)
6007 continue;
6008 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306009 /*
6010 * Validate magic so we don't end up accessing
6011 * an invalid adapter.
6012 */
6013 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6014 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006016 if ((adapter->device_mode == QDF_STA_MODE ||
6017 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6019 != eConnectionState_Associated) {
6020
6021 continue;
6022 }
6023
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006024 if ((adapter->device_mode == QDF_SAP_MODE ||
6025 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6027
6028 continue;
6029 }
6030
6031 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6032 adapter->prev_tx_packets);
6033 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6034 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306035
6036 if (adapter->device_mode == QDF_SAP_MODE ||
6037 adapter->device_mode == QDF_P2P_GO_MODE ||
6038 adapter->device_mode == QDF_IBSS_MODE) {
6039
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006040 ret = cdp_get_intra_bss_fwd_pkts_count(
6041 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306042 adapter->sessionId,
6043 &fwd_tx_packets, &fwd_rx_packets);
6044 if (ret == A_OK) {
6045 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6046 fwd_tx_packets,
6047 adapter->prev_fwd_tx_packets);
6048 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6049 fwd_tx_packets,
6050 adapter->prev_fwd_rx_packets);
6051 }
6052 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053
6054 total_rx += adapter->stats.rx_packets;
6055 total_tx += adapter->stats.tx_packets;
6056
6057 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6058 adapter->prev_tx_packets = adapter->stats.tx_packets;
6059 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306060 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6061 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6063 connected = true;
6064 }
6065
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306066 /* add intra bss forwarded tx and rx packets */
6067 tx_packets += fwd_tx_packets_diff;
6068 rx_packets += fwd_rx_packets_diff;
6069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6071 tx_packets += (uint64_t)ipa_tx_packets;
6072 rx_packets += (uint64_t)ipa_rx_packets;
6073
6074 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006075 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076 return;
6077 }
6078
Yuanyuan Liu13738502016-04-06 17:41:37 -07006079 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080
6081 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6082 hdd_ipa_uc_stat_request(adapter, 2);
6083
Dustin Brown2ed60362017-01-18 12:25:50 -08006084 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006085 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006086 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306087 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006088 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006089 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006090}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006091
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306092/**
6093 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6094 * @arg: Argument of timer function
6095 *
6096 * Schedule a workqueue in this function where all the processing is done.
6097 *
6098 * Return: None.
6099 */
6100static void __hdd_bus_bw_cbk(void *arg)
6101{
6102 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
6103
6104 if (wlan_hdd_validate_context(hdd_ctx))
6105 return;
6106
6107 schedule_work(&hdd_ctx->bus_bw_work);
6108}
6109
6110/**
6111 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6112 * @arg: Argument of timer function
6113 *
6114 * Return: None.
6115 */
6116static void hdd_bus_bw_cbk(void *arg)
6117{
6118 cds_ssr_protect(__func__);
6119 __hdd_bus_bw_cbk(arg);
6120 cds_ssr_unprotect(__func__);
6121}
6122
Prashanth Bhattaab004382016-10-11 16:08:11 -07006123int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
6124{
6125 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306126 INIT_WORK(&hdd_ctx->bus_bw_work,
6127 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006128 hdd_ctx->bus_bw_timer_running = false;
6129 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306130 qdf_timer_init(NULL,
6131 &hdd_ctx->bus_bw_timer,
6132 hdd_bus_bw_cbk, (void *)hdd_ctx,
6133 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006134
6135 return 0;
6136}
6137
6138void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
6139{
Dustin Brownfce08d12017-01-17 16:29:38 -08006140 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006141 hdd_reset_tcp_delack(hdd_ctx);
6142
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006143 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306144 cancel_work_sync(&hdd_ctx->bus_bw_work);
6145 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006146 hdd_ctx->bus_bw_timer_running = false;
6147 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006148}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149#endif
6150
6151/**
Nirav Shahed34b212016-04-25 10:59:16 +05306152 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6153 * @hdd_ctx: hdd context
6154 *
6155 * Return: 0 for success or error code
6156 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07006157static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306158{
6159 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6160 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6161 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006162 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306163 return -ENOMEM;
6164 }
6165 return 0;
6166}
6167
6168/**
6169 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6170 * @hdd_ctx: hdd context
6171 *
6172 * Return: none
6173 */
6174void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
6175{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306176 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6177 return;
6178
6179 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6180 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306181}
6182
Nirav Shahda008342016-05-17 18:50:40 +05306183static uint8_t *convert_level_to_string(uint32_t level)
6184{
6185 switch (level) {
6186 /* initialize the wlan sub system */
6187 case WLAN_SVC_TP_NONE:
6188 return "NONE";
6189 case WLAN_SVC_TP_LOW:
6190 return "LOW";
6191 case WLAN_SVC_TP_MEDIUM:
6192 return "MED";
6193 case WLAN_SVC_TP_HIGH:
6194 return "HIGH";
6195 default:
6196 return "INVAL";
6197 }
6198}
6199
Nirav Shahed34b212016-04-25 10:59:16 +05306200
6201/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6203 * @hdd_ctx: hdd context
6204 *
6205 * Return: none
6206 */
6207void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
6208{
6209 int i;
6210
6211#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006212 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306213 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006214 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 hdd_ctx->config->busBandwidthHighThreshold,
6216 hdd_ctx->config->busBandwidthMediumThreshold,
6217 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006218 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306219 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006220 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221 hdd_ctx->config->tcpDelackThresholdHigh,
6222 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006223 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306224 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225#endif
6226
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006227 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306228 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6229
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006230 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231
6232 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006233 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006234 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006235 hdd_log(QDF_TRACE_LEVEL_ERROR,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006236 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6237 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006238 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006239 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6240 convert_level_to_string(
6241 hdd_ctx->hdd_txrx_hist[i].
6242 next_vote_level),
6243 convert_level_to_string(
6244 hdd_ctx->hdd_txrx_hist[i].
6245 next_rx_level),
6246 convert_level_to_string(
6247 hdd_ctx->hdd_txrx_hist[i].
6248 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006250}
6251
6252/**
6253 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6254 * @hdd_ctx: hdd context
6255 *
6256 * Return: none
6257 */
6258void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
6259{
6260 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306261 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6262 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006263}
6264
6265/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006266 * wlan_hdd_display_netif_queue_history() - display netif queue history
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267 * @pHddCtx: hdd context
6268 *
6269 * Return: none
6270 */
6271void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
6272{
6273
6274 hdd_adapter_t *adapter = NULL;
6275 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306276 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306278 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279
6280 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306281 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006282 adapter = adapter_node->pAdapter;
6283
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006284 hdd_debug("Netif queue operation statistics:");
6285 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306286 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006287 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306288 curr_time = qdf_system_ticks();
6289 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306290 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306291 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306292 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306293 unpause = adapter->total_unpause_time;
6294 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306295 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306296 pause = adapter->total_pause_time;
6297 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006298 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306299 qdf_system_ticks_to_msecs(total),
6300 qdf_system_ticks_to_msecs(pause),
6301 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006302 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006303
Nirav Shahda008342016-05-17 18:50:40 +05306304 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6305 qdf_time_t pause_delta = 0;
6306
6307 if (adapter->pause_map & (1 << i))
6308 pause_delta = delta;
6309
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006310 /* using hdd_log to avoid printing function name */
6311 hdd_log(QDF_TRACE_LEVEL_ERROR,
6312 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006313 hdd_reason_type_to_string(i),
6314 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306315 adapter->queue_oper_stats[i].unpause_count,
6316 qdf_system_ticks_to_msecs(
6317 adapter->queue_oper_stats[i].total_pause_time +
6318 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006319 }
6320
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006321 hdd_debug("Netif queue operation history:");
6322 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306323 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6324
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006325 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326
6327 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006328 /* using hdd_log to avoid printing function name */
6329 if (adapter->queue_oper_history[i].time == 0)
6330 continue;
6331 hdd_log(QDF_TRACE_LEVEL_ERROR,
6332 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306333 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334 adapter->queue_oper_history[i].time),
6335 hdd_action_type_to_string(
6336 adapter->queue_oper_history[i].netif_action),
6337 hdd_reason_type_to_string(
6338 adapter->queue_oper_history[i].netif_reason),
6339 adapter->queue_oper_history[i].pause_map);
6340 }
6341
6342 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6343 adapter_node = next;
6344 }
6345
6346
6347}
6348
6349/**
6350 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6351 * @hdd_ctx: hdd context
6352 *
6353 * Return: none
6354 */
6355void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
6356{
6357 hdd_adapter_t *adapter = NULL;
6358 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306359 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360
6361 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306362 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363 adapter = adapter_node->pAdapter;
6364
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306365 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306367 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306369 adapter->history_index = 0;
6370 adapter->start_time = adapter->last_time = qdf_system_ticks();
6371 adapter->total_pause_time = 0;
6372 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006373 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6374 adapter_node = next;
6375 }
6376}
6377
6378/**
6379 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6380 * @halHandle: Hal handle
6381 * @pContext: Pointer to the context
6382 * @sessionId: Session ID
6383 * @scanId: Scan ID
6384 * @status: Status
6385 *
6386 * This is the callback to be executed when 11d scan is completed to flush out
6387 * the scan results
6388 *
6389 * 11d scan is done during driver load and is a passive scan on all
6390 * channels supported by the device, 11d scans may find some APs on
6391 * frequencies which are forbidden to be used in the regulatory domain
6392 * the device is operating in. If these APs are notified to the supplicant
6393 * it may try to connect to these APs, thus flush out all the scan results
6394 * which are present in SME after 11d scan is done.
6395 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306396 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306398static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399 uint8_t sessionId, uint32_t scanId,
6400 eCsrScanStatus status)
6401{
6402 ENTER();
6403
6404 sme_scan_flush_result(halHandle);
6405
6406 EXIT();
6407
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306408 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006409}
6410
6411#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6412/**
6413 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6414 * @hdd_ctx: hdd global context
6415 *
6416 * Return: none
6417 */
6418static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6419{
6420 uint8_t i;
6421
6422 mutex_init(&hdd_ctx->op_ctx.op_lock);
6423 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6424 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6425 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6426 }
6427}
6428#else
6429static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6430{
6431}
6432#endif
6433
Yingying Tang95409972016-10-20 15:16:15 +08006434#ifdef WLAN_FEATURE_WOW_PULSE
6435/**
6436 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6437 * @phddctx: hdd_context_t structure pointer
6438 * @enable: enable or disable this behaviour
6439 *
6440 * Return: int
6441 */
6442static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6443{
6444 struct hdd_config *pcfg_ini = phddctx->config;
6445 struct wow_pulse_mode wow_pulse_set_info;
6446 QDF_STATUS status;
6447
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006448 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006449
6450 if (false == phddctx->config->wow_pulse_support)
6451 return 0;
6452
6453 /* prepare the request to send to SME */
6454 if (enable == true) {
6455 wow_pulse_set_info.wow_pulse_enable = true;
6456 wow_pulse_set_info.wow_pulse_pin =
6457 pcfg_ini->wow_pulse_pin;
6458 wow_pulse_set_info.wow_pulse_interval_low =
6459 pcfg_ini->wow_pulse_interval_low;
6460 wow_pulse_set_info.wow_pulse_interval_high =
6461 pcfg_ini->wow_pulse_interval_high;
6462 } else {
6463 wow_pulse_set_info.wow_pulse_enable = false;
6464 wow_pulse_set_info.wow_pulse_pin = 0;
6465 wow_pulse_set_info.wow_pulse_interval_low = 0;
6466 wow_pulse_set_info.wow_pulse_interval_high = 0;
6467 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006468 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006469 wow_pulse_set_info.wow_pulse_enable,
6470 wow_pulse_set_info.wow_pulse_pin,
6471 wow_pulse_set_info.wow_pulse_interval_low,
6472 wow_pulse_set_info.wow_pulse_interval_high);
6473
6474 status = sme_set_wow_pulse(&wow_pulse_set_info);
6475 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006476 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006477 return -EIO;
6478 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006479 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006480 return 0;
6481}
6482#else
6483static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6484{
6485 return 0;
6486}
6487#endif
6488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489#ifdef WLAN_FEATURE_FASTPATH
6490/**
6491 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6492 * @hdd_cfg: hdd config
6493 * @context: lower layer context
6494 *
6495 * Return: none
6496 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306497void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498 void *context)
6499{
6500 if (hdd_cfg->fastpath_enable)
6501 hif_enable_fastpath(context);
6502}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503#endif
6504
Yuanyuan Liu13738502016-04-06 17:41:37 -07006505#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506/**
6507 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006508 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509 * @level: thermal level
6510 *
6511 * Change IPA data path to SW path when the thermal throttle level greater
6512 * than 0, and restore the original data path when throttle level is 0
6513 *
6514 * Return: none
6515 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006516static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006517{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006518 hdd_context_t *hdd_ctx = context;
6519
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006520 /* Change IPA to SW path when throttle level greater than 0 */
6521 if (level > THROTTLE_LEVEL_0)
6522 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6523 else
6524 /* restore original concurrency mode */
6525 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6526}
6527
6528/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306529 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6530 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306531 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306533 * Get a safe channel to restart SAP. PCL already takes into account the
6534 * unsafe channels. So, the PCL is validated with the ACS range to provide
6535 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306537 * Return: Channel number to restart SAP in case of success. In case of any
6538 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306540static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6541 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306543 struct sir_pcl_list pcl;
6544 QDF_STATUS status;
6545 uint32_t i, j;
6546 tHalHandle *hal_handle;
6547 hdd_context_t *hdd_ctx;
6548 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306550 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6551 if (!hdd_ctx) {
6552 hdd_err("invalid HDD context");
6553 return INVALID_CHANNEL_ID;
6554 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006555
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306556 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6557 if (!hal_handle) {
6558 hdd_err("invalid HAL handle");
6559 return INVALID_CHANNEL_ID;
6560 }
6561
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006562 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6563 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306564 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list));
6565 if (QDF_IS_STATUS_ERROR(status)) {
6566 hdd_err("Get PCL failed");
6567 return INVALID_CHANNEL_ID;
6568 }
6569
6570 if (!pcl.pcl_len) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006571 hdd_err("pcl length is zero. this is not expected");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306572 return INVALID_CHANNEL_ID;
6573 }
6574
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006575 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306576 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6577 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6578
6579 /* PCL already takes unsafe channel into account */
6580 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006581 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306582 if ((pcl.pcl_list[i] >=
6583 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6584 (pcl.pcl_list[i] <=
6585 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006586 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306587 return pcl.pcl_list[i];
6588 }
6589 }
6590
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006591 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306592
6593 /* Try for safe channel from all valid channel */
6594 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006595 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306596 &pcl.pcl_len);
6597 if (QDF_IS_STATUS_ERROR(status)) {
6598 hdd_err("error in getting valid channel list");
6599 return INVALID_CHANNEL_ID;
6600 }
6601
6602 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006603 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306604 found = false;
6605 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006606 if (pcl.pcl_list[i] ==
6607 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006608 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306609 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610 break;
6611 }
6612 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306613
6614 if (found)
6615 continue;
6616
6617 if ((pcl.pcl_list[i] >=
6618 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6619 (pcl.pcl_list[i] <=
6620 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006621 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306622 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006623 }
6624 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306625
6626 return INVALID_CHANNEL_ID;
6627}
6628
6629/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006630 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306631 * @adapter: AP adapter
6632 * @channel: Channel
6633 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006634 * Moves the SAP interface by invoking the function which
6635 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306636 *
6637 * Return: None
6638 */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006639void hdd_switch_sap_channel(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306640{
6641 hdd_ap_ctx_t *hdd_ap_ctx;
6642 tHalHandle *hal_handle;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006643 hdd_context_t *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306644
6645 if (!adapter) {
6646 hdd_err("invalid adapter");
6647 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306649
6650 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
6651
6652 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6653 if (!hal_handle) {
6654 hdd_err("invalid HAL handle");
6655 return;
6656 }
6657
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006658 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6659
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306660 hdd_ap_ctx->sapConfig.channel = channel;
6661 hdd_ap_ctx->sapConfig.ch_params.ch_width =
6662 hdd_ap_ctx->sapConfig.ch_width_orig;
6663
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006664 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306665 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
6666
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006667 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
6668 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306669 hdd_ap_ctx->sapConfig.sec_ch,
6670 &hdd_ap_ctx->sapConfig.ch_params);
6671
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006672 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
6673 adapter->sessionId, channel,
6674 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675}
Kapil Gupta8878ad92017-02-13 11:56:04 +05306676
6677int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
6678{
6679 struct hdd_external_acs_timer_context *timer_context;
6680
6681 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6682
6683 if (QDF_TIMER_STATE_RUNNING ==
6684 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
6685 ap.vendor_acs_timer)) {
6686 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
6687 }
6688 timer_context = (struct hdd_external_acs_timer_context *)
6689 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
6690 timer_context->reason = reason;
6691 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
6692 WLAN_VENDOR_ACS_WAIT_TIME);
6693 /* Update config to application */
6694 hdd_cfg80211_update_acs_config(adapter, reason);
6695 hdd_notice("Updated ACS config to nl with reason %d", reason);
6696
6697 return 0;
6698}
6699
Agrawal Ashish467dde42016-09-08 18:44:22 +05306700/**
6701 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
6702 * @hdd_ctx: hdd context pointer
6703 *
6704 * hdd_unsafe_channel_restart_sap check all unsafe channel list
6705 * and if ACS is enabled, driver will ask userspace to restart the
6706 * sap. User space on LTE coex indication restart driver.
6707 *
6708 * Return - none
6709 */
6710void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
6711{
6712 QDF_STATUS status;
6713 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
6714 hdd_adapter_t *adapter_temp;
6715 uint32_t i;
6716 bool found = false;
6717 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718
Agrawal Ashish467dde42016-09-08 18:44:22 +05306719 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
6720 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
6721 adapter_temp = adapter_node->pAdapter;
6722
6723 if (!adapter_temp) {
6724 hdd_err("adapter is NULL, moving to next one");
6725 goto next_adapater;
6726 }
6727
6728 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
6729 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006730 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05306731 adapter_temp->device_mode,
6732 adapter_temp->sessionCtx.ap.sapConfig.
6733 acs_cfg.acs_mode);
6734 goto next_adapater;
6735 }
6736
6737 found = false;
6738 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006739 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05306740 hdd_ctxt->unsafe_channel_list[i]) {
6741 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006742 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05306743 adapter_temp->sessionCtx.ap.operatingChannel);
6744 break;
6745 }
6746 }
6747
6748 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006749 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05306750 adapter_temp->sessionCtx.ap.operatingChannel);
6751 goto next_adapater;
6752 }
6753
Kapil Gupta8878ad92017-02-13 11:56:04 +05306754 if (hdd_ctxt->config->vendor_acs_support &&
6755 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
6756 hdd_update_acs_timer_reason(adapter_temp,
6757 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
6758 goto next_adapater;
6759 } else
6760 restart_chan =
6761 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05306762 adapter_temp);
6763 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006764 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05306765 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006766 /*
6767 * SAP restart due to unsafe channel. While
6768 * restarting the SAP, make sure to clear
6769 * acs_channel, channel to reset to
6770 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306771 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08006772 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05306773 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
6774 adapter_temp->sessionCtx.ap.sapConfig.channel =
6775 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006776 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05306777 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
6778 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006779 hdd_switch_sap_channel(adapter_temp, restart_chan);
Agrawal Ashish467dde42016-09-08 18:44:22 +05306780 }
6781
6782next_adapater:
6783 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
6784 adapter_node = next;
6785 }
6786}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006787/**
6788 * hdd_ch_avoid_cb() - Avoid notified channels from FW handler
6789 * @adapter: HDD adapter pointer
6790 * @indParam: Channel avoid notification parameter
6791 *
6792 * Avoid channel notification from FW handler.
6793 * FW will send un-safe channel list to avoid over wrapping.
6794 * hostapd should not use notified channel
6795 *
6796 * Return: None
6797 */
Agrawal Ashish467dde42016-09-08 18:44:22 +05306798void hdd_ch_avoid_cb(void *hdd_context, void *indi_param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006799{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800 hdd_context_t *hdd_ctxt;
6801 tSirChAvoidIndType *ch_avoid_indi;
6802 uint8_t range_loop;
Amar Singhalb8d4f152016-02-10 10:21:43 -08006803 enum channel_enum channel_loop, start_channel_idx = INVALID_CHANNEL,
6804 end_channel_idx = INVALID_CHANNEL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 uint16_t start_channel;
6806 uint16_t end_channel;
6807 v_CONTEXT_t cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006808 tHddAvoidFreqList hdd_avoid_freq_list;
6809 uint32_t i;
6810
6811 /* Basic sanity */
6812 if (!hdd_context || !indi_param) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006813 hdd_err("Invalid arguments");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814 return;
6815 }
6816
6817 hdd_ctxt = (hdd_context_t *) hdd_context;
6818 ch_avoid_indi = (tSirChAvoidIndType *) indi_param;
6819 cds_context = hdd_ctxt->pcds_context;
6820
6821 /* Make unsafe channel list */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006822 hdd_debug("band count %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823 ch_avoid_indi->avoid_range_count);
6824
6825 /* generate vendor specific event */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306826 qdf_mem_zero((void *)&hdd_avoid_freq_list, sizeof(tHddAvoidFreqList));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827 for (i = 0; i < ch_avoid_indi->avoid_range_count; i++) {
6828 hdd_avoid_freq_list.avoidFreqRange[i].startFreq =
6829 ch_avoid_indi->avoid_freq_range[i].start_freq;
6830 hdd_avoid_freq_list.avoidFreqRange[i].endFreq =
6831 ch_avoid_indi->avoid_freq_range[i].end_freq;
6832 }
6833 hdd_avoid_freq_list.avoidFreqRangeCount =
6834 ch_avoid_indi->avoid_range_count;
6835
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006836 /* clear existing unsafe channel cache */
6837 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306838 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006839 sizeof(hdd_ctxt->unsafe_channel_list));
6840
6841 for (range_loop = 0; range_loop < ch_avoid_indi->avoid_range_count;
6842 range_loop++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -08006843 if (hdd_ctxt->unsafe_channel_count >= NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006844 hdd_warn("LTE Coex unsafe channel list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006845 break;
6846 }
6847
6848 start_channel = ieee80211_frequency_to_channel(
6849 ch_avoid_indi->avoid_freq_range[range_loop].start_freq);
6850 end_channel = ieee80211_frequency_to_channel(
6851 ch_avoid_indi->avoid_freq_range[range_loop].end_freq);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006852 hdd_debug("start %d : %d, end %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006853 ch_avoid_indi->avoid_freq_range[range_loop].start_freq,
6854 start_channel,
6855 ch_avoid_indi->avoid_freq_range[range_loop].end_freq,
6856 end_channel);
6857
6858 /* do not process frequency bands that are not mapped to
6859 * predefined channels
6860 */
6861 if (start_channel == 0 || end_channel == 0)
6862 continue;
6863
Amar Singhalb8d4f152016-02-10 10:21:43 -08006864 for (channel_loop = CHAN_ENUM_1; channel_loop <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006865 CHAN_ENUM_184; channel_loop++) {
6866 if (WLAN_REG_CH_TO_FREQ(channel_loop) >=
6867 ch_avoid_indi->avoid_freq_range[
6868 range_loop].start_freq) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869 start_channel_idx = channel_loop;
6870 break;
6871 }
6872 }
Amar Singhalb8d4f152016-02-10 10:21:43 -08006873 for (channel_loop = CHAN_ENUM_1; channel_loop <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006874 CHAN_ENUM_184; channel_loop++) {
6875 if (WLAN_REG_CH_TO_FREQ(channel_loop) >=
6876 ch_avoid_indi->avoid_freq_range[
6877 range_loop].end_freq) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006878 end_channel_idx = channel_loop;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006879 if (WLAN_REG_CH_TO_FREQ(channel_loop) >
6880 ch_avoid_indi->avoid_freq_range[
6881 range_loop].end_freq)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 end_channel_idx--;
6883 break;
6884 }
6885 }
6886
Amar Singhalb8d4f152016-02-10 10:21:43 -08006887 if (start_channel_idx == INVALID_CHANNEL ||
6888 end_channel_idx == INVALID_CHANNEL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889 continue;
6890
6891 for (channel_loop = start_channel_idx; channel_loop <=
6892 end_channel_idx; channel_loop++) {
6893 hdd_ctxt->unsafe_channel_list[
Amar Singhal7a1726a2015-10-14 16:28:11 -07006894 hdd_ctxt->unsafe_channel_count++] =
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006895 WLAN_REG_CH_NUM(channel_loop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 if (hdd_ctxt->unsafe_channel_count >=
Amar Singhalb8d4f152016-02-10 10:21:43 -08006897 NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07006898 hdd_warn("LTECoex unsafe ch list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006899 break;
6900 }
6901 }
6902 }
6903
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006904 hdd_debug("number of unsafe channels is %d ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006905 hdd_ctxt->unsafe_channel_count);
6906
Yuanyuan Liu13738502016-04-06 17:41:37 -07006907 if (pld_set_wlan_unsafe_channel(hdd_ctxt->parent_dev,
6908 hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909 hdd_ctxt->unsafe_channel_count)) {
6910 hdd_err("Failed to set unsafe channel");
6911
6912 /* clear existing unsafe channel cache */
6913 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306914 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915 sizeof(hdd_ctxt->unsafe_channel_list));
6916
6917 return;
6918 }
6919
6920 for (channel_loop = 0;
6921 channel_loop < hdd_ctxt->unsafe_channel_count; channel_loop++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006922 hdd_debug("channel %d is not safe ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923 hdd_ctxt->unsafe_channel_list[channel_loop]);
6924 }
6925
Kondabattini, Ganeshcf7b60f2016-08-10 16:31:55 +05306926 /*
6927 * first update the unsafe channel list to the platform driver and
6928 * send the avoid freq event to the application
6929 */
6930 wlan_hdd_send_avoid_freq_event(hdd_ctxt, &hdd_avoid_freq_list);
6931
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306932 if (!hdd_ctxt->unsafe_channel_count) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006933 hdd_debug("no unsafe channels - not restarting SAP");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306934 return;
6935 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05306936 hdd_unsafe_channel_restart_sap(hdd_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006937}
6938
6939/**
6940 * hdd_init_channel_avoidance() - Initialize channel avoidance
6941 * @hdd_ctx: HDD global context
6942 *
6943 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07006944 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945 * down to the lower layers. Then subscribe to subsequent channel
6946 * avoidance events.
6947 *
6948 * Return: None
6949 */
6950static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6951{
6952 uint16_t unsafe_channel_count;
6953 int index;
6954
Yuanyuan Liu13738502016-04-06 17:41:37 -07006955 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
6956 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006957 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08006958 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006959
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006960 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006961 hdd_ctx->unsafe_channel_count);
6962
Anurag Chouhan6d760662016-02-20 16:05:43 +05306963 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08006964 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965
6966 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006967 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006968 hdd_ctx->unsafe_channel_list[index]);
6969
6970 }
6971
6972 /* Plug in avoid channel notification callback */
6973 sme_add_ch_avoid_callback(hdd_ctx->hHal, hdd_ch_avoid_cb);
6974}
6975#else
6976static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
6977{
6978}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006979static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980{
6981}
Yuanyuan Liu13738502016-04-06 17:41:37 -07006982#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983
6984/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08006985 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
6986 * user space
6987 * @frame_ind: Management frame data to be informed.
6988 *
6989 * This function is used to indicate management frame to
6990 * user space
6991 *
6992 * Return: None
6993 *
6994 */
6995void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
6996{
6997 hdd_context_t *hdd_ctx = NULL;
6998 hdd_adapter_t *adapter = NULL;
6999 void *cds_context = NULL;
7000 int i;
7001
7002 /* Get the global VOSS context.*/
7003 cds_context = cds_get_global_context();
7004 if (!cds_context) {
7005 hdd_err("Global CDS context is Null");
7006 return;
7007 }
7008 /* Get the HDD context.*/
7009 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
7010
7011 if (0 != wlan_hdd_validate_context(hdd_ctx))
7012 return;
7013
7014 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7015 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7016 adapter =
7017 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7018 if (adapter)
7019 break;
7020 }
7021 } else {
7022 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7023 frame_ind->sessionId);
7024 }
7025
7026 if ((NULL != adapter) &&
7027 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7028 __hdd_indicate_mgmt_frame(adapter,
7029 frame_ind->frame_len,
7030 frame_ind->frameBuf,
7031 frame_ind->frameType,
7032 frame_ind->rxChan,
7033 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007034}
7035
Kapil Gupta8878ad92017-02-13 11:56:04 +05307036static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
7037 hdd_context_t *hdd_ctx)
7038{
7039 uint8_t restart_chan = 0;
7040
7041 restart_chan =
7042 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7043 if (!restart_chan) {
7044 hdd_alert("fail to restart SAP");
7045 } else {
7046 /* SAP restart due to unsafe channel. While restarting
7047 * the SAP, make sure to clear acs_channel, channel to
7048 * reset to 0. Otherwise these settings will override
7049 * the ACS while restart.
7050 */
7051 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7052 adapter->sessionCtx.ap.sapConfig.channel =
7053 AUTO_CHANNEL_SELECT;
7054 hdd_info("sending coex indication");
7055 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7056 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007057 hdd_switch_sap_channel(adapter, restart_chan);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307058 }
7059}
7060
7061void hdd_acs_response_timeout_handler(void *context)
7062{
7063 struct hdd_external_acs_timer_context *timer_context =
7064 (struct hdd_external_acs_timer_context *)context;
7065 hdd_adapter_t *adapter;
7066 hdd_context_t *hdd_ctx;
7067 uint8_t reason;
7068
7069 ENTER();
7070 if (!timer_context) {
7071 hdd_err("invlaid timer context");
7072 return;
7073 }
7074 adapter = timer_context->adapter;
7075 reason = timer_context->reason;
7076
7077
7078 if ((!adapter) ||
7079 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7080 hdd_err("invalid adapter or adapter has invalid magic");
7081 return;
7082 }
7083 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7084 if (wlan_hdd_validate_context(hdd_ctx))
7085 return;
7086
7087 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7088 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7089 else
7090 return;
7091
7092 hdd_err("ACS timeout happened for %s reason %d",
7093 adapter->dev->name, reason);
7094 switch (reason) {
7095 /* SAP init case */
7096 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7097 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7098 false);
7099 wlan_hdd_cfg80211_start_acs(adapter);
7100 break;
7101 /* DFS detected on current channel */
7102 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7103 wlan_sap_update_next_channel(
7104 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7105 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7106 adapter->sessionId);
7107 break;
7108 /* LTE coex event on current channel */
7109 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7110 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7111 break;
7112 default:
7113 hdd_info("invalid reason for timer invoke");
7114
7115 }
7116}
7117
Rajeev Kumard004abc2016-02-17 12:09:56 -08007118/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007119 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7120 * @hdd_ctx: HDD context
7121 *
7122 * Disables all the dual mac features like DBS, Agile DFS etc.
7123 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307124 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307126static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007127{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007128 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307129 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130
7131 if (!hdd_ctx) {
7132 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307133 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007134 }
7135
7136 cfg.scan_config = 0;
7137 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007138 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007139
7140 hdd_debug("Disabling all dual mac features...");
7141
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007142 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307143 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007144 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7145 return status;
7146 }
7147
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307148 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149}
7150
7151/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007152 * hdd_override_ini_config - Override INI config
7153 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007155 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007156 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007157 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007158 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007159static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007160{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007162 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7163 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007164 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007165 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007166 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007167 if (0 == enable_11d || 1 == enable_11d) {
7168 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007169 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007170 }
Leo Chang11545d62016-10-17 14:53:50 -07007171
7172 if (!hdd_ipa_is_present(hdd_ctx))
7173 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007174}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007176/**
7177 * hdd_set_trace_level_for_each - Set trace level for each INI config
7178 * @hdd_ctx - HDD context
7179 *
7180 * Set trace level for each module based on INI config.
7181 *
7182 * Return: None
7183 */
7184static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
7185{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307186 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7187 hdd_ctx->config->qdf_trace_enable_wdi);
7188 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7189 hdd_ctx->config->qdf_trace_enable_hdd);
7190 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7191 hdd_ctx->config->qdf_trace_enable_sme);
7192 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7193 hdd_ctx->config->qdf_trace_enable_pe);
7194 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7195 hdd_ctx->config->qdf_trace_enable_wma);
7196 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7197 hdd_ctx->config->qdf_trace_enable_sys);
7198 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7199 hdd_ctx->config->qdf_trace_enable_qdf);
7200 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7201 hdd_ctx->config->qdf_trace_enable_sap);
7202 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7203 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7204 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7205 hdd_ctx->config->qdf_trace_enable_bmi);
7206 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7207 hdd_ctx->config->qdf_trace_enable_cfg);
7208 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7209 hdd_ctx->config->qdf_trace_enable_epping);
7210 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7211 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7212 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05307213 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307214 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7215 hdd_ctx->config->qdf_trace_enable_htc);
7216 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7217 hdd_ctx->config->qdf_trace_enable_hif);
7218 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7219 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7220 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7221 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007222 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7223 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007224 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7225 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007226 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7227 hdd_ctx->config->qdf_trace_enable_regulatory);
7228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007230}
7231
7232/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007233 * hdd_context_init() - Initialize HDD context
7234 * @hdd_ctx: HDD context.
7235 *
7236 * Initialize HDD context along with all the feature specific contexts.
7237 *
7238 * return: 0 on success and errno on failure.
7239 */
7240static int hdd_context_init(hdd_context_t *hdd_ctx)
7241{
7242 int ret;
7243
7244 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7245 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7246
7247 hdd_init_ll_stats_ctx();
7248
7249 init_completion(&hdd_ctx->mc_sus_event_var);
7250 init_completion(&hdd_ctx->ready_to_suspend);
7251
7252 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307253 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007254 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307255
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007256 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7257
7258 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7259
7260 ret = hdd_scan_context_init(hdd_ctx);
7261 if (ret)
7262 goto list_destroy;
7263
Nitesh Shahd1266d72017-01-25 22:07:07 +05307264 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007265
7266 hdd_rx_wake_lock_create(hdd_ctx);
7267
7268 ret = hdd_sap_context_init(hdd_ctx);
7269 if (ret)
7270 goto scan_destroy;
7271
7272 ret = hdd_roc_context_init(hdd_ctx);
7273 if (ret)
7274 goto sap_destroy;
7275
7276 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7277
7278 hdd_init_offloaded_packets_ctx(hdd_ctx);
7279
7280 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7281 hdd_ctx->config);
7282 if (ret)
7283 goto roc_destroy;
7284
7285 return 0;
7286
7287roc_destroy:
7288 hdd_roc_context_destroy(hdd_ctx);
7289
7290sap_destroy:
7291 hdd_sap_context_destroy(hdd_ctx);
7292
7293scan_destroy:
7294 hdd_scan_context_destroy(hdd_ctx);
7295 hdd_rx_wake_lock_destroy(hdd_ctx);
7296 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007297list_destroy:
7298 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007299
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007300 return ret;
7301}
7302
7303/**
7304 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307305 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007306 *
7307 * Allocate and initialize HDD context. HDD context is allocated as part of
7308 * wiphy allocation and then context is initialized.
7309 *
7310 * Return: HDD context on success and ERR_PTR on failure
7311 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007312static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007313{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307314 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007315 int ret = 0;
7316 hdd_context_t *hdd_ctx;
7317 v_CONTEXT_t p_cds_context;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307318 int qdf_print_idx = -1;
7319
7320 struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
7321 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
7322 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
7323 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
7324 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
7325 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
7326 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
7327 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
7328 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
7329 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
7330 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
7331 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
7332 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7333 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7334 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
7335 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
7336 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
7337 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
7338 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
7339 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
7340 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiyaf928edf2017-02-06 14:43:24 +05307341 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
7342 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
7343 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
7344 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
7345 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
7346 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
Mukul Sharma4d7d6b02017-02-13 20:45:22 +05307347 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh9679dbf2017-02-15 11:35:41 +05307348 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
Tushnim Bhattacharyya6796d8d2017-03-17 11:06:03 -07007349 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
7350 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
Wu Gao9a704f42017-03-10 18:42:11 +08007351 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
Frank Liud4b2fa02017-03-29 11:46:48 +08007352 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007353 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307354 };
7355
7356 status = qdf_print_setup();
7357 if (status != QDF_STATUS_SUCCESS) {
7358 pr_err("QDF print control object setup failed\n");
7359 ret = -EINVAL;
7360 goto err_out;
7361 }
7362 /* Register the module here with QDF */
7363 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL,
7364 "MCL_WLAN");
7365
7366 /* if qdf_print_idx is negative */
7367 if (qdf_print_idx < 0) {
7368 pr_err("QDF print control can not be registered %d\n",
7369 qdf_print_idx);
7370 ret = -EINVAL;
7371 goto err_out;
7372 }
7373
7374 /* Store the qdf_pidx information into qdf module */
7375 qdf_set_pidx(qdf_print_idx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007376
7377 ENTER();
7378
7379 p_cds_context = cds_get_global_context();
7380 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007381 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007382 ret = -EINVAL;
7383 goto err_out;
7384 }
7385
7386 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
7387
7388 if (hdd_ctx == NULL) {
7389 ret = -ENOMEM;
7390 goto err_out;
7391 }
7392
7393 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007394 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307395 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007396
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307397 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007398 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007399 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007400 ret = -ENOMEM;
7401 goto err_free_hdd_context;
7402 }
7403
7404 /* Read and parse the qcom_cfg.ini file */
7405 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307406 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307407 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007408 WLAN_INI_FILE);
7409 ret = -EINVAL;
7410 goto err_free_config;
7411 }
7412
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007413 hdd_debug("Setting configuredMcastBcastFilter: %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007414 hdd_ctx->config->mcastBcastFilterSetting);
7415
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307416 if (hdd_ctx->config->fhostNSOffload)
7417 hdd_ctx->ns_offload_enable = true;
7418
Abhishek Singh5ea86532016-04-27 14:10:53 +05307419 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7420
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007421 hdd_override_ini_config(hdd_ctx);
7422
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007423 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007424
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007425 ret = hdd_context_init(hdd_ctx);
7426
7427 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007428 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007429
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007430
Yuanyuan Liu7a97b8f2017-01-27 10:42:52 -08007431 pld_set_fw_log_mode(hdd_ctx->parent_dev,
7432 hdd_ctx->config->enable_fw_log);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007433
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007434
7435 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307436 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007437
Anurag Chouhan6d760662016-02-20 16:05:43 +05307438 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007439 goto skip_multicast_logging;
7440
7441 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7442
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007443 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7444 if (ret)
7445 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307446
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007447 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7448 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307449 goto err_free_histogram;
7450
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007451skip_multicast_logging:
7452 hdd_set_trace_level_for_each(hdd_ctx);
7453
7454 return hdd_ctx;
7455
Nirav Shahed34b212016-04-25 10:59:16 +05307456err_free_histogram:
7457 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7458
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007459err_deinit_hdd_context:
7460 hdd_context_deinit(hdd_ctx);
7461
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007462err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307463 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007464
7465err_free_hdd_context:
7466 wiphy_free(hdd_ctx->wiphy);
7467
7468err_out:
7469 return ERR_PTR(ret);
7470}
7471
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007472#ifdef WLAN_OPEN_P2P_INTERFACE
7473/**
7474 * hdd_open_p2p_interface - Open P2P interface
7475 * @hdd_ctx: HDD context
7476 * @rtnl_held: True if RTNL lock held
7477 *
7478 * Open P2P interface during probe. This function called to open the P2P
7479 * interface at probe along with STA interface.
7480 *
7481 * Return: 0 on success and errno on failure
7482 */
7483static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7484{
7485 hdd_adapter_t *adapter;
7486 uint8_t *p2p_dev_addr;
7487
7488 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7489 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307490 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007491 hdd_ctx->config->intfMacAddr[0].bytes,
7492 sizeof(tSirMacAddr));
7493
7494 /*
7495 * Generate the P2P Device Address. This consists of
7496 * the device's primary MAC address with the locally
7497 * administered bit set.
7498 */
7499 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7500 } else {
7501 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7502 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007503 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007504 return -ENOSPC;
7505 }
7506
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307507 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307508 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007509 }
7510
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007511 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007512 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007513 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007514
7515 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007516 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007517 return -ENOSPC;
7518 }
7519
7520 return 0;
7521}
7522#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307523static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007524 bool rtnl_held)
7525{
7526 return 0;
7527}
7528#endif
7529
Jeff Johnson957bc272017-02-02 08:54:48 -08007530static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7531{
7532 hdd_adapter_t *adapter;
7533 int ret = 0;
7534
7535 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7536 wlan_hdd_get_intf_addr(hdd_ctx),
7537 NET_NAME_UNKNOWN, rtnl_held);
7538 if (adapter == NULL) {
7539 hdd_err("Failed to open 802.11p interface");
7540 ret = -ENOSPC;
7541 }
7542
7543 return ret;
7544}
7545
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007546/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307547 * hdd_start_station_adapter()- Start the Station Adapter
7548 * @adapter: HDD adapter
7549 *
7550 * This function initializes the adapter for the station mode.
7551 *
7552 * Return: 0 on success or errno on failure.
7553 */
7554int hdd_start_station_adapter(hdd_adapter_t *adapter)
7555{
7556 QDF_STATUS status;
7557
7558 ENTER_DEV(adapter->dev);
7559
7560 status = hdd_init_station_mode(adapter);
7561
7562 if (QDF_STATUS_SUCCESS != status) {
7563 hdd_err("Error Initializing station mode: %d", status);
7564 return qdf_status_to_os_return(status);
7565 }
7566
Arun Khandavallifae92942016-08-01 13:31:08 +05307567 hdd_register_tx_flow_control(adapter,
7568 hdd_tx_resume_timer_expired_handler,
7569 hdd_tx_resume_cb);
7570
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307571 EXIT();
7572 return 0;
7573}
7574
7575/**
7576 * hdd_start_ap_adapter()- Start AP Adapter
7577 * @adapter: HDD adapter
7578 *
7579 * This function initializes the adapter for the AP mode.
7580 *
7581 * Return: 0 on success errno on failure.
7582 */
7583int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7584{
7585 QDF_STATUS status;
7586
7587 ENTER();
7588
Arun Khandavallicc544b32017-01-30 19:52:16 +05307589 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307590
7591 if (QDF_STATUS_SUCCESS != status) {
7592 hdd_err("Error Initializing the AP mode: %d", status);
7593 return qdf_status_to_os_return(status);
7594 }
7595
Arun Khandavallifae92942016-08-01 13:31:08 +05307596 hdd_register_tx_flow_control(adapter,
7597 hdd_softap_tx_resume_timer_expired_handler,
7598 hdd_softap_tx_resume_cb);
7599
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307600 EXIT();
7601 return 0;
7602}
7603
7604/**
7605 * hdd_start_ftm_adapter()- Start FTM adapter
7606 * @adapter: HDD adapter
7607 *
7608 * This function initializes the adapter for the FTM mode.
7609 *
7610 * Return: 0 on success or errno on failure.
7611 */
7612int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7613{
7614 QDF_STATUS qdf_status;
7615
7616 ENTER_DEV(adapter->dev);
7617
7618 qdf_status = hdd_init_tx_rx(adapter);
7619
7620 if (QDF_STATUS_SUCCESS != qdf_status) {
7621 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7622 return qdf_status_to_os_return(qdf_status);
7623 }
7624
7625 return 0;
7626 EXIT();
7627}
7628
7629/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007630 * hdd_open_interfaces - Open all required interfaces
7631 * hdd_ctx: HDD context
7632 * rtnl_held: True if RTNL lock is held
7633 *
7634 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7635 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007636 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007637 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007638static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007639{
Jeff Johnson957bc272017-02-02 08:54:48 -08007640 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007641 int ret;
7642
Jeff Johnson957bc272017-02-02 08:54:48 -08007643 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307644 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007645 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007646
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007647 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007648 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007649 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007650
7651 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007652 return -ENOSPC;
7653
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007654 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7655 adapter->fast_roaming_allowed = true;
7656
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007657 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7658 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007659 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007660
7661 /* Open 802.11p Interface */
7662 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007663 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7664 if (ret)
7665 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007666 }
7667
Jeff Johnson957bc272017-02-02 08:54:48 -08007668 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007669
Jeff Johnson957bc272017-02-02 08:54:48 -08007670err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007671 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007672 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007673}
7674
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007675/**
7676 * hdd_update_country_code - Update country code
7677 * @hdd_ctx: HDD context
7678 * @adapter: Primary adapter context
7679 *
7680 * Update country code based on module parameter country_code at SME and wait
7681 * for the settings to take effect.
7682 *
7683 * Return: 0 on success and errno on failure
7684 */
7685static int hdd_update_country_code(hdd_context_t *hdd_ctx,
7686 hdd_adapter_t *adapter)
7687{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307688 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007689 int ret = 0;
7690 unsigned long rc;
7691
7692 if (country_code == NULL)
7693 return 0;
7694
7695 INIT_COMPLETION(adapter->change_country_code);
7696
7697 status = sme_change_country_code(hdd_ctx->hHal,
7698 wlan_hdd_change_country_code_callback,
7699 country_code, adapter,
7700 hdd_ctx->pcds_context, eSIR_TRUE,
7701 eSIR_TRUE);
7702
7703
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307704 if (!QDF_IS_STATUS_SUCCESS(status)) {
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007705 hdd_err("SME Change Country code from module param fail ret=%d",
7706 ret);
7707 return -EINVAL;
7708 }
7709
7710 rc = wait_for_completion_timeout(&adapter->change_country_code,
7711 msecs_to_jiffies(WLAN_WAIT_TIME_COUNTRY));
7712 if (!rc) {
7713 hdd_err("SME while setting country code timed out");
7714 ret = -ETIMEDOUT;
7715 }
7716
7717 return ret;
7718}
7719
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307720#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7721/**
7722 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7723 * @cds_cfg: CDS Configuration
7724 * @hdd_ctx: Pointer to hdd context
7725 *
7726 * Return: none
7727 */
7728static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7729 *cds_cfg,
7730 hdd_context_t *hdd_ctx)
7731{
7732 cds_cfg->tx_flow_stop_queue_th =
7733 hdd_ctx->config->TxFlowStopQueueThreshold;
7734 cds_cfg->tx_flow_start_queue_offset =
7735 hdd_ctx->config->TxFlowStartQueueOffset;
7736}
7737#else
7738static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7739 *cds_cfg,
7740 hdd_context_t *hdd_ctx)
7741{
7742}
7743#endif
7744
7745#ifdef FEATURE_WLAN_RA_FILTERING
7746/**
7747 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
7748 * @cds_cfg: CDS Configuration
7749 * @hdd_ctx: Pointer to hdd context
7750 *
7751 * Return: none
7752 */
Anand Kumar3b92a912016-12-05 12:01:26 +05307753static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307754 hdd_context_t *hdd_ctx)
7755{
7756 cds_cfg->ra_ratelimit_interval =
7757 hdd_ctx->config->RArateLimitInterval;
7758 cds_cfg->is_ra_ratelimit_enabled =
7759 hdd_ctx->config->IsRArateLimitEnabled;
7760}
7761#else
Anand Kumar3b92a912016-12-05 12:01:26 +05307762static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307763 hdd_context_t *hdd_ctx)
7764{
7765}
7766#endif
7767
7768/**
7769 * hdd_update_cds_config() - API to update cds configuration parameters
7770 * @hdd_ctx: HDD Context
7771 *
7772 * Return: 0 for Success, errno on failure
7773 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007774static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307775{
7776 struct cds_config_info *cds_cfg;
7777
7778 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
7779 if (!cds_cfg) {
7780 hdd_err("failed to allocate cds config");
7781 return -ENOMEM;
7782 }
7783
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307784 cds_cfg->driver_type = DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08007785 if (!hdd_ctx->config->nMaxPsPoll ||
7786 !hdd_ctx->config->enablePowersaveOffload) {
7787 cds_cfg->powersave_offload_enabled =
7788 hdd_ctx->config->enablePowersaveOffload;
7789 } else {
7790 if ((hdd_ctx->config->enablePowersaveOffload ==
7791 PS_QPOWER_NODEEPSLEEP) ||
7792 (hdd_ctx->config->enablePowersaveOffload ==
7793 PS_LEGACY_NODEEPSLEEP))
7794 cds_cfg->powersave_offload_enabled =
7795 PS_LEGACY_NODEEPSLEEP;
7796 else
7797 cds_cfg->powersave_offload_enabled =
7798 PS_LEGACY_DEEPSLEEP;
7799 hdd_info("Qpower disabled in cds config, %d",
7800 cds_cfg->powersave_offload_enabled);
7801 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307802 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
7803 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
7804 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
7805 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
7806 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
7807
7808 /* Here ol_ini_info is used to store ini status of arp offload
7809 * ns offload and others. Currently 1st bit is used for arp
7810 * off load and 2nd bit for ns offload currently, rest bits are unused
7811 */
7812 if (hdd_ctx->config->fhostArpOffload)
7813 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
7814 if (hdd_ctx->config->fhostNSOffload)
7815 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
7816
7817 /*
7818 * Copy the DFS Phyerr Filtering Offload status.
7819 * This parameter reflects the value of the
7820 * dfs_phyerr_filter_offload flag as set in the ini.
7821 */
7822 cds_cfg->dfs_phyerr_filter_offload =
7823 hdd_ctx->config->fDfsPhyerrFilterOffload;
7824 if (hdd_ctx->config->ssdp)
7825 cds_cfg->ssdp = hdd_ctx->config->ssdp;
7826
7827 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
7828 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
7829
7830 cds_cfg->ap_maxoffload_reorderbuffs =
7831 hdd_ctx->config->apMaxOffloadReorderBuffs;
7832
7833 cds_cfg->ap_disable_intrabss_fwd =
7834 hdd_ctx->config->apDisableIntraBssFwd;
7835
7836 cds_cfg->dfs_pri_multiplier =
7837 hdd_ctx->config->dfsRadarPriMultiplier;
7838 cds_cfg->reorder_offload =
7839 hdd_ctx->config->reorderOffloadSupport;
7840
7841 /* IPA micro controller data path offload resource config item */
7842 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07007843 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
7844 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007845 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07007846 hdd_ctx->config->IpaUcTxBufCount);
7847 hdd_ctx->config->IpaUcTxBufCount =
7848 rounddown_pow_of_two(
7849 hdd_ctx->config->IpaUcTxBufCount);
7850 if (!hdd_ctx->config->IpaUcTxBufCount) {
7851 hdd_err("Failed to round down IpaUcTxBufCount");
7852 return -EINVAL;
7853 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007854 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07007855 hdd_ctx->config->IpaUcTxBufCount);
7856 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307857 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
7858 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07007859 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
7860 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007861 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07007862 hdd_ctx->config->IpaUcRxIndRingCount);
7863 hdd_ctx->config->IpaUcRxIndRingCount =
7864 rounddown_pow_of_two(
7865 hdd_ctx->config->IpaUcRxIndRingCount);
7866 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
7867 hdd_err("Failed to round down IpaUcRxIndRingCount");
7868 return -EINVAL;
7869 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007870 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07007871 hdd_ctx->config->IpaUcRxIndRingCount);
7872 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307873 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07007874 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307875 cds_cfg->uc_tx_partition_base =
7876 hdd_ctx->config->IpaUcTxPartitionBase;
7877 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
7878
7879 cds_cfg->ip_tcp_udp_checksum_offload =
7880 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05307881 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307882 cds_cfg->ce_classify_enabled =
7883 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07007884 cds_cfg->bpf_packet_filter_enable =
7885 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307886 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
7887 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
7888 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07007889 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07007890 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07007891 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07007892 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05307893 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
7894 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307895
7896 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
7897 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
7898 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07007899 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307900 cds_init_ini_config(cds_cfg);
7901 return 0;
7902}
7903
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007904/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08007905 * hdd_update_user_config() - API to update user configuration
7906 * parameters to obj mgr which are used by multiple components
7907 * @hdd_ctx: HDD Context
7908 *
7909 * Return: 0 for Success, errno on failure
7910 */
7911static int hdd_update_user_config(hdd_context_t *hdd_ctx)
7912{
7913 struct wlan_objmgr_psoc_user_config *user_config;
7914
7915 user_config = qdf_mem_malloc(sizeof(*user_config));
7916 if (user_config == NULL) {
7917 hdd_alert("Failed to alloc memory for user_config!");
7918 return -ENOMEM;
7919 }
7920
7921 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
7922 user_config->dual_mac_feature_disable =
7923 hdd_ctx->config->dual_mac_feature_disable;
7924 user_config->indoor_channel_support =
7925 hdd_ctx->config->indoor_channel_support;
7926 user_config->is_11d_support_enabled =
7927 hdd_ctx->config->Is11dSupportEnabled;
7928 user_config->is_11h_support_enabled =
7929 hdd_ctx->config->Is11hSupportEnabled;
7930 user_config->optimize_chan_avoid_event =
7931 hdd_ctx->config->goptimize_chan_avoid_event;
7932 user_config->skip_dfs_chnl_in_p2p_search =
7933 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07007934 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08007935 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
7936
7937 qdf_mem_free(user_config);
7938 return 0;
7939}
7940
7941/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007942 * hdd_init_thermal_info - Initialize thermal level
7943 * @hdd_ctx: HDD context
7944 *
7945 * Initialize thermal level at SME layer and set the thermal level callback
7946 * which would be called when a configured thermal threshold is hit.
7947 *
7948 * Return: 0 on success and errno on failure
7949 */
7950static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
7951{
7952 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307953 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007954
7955 thermal_param.smeThermalMgmtEnabled =
7956 hdd_ctx->config->thermalMitigationEnable;
7957 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
7958
Poddar, Siddarth83905022016-04-16 17:56:08 -07007959 thermal_param.sme_throttle_duty_cycle_tbl[0] =
7960 hdd_ctx->config->throttle_dutycycle_level0;
7961 thermal_param.sme_throttle_duty_cycle_tbl[1] =
7962 hdd_ctx->config->throttle_dutycycle_level1;
7963 thermal_param.sme_throttle_duty_cycle_tbl[2] =
7964 hdd_ctx->config->throttle_dutycycle_level2;
7965 thermal_param.sme_throttle_duty_cycle_tbl[3] =
7966 hdd_ctx->config->throttle_dutycycle_level3;
7967
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007968 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
7969 hdd_ctx->config->thermalTempMinLevel0;
7970 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
7971 hdd_ctx->config->thermalTempMaxLevel0;
7972 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
7973 hdd_ctx->config->thermalTempMinLevel1;
7974 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
7975 hdd_ctx->config->thermalTempMaxLevel1;
7976 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
7977 hdd_ctx->config->thermalTempMinLevel2;
7978 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
7979 hdd_ctx->config->thermalTempMaxLevel2;
7980 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
7981 hdd_ctx->config->thermalTempMinLevel3;
7982 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
7983 hdd_ctx->config->thermalTempMaxLevel3;
7984
7985 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
7986
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307987 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05307988 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007989
7990 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
7991 hdd_set_thermal_level_cb);
7992
7993 return 0;
7994
7995}
7996
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007997#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
7998/**
7999 * hdd_hold_rtnl_lock - Hold RTNL lock
8000 *
8001 * Hold RTNL lock
8002 *
8003 * Return: True if held and false otherwise
8004 */
8005static inline bool hdd_hold_rtnl_lock(void)
8006{
8007 rtnl_lock();
8008 return true;
8009}
8010
8011/**
8012 * hdd_release_rtnl_lock - Release RTNL lock
8013 *
8014 * Release RTNL lock
8015 *
8016 * Return: None
8017 */
8018static inline void hdd_release_rtnl_lock(void)
8019{
8020 rtnl_unlock();
8021}
8022#else
8023static inline bool hdd_hold_rtnl_lock(void) { return false; }
8024static inline void hdd_release_rtnl_lock(void) { }
8025#endif
8026
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008027#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008028
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308029/* MAX iwpriv command support */
8030#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308031#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308032#define MAX_PKTLOG_SIZE 16
8033
8034/**
8035 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8036 * @hdd_ctx: hdd context
8037 * @set_value2: pktlog buffer size value
8038 *
8039 *
8040 * Return: 0 for success or error.
8041 */
8042static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
8043{
8044 struct sir_wifi_start_log start_log = { 0 };
8045 QDF_STATUS status;
8046
8047 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8048 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8049 start_log.ini_triggered = cds_is_packet_log_enabled();
8050 start_log.user_triggered = 1;
8051 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308052 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308053
8054 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8055 if (!QDF_IS_STATUS_SUCCESS(status)) {
8056 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8057 EXIT();
8058 return -EINVAL;
8059 }
8060
8061 return 0;
8062}
8063
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008064/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308065 * hdd_pktlog_clear_buff() - clear pktlog buffer
8066 * @hdd_ctx: hdd context
8067 *
8068 * Return: 0 for success or error.
8069 */
8070static int hdd_pktlog_clear_buff(hdd_context_t *hdd_ctx)
8071{
8072 struct sir_wifi_start_log start_log;
8073 QDF_STATUS status;
8074
8075 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8076 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8077 start_log.ini_triggered = cds_is_packet_log_enabled();
8078 start_log.user_triggered = 1;
8079 start_log.size = 0;
8080 start_log.is_pktlog_buff_clear = true;
8081
8082 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8083 if (!QDF_IS_STATUS_SUCCESS(status)) {
8084 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8085 EXIT();
8086 return -EINVAL;
8087 }
8088
8089 return 0;
8090}
8091
8092
8093/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008094 * hdd_process_pktlog_command() - process pktlog command
8095 * @hdd_ctx: hdd context
8096 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308097 * @set_value2: pktlog buffer size value
8098 *
8099 * This function process pktlog command.
8100 * set_value2 only matters when set_value is 3 (set buff size)
8101 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008102 *
8103 * Return: 0 for success or error.
8104 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308105int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
8106 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008107{
8108 int ret;
8109 bool enable;
8110 uint8_t user_triggered = 0;
8111
8112 ret = wlan_hdd_validate_context(hdd_ctx);
8113 if (0 != ret)
8114 return ret;
8115
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008116 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008117
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308118 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008119 hdd_err("invalid pktlog value %d", set_value);
8120 return -EINVAL;
8121 }
8122
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308123 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8124 if (set_value2 <= 0) {
8125 hdd_err("invalid pktlog size %d", set_value2);
8126 return -EINVAL;
8127 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8128 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8129 return -EINVAL;
8130 }
8131 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308132 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8133 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308134 }
8135
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008136 /*
8137 * set_value = 0 then disable packetlog
8138 * set_value = 1 enable packetlog forcefully
8139 * set_vlaue = 2 then disable packetlog if disabled through ini or
8140 * enable packetlog with AUTO type.
8141 */
8142 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8143 true : false;
8144
8145 if (1 == set_value) {
8146 enable = true;
8147 user_triggered = 1;
8148 }
8149
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308150 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008151}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008152/**
8153 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8154 * @hdd_ctx: HDD context
8155 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308156 * @user_triggered: triggered through iwpriv
8157 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008158 *
8159 * Return: 0 on success; error number otherwise
8160 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008161int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308162 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008163{
8164 struct sir_wifi_start_log start_log;
8165 QDF_STATUS status;
8166
8167 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8168 start_log.verbose_level =
8169 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008170 start_log.ini_triggered = cds_is_packet_log_enabled();
8171 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308172 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308173 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308174 /*
8175 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8176 * commands. Host uses this flag to decide whether to send pktlog
8177 * disable command to fw without sending pktlog enable command
8178 * previously. For eg, If vendor sends pktlog disable command without
8179 * sending pktlog enable command, then host discards the packet
8180 * but for iwpriv command, host will send it to fw.
8181 */
8182 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008183 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8184 if (!QDF_IS_STATUS_SUCCESS(status)) {
8185 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8186 EXIT();
8187 return -EINVAL;
8188 }
8189
8190 return 0;
8191}
8192#endif /* REMOVE_PKT_LOG */
8193
Komal Seelam92fff912016-03-24 11:51:41 +05308194/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008195 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8196 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308197 * @dev: Device Pointer
8198 * @num: Number of Valid Mac address
8199 *
8200 * Return: Pointer to MAC address buffer
8201 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008202static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8203 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308204{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008205 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308206}
Komal Seelam92fff912016-03-24 11:51:41 +05308207
8208/**
8209 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8210 * @hdd_ctx: HDD Context
8211 * @num: Number of random mac addresses needed
8212 *
8213 * Generate random addresses using bit manipulation on the base mac address
8214 *
8215 * Return: None
8216 */
8217static void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
8218{
8219 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8220 uint32_t iter;
8221 struct hdd_config *ini = hdd_ctx->config;
8222 uint8_t *buf = NULL;
8223 uint8_t macaddr_b3, tmp_br3;
8224 uint8_t *src = ini->intfMacAddr[0].bytes;
8225
8226 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8227 buf = ini->intfMacAddr[iter].bytes;
8228 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8229 macaddr_b3 = buf[3];
8230 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8231 INTF_MACADDR_MASK;
8232 macaddr_b3 += tmp_br3;
8233 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8234 buf[0] |= 0x02;
8235 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008236 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308237 }
8238}
8239
8240/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008241 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308242 * @hdd_ctx: HDD Context
8243 *
8244 * API to get mac addresses from platform driver and update the driver
8245 * structures and configure FW with the base mac address.
8246 * Return: int
8247 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008248static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308249{
8250 uint32_t no_of_mac_addr, iter;
8251 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8252 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8253 uint8_t *addr, *buf;
8254 struct device *dev = hdd_ctx->parent_dev;
8255 struct hdd_config *ini = hdd_ctx->config;
8256 tSirMacAddr mac_addr;
8257 QDF_STATUS status;
8258
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008259 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308260
8261 if (no_of_mac_addr == 0 || !addr) {
8262 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8263 return -EINVAL;
8264 }
8265
8266 if (no_of_mac_addr > max_mac_addr)
8267 no_of_mac_addr = max_mac_addr;
8268
8269 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8270
8271 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8272 buf = ini->intfMacAddr[iter].bytes;
8273 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008274 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308275 }
8276
8277 status = sme_set_custom_mac_addr(mac_addr);
8278
8279 if (!QDF_IS_STATUS_SUCCESS(status))
8280 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008281
Komal Seelam92fff912016-03-24 11:51:41 +05308282 if (no_of_mac_addr < max_mac_addr)
8283 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8284 no_of_mac_addr);
8285 return 0;
8286}
8287
8288/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008289 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8290 * @hdd_ctx: HDD Context
8291 *
8292 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8293 * will generate its own MAC and update it to FW.
8294 *
8295 * Return: 0 for success
8296 * Non-zero error code for failure
8297 */
8298static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
8299{
8300 tSirMacAddr customMacAddr;
8301 QDF_STATUS status;
8302
8303 qdf_mem_copy(&customMacAddr,
8304 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8305 sizeof(tSirMacAddr));
8306 status = sme_set_custom_mac_addr(customMacAddr);
8307 if (!QDF_IS_STATUS_SUCCESS(status))
8308 return -EAGAIN;
8309 return 0;
8310}
8311
8312/**
Komal Seelam92fff912016-03-24 11:51:41 +05308313 * hdd_initialize_mac_address() - API to get wlan mac addresses
8314 * @hdd_ctx: HDD Context
8315 *
8316 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8317 * is provisioned with mac addresses, driver uses it, else it will use
8318 * wlan_mac.bin to update HW MAC addresses.
8319 *
8320 * Return: None
8321 */
8322static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
8323{
8324 QDF_STATUS status;
8325 int ret;
8326
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008327 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308328 if (ret == 0)
8329 return;
8330
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008331 hdd_warn("Can't update mac config via platform driver ret: %d", ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308332
8333 status = hdd_update_mac_config(hdd_ctx);
8334
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008335 if (QDF_IS_STATUS_SUCCESS(status))
8336 return;
8337
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008338 hdd_warn("Can't update mac config via wlan_mac.bin, using MAC from ini file or auto-gen");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008339
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008340 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008341 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008342 if (ret != 0) {
8343 hdd_err("MAC address out-of-sync, ret:%d", ret);
8344 QDF_ASSERT(ret);
8345 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008346 }
Komal Seelam92fff912016-03-24 11:51:41 +05308347}
8348
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008349/**
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008350 * hdd_tsf_init() - Initialize the TSF synchronization interface
8351 * @hdd_ctx: HDD global context
8352 *
8353 * When TSF synchronization via GPIO is supported by the driver and
8354 * has been enabled in the configuration file, this function plumbs
8355 * the GPIO value down to firmware via SME.
8356 *
8357 * Return: None
8358 */
8359#ifdef WLAN_FEATURE_TSF
8360static void hdd_tsf_init(hdd_context_t *hdd_ctx)
8361{
8362 QDF_STATUS status;
8363
8364 if (hdd_ctx->config->tsf_gpio_pin == TSF_GPIO_PIN_INVALID)
8365 return;
8366
8367 status = sme_set_tsf_gpio(hdd_ctx->hHal,
8368 hdd_ctx->config->tsf_gpio_pin);
8369 if (!QDF_IS_STATUS_SUCCESS(status))
8370 hdd_err("Set tsf GPIO failed, status: %d", status);
8371}
8372#else
8373static void hdd_tsf_init(hdd_context_t *hdd_ctx)
8374{
8375}
8376#endif
8377
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008378static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
8379{
8380 int vdev_id = 0;
8381 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8382 int value = hdd_ctx->config->smart_chainmask_enabled;
8383 int vpdev = PDEV_CMD;
8384 int ret;
8385
8386 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
8387 if (ret)
8388 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8389
8390 return ret;
8391}
8392
8393static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
8394{
8395 int vdev_id = 0;
8396 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8397 int value = hdd_ctx->config->alternative_chainmask_enabled;
8398 int vpdev = PDEV_CMD;
8399 int ret;
8400
8401 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
8402 if (ret)
8403 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8404 ret);
8405
8406 return ret;
8407}
8408
Jeff Johnson12a744b2017-04-04 08:19:37 -07008409static int hdd_set_ani_enabled(hdd_context_t *hdd_ctx)
8410{
8411 int vdev_id = 0;
8412 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8413 int value = hdd_ctx->config->ani_enabled;
8414 int vpdev = PDEV_CMD;
8415 int ret;
8416
8417 ret = wma_cli_set_command(vdev_id, param_id, value, vpdev);
8418 if (ret)
8419 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8420
8421 return ret;
8422}
8423
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008424/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008425 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8426 * @hdd_ctx: HDD context
8427 *
8428 * Pre configurations to be done at lower layer before calling cds enable.
8429 *
8430 * Return: 0 on success and errno on failure.
8431 */
8432static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
8433{
8434 int ret;
8435 QDF_STATUS status;
8436 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008437 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008438
Leo Changfdb45c32016-10-28 11:09:23 -07008439 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008440 /*
8441 * Set 802.11p config
8442 * TODO-OCB: This has been temporarily added here to ensure this
8443 * parameter is set in CSR when we init the channel list. This should
8444 * be removed once the 5.9 GHz channels are added to the regulatory
8445 * domain.
8446 */
8447 hdd_set_dot11p_config(hdd_ctx);
8448
8449 /*
8450 * Note that the cds_pre_enable() sequence triggers the cfg download.
8451 * The cfg download must occur before we update the SME config
8452 * since the SME config operation must access the cfg database
8453 */
8454 status = hdd_set_sme_config(hdd_ctx);
8455
8456 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008457 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008458 ret = qdf_status_to_os_return(status);
8459 goto out;
8460 }
8461
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008462 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8463 if (QDF_STATUS_SUCCESS != status) {
8464 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8465 ret = qdf_status_to_os_return(status);
8466 goto out;
8467 }
8468
Prashanth Bhatta07998752016-04-28 12:35:33 -07008469 ret = wma_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
8470 hdd_ctx->config->tx_chain_mask_1ss,
8471 PDEV_CMD);
8472 if (0 != ret) {
8473 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8474 goto out;
8475 }
8476
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008477 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8478 if (ret)
8479 goto out;
8480
8481 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8482 if (ret)
8483 goto out;
8484
Jeff Johnson12a744b2017-04-04 08:19:37 -07008485 ret = hdd_set_ani_enabled(hdd_ctx);
8486 if (ret)
8487 goto out;
8488
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008489 ret = wma_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
8490 hdd_ctx->config->arp_ac_category,
8491 PDEV_CMD);
8492 if (0 != ret) {
8493 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8494 hdd_ctx->config->arp_ac_category, ret);
8495 goto out;
8496 }
8497
8498
Prashanth Bhatta07998752016-04-28 12:35:33 -07008499 status = hdd_set_sme_chan_list(hdd_ctx);
8500 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008501 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008502 ret = qdf_status_to_os_return(status);
8503 goto out;
8504 }
8505
8506 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008507 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008508 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008509 ret = -EINVAL;
8510 goto out;
8511 }
8512
Prashanth Bhatta07998752016-04-28 12:35:33 -07008513 /*
8514 * Set the MAC Address Currently this is used by HAL to add self sta.
8515 * Remove this once self sta is added as part of session open.
8516 */
8517 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8518 hdd_ctx->config->intfMacAddr[0].bytes,
8519 sizeof(hdd_ctx->config->intfMacAddr[0]));
8520
8521 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8522 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8523 hal_status, hal_status);
8524 ret = -EINVAL;
8525 goto out;
8526 }
8527
8528 hdd_init_channel_avoidance(hdd_ctx);
8529
8530out:
8531 return ret;
8532}
8533
8534/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008535 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8536 * @context_ptr - hdd context pointer
8537 * @event_ptr - event structure pointer
8538 *
8539 * This is the p2p listen offload stop event handler, it sends vendor
8540 * event back to supplicant to notify the stop reason.
8541 *
8542 * Return: None
8543 */
8544static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8545 void *event_ptr)
8546{
8547 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8548 struct sir_p2p_lo_event *evt = event_ptr;
8549 struct sk_buff *vendor_event;
8550
8551 ENTER();
8552
8553 if (hdd_ctx == NULL) {
8554 hdd_err("Invalid HDD context pointer");
8555 return;
8556 }
8557
8558 vendor_event =
8559 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
8560 NULL, sizeof(uint32_t) + NLMSG_HDRLEN,
8561 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8562 GFP_KERNEL);
8563
8564 if (!vendor_event) {
8565 hdd_err("cfg80211_vendor_event_alloc failed");
8566 return;
8567 }
8568
8569 if (nla_put_u32(vendor_event,
8570 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8571 evt->reason_code)) {
8572 hdd_err("nla put failed");
8573 kfree_skb(vendor_event);
8574 return;
8575 }
8576
8577 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
8578}
8579
8580/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308581 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8582 * @hdd_ctx: HDD context
8583 *
8584 * This function sends the adaptive dwell time config configuration to the
8585 * firmware via WMA
8586 *
8587 * Return: 0 - success, < 0 - failure
8588 */
8589static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8590{
8591 QDF_STATUS status;
8592 struct adaptive_dwelltime_params dwelltime_params;
8593
8594 dwelltime_params.is_enabled =
8595 hdd_ctx->config->adaptive_dwell_mode_enabled;
8596 dwelltime_params.dwelltime_mode =
8597 hdd_ctx->config->global_adapt_dwelltime_mode;
8598 dwelltime_params.lpf_weight =
8599 hdd_ctx->config->adapt_dwell_lpf_weight;
8600 dwelltime_params.passive_mon_intval =
8601 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8602 dwelltime_params.wifi_act_threshold =
8603 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8604
8605 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8606 &dwelltime_params);
8607
8608 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8609 if (!QDF_IS_STATUS_SUCCESS(status)) {
8610 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8611 return -EAGAIN;
8612 }
8613 return 0;
8614}
8615
Arun Khandavallid4349a92016-07-25 11:10:43 +05308616#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8617/**
8618 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8619 * @hdd_ctx: HDD context
8620 *
8621 * Set auto shutdown callback to get indications from firmware to indicate
8622 * userspace to shutdown WLAN after a configured amount of inactivity.
8623 *
8624 * Return: 0 on success and errno on failure.
8625 */
8626static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8627{
8628 QDF_STATUS status;
8629
8630 if (!hdd_ctx->config->WlanAutoShutdown)
8631 return 0;
8632
8633 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8634 wlan_hdd_auto_shutdown_cb);
8635 if (status != QDF_STATUS_SUCCESS)
8636 hdd_err("Auto shutdown feature could not be enabled: %d",
8637 status);
8638
8639 return qdf_status_to_os_return(status);
8640}
8641#else
8642static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8643{
8644 return 0;
8645}
8646#endif
8647
8648/**
8649 * hdd_features_init() - Init features
8650 * @hdd_ctx: HDD context
8651 * @adapter: Primary adapter context
8652 *
8653 * Initialize features and their feature context after WLAN firmware is up.
8654 *
8655 * Return: 0 on success and errno on failure.
8656 */
8657static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8658{
8659 tSirTxPowerLimit hddtxlimit;
8660 QDF_STATUS status;
8661 int ret;
8662
8663 ENTER();
8664
8665 ret = hdd_update_country_code(hdd_ctx, adapter);
8666 if (ret) {
8667 hdd_err("Failed to update country code: %d", ret);
8668 goto out;
8669 }
8670
8671 /* FW capabilities received, Set the Dot11 mode */
8672 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008673 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8674 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308675
Arun Khandavallid4349a92016-07-25 11:10:43 +05308676
8677 if (hdd_ctx->config->fIsImpsEnabled)
8678 hdd_set_idle_ps_config(hdd_ctx, true);
8679 else
8680 hdd_set_idle_ps_config(hdd_ctx, false);
8681
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308682 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008683 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308684
Arun Khandavallid4349a92016-07-25 11:10:43 +05308685 if (hdd_lro_init(hdd_ctx))
8686 hdd_err("Unable to initialize LRO in fw");
8687
8688 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8689 hdd_err("Unable to send adaptive dwelltime setting to FW");
8690
8691 ret = hdd_init_thermal_info(hdd_ctx);
8692 if (ret) {
8693 hdd_err("Error while initializing thermal information");
8694 goto deregister_frames;
8695 }
8696
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308697 if (cds_is_packet_log_enabled())
8698 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8699
Arun Khandavallid4349a92016-07-25 11:10:43 +05308700 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
8701 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
8702 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
8703 if (!QDF_IS_STATUS_SUCCESS(status))
8704 hdd_err("Error setting txlimit in sme: %d", status);
8705
8706 hdd_tsf_init(hdd_ctx);
8707
Arun Khandavallid4349a92016-07-25 11:10:43 +05308708 ret = hdd_register_cb(hdd_ctx);
8709 if (ret) {
8710 hdd_err("Failed to register HDD callbacks!");
8711 goto deregister_frames;
8712 }
8713
8714 if (hdd_ctx->config->dual_mac_feature_disable) {
8715 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
8716 if (status != QDF_STATUS_SUCCESS) {
8717 hdd_err("Failed to disable dual mac features");
8718 goto deregister_cb;
8719 }
8720 }
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05308721 if (hdd_ctx->config->goptimize_chan_avoid_event) {
8722 status = sme_enable_disable_chanavoidind_event(
8723 hdd_ctx->hHal, 0);
8724 if (!QDF_IS_STATUS_SUCCESS(status)) {
8725 hdd_err("Failed to disable Chan Avoidance Indication");
8726 goto deregister_cb;
8727 }
8728 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05308729
8730 /* register P2P Listen Offload event callback */
8731 if (wma_is_p2p_lo_capable())
8732 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
8733 wlan_hdd_p2p_lo_event_callback);
8734
8735 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
8736
8737 if (ret)
8738 goto deregister_cb;
8739
8740 EXIT();
8741 return 0;
8742
8743deregister_cb:
8744 hdd_deregister_cb(hdd_ctx);
8745deregister_frames:
8746 wlan_hdd_cfg80211_deregister_frames(adapter);
8747out:
8748 return -EINVAL;
8749
8750}
8751
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308752#ifdef NAPIER_SCAN
8753/**
8754 *
8755 * hdd_post_cds_enable_config() - HDD post cds start config helper
8756 * @adapter - Pointer to the HDD
8757 *
8758 * Return: None
8759 */
8760static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8761{
8762 QDF_STATUS status;
8763
8764 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
8765 wlan_cfg80211_inform_bss_frame,
8766 SCAN_CB_TYPE_INFORM_BCN);
8767 if (!QDF_IS_STATUS_SUCCESS(status)) {
8768 hdd_err("failed with status code %08d [x%08x]",
8769 status, status);
8770 return status;
8771 }
8772
8773 return QDF_STATUS_SUCCESS;
8774}
8775#else
8776static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
8777{
8778 return QDF_STATUS_SUCCESS;
8779}
8780
8781#endif
Arun Khandavallid4349a92016-07-25 11:10:43 +05308782
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308783/**
Arun Khandavallifae92942016-08-01 13:31:08 +05308784 * hdd_configure_cds() - Configure cds modules
8785 * @hdd_ctx: HDD context
8786 * @adapter: Primary adapter context
8787 *
8788 * Enable Cds modules after WLAN firmware is up.
8789 *
8790 * Return: 0 on success and errno on failure.
8791 */
8792int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8793{
8794 int ret;
8795 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05308796
8797 ret = hdd_pre_enable_configure(hdd_ctx);
8798 if (ret) {
8799 hdd_err("Failed to pre-configure cds");
8800 goto out;
8801 }
8802
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08008803 /* Always get latest IPA resources allocated from cds_open and configure
8804 * IPA module before configuring them to FW. Sequence required as crash
8805 * observed otherwise.
8806 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08008807 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
8808 hdd_err("Failed to setup pipes");
8809 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08008810 }
8811
Arun Khandavallifae92942016-08-01 13:31:08 +05308812 /*
8813 * Start CDS which starts up the SME/MAC/HAL modules and everything
8814 * else
8815 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308816 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308817
8818 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008819 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05308820 goto out;
8821 }
8822
8823 status = hdd_post_cds_enable_config(hdd_ctx);
8824 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008825 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008826 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308827 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05308828 status = hdd_register_bcn_cb(hdd_ctx);
8829 if (!QDF_IS_STATUS_SUCCESS(status)) {
8830 hdd_alert("hdd_post_cds_enable_config failed");
8831 goto cds_disable;
8832 }
Arun Khandavallifae92942016-08-01 13:31:08 +05308833
8834 ret = hdd_features_init(hdd_ctx, adapter);
8835 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008836 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05308837
Arun Khandavallifae92942016-08-01 13:31:08 +05308838
8839 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008840
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008841cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308842 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07008843
Arun Khandavallifae92942016-08-01 13:31:08 +05308844out:
8845 return -EINVAL;
8846}
8847
8848/**
8849 * hdd_deconfigure_cds() -De-Configure cds
8850 * @hdd_ctx: HDD context
8851 *
8852 * Deconfigure Cds modules before WLAN firmware is down.
8853 *
8854 * Return: 0 on success and errno on failure.
8855 */
Jeff Johnson590e2012016-10-05 16:16:24 -07008856static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05308857{
8858 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07008859 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05308860
8861 ENTER();
8862 /* De-register the SME callbacks */
8863 hdd_deregister_cb(hdd_ctx);
8864
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308865 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308866 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8867 hdd_err("Failed to Disable the CDS Modules! :%d",
8868 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07008869 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308870 }
8871
8872 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07008873 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05308874}
8875
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07008876#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
8877static void hdd_deregister_policy_manager_callback(
8878 struct wlan_objmgr_psoc *psoc)
8879{
8880 if (QDF_STATUS_SUCCESS !=
8881 policy_mgr_deregister_hdd_cb(psoc)) {
8882 hdd_err("HDD callback deregister with policy manager failed");
8883 }
8884}
8885#else
8886static void hdd_deregister_policy_manager_callback(
8887 struct wlan_objmgr_psoc *psoc)
8888{
8889}
8890#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05308891
8892/**
8893 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
8894 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07008895 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05308896 *
8897 * This function maintains the driver state machine it will be invoked from
8898 * exit, shutdown and con_mode change handler. Depending on the driver state
8899 * shall perform the stopping/closing of the modules.
8900 *
8901 * Return: 0 for success; non-zero for failure
8902 */
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07008903int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05308904{
8905 void *hif_ctx;
8906 qdf_device_t qdf_ctx;
8907 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308908 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07008909 bool is_idle_stop = !cds_is_driver_unloading() &&
8910 !cds_is_driver_recovering();
8911 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05308912
8913 ENTER();
8914
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07008915 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
8916
Arun Khandavallifae92942016-08-01 13:31:08 +05308917 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
8918 if (!qdf_ctx) {
8919 hdd_err("QDF device context NULL");
8920 return -EINVAL;
8921 }
8922
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308923 mutex_lock(&hdd_ctx->iface_change_lock);
8924 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05308925
Dustin Brown70111822017-03-30 15:31:40 -07008926 active_threads = cds_return_external_threads_count();
8927 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07008928 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07008929 active_threads, hdd_ctx->isWiphySuspended);
8930
8931 cds_print_external_threads();
8932
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07008933 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07008934 mutex_unlock(&hdd_ctx->iface_change_lock);
8935 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07008936 hdd_ctx->config->iface_change_wait_time);
8937 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07008938 return 0;
8939 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07008940 }
8941
Arun Khandavallifae92942016-08-01 13:31:08 +05308942 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
8943
8944 switch (hdd_ctx->driver_status) {
8945 case DRIVER_MODULES_UNINITIALIZED:
8946 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308947 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308948 case DRIVER_MODULES_CLOSED:
8949 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308950 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308951 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05308952 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05308953 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008954 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05308955 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308956 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308957 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008958 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05308959 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
8960 break;
8961 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008962 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05308963 break;
8964 default:
8965 hdd_err("Trying to stop wlan in a wrong state: %d",
8966 hdd_ctx->driver_status);
8967 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308968 ret = -EINVAL;
8969 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05308970 }
8971
Govind Singhb048e872016-09-27 22:07:43 +05308972 qdf_status = cds_post_disable(hdd_ctx->pcds_context);
8973 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
8974 hdd_err("Failed to process post CDS disable Modules! :%d",
8975 qdf_status);
8976 ret = -EINVAL;
8977 QDF_ASSERT(0);
8978 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05308979 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05308980 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008981 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05308982 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308983 QDF_ASSERT(0);
8984 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07008985
Arun Khandavallifae92942016-08-01 13:31:08 +05308986 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
8987 if (!hif_ctx) {
8988 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05308989 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05308990 }
8991
8992 hdd_hif_close(hif_ctx);
8993
8994 ol_cds_free();
8995
Dustin Brown70111822017-03-30 15:31:40 -07008996 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308997 ret = pld_power_off(qdf_ctx->dev);
8998 if (ret)
8999 hdd_err("CNSS power down failed put device into Low power mode:%d",
9000 ret);
9001 }
9002 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009003 /*
9004 * Reset total mac phy during module stop such that during
9005 * next module start same psoc is used to populate new service
9006 * ready data
9007 */
9008 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309009
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309010done:
9011 hdd_ctx->stop_modules_in_progress = false;
9012 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309013 EXIT();
9014
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309015 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309016
9017}
9018
9019/**
9020 * hdd_iface_change_callback() - Function invoked when stop modules expires
9021 * @priv: pointer to hdd context
9022 *
9023 * This function is invoked when the timer waiting for the interface change
9024 * expires, it shall cut-down the power to wlan and stop all the modules.
9025 *
9026 * Return: void
9027 */
9028static void hdd_iface_change_callback(void *priv)
9029{
9030 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
9031 int ret;
9032 int status = wlan_hdd_validate_context(hdd_ctx);
9033
9034 if (status)
9035 return;
9036
9037 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009038 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009039 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309040 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009041 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309042 EXIT();
9043}
9044
9045/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309046 * hdd_state_info_dump() - prints state information of hdd layer
9047 * @buf: buffer pointer
9048 * @size: size of buffer to be filled
9049 *
9050 * This function is used to dump state information of hdd layer
9051 *
9052 * Return: None
9053 */
9054static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9055{
9056 hdd_context_t *hdd_ctx;
9057 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9058 QDF_STATUS status;
9059 hdd_station_ctx_t *hdd_sta_ctx;
9060 hdd_adapter_t *adapter;
9061 uint16_t len = 0;
9062 char *buf = *buf_ptr;
9063
9064 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9065 if (!hdd_ctx) {
9066 hdd_err("Failed to get hdd context ");
9067 return;
9068 }
9069
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009070 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309071
9072 len += scnprintf(buf + len, *size - len,
9073 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9074 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009075 "\n is_scheduler_suspended %d",
9076 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309077
9078 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9079
9080 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9081 adapter = adapter_node->pAdapter;
9082 if (adapter->dev)
9083 len += scnprintf(buf + len, *size - len,
9084 "\n device name: %s", adapter->dev->name);
9085 len += scnprintf(buf + len, *size - len,
9086 "\n device_mode: %d", adapter->device_mode);
9087 switch (adapter->device_mode) {
9088 case QDF_STA_MODE:
9089 case QDF_P2P_CLIENT_MODE:
9090 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9091 len += scnprintf(buf + len, *size - len,
9092 "\n connState: %d",
9093 hdd_sta_ctx->conn_info.connState);
9094 break;
9095
9096 default:
9097 break;
9098 }
9099 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9100 adapter_node = next;
9101 }
9102
9103 *size -= len;
9104 *buf_ptr += len;
9105}
9106
9107/**
9108 * hdd_register_debug_callback() - registration function for hdd layer
9109 * to print hdd state information
9110 *
9111 * Return: None
9112 */
9113static void hdd_register_debug_callback(void)
9114{
9115 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9116}
9117
9118/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009119 * hdd_wlan_startup() - HDD init function
9120 * @dev: Pointer to the underlying device
9121 *
9122 * This is the driver startup code executed once a WLAN device has been detected
9123 *
9124 * Return: 0 for success, < 0 for failure
9125 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309126int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009127{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309128 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08009129 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009130 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009131 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309132 int set_value;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009133
9134 ENTER();
9135
Arun Khandavallifae92942016-08-01 13:31:08 +05309136 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009137
9138 if (IS_ERR(hdd_ctx))
9139 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009140
Abhishek Singhe9068f12017-03-31 14:14:52 +05309141 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9142 DEFAULT_PSOC_ID);
9143 if (ret) {
9144 hdd_err("Psoc creation fails!");
9145 QDF_BUG(0);
9146 goto err_hdd_free_context;
9147 }
9148
Arun Khandavallifae92942016-08-01 13:31:08 +05309149 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9150 hdd_iface_change_callback, (void *)hdd_ctx);
9151
9152 mutex_init(&hdd_ctx->iface_change_lock);
9153
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009154 ret = hdd_init_netlink_services(hdd_ctx);
9155 if (ret)
9156 goto err_hdd_free_context;
9157
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009158 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009159 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309160
Jeff Johnson957bc272017-02-02 08:54:48 -08009161 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309162 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009163 hdd_err("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009164 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009165 }
9166
Yingying Tang80e15f32016-09-27 18:23:01 +08009167 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009168
Yingying Tang95409972016-10-20 15:16:15 +08009169 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009170 hdd_debug("Failed to set wow pulse");
Yingying Tang95409972016-10-20 15:16:15 +08009171
Anurag Chouhan6d760662016-02-20 16:05:43 +05309172 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009173
9174 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009175 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309176 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009177 }
9178
Prashanth Bhatta07998752016-04-28 12:35:33 -07009179 ret = hdd_wiphy_init(hdd_ctx);
9180 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009181 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309182 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009183 }
9184
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309185 if (hdd_ctx->config->enable_dp_trace)
9186 qdf_dp_trace_init();
9187
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309188 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009189 goto err_wiphy_unregister;
9190
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309191 wlan_hdd_init_chan_info(hdd_ctx);
9192
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009193 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009194
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009195 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009196
Jeff Johnson957bc272017-02-02 08:54:48 -08009197 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9198 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009199 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009200 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009201 }
9202
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009203 hdd_release_rtnl_lock();
9204 rtnl_held = false;
9205
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009206 wlan_hdd_update_11n_mode(hdd_ctx->config);
9207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009208#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309209 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309210 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009211 hdd_skip_acs_scan_timer_handler,
9212 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309213 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009214 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009215 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009216#endif
9217
Nitesh Shah61c10d92016-10-19 19:29:15 +05309218 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9219 QDF_TIMER_TYPE_SW,
9220 wlan_hdd_change_tdls_mode,
9221 hdd_ctx);
9222
Prashanth Bhattaab004382016-10-11 16:08:11 -07009223 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009224
Jeff Johnson9afc5012016-09-23 13:56:27 -07009225 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009226
Nirav Shahbd36b062016-07-18 11:12:59 +05309227 if (hdd_ctx->rps)
9228 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009229
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009230 ret = hdd_register_notifiers(hdd_ctx);
9231 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009232 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309233
9234 status = wlansap_global_init();
9235 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009236 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009237
Komal Seelam8634b772016-09-29 12:12:24 +05309238 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009239 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309240 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009241
bings612b9c42016-11-07 10:52:03 +08009242 if (hdd_enable_egap(hdd_ctx))
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08009243 hdd_debug("enhance green ap is not enabled");
bings612b9c42016-11-07 10:52:03 +08009244
Arun Khandavallifae92942016-08-01 13:31:08 +05309245 if (hdd_ctx->config->fIsImpsEnabled)
9246 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309247
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309248 if (hdd_ctx->config->sifs_burst_duration) {
9249 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9250 hdd_ctx->config->sifs_burst_duration;
9251
9252 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
9253 wma_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
9254 set_value, PDEV_CMD);
9255 }
9256
Arun Khandavallifae92942016-08-01 13:31:08 +05309257 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
9258 hdd_ctx->config->iface_change_wait_time * 5000);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309259
Sachin Ahujadddd2632017-03-07 19:07:24 +05309260 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009261 goto success;
9262
Jeff Johnson957bc272017-02-02 08:54:48 -08009263err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009264 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009265
Jeff Johnson46bde382017-02-01 15:31:16 -08009266err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309267 if (rtnl_held)
9268 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009269
Anurag Chouhance6a4052016-09-14 18:20:42 +05309270 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009272err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009273 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009274
Arun Khandavallifae92942016-08-01 13:31:08 +05309275err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009276 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309277
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05309278err_exit_nl_srv:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309279 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
9280 status = cds_sched_close(hdd_ctx->pcds_context);
9281 if (!QDF_IS_STATUS_SUCCESS(status)) {
9282 hdd_err("Failed to close CDS Scheduler");
9283 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9284 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009285 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009286
Houston Hoffman47a4a052016-11-14 23:22:44 -08009287 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009288 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009289 hdd_exit_netlink_services(hdd_ctx);
9290
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309291 cds_deinit_ini_config();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009292err_hdd_free_context:
Sachin Ahujadddd2632017-03-07 19:07:24 +05309293 hdd_start_complete(ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309294 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9295 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009296 hdd_context_destroy(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05309297 QDF_BUG(1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009298 return -EIO;
9299
9300success:
9301 EXIT();
9302 return 0;
9303}
9304
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009305/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309306 * hdd_wlan_update_target_info() - update target type info
9307 * @hdd_ctx: HDD context
9308 * @context: hif context
9309 *
9310 * Update target info received from firmware in hdd context
9311 * Return:None
9312 */
9313
9314void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
9315{
9316 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9317
9318 if (!tgt_info) {
9319 hdd_err("Target info is Null");
9320 return;
9321 }
9322
9323 hdd_ctx->target_type = tgt_info->target_type;
9324}
9325
9326/**
9327 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309328 * @hdd_ctx: HDD context
9329 *
9330 * Register the HDD callbacks to CDS/SME.
9331 *
9332 * Return: 0 for success or Error code for failure
9333 */
9334int hdd_register_cb(hdd_context_t *hdd_ctx)
9335{
9336 QDF_STATUS status;
9337 int ret = 0;
9338
9339 ENTER();
9340
9341 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9342
9343 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9344 hdd_send_oem_data_rsp_msg);
9345
9346 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9347 wlan_hdd_cfg80211_fw_mem_dump_cb);
9348 if (!QDF_IS_STATUS_SUCCESS(status)) {
9349 hdd_err("Failed to register memdump callback");
9350 ret = -EINVAL;
9351 return ret;
9352 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309353 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9354 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309355 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9356 sme_nan_register_callback(hdd_ctx->hHal,
9357 wlan_hdd_cfg80211_nan_callback);
9358 sme_stats_ext_register_callback(hdd_ctx->hHal,
9359 wlan_hdd_cfg80211_stats_ext_callback);
9360
9361 sme_ext_scan_register_callback(hdd_ctx->hHal,
9362 wlan_hdd_cfg80211_extscan_callback);
9363
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309364 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9365 hdd_rssi_threshold_breached);
9366
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309367 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9368 wlan_hdd_cfg80211_link_layer_stats_callback);
9369
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309370 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9371
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309372 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9373 hdd_lost_link_info_cb);
9374 /* print error and not block the startup process */
9375 if (!QDF_IS_STATUS_SUCCESS(status))
9376 hdd_err("set lost link info callback failed");
9377
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309378 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9379
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009380 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009381 hdd_set_connection_in_progress,
9382 hdd_is_connection_in_progress);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309383 EXIT();
9384
9385 return ret;
9386}
9387
9388/**
9389 * hdd_deregister_cb() - De-Register HDD callbacks.
9390 * @hdd_ctx: HDD context
9391 *
9392 * De-Register the HDD callbacks to CDS/SME.
9393 *
9394 * Return: void
9395 */
9396void hdd_deregister_cb(hdd_context_t *hdd_ctx)
9397{
9398 QDF_STATUS status;
9399
9400 ENTER();
9401
9402 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9403 if (!QDF_IS_STATUS_SUCCESS(status))
9404 hdd_err("De-register of dcc stats callback failed: %d",
9405 status);
9406
9407 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309408 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9409
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309410 sme_stats_ext_register_callback(hdd_ctx->hHal,
9411 wlan_hdd_cfg80211_stats_ext_callback);
9412
9413 sme_nan_deregister_callback(hdd_ctx->hHal);
9414 status = sme_reset_tsfcb(hdd_ctx->hHal);
9415 if (!QDF_IS_STATUS_SUCCESS(status))
9416 hdd_err("Failed to de-register tsfcb the callback:%d",
9417 status);
9418 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9419 if (!QDF_IS_STATUS_SUCCESS(status))
9420 hdd_err("Failed to de-register the fw mem dump callback: %d",
9421 status);
9422
9423 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9424 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9425
9426 EXIT();
9427}
9428
9429/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009430 * hdd_softap_sta_deauth() - handle deauth req from HDD
9431 * @adapter: Pointer to the HDD
9432 * @enable: bool value
9433 *
9434 * This to take counter measure to handle deauth req from HDD
9435 *
9436 * Return: None
9437 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309438QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009439 struct tagCsrDelStaParams *pDelStaParams)
9440{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309441 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009442
9443 ENTER();
9444
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009445 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009446 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9447
9448 /* Ignore request to deauth bcmc station */
9449 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309450 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009451
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309452 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009453 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9454 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009455
9456 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309457 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009458}
9459
9460/**
9461 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
9462 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309463 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009464 *
9465 * This to take counter measure to handle deauth req from HDD
9466 *
9467 * Return: None
9468 */
9469void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309470 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009471{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009472 ENTER();
9473
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009474 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009475 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9476
9477 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309478 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009479 return;
9480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009481 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309482 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009483}
9484
9485void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9486 bool enable)
9487{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009488 ENTER();
9489
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009490 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009491 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009493 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9494 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009495}
9496
9497/**
9498 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9499 * @hdd_ctx: HDD Context
9500 *
9501 * API to find if there is any STA or P2P-Client is connected
9502 *
9503 * Return: true if connected; false otherwise
9504 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309505QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009506{
9507 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9508}
9509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009510/**
9511 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9512 * @adapter: HDD adapter pointer
9513 *
9514 * This function loop through each adapter and disable roaming on each STA
9515 * device mode except the input adapter.
9516 *
9517 * Note: On the input adapter roaming is not enabled yet hence no need to
9518 * disable.
9519 *
9520 * Return: None
9521 */
9522void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9523{
9524 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9525 hdd_adapter_t *adapterIdx = NULL;
9526 hdd_adapter_list_node_t *adapterNode = NULL;
9527 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309528 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009529
9530 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009531 hdd_ctx->config->isRoamOffloadScanEnabled &&
9532 QDF_STA_MODE == adapter->device_mode &&
9533 policy_mgr_is_sta_active_connection_exists(
9534 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009535 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009536 adapter->sessionId);
9537 /*
9538 * Loop through adapter and disable roaming for each STA device
9539 * mode except the input adapter.
9540 */
9541 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9542
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309543 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009544 adapterIdx = adapterNode->pAdapter;
9545
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009546 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009547 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009548 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009549 adapterIdx->sessionId);
9550 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9551 (adapterIdx),
9552 adapterIdx->sessionId, 0);
9553 }
9554
9555 status = hdd_get_next_adapter(hdd_ctx,
9556 adapterNode,
9557 &pNext);
9558 adapterNode = pNext;
9559 }
9560 }
9561}
9562
9563/**
9564 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9565 * @adapter: HDD adapter pointer
9566 *
9567 * This function loop through each adapter and enable roaming on each STA
9568 * device mode except the input adapter.
9569 * Note: On the input adapter no need to enable roaming because link got
9570 * disconnected on this.
9571 *
9572 * Return: None
9573 */
9574void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
9575{
9576 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9577 hdd_adapter_t *adapterIdx = NULL;
9578 hdd_adapter_list_node_t *adapterNode = NULL;
9579 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309580 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009581
9582 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009583 hdd_ctx->config->isRoamOffloadScanEnabled &&
9584 QDF_STA_MODE == adapter->device_mode &&
9585 policy_mgr_is_sta_active_connection_exists(
9586 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009587 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009588 adapter->sessionId);
9589 /*
9590 * Loop through adapter and enable roaming for each STA device
9591 * mode except the input adapter.
9592 */
9593 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9594
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309595 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009596 adapterIdx = adapterNode->pAdapter;
9597
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009598 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009599 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009600 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009601 adapterIdx->sessionId);
9602 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
9603 (adapterIdx),
9604 adapterIdx->sessionId,
9605 REASON_CONNECT);
9606 }
9607
9608 status = hdd_get_next_adapter(hdd_ctx,
9609 adapterNode,
9610 &pNext);
9611 adapterNode = pNext;
9612 }
9613 }
9614}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009615
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +05309616/**
9617 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
9618 * @skb: sk buffer pointer
9619 *
9620 * Sends the bcast message to SVC multicast group with generic nl socket
9621 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
9622 *
9623 * Return: None
9624 */
9625static void nl_srv_bcast_svc(struct sk_buff *skb)
9626{
9627#ifdef CNSS_GENL
9628 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
9629#else
9630 nl_srv_bcast(skb);
9631#endif
9632}
9633
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309634void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009635{
9636 struct sk_buff *skb;
9637 struct nlmsghdr *nlh;
9638 tAniMsgHdr *ani_hdr;
9639 void *nl_data = NULL;
9640 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309641 struct radio_index_tlv *radio_info;
9642 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009643
9644 if (in_interrupt() || irqs_disabled() || in_atomic())
9645 flags = GFP_ATOMIC;
9646
9647 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
9648
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009649 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009650 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009651
9652 nlh = (struct nlmsghdr *)skb->data;
9653 nlh->nlmsg_pid = 0; /* from kernel */
9654 nlh->nlmsg_flags = 0;
9655 nlh->nlmsg_seq = 0;
9656 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
9657
9658 ani_hdr = NLMSG_DATA(nlh);
9659 ani_hdr->type = type;
9660
9661 switch (type) {
9662 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +05309663 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009664 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009665 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009666 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009667 ani_hdr->length = 0;
9668 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009669 break;
9670 case WLAN_SVC_WLAN_STATUS_IND:
9671 case WLAN_SVC_WLAN_VERSION_IND:
9672 case WLAN_SVC_DFS_CAC_START_IND:
9673 case WLAN_SVC_DFS_CAC_END_IND:
9674 case WLAN_SVC_DFS_RADAR_DETECT_IND:
9675 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
9676 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -08009677 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +05309678 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009679 ani_hdr->length = len;
9680 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
9681 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
9682 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009683 break;
9684
9685 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -07009686 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009687 type);
9688 kfree_skb(skb);
9689 return;
9690 }
9691
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309692 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08009693 * Add radio index at the end of the svc event in TLV format
9694 * to maintain the backward compatibility with userspace
9695 * applications.
9696 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309697
9698 tlv_len = 0;
9699
9700 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
9701 < WLAN_NL_MAX_PAYLOAD) {
9702 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
9703 sizeof(*ani_hdr) + len);
9704 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
9705 radio_info->length = (unsigned short) sizeof(radio_info->radio);
9706 radio_info->radio = radio;
9707 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08009708 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309709 "Added radio index tlv - radio index %d",
9710 radio_info->radio);
9711 }
9712
9713 nlh->nlmsg_len += tlv_len;
9714 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
9715
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +05309716 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009717}
9718
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009719#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9720void wlan_hdd_auto_shutdown_cb(void)
9721{
Mahesh Kumar Kalikot Veetild214d552016-09-14 15:15:49 -07009722 hdd_context_t *hdd_ctx = cds_get_global_context();
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309723
9724 if (!hdd_ctx)
9725 return;
9726
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009727 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309728 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
9729 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009730}
9731
9732void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
9733{
9734 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309735 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009736 hdd_adapter_t *adapter;
9737 bool ap_connected = false, sta_connected = false;
9738 tHalHandle hal_handle;
9739
9740 hal_handle = hdd_ctx->hHal;
9741 if (hal_handle == NULL)
9742 return;
9743
9744 if (hdd_ctx->config->WlanAutoShutdown == 0)
9745 return;
9746
9747 if (enable == false) {
9748 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309749 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -07009750 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009751 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05309752 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -07009753 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009754 return;
9755 }
9756
9757 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009758 if (policy_mgr_concurrent_open_sessions_running(
9759 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009760 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9761
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309762 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009763 adapter = adapterNode->pAdapter;
9764 if (adapter
9765 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009766 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009767 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9768 conn_info.connState ==
9769 eConnectionState_Associated) {
9770 sta_connected = true;
9771 break;
9772 }
9773 }
9774 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009775 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009776 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
9777 bApActive == true) {
9778 ap_connected = true;
9779 break;
9780 }
9781 }
9782 status = hdd_get_next_adapter(hdd_ctx,
9783 adapterNode,
9784 &pNext);
9785 adapterNode = pNext;
9786 }
9787 }
9788
9789 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009790 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009791 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009792 }
Jeff Johnson68755312017-02-10 11:46:55 -08009793
9794 if (sme_set_auto_shutdown_timer(hal_handle,
9795 hdd_ctx->config->WlanAutoShutdown)
9796 != QDF_STATUS_SUCCESS)
9797 hdd_err("Failed to start wlan auto shutdown timer");
9798 else
9799 hdd_notice("Auto Shutdown timer for %d seconds enabled",
9800 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009801}
9802#endif
9803
9804hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
9805 bool check_start_bss)
9806{
9807 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
9808 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309809 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009810 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
9811
9812 con_sap_adapter = NULL;
9813
9814 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309815 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009816 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009817 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
9818 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009819 adapter != this_sap_adapter) {
9820 if (check_start_bss) {
9821 if (test_bit(SOFTAP_BSS_STARTED,
9822 &adapter->event_flags)) {
9823 con_sap_adapter = adapter;
9824 break;
9825 }
9826 } else {
9827 con_sap_adapter = adapter;
9828 break;
9829 }
9830 }
9831 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
9832 adapterNode = pNext;
9833 }
9834
9835 return con_sap_adapter;
9836}
9837
9838#ifdef MSM_PLATFORM
Dustin Brown5ec6b552017-03-31 12:11:40 -07009839static inline bool hdd_adapter_is_sta(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009840{
Dustin Brown5ec6b552017-03-31 12:11:40 -07009841 return adapter->device_mode == QDF_STA_MODE ||
9842 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009843}
9844
Dustin Brown5ec6b552017-03-31 12:11:40 -07009845static inline bool hdd_adapter_is_ap(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009846{
Dustin Brown5ec6b552017-03-31 12:11:40 -07009847 return adapter->device_mode == QDF_SAP_MODE ||
9848 adapter->device_mode == QDF_P2P_GO_MODE;
9849}
9850
9851static bool hdd_any_adapter_is_assoc(hdd_context_t *hdd_ctx)
9852{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309853 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -07009854 hdd_adapter_list_node_t *node;
9855
9856 status = hdd_get_front_adapter(hdd_ctx, &node);
9857 while (QDF_IS_STATUS_SUCCESS(status) && node) {
9858 hdd_adapter_t *adapter = node->pAdapter;
9859
9860 if (adapter &&
9861 hdd_adapter_is_sta(adapter) &&
9862 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
9863 conn_info.connState == eConnectionState_Associated) {
9864 return true;
9865 }
9866
9867 if (adapter &&
9868 hdd_adapter_is_ap(adapter) &&
9869 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
9870 return true;
9871 }
9872
9873 status = hdd_get_next_adapter(hdd_ctx, node, &node);
9874 }
9875
9876 return false;
9877}
9878
9879static bool hdd_bus_bw_compute_timer_is_running(hdd_context_t *hdd_ctx)
9880{
9881 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009882
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309883 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -07009884 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05309885 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009886
Dustin Brown5ec6b552017-03-31 12:11:40 -07009887 return is_running;
9888}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889
Dustin Brown5ec6b552017-03-31 12:11:40 -07009890static void __hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
9891{
9892 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
9893 hdd_ctx->bus_bw_timer_running = true;
9894 qdf_timer_start(&hdd_ctx->bus_bw_timer,
9895 hdd_ctx->config->busBandwidthComputeInterval);
9896 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
9897}
9898
9899void hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
9900{
9901 ENTER();
9902
9903 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
9904 hdd_debug("Bandwidth compute timer already started");
9905 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009906 }
9907
Dustin Brown5ec6b552017-03-31 12:11:40 -07009908 __hdd_bus_bw_compute_timer_start(hdd_ctx);
9909
9910 EXIT();
9911}
9912
9913void hdd_bus_bw_compute_timer_try_start(hdd_context_t *hdd_ctx)
9914{
9915 ENTER();
9916
9917 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
9918 hdd_debug("Bandwidth compute timer already started");
9919 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -07009920 }
Dustin Brown5ec6b552017-03-31 12:11:40 -07009921
9922 if (hdd_any_adapter_is_assoc(hdd_ctx))
9923 __hdd_bus_bw_compute_timer_start(hdd_ctx);
9924
9925 EXIT();
9926}
9927
9928static void __hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
9929{
9930 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
9931
9932 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
9933 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
9934 hdd_ctx->bus_bw_timer_running = false;
9935 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
9936
9937 hdd_reset_tcp_delack(hdd_ctx);
9938}
9939
9940void hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
9941{
9942 ENTER();
9943
9944 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
9945 hdd_debug("Bandwidth compute timer already stopped");
9946 return;
9947 }
9948
9949 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
9950
9951 EXIT();
9952}
9953
9954void hdd_bus_bw_compute_timer_try_stop(hdd_context_t *hdd_ctx)
9955{
9956 ENTER();
9957
9958 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
9959 hdd_debug("Bandwidth compute timer already stopped");
9960 return;
9961 }
9962
9963 if (!hdd_any_adapter_is_assoc(hdd_ctx))
9964 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
9965
9966 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009967}
9968#endif
9969
9970/**
9971 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
9972 * and sta's operating channel.
9973 * @sta_adapter: Describe the first argument to foobar.
9974 * @ap_adapter: Describe the second argument to foobar.
9975 * @roam_profile: Roam profile of AP to which STA wants to connect.
9976 * @concurrent_chnl_same: If both SAP and STA channels are same then
9977 * set this flag to true else false.
9978 *
9979 * This function checks the sap's operating channel and sta's operating channel.
9980 * if both are same then it will return false else it will restart the sap in
9981 * sta's channel and return true.
9982 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309983 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009984 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309985QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009986 hdd_adapter_t *ap_adapter,
9987 tCsrRoamProfile *roam_profile,
9988 tScanResultHandle *scan_cache,
9989 bool *concurrent_chnl_same)
9990{
9991 hdd_ap_ctx_t *hdd_ap_ctx;
9992 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309993 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009994 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009995 *concurrent_chnl_same = true;
9996
9997 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
9998 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -07009999 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010000 scan_cache,
10001 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010002 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010003 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010004 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10005 if (hdd_ap_ctx->operatingChannel != channel_id) {
10006 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010007 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010008 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010009 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010010 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10011 if (hdd_ap_ctx->operatingChannel != channel_id) {
10012 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010013 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010014 }
10015 }
10016 } else {
10017 /*
10018 * Lets handle worst case scenario here, Scan cache lookup is
10019 * failed so we have to stop the SAP to avoid any channel
10020 * discrepancy between SAP's channel and STA's channel.
10021 * Return the status as failure so caller function could know
10022 * that scan look up is failed.
10023 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010024 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010025 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010026 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010027 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010028}
10029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010030/**
10031 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10032 * @ap_adapter: SAP adapter
10033 *
10034 * This function will process the stopping of sap adapter.
10035 *
10036 * Return: None
10037 */
10038void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
10039{
10040 hdd_ap_ctx_t *hdd_ap_ctx;
10041 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010042 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010043 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010044
10045 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010046 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010047 return;
10048 }
10049
10050 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10051 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010052 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010053 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010054
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010055 mutex_lock(&hdd_ctx->sap_lock);
10056 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010057 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010058 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10059 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010060 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010061 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010062 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010063 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010064 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010065 qdf_stop_bss_event,
10066 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010067 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010068 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010069 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010070 return;
10071 }
10072 }
10073 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010074 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10075 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010076 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010077 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010078 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010079 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010080 }
10081 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010082}
10083
10084/**
10085 * wlan_hdd_start_sap() - this function starts bss of SAP.
10086 * @ap_adapter: SAP adapter
10087 *
10088 * This function will process the starting of sap adapter.
10089 *
10090 * Return: None
10091 */
Arun Khandavallicc544b32017-01-30 19:52:16 +053010092void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010093{
10094 hdd_ap_ctx_t *hdd_ap_ctx;
10095 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010096 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010097 hdd_context_t *hdd_ctx;
10098 tsap_Config_t *sap_config;
10099
10100 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010101 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010102 return;
10103 }
10104
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010105 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010106 hdd_err("SoftAp role has not been enabled");
10107 return;
10108 }
10109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010110 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10111 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10112 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10113 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010115 mutex_lock(&hdd_ctx->sap_lock);
10116 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10117 goto end;
10118
10119 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010120 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010121 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10122 goto end;
10123 }
10124
Wei Song2f76f642016-11-18 16:32:53 +080010125 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010126 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10127 &hdd_ap_ctx->sapConfig,
10128 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010129 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010130 goto end;
10131
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010132 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010133 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010134 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010135 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010136 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010137 goto end;
10138 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010139 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010140 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010141 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010142 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10143 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010144 ap_adapter->sessionId);
10145 hostapd_state->bCommit = true;
10146
10147end:
10148 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010149}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010150
10151/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010152 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10153 * mac scan config
10154 * @status: Status of set antenna mode
10155 *
10156 * Callback on setting the dual mac configuration
10157 *
10158 * Return: None
10159 */
10160void wlan_hdd_soc_set_antenna_mode_cb(
10161 enum set_antenna_mode_status status)
10162{
10163 hdd_context_t *hdd_ctx;
10164
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010165 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010166
10167 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10168 if (0 != wlan_hdd_validate_context(hdd_ctx))
10169 return;
10170
10171 /* Signal the completion of set dual mac config */
10172 complete(&hdd_ctx->set_antenna_mode_cmpl);
10173}
10174
10175/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176 * hdd_get_fw_version() - Get FW version
10177 * @hdd_ctx: pointer to HDD context.
10178 * @major_spid: FW version - major spid.
10179 * @minor_spid: FW version - minor spid
10180 * @ssid: FW version - ssid
10181 * @crmid: FW version - crmid
10182 *
10183 * This function is called to get the firmware build version stored
10184 * as part of the HDD context
10185 *
10186 * Return: None
10187 */
10188void hdd_get_fw_version(hdd_context_t *hdd_ctx,
10189 uint32_t *major_spid, uint32_t *minor_spid,
10190 uint32_t *siid, uint32_t *crmid)
10191{
10192 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10193 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10194 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10195 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10196}
10197
10198#ifdef QCA_CONFIG_SMP
10199/**
10200 * wlan_hdd_get_cpu() - get cpu_index
10201 *
10202 * Return: cpu_index
10203 */
10204int wlan_hdd_get_cpu(void)
10205{
10206 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010208 put_cpu();
10209 return cpu_index;
10210}
10211#endif
10212
10213/**
10214 * hdd_get_fwpath() - get framework path
10215 *
10216 * This function is used to get the string written by
10217 * userspace to start the wlan driver
10218 *
10219 * Return: string
10220 */
10221const char *hdd_get_fwpath(void)
10222{
10223 return fwpath.string;
10224}
10225
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010226/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010227 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010228 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010229 * This function initilizes CDS global context with the help of cds_init. This
10230 * has to be the first function called after probe to get a valid global
10231 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010232 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010233 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010234 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010235int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010236{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010237 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010238 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010239
Houston Hoffman9e06e542016-12-12 12:06:26 -080010240 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010241#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10242 wlan_logging_sock_init_svc();
10243#endif
10244
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010245 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010246 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010247 ret = -ENOMEM;
10248 goto err_out;
10249 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010250
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010251 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010252 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010253
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010254err_out:
10255 return ret;
10256}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010257
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010258/**
10259 * hdd_deinit() - Deinitialize Driver
10260 *
10261 * This function frees CDS global context with the help of cds_deinit. This
10262 * has to be the last function call in remove callback to free the global
10263 * context.
10264 */
10265void hdd_deinit(void)
10266{
10267 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010268
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010269#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10270 wlan_logging_sock_deinit_svc();
10271#endif
10272}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010273
Yue Ma6e7b1a02017-04-03 14:17:46 -070010274#ifdef QCA_WIFI_NAPIER_EMULATION
10275#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10276#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010277#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010278#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010279
Sachin Ahujadddd2632017-03-07 19:07:24 +053010280static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10281 struct file *file)
10282{
10283 return 0;
10284}
10285
10286static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10287 const char __user *user_buf,
10288 size_t count,
10289 loff_t *f_pos)
10290{
10291 char buf;
10292 static const char wlan_off_str[] = "OFF";
10293 static const char wlan_on_str[] = "ON";
10294 int ret;
10295 unsigned long rc;
10296
10297 if (copy_from_user(&buf, user_buf, 3)) {
10298 pr_err("Failed to read buffer\n");
10299 return -EINVAL;
10300 }
10301
10302 if (strncmp(&buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
10303 pr_debug("Wifi turning off from UI\n");
10304 goto exit;
10305 }
10306
10307 if (strncmp(&buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
10308 pr_err("Invalid value received from framework");
10309 goto exit;
10310 }
10311
10312 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010313 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010314 rc = wait_for_completion_timeout(&wlan_start_comp,
10315 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10316 if (!rc) {
10317 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10318 ret = -EINVAL;
10319 hdd_start_complete(ret);
10320 return ret;
10321 }
10322
10323 hdd_start_complete(0);
10324 }
10325
10326exit:
10327 return count;
10328}
10329
10330
10331const struct file_operations wlan_hdd_state_fops = {
10332 .owner = THIS_MODULE,
10333 .open = wlan_hdd_state_ctrl_param_open,
10334 .write = wlan_hdd_state_ctrl_param_write,
10335};
10336
10337static int wlan_hdd_state_ctrl_param_create(void)
10338{
10339 unsigned int wlan_hdd_state_major = 0;
10340 int ret;
10341 struct device *dev;
10342
10343 device = MKDEV(wlan_hdd_state_major, 0);
10344
10345 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10346 if (ret) {
10347 pr_err("Failed to register qcwlanstate");
10348 goto dev_alloc_err;
10349 }
10350 wlan_hdd_state_major = MAJOR(device);
10351
10352 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10353 if (IS_ERR(class)) {
10354 pr_err("wlan_hdd_state class_create error");
10355 goto class_err;
10356 }
10357
10358 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10359 if (IS_ERR(dev)) {
10360 pr_err("wlan_hdd_statedevice_create error");
10361 goto err_class_destroy;
10362 }
10363
10364 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10365 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10366 if (ret) {
10367 pr_err("Failed to add cdev error");
10368 goto cdev_add_err;
10369 }
10370
10371 pr_info("wlan_hdd_state %s major(%d) initialized",
10372 WLAN_MODULE_NAME, wlan_hdd_state_major);
10373
10374 return 0;
10375
10376cdev_add_err:
10377 device_destroy(class, device);
10378err_class_destroy:
10379 class_destroy(class);
10380class_err:
10381 unregister_chrdev_region(device, dev_num);
10382dev_alloc_err:
10383 return -ENODEV;
10384}
10385
10386static void wlan_hdd_state_ctrl_param_destroy(void)
10387{
10388 cdev_del(&wlan_hdd_state_cdev);
10389 device_destroy(class, device);
10390 class_destroy(class);
10391 unregister_chrdev_region(device, dev_num);
10392
10393 pr_info("Device node unregistered");
10394}
10395
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010396/**
10397 * __hdd_module_init - Module init helper
10398 *
10399 * Module init helper function used by both module and static driver.
10400 *
10401 * Return: 0 for success, errno on failure
10402 */
10403static int __hdd_module_init(void)
10404{
10405 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010406
Arun Khandavallifae92942016-08-01 13:31:08 +053010407 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010408 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010409
Sachin Ahujadddd2632017-03-07 19:07:24 +053010410 ret = wlan_hdd_state_ctrl_param_create();
10411 if (ret) {
10412 pr_err("wlan_hdd_state_create:%x\n", ret);
10413 goto err_dev_state;
10414 }
10415
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010416 pld_init();
10417
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010418 ret = hdd_init();
10419 if (ret) {
10420 pr_err("hdd_init failed %x\n", ret);
10421 goto err_hdd_init;
10422 }
10423
Rajeev Kumar97767a02016-11-30 11:20:40 -080010424 dispatcher_init();
10425
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010426 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010427
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010428 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010429
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010430 ret = wlan_hdd_register_driver();
10431 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070010432 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
10433 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010434 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010435 }
10436
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010437 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010438
10439 return 0;
10440out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010441 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080010442 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010443 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080010444
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010445err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010446 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053010447 wlan_hdd_state_ctrl_param_destroy();
10448err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010449 return ret;
10450}
10451
10452/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010453 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
10454 *
10455 * Block the unloading of the driver until the cds recovery is completed
10456 *
10457 * Return: None
10458 */
10459static void hdd_wait_for_recovery_completion(void)
10460{
10461 int retry = 0;
10462
10463 /* Wait for recovery to complete */
10464 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010465 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010466 msleep(1000);
10467 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010468 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010469 QDF_BUG(0);
10470 }
10471 }
10472}
10473
10474/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010475 * __hdd_module_exit - Module exit helper
10476 *
10477 * Module exit helper function used by both module and static driver.
10478 */
10479static void __hdd_module_exit(void)
10480{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010481 int qdf_print_idx = -1;
10482
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010483 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
10484 QWLAN_VERSIONSTR);
10485
bings6028ee82017-03-29 07:51:40 +080010486 cds_set_unload_in_progress(true);
10487
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010488 hdd_wait_for_recovery_completion();
10489
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010490 wlan_hdd_unregister_driver();
10491
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010492 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010493
Rajeev Kumar97767a02016-11-30 11:20:40 -080010494 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010495 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010496 pld_deinit();
10497
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010498 qdf_print_idx = qdf_get_pidx();
10499 qdf_print_ctrl_cleanup(qdf_print_idx);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010500 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010501}
10502
Arun Khandavallifae92942016-08-01 13:31:08 +053010503#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010504/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010505 * wlan_boot_cb() - Wlan boot callback
10506 * @kobj: object whose directory we're creating the link in.
10507 * @attr: attribute the user is interacting with
10508 * @buff: the buffer containing the user data
10509 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010510 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010511 * This callback is invoked when the fs is ready to start the
10512 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010513 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010514 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010515 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010516static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010517 struct kobj_attribute *attr,
10518 const char *buf,
10519 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010520{
Arun Khandavallifae92942016-08-01 13:31:08 +053010521
Arun Khandavallifae92942016-08-01 13:31:08 +053010522 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010523 pr_err("%s: wlan driver already initialized\n", __func__);
10524 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053010525 }
10526
Arun Khandavallifae92942016-08-01 13:31:08 +053010527 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010528 pr_err("%s: wlan driver initialization failed\n", __func__);
10529 return -EIO;
10530 }
10531
10532 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053010533
10534 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010535}
Arun Khandavallifae92942016-08-01 13:31:08 +053010536
10537/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010538 * hdd_sysfs_cleanup() - cleanup sysfs
10539 *
10540 * Return: None
10541 *
10542 */
10543static void hdd_sysfs_cleanup(void)
10544{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010545 /* remove from group */
10546 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
10547 sysfs_remove_group(wlan_loader->boot_wlan_obj,
10548 wlan_loader->attr_group);
10549
10550 /* unlink the object from parent */
10551 kobject_del(wlan_loader->boot_wlan_obj);
10552
10553 /* free the object */
10554 kobject_put(wlan_loader->boot_wlan_obj);
10555
10556 kfree(wlan_loader->attr_group);
10557 kfree(wlan_loader);
10558
10559 wlan_loader = NULL;
10560}
10561
10562/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010563 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
10564 * ready
10565 *
10566 * This is creates the syfs entry boot_wlan. Which shall be invoked
10567 * when the filesystem is ready.
10568 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010569 * QDF API cannot be used here since this function is called even before
10570 * initializing WLAN driver.
10571 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070010572 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053010573 */
10574static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010575{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010576 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053010577
10578 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010579 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010580 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053010581
10582 wlan_loader->boot_wlan_obj = NULL;
10583 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
10584 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010585 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053010586 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053010587
10588 wlan_loader->loaded_state = 0;
10589 wlan_loader->attr_group->attrs = attrs;
10590
10591 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
10592 kernel_kobj);
10593 if (!wlan_loader->boot_wlan_obj) {
10594 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053010595 goto error_return;
10596 }
10597
10598 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
10599 wlan_loader->attr_group);
10600 if (ret) {
10601 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
10602 goto error_return;
10603 }
10604
10605 return 0;
10606
10607error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010608 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053010609
10610 return ret;
10611}
10612
10613/**
10614 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
10615 *
10616 * Return: 0 on success or errno on failure
10617 */
10618static int wlan_deinit_sysfs(void)
10619{
Arun Khandavallifae92942016-08-01 13:31:08 +053010620 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010621 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053010622 return -EINVAL;
10623 }
10624
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010625 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010626 return 0;
10627}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010628
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010629#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053010630
10631#ifdef MODULE
10632/**
10633 * __hdd_module_init - Module init helper
10634 *
10635 * Module init helper function used by both module and static driver.
10636 *
10637 * Return: 0 for success, errno on failure
10638 */
10639static int hdd_module_init(void)
10640{
10641 int ret = 0;
10642
10643 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
10644 QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR);
10645
10646 if (__hdd_module_init()) {
10647 pr_err("%s: Failed to register handler\n", __func__);
10648 ret = -EINVAL;
10649 }
10650
10651 return ret;
10652}
10653#else
10654static int __init hdd_module_init(void)
10655{
10656 int ret = -EINVAL;
10657
10658 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070010659 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053010660 pr_err("Failed to create sysfs entry for loading wlan");
10661
10662 return ret;
10663}
10664#endif
10665
10666
10667#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010668/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010669 * hdd_module_exit() - Exit function
10670 *
10671 * This is the driver exit point (invoked when module is unloaded using rmmod)
10672 *
10673 * Return: None
10674 */
10675static void __exit hdd_module_exit(void)
10676{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010677 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010678}
Arun Khandavallifae92942016-08-01 13:31:08 +053010679#else
10680static void __exit hdd_module_exit(void)
10681{
10682 __hdd_module_exit();
10683 wlan_deinit_sysfs();
10684}
10685#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010686
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010687static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
10688{
10689 return param_set_copystring(kmessage, kp);
10690}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010691
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010692/**
10693 * is_con_mode_valid() check con mode is valid or not
10694 * @mode: global con mode
10695 *
10696 * Return: TRUE on success FALSE on failure
10697 */
10698static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
10699{
10700 switch (mode) {
10701 case QDF_GLOBAL_MONITOR_MODE:
10702 case QDF_GLOBAL_FTM_MODE:
10703 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010704 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010705 return true;
10706 default:
10707 return false;
10708 }
10709}
10710
10711/**
10712 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
10713 * @mode: global con mode
10714 *
10715 * Return: adapter mode
10716 */
10717static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
10718 enum tQDF_GLOBAL_CON_MODE mode)
10719{
10720
10721 switch (mode) {
10722 case QDF_GLOBAL_MISSION_MODE:
10723 return QDF_STA_MODE;
10724 case QDF_GLOBAL_MONITOR_MODE:
10725 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010726 case QDF_GLOBAL_EPPING_MODE:
10727 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010728 case QDF_GLOBAL_FTM_MODE:
10729 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010730 case QDF_GLOBAL_QVIT_MODE:
10731 return QDF_QVIT_MODE;
10732 default:
10733 return QDF_MAX_NO_OF_MODE;
10734 }
10735}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010736
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010737static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
10738 enum tQDF_GLOBAL_CON_MODE curr_mode)
10739{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010740 int driver_status;
10741
10742 driver_status = hdd_ctx->driver_status;
10743
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010744 switch (curr_mode) {
10745 case QDF_GLOBAL_MISSION_MODE:
10746 case QDF_GLOBAL_MONITOR_MODE:
10747 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053010748 if (driver_status != DRIVER_MODULES_CLOSED) {
10749 hdd_abort_mac_scan_all_adapters(hdd_ctx);
10750 hdd_stop_all_adapters(hdd_ctx);
10751 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010752 hdd_deinit_all_adapters(hdd_ctx, false);
10753 hdd_close_all_adapters(hdd_ctx, false);
10754 break;
10755 case QDF_GLOBAL_EPPING_MODE:
10756 epping_disable();
10757 epping_close();
10758 break;
10759 default:
10760 return;
10761 }
10762}
10763
10764static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
10765 enum tQDF_GLOBAL_CON_MODE mode)
10766{
10767 hdd_adapter_t *adapter;
10768 int ret = 0;
10769 bool rtnl_held;
10770 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10771 QDF_STATUS status;
10772
10773 if (!qdf_dev) {
10774 hdd_err("qdf device context is Null return!");
10775 return -EINVAL;
10776 }
10777
10778 rtnl_held = hdd_hold_rtnl_lock();
10779 switch (mode) {
10780 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080010781 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10782 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010783 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010784 break;
10785 case QDF_GLOBAL_FTM_MODE:
10786 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
10787 wlan_hdd_get_intf_addr(hdd_ctx),
10788 NET_NAME_UNKNOWN, rtnl_held);
10789 if (adapter == NULL)
10790 ret = -EINVAL;
10791 break;
10792 case QDF_GLOBAL_MONITOR_MODE:
10793 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
10794 wlan_hdd_get_intf_addr(hdd_ctx),
10795 NET_NAME_UNKNOWN, rtnl_held);
10796 if (adapter == NULL)
10797 ret = -EINVAL;
10798 break;
10799 case QDF_GLOBAL_EPPING_MODE:
10800 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010801 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010802 hdd_err("Failed to open in eeping mode: %d", status);
10803 ret = -EINVAL;
10804 break;
10805 }
10806 ret = epping_enable(qdf_dev->dev);
10807 if (ret) {
10808 hdd_err("Failed to enable in epping mode : %d", ret);
10809 epping_close();
10810 }
10811 break;
10812 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010813 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010814 ret = -ENOTSUPP;
10815 break;
10816 }
10817 hdd_release_rtnl_lock();
10818 rtnl_held = false;
10819 return ret;
10820}
10821
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010822/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010823 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010824 * @kmessage: con mode name on which driver to be bring up
10825 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010826 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010827 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010828 * This function is invoked when user updates con mode using sys entry,
10829 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010830 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010831 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010832 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010833static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
10834 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010835{
10836 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010837 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010838 enum tQDF_GLOBAL_CON_MODE curr_mode;
10839 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010840
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010841 ret = wlan_hdd_validate_context(hdd_ctx);
10842 if (ret)
10843 return ret;
10844
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010845 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010846
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010847 hdd_debug("con_mode handler: %s", kmessage);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010848 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053010849
Arun Khandavallifae92942016-08-01 13:31:08 +053010850
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010851
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010852 if (!(is_con_mode_valid(con_mode))) {
10853 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010854 ret = -EINVAL;
10855 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010856 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010857
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010858 curr_mode = hdd_get_conparam();
10859 if (curr_mode == con_mode) {
10860 hdd_err("curr mode: %d is same as user triggered mode %d",
10861 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010862 ret = 0;
10863 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010864 }
10865
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010866 /* Cleanup present mode before switching to new mode */
10867 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +053010868
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010869 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010870 if (ret) {
10871 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010872 goto reset_flags;
10873 }
10874
10875 hdd_set_conparam(con_mode);
10876
10877 /* Register for new con_mode & then kick_start modules again */
10878 ret = hdd_register_req_mode(hdd_ctx, con_mode);
10879 if (ret) {
10880 hdd_err("Failed to register for new mode");
10881 goto reset_flags;
10882 }
10883
10884 adapter_mode = hdd_get_adpter_mode(con_mode);
10885 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
10886 hdd_err("invalid adapter");
10887 ret = -EINVAL;
10888 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010889 }
10890
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053010891 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053010892 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010893 hdd_err("Failed to get adapter:%d", adapter_mode);
10894 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010895 }
10896
10897 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
10898 if (ret) {
10899 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010900 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053010901 }
10902
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010903 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
10904 con_mode == QDF_GLOBAL_FTM_MODE) {
10905 if (hdd_start_adapter(adapter)) {
10906 hdd_err("Failed to start %s adapter", kmessage);
10907 ret = -EINVAL;
10908 goto reset_flags;
10909 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010910 }
10911
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053010912 hdd_info("Mode successfully changed to %s", kmessage);
10913 ret = 0;
10914
10915reset_flags:
10916 cds_set_load_in_progress(false);
10917 return ret;
10918}
10919
10920
10921static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
10922{
10923 int ret;
10924 hdd_context_t *hdd_ctx;
10925
10926 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10927 ret = wlan_hdd_validate_context(hdd_ctx);
10928 if (ret)
10929 return ret;
10930
10931 cds_ssr_protect(__func__);
10932 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
10933 cds_ssr_unprotect(__func__);
10934
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010935 return ret;
10936}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010937
10938/**
10939 * hdd_get_conparam() - driver exit point
10940 *
10941 * This is the driver exit point (invoked when module is unloaded using rmmod)
10942 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053010943 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010944 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053010945enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010946{
Anurag Chouhan6d760662016-02-20 16:05:43 +053010947 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010948}
10949
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010950void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010951{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080010952 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010953}
10954
Komal Seelamc11bb222016-01-27 18:57:10 +053010955/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053010956 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
10957 * @hdd_ctx: HDD context
10958 *
10959 * Cleans up the pre cac interface, if it exists
10960 *
10961 * Return: None
10962 */
10963void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
10964{
10965 uint8_t session_id;
10966 QDF_STATUS status;
10967 struct hdd_adapter_s *precac_adapter;
10968
10969 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
10970 if (QDF_IS_STATUS_ERROR(status)) {
10971 hdd_err("failed to get pre cac vdev id");
10972 return;
10973 }
10974
10975 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
10976 if (!precac_adapter) {
10977 hdd_err("invalid pre cac adapater");
10978 return;
10979 }
10980
10981 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
10982 wlan_hdd_sap_pre_cac_failure,
10983 (void *)precac_adapter);
10984 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
10985
10986}
10987
10988/**
Komal Seelamec702b02016-02-24 18:42:16 +053010989 * hdd_update_ol_config - API to update ol configuration parameters
10990 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053010991 *
Komal Seelamc11bb222016-01-27 18:57:10 +053010992 * Return: void
10993 */
Komal Seelamec702b02016-02-24 18:42:16 +053010994static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053010995{
Komal Seelamec702b02016-02-24 18:42:16 +053010996 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053010997 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053010998
Komal Seelamec702b02016-02-24 18:42:16 +053010999 if (!ol_ctx)
11000 return;
11001
11002 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11003 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11004 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11005 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011006 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011007
11008 ol_init_ini_config(ol_ctx, &cfg);
11009}
11010
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011011#ifdef FEATURE_RUNTIME_PM
11012/**
11013 * hdd_populate_runtime_cfg() - populate runtime configuration
11014 * @hdd_ctx: hdd context
11015 * @cfg: pointer to the configuration memory being populated
11016 *
11017 * Return: void
11018 */
11019static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11020 struct hif_config_info *cfg)
11021{
11022 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11023 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11024}
11025#else
11026static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11027 struct hif_config_info *cfg)
11028{
11029}
11030#endif
11031
Komal Seelamec702b02016-02-24 18:42:16 +053011032/**
11033 * hdd_update_hif_config - API to update HIF configuration parameters
11034 * @hdd_ctx: HDD Context
11035 *
11036 * Return: void
11037 */
11038static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
11039{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011040 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011041 struct hif_config_info cfg;
11042
11043 if (!scn)
11044 return;
11045
11046 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011047 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011048 hif_init_ini_config(scn, &cfg);
11049}
11050
11051/**
11052 * hdd_update_config() - Initialize driver per module ini parameters
11053 * @hdd_ctx: HDD Context
11054 *
11055 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011056 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011057 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011058int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011059{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011060 int ret;
11061
Komal Seelamec702b02016-02-24 18:42:16 +053011062 hdd_update_ol_config(hdd_ctx);
11063 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011064 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11065 ret = hdd_update_cds_config_ftm(hdd_ctx);
11066 else
11067 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011068 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011069
11070 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011071}
11072
Mukul Sharma9d797a02017-01-05 20:26:03 +053011073#ifdef FEATURE_WLAN_RA_FILTERING
11074/**
11075 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11076 * @psoc_cfg: pmo psoc Configuration
11077 * @hdd_ctx: Pointer to hdd context
11078 *
11079 * Return: none
11080 */
11081static inline void hdd_ra_populate_pmo_config(
11082 struct pmo_psoc_cfg *psoc_cfg,
11083 hdd_context_t *hdd_ctx)
11084{
11085 psoc_cfg->ra_ratelimit_interval =
11086 hdd_ctx->config->RArateLimitInterval;
11087 psoc_cfg->ra_ratelimit_enable =
11088 hdd_ctx->config->IsRArateLimitEnabled;
11089}
11090#else
11091static inline void hdd_ra_populate_pmo_config(
11092 struct cds_config_info *cds_cfg,
11093 hdd_context_t *hdd_ctx)
11094{
11095}
11096#endif
11097/**
11098 * hdd_update_pmo_config - API to update pmo configuration parameters
11099 * @hdd_ctx: HDD context
11100 *
11101 * Return: void
11102 */
11103static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
11104{
11105 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11106 struct pmo_psoc_cfg psoc_cfg;
11107 QDF_STATUS status;
11108
11109 /*
11110 * Value of hdd_ctx->wowEnable can be,
11111 * 0 - Disable both magic pattern match and pattern byte match.
11112 * 1 - Enable magic pattern match on all interfaces.
11113 * 2 - Enable pattern byte match on all interfaces.
11114 * 3 - Enable both magic patter and pattern byte match on
11115 * all interfaces.
11116 */
11117 psoc_cfg.magic_ptrn_enable =
11118 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11119 psoc_cfg.ptrn_match_enable_all_vdev =
11120 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11121 psoc_cfg.bpf_enable =
11122 hdd_ctx->config->bpf_packet_filter_enable;
11123 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Ravi Kumar Bokka794fd712017-03-21 20:52:46 +053011124 psoc_cfg.hw_bcast_filter = hdd_ctx->config->hw_broadcast_filter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011125 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11126 if (hdd_ctx->config->fhostNSOffload)
11127 psoc_cfg.ns_offload_enable_dynamic = true;
11128 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11129 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11130 psoc_cfg.active_mode_offload =
11131 hdd_ctx->config->active_mode_offload;
11132 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11133 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011134 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11135 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11136 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11137 psoc_cfg.power_save_mode =
11138 hdd_ctx->config->enablePowersaveOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011139
11140 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011141 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11142 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011143 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11144 if (status != QDF_STATUS_SUCCESS) {
11145 hdd_err("failed pmo psoc configuration");
11146 return -EINVAL;
11147 }
11148
11149 return 0;
11150}
11151
Abhishek Singh257a9482017-03-06 16:52:39 +053011152#ifdef NAPIER_SCAN
Abhishek Singhb20db962017-03-03 21:28:46 +053011153
11154#ifdef FEATURE_WLAN_SCAN_PNO
11155static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11156 struct hdd_config *cfg)
11157{
11158 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11159 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11160 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11161 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11162 pno_cfg->channel_prediction_full_scan =
11163 cfg->channel_prediction_full_scan;
11164}
11165#else
11166static inline void
11167hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11168 struct hdd_config *cfg)
11169{
11170 return;
11171}
11172#endif
11173
Abhishek Singh257a9482017-03-06 16:52:39 +053011174/**
11175 * hdd_update_scan_config - API to update scan configuration parameters
11176 * @hdd_ctx: HDD context
11177 *
11178 * Return: 0 if success else err
11179 */
11180static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11181{
11182 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11183 struct scan_user_cfg scan_cfg;
11184 struct hdd_config *cfg = hdd_ctx->config;
11185 QDF_STATUS status;
11186
11187 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11188 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11189 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11190 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11191 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11192 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11193 scan_cfg.conc_idle_time = cfg->idle_time_conc;
11194 scan_cfg.scan_cache_aging_time = cfg->scanAgingTimeout;
11195 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011196 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011197
Abhishek Singhb20db962017-03-03 21:28:46 +053011198 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
11199
Abhishek Singh257a9482017-03-06 16:52:39 +053011200 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11201 if (status != QDF_STATUS_SUCCESS) {
11202 hdd_err("failed pmo psoc configuration");
11203 return -EINVAL;
11204 }
11205
11206 return 0;
11207}
11208#else
11209static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11210{
11211 return 0;
11212}
11213#endif
11214
Frank Liud4b2fa02017-03-29 11:46:48 +080011215#ifdef CONVERGED_TDLS_ENABLE
11216static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11217{
11218 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11219 struct tdls_start_params tdls_cfg;
11220 struct tdls_user_config *config = &tdls_cfg.config;
11221 struct hdd_config *cfg = hdd_ctx->config;
11222 QDF_STATUS status;
11223
11224 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11225 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11226 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11227 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11228 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11229 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11230 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11231 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11232 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11233 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11234 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11235 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11236 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11237 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11238 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11239 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11240 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11241 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11242 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11243 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11244 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11245 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11246 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11247 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11248 (cfg->fEnableTDLSImplicitTrigger ?
11249 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11250 (cfg->fTDLSExternalControl ?
11251 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11252
11253 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11254 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11255 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11256 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011257 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011258 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11259 tdls_cfg.tdls_evt_cb_data = psoc;
11260 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11261 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11262 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011263 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11264 tdls_cfg.tdls_wmm_cb_data = psoc;
11265 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11266 tdls_cfg.tdls_rx_cb_data = psoc;
Frank Liud4b2fa02017-03-29 11:46:48 +080011267
11268 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11269 if (status != QDF_STATUS_SUCCESS) {
11270 hdd_err("failed pmo psoc configuration");
11271 return -EINVAL;
11272 }
11273
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011274 hdd_ctx->tdls_umac_comp_active = true;
11275
Frank Liud4b2fa02017-03-29 11:46:48 +080011276 return 0;
11277}
11278#else
11279static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11280{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011281 hdd_ctx->tdls_umac_comp_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080011282 return 0;
11283}
11284#endif
11285
Mukul Sharma9d797a02017-01-05 20:26:03 +053011286int hdd_update_components_config(hdd_context_t *hdd_ctx)
11287{
11288 int ret;
11289
11290 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053011291 if (ret)
11292 return ret;
11293 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080011294 if (ret)
11295 return ret;
11296 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011297
11298 return ret;
11299}
11300
Agrawal Ashish65634612016-08-18 13:24:32 +053011301/**
11302 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
11303 * @mode : cfg80211 DFS mode
11304 *
11305 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
11306 */
11307enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
11308{
11309 switch (mode) {
11310 case DFS_MODE_ENABLE:
11311 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011312 case DFS_MODE_DISABLE:
11313 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011314 case DFS_MODE_DEPRIORITIZE:
11315 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011316 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011317 hdd_debug("ACS dfs mode is NONE");
11318 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011319 }
11320}
11321
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011322/**
11323 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
11324 * @hddctx: pointer to hdd context
11325 * @set_value: enable/disable
11326 *
11327 * When Host sends vendor command enable, FW will send *ONE* CA ind to
11328 * Host(even though it is duplicate). When Host send vendor command
11329 * disable,FW doesn't perform any action. Whenever any change in
11330 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
11331 *
11332 * return - 0 on success, appropriate error values on failure.
11333 */
11334int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
11335{
11336 QDF_STATUS status;
11337
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011338 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011339 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011340
11341 if (!hddctx->config->goptimize_chan_avoid_event) {
11342 hdd_warn("goptimize_chan_avoid_event ini param disabled");
11343 return -EINVAL;
11344 }
11345
11346 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
11347 if (!QDF_IS_STATUS_SUCCESS(status)) {
11348 hdd_err("Failed to send chan avoid command to SME");
11349 return -EINVAL;
11350 }
11351 return 0;
11352}
Agrawal Ashish65634612016-08-18 13:24:32 +053011353
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011354/**
11355 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
11356 * @value: value to set
11357 *
11358 * This function will set the passed value to roaming in progress flag.
11359 *
11360 * Return: None
11361 */
11362void hdd_set_roaming_in_progress(bool value)
11363{
11364 hdd_context_t *hdd_ctx;
11365
11366 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11367 if (!hdd_ctx) {
11368 hdd_err("HDD context is NULL");
11369 return;
11370 }
11371
11372 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011373 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011374}
11375
11376/**
11377 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011378 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011379 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011380 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011381 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011382bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011383{
11384 hdd_context_t *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011385 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011386
11387 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11388 if (!hdd_ctx) {
11389 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011390 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011391 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011392 hdd_debug("dev mode = %d, roaming_in_progress = %d",
11393 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011394 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
11395 hdd_ctx->roaming_in_progress);
11396
11397 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011398}
11399
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011400/**
11401 * hdd_is_connection_in_progress() - check if connection is in
11402 * progress
11403 * @session_id: session id
11404 * @reason: scan reject reason
11405 *
11406 * Go through each adapter and check if Connection is in progress
11407 *
11408 * Return: true if connection is in progress else false
11409 */
11410bool hdd_is_connection_in_progress(uint8_t *session_id,
11411 enum scan_reject_states *reason)
11412{
11413 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
11414 hdd_station_ctx_t *hdd_sta_ctx = NULL;
11415 hdd_adapter_t *adapter = NULL;
11416 QDF_STATUS status = 0;
11417 uint8_t sta_id = 0;
11418 uint8_t *sta_mac = NULL;
11419 hdd_context_t *hdd_ctx;
11420
11421 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11422 if (!hdd_ctx) {
11423 hdd_err("HDD context is NULL");
11424 return false;
11425 }
11426
11427 if (true == hdd_ctx->btCoexModeSet) {
11428 hdd_info("BTCoex Mode operation in progress");
11429 return true;
11430 }
11431 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
11432 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
11433 adapter = adapter_node->pAdapter;
11434 if (!adapter)
11435 goto end;
11436
11437 hdd_info("Adapter with device mode %s(%d) exists",
11438 hdd_device_mode_to_string(adapter->device_mode),
11439 adapter->device_mode);
11440 if (((QDF_STA_MODE == adapter->device_mode)
11441 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
11442 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
11443 && (eConnectionState_Connecting ==
11444 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
11445 conn_info.connState)) {
11446 hdd_err("%p(%d) Connection is in progress",
11447 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11448 adapter->sessionId);
11449 if (session_id && reason) {
11450 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011451 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011452 }
11453 return true;
11454 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070011455 /*
11456 * sme_neighbor_middle_of_roaming is for LFR2
11457 * hdd_is_roaming_in_progress is for LFR3
11458 */
11459 if (((QDF_STA_MODE == adapter->device_mode) &&
11460 sme_neighbor_middle_of_roaming(
11461 WLAN_HDD_GET_HAL_CTX(adapter),
11462 adapter->sessionId)) ||
11463 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011464 hdd_err("%p(%d) Reassociation in progress",
11465 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11466 adapter->sessionId);
11467 if (session_id && reason) {
11468 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011469 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011470 }
11471 return true;
11472 }
11473 if ((QDF_STA_MODE == adapter->device_mode) ||
11474 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
11475 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
11476 hdd_sta_ctx =
11477 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11478 if ((eConnectionState_Associated ==
11479 hdd_sta_ctx->conn_info.connState)
11480 && (false ==
11481 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
11482 sta_mac = (uint8_t *)
11483 &(adapter->macAddressCurrent.bytes[0]);
11484 hdd_err("client " MAC_ADDRESS_STR
11485 " is in middle of WPS/EAPOL exchange.",
11486 MAC_ADDR_ARRAY(sta_mac));
11487 if (session_id && reason) {
11488 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011489 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011490 }
11491 return true;
11492 }
11493 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
11494 (QDF_P2P_GO_MODE == adapter->device_mode)) {
11495 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
11496 sta_id++) {
11497 if (!((adapter->aStaInfo[sta_id].isUsed)
11498 && (OL_TXRX_PEER_STATE_CONN ==
11499 adapter->aStaInfo[sta_id].tlSTAState)))
11500 continue;
11501
11502 sta_mac = (uint8_t *)
11503 &(adapter->aStaInfo[sta_id].
11504 macAddrSTA.bytes[0]);
11505 hdd_err("client " MAC_ADDRESS_STR
11506 " of SAP/GO is in middle of WPS/EAPOL exchange",
11507 MAC_ADDR_ARRAY(sta_mac));
11508 if (session_id && reason) {
11509 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011510 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011511 }
11512 return true;
11513 }
11514 if (hdd_ctx->connection_in_progress) {
11515 hdd_err("AP/GO: connection is in progress");
11516 return true;
11517 }
11518 }
11519end:
11520 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
11521 adapter_node = next;
11522 }
11523 return false;
11524}
11525
11526/**
11527 * hdd_restart_sap() - to restart SAP in driver internally
11528 * @ap_adapter: Pointer to SAP hdd_adapter_t structure
11529 *
11530 * Return: None
11531 */
11532void hdd_restart_sap(hdd_adapter_t *ap_adapter)
11533{
11534 hdd_ap_ctx_t *hdd_ap_ctx;
11535 hdd_hostapd_state_t *hostapd_state;
11536 QDF_STATUS qdf_status;
11537 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11538 tsap_Config_t *sap_config;
11539 void *sap_ctx;
11540
11541 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11542 sap_config = &hdd_ap_ctx->sapConfig;
11543 sap_ctx = hdd_ap_ctx->sapContext;
11544
11545 mutex_lock(&hdd_ctx->sap_lock);
11546 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
11547 wlan_hdd_del_station(ap_adapter);
11548 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
11549 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
11550 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
11551 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
11552 qdf_status =
11553 qdf_wait_single_event(&hostapd_state->
11554 qdf_stop_bss_event,
11555 SME_CMD_TIMEOUT_VALUE);
11556
11557 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11558 cds_err("SAP Stop Failed");
11559 goto end;
11560 }
11561 }
11562 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011563 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011564 ap_adapter->device_mode, ap_adapter->sessionId);
11565 cds_err("SAP Stop Success");
11566
11567 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
11568 cds_err("SAP Not able to set AP IEs");
11569 wlansap_reset_sap_config_add_ie(sap_config,
11570 eUPDATE_IE_ALL);
11571 goto end;
11572 }
11573
11574 qdf_event_reset(&hostapd_state->qdf_event);
11575 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
11576 sap_config,
11577 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
11578 cds_err("SAP Start Bss fail");
11579 wlansap_reset_sap_config_add_ie(sap_config,
11580 eUPDATE_IE_ALL);
11581 goto end;
11582 }
11583
11584 cds_info("Waiting for SAP to start");
11585 qdf_status =
11586 qdf_wait_single_event(&hostapd_state->qdf_event,
11587 SME_CMD_TIMEOUT_VALUE);
11588 wlansap_reset_sap_config_add_ie(sap_config,
11589 eUPDATE_IE_ALL);
11590 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11591 cds_err("SAP Start failed");
11592 goto end;
11593 }
11594 cds_err("SAP Start Success");
11595 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
11596 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011597 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11598 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011599 ap_adapter->sessionId);
11600 hostapd_state->bCommit = true;
11601 }
11602end:
11603 mutex_unlock(&hdd_ctx->sap_lock);
11604 return;
11605}
11606
11607/**
11608 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
11609 * with non dfs acs
11610 *
11611 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
11612 *
11613 * Return: None
11614 */
11615void hdd_check_and_restart_sap_with_non_dfs_acs(void)
11616{
11617 hdd_adapter_t *ap_adapter;
11618 hdd_context_t *hdd_ctx;
11619 cds_context_type *cds_ctx;
11620
11621 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11622 if (!hdd_ctx) {
11623 cds_err("HDD context is NULL");
11624 return;
11625 }
11626
11627 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
11628 if (!cds_ctx) {
11629 cds_err("Invalid CDS Context");
11630 return;
11631 }
11632
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011633 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
11634 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011635 cds_info("Concurrency mode is not SAP");
11636 return;
11637 }
11638
11639 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070011640 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
11641 &ap_adapter->event_flags) &&
11642 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
11643 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011644
11645 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
11646 ap_adapter->sessionCtx.ap.sapConfig.channel =
11647 AUTO_CHANNEL_SELECT;
11648 ap_adapter->sessionCtx.ap.sapConfig.
11649 acs_cfg.acs_mode = true;
11650
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011651 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011652 }
11653}
11654
11655/**
11656 * hdd_set_connection_in_progress() - to set the connection in
11657 * progress flag
11658 * @value: value to set
11659 *
11660 * This function will set the passed value to connection in progress flag.
11661 * If value is previously being set to true then no need to set it again.
11662 *
11663 * Return: true if value is being set correctly and false otherwise.
11664 */
11665bool hdd_set_connection_in_progress(bool value)
11666{
11667 bool status = true;
11668 hdd_context_t *hdd_ctx;
11669
11670 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11671 if (!hdd_ctx) {
11672 cds_err("HDD context is NULL");
11673 return false;
11674 }
11675
11676 qdf_spin_lock(&hdd_ctx->connection_status_lock);
11677 /*
11678 * if the value is set to true previously and if someone is
11679 * trying to make it true again then it could be some race
11680 * condition being triggered. Avoid this situation by returning
11681 * false
11682 */
11683 if (hdd_ctx->connection_in_progress && value)
11684 status = false;
11685 else
11686 hdd_ctx->connection_in_progress = value;
11687 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
11688 return status;
11689}
11690
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070011691int wlan_hdd_send_p2p_quota(hdd_adapter_t *adapter, int set_value)
11692{
11693 if (!adapter) {
11694 hdd_err("Invalid adapter");
11695 return -EINVAL;
11696 }
11697 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
11698 wma_cli_set_command(adapter->sessionId,
11699 WMA_VDEV_MCC_SET_TIME_QUOTA,
11700 set_value, VDEV_CMD);
11701 return 0;
11702
11703}
11704
11705int wlan_hdd_send_mcc_latency(hdd_adapter_t *adapter, int set_value)
11706{
11707 if (!adapter) {
11708 hdd_err("Invalid adapter");
11709 return -EINVAL;
11710 }
11711
11712 hdd_info("Send MCC latency WMA: %d", set_value);
11713 wma_cli_set_command(adapter->sessionId,
11714 WMA_VDEV_MCC_SET_TIME_LATENCY,
11715 set_value, VDEV_CMD);
11716 return 0;
11717}
11718
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011719hdd_adapter_t *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
11720 *psoc, uint8_t vdev_id)
11721{
11722 hdd_adapter_t *adapter = NULL;
11723 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11724
11725 /*
11726 * Currently PSOC is not being used. But this logic will
11727 * change once we have the converged implementation of
11728 * HDD context per PSOC in place. This would break if
11729 * multiple vdev objects reuse the vdev id.
11730 */
11731 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
11732 if (!adapter)
11733 hdd_err("Get adapter by vdev id failed");
11734
11735 return adapter;
11736}
11737
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011738/* Register the module init/exit functions */
11739module_init(hdd_module_init);
11740module_exit(hdd_module_exit);
11741
11742MODULE_LICENSE("Dual BSD/GPL");
11743MODULE_AUTHOR("Qualcomm Atheros, Inc.");
11744MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
11745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011746module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
11747 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011748
11749module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
11750 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
11751
11752module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
11753
11754module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
11755
11756module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);