blob: 30f36cc756f7f58a8101d16d7c233ea36059b254 [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"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700122#include "wlan_reg_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800124
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530125#ifdef CNSS_GENL
126#include <net/cnss_nl.h>
127#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800128#include "wlan_reg_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530129
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800130#ifdef MODULE
131#define WLAN_MODULE_NAME module_name(THIS_MODULE)
132#else
133#define WLAN_MODULE_NAME "wlan"
134#endif
135
136#ifdef TIMER_MANAGER
137#define TIMER_MANAGER_STR " +TIMER_MANAGER"
138#else
139#define TIMER_MANAGER_STR ""
140#endif
141
142#ifdef MEMORY_DEBUG
143#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
144#else
145#define MEMORY_DEBUG_STR ""
146#endif
147
Sachin Ahujadddd2632017-03-07 19:07:24 +0530148int wlan_start_ret_val;
149static DECLARE_COMPLETION(wlan_start_comp);
150static unsigned int dev_num = 1;
151static struct cdev wlan_hdd_state_cdev;
152static struct class *class;
153static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530154#ifndef MODULE
155static struct gwlan_loader *wlan_loader;
156static ssize_t wlan_boot_cb(struct kobject *kobj,
157 struct kobj_attribute *attr,
158 const char *buf, size_t count);
159struct gwlan_loader {
160 bool loaded_state;
161 struct kobject *boot_wlan_obj;
162 struct attribute_group *attr_group;
163};
164
165static struct kobj_attribute wlan_boot_attribute =
166 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
167
168static struct attribute *attrs[] = {
169 &wlan_boot_attribute.attr,
170 NULL,
171};
172
173#define MODULE_INITIALIZED 1
174#endif
175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176/* the Android framework expects this param even though we don't use it */
177#define BUF_LEN 20
178static char fwpath_buffer[BUF_LEN];
179static struct kparam_string fwpath = {
180 .string = fwpath_buffer,
181 .maxlen = BUF_LEN,
182};
183
184static char *country_code;
185static int enable_11d = -1;
186static int enable_dfs_chan_scan = -1;
187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800188/*
189 * spinlock for synchronizing asynchronous request/response
190 * (full description of use in wlan_hdd_main.h)
191 */
192DEFINE_SPINLOCK(hdd_context_lock);
193
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800194#define WLAN_NLINK_CESIUM 30
195
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530196static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800197
198#define WOW_MAX_FILTER_LISTS 1
199#define WOW_MAX_FILTERS_PER_LIST 4
200#define WOW_MIN_PATTERN_SIZE 6
201#define WOW_MAX_PATTERN_SIZE 64
202
203#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
204static const struct wiphy_wowlan_support wowlan_support_reg_init = {
205 .flags = WIPHY_WOWLAN_ANY |
206 WIPHY_WOWLAN_MAGIC_PKT |
207 WIPHY_WOWLAN_DISCONNECT |
208 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
209 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
210 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
211 WIPHY_WOWLAN_4WAY_HANDSHAKE |
212 WIPHY_WOWLAN_RFKILL_RELEASE,
213 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
214 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
215 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
216};
217#endif
218
219/* internal function declaration */
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530220struct notifier_block hdd_netdev_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800221
222struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700224static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225#endif
226
Sachin Ahujadddd2632017-03-07 19:07:24 +0530227void hdd_start_complete(int ret)
228{
229 wlan_start_ret_val = ret;
230
231 complete(&wlan_start_comp);
232}
233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800234/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530235 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
236 * @hdd_ctx: pointer to hdd_context_t
237 *
238 * Return: none
239 */
Jeff Johnson590e2012016-10-05 16:16:24 -0700240static void hdd_set_rps_cpu_mask(hdd_context_t *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530241{
242 hdd_adapter_t *adapter;
243 hdd_adapter_list_node_t *adapter_node, *next;
244 QDF_STATUS status = QDF_STATUS_SUCCESS;
245
246 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
247 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
248 adapter = adapter_node->pAdapter;
249 if (NULL != adapter)
250 hdd_send_rps_ind(adapter);
251 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
252 adapter_node = next;
253 }
254}
255
256/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800257 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
258 * @vdev_id: vdev_id
259 * @action: action type
260 * @reason: reason type
261 *
262 * Return: none
263 */
264void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
265 enum netif_action_type action, enum netif_reason_type reason)
266{
Anurag Chouhan6d760662016-02-20 16:05:43 +0530267 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800268 hdd_adapter_t *adapter;
269
270 if (!hdd_ctx) {
271 hdd_err("hdd ctx is NULL");
272 return;
273 }
274 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
275
276 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800277}
278
279/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700280 * Store WLAN driver version and timestamp info in global variables such that
281 * crash debugger can extract them from driver debug symbol and crashdump for
282 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800283 */
284uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700285
286#ifndef BUILD_TIMESTAMP
287#define BUILD_TIMESTAMP ""
288#endif
Dustin Brownab482ac2017-06-09 17:00:44 -0700289uint8_t g_wlan_driver_timestamp[] = BUILD_TIMESTAMP;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800290
291/**
292 * hdd_device_mode_to_string() - return string conversion of device mode
293 * @device_mode: device mode
294 *
295 * This utility function helps log string conversion of device mode.
296 *
297 * Return: string conversion of device mode, if match found;
298 * "Unknown" otherwise.
299 */
300const char *hdd_device_mode_to_string(uint8_t device_mode)
301{
302 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800303 CASE_RETURN_STRING(QDF_STA_MODE);
304 CASE_RETURN_STRING(QDF_SAP_MODE);
305 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
306 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
307 CASE_RETURN_STRING(QDF_FTM_MODE);
308 CASE_RETURN_STRING(QDF_IBSS_MODE);
309 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
310 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700311 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800312 default:
313 return "Unknown";
314 }
315}
316
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530317/**
318 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
319 * @adapter: HDD adapter
320 * @chan_number: Channel number
321 * @chan_bw: Bandwidth
322 *
323 * Checks if the given bandwidth is valid for the given channel number.
324 *
325 * Return: 0 for success, non-zero for failure
326 */
327int hdd_validate_channel_and_bandwidth(hdd_adapter_t *adapter,
328 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800329 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530330{
331 uint8_t chan[WNI_CFG_VALID_CHANNEL_LIST_LEN];
332 uint32_t len = WNI_CFG_VALID_CHANNEL_LIST_LEN, i;
333 bool found = false;
334 tHalHandle hal;
335
336 hal = WLAN_HDD_GET_HAL_CTX(adapter);
337 if (!hal) {
338 hdd_err("Invalid HAL context");
339 return -EINVAL;
340 }
341
342 if (0 != sme_cfg_get_str(hal, WNI_CFG_VALID_CHANNEL_LIST, chan, &len)) {
343 hdd_err("No valid channel list");
344 return -EOPNOTSUPP;
345 }
346
347 for (i = 0; i < len; i++) {
348 if (chan[i] == chan_number) {
349 found = true;
350 break;
351 }
352 }
353
354 if (found == false) {
355 hdd_err("Channel not in driver's valid channel list");
356 return -EOPNOTSUPP;
357 }
358
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700359 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
360 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530361 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
362 return -EINVAL;
363 }
364
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700365 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530366 if (chan_bw == CH_WIDTH_80MHZ) {
367 hdd_err("BW80 not possible in 2.4GHz band");
368 return -EINVAL;
369 }
370 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
371 (chan_bw != CH_WIDTH_MAX)) {
372 hdd_err("Only BW20 possible on channel 14");
373 return -EINVAL;
374 }
375 }
376
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700377 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530378 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
379 (chan_bw != CH_WIDTH_MAX)) {
380 hdd_err("Only BW20 possible on channel 165");
381 return -EINVAL;
382 }
383 }
384
385 return 0;
386}
387
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800388static int __hdd_netdev_notifier_call(struct notifier_block *nb,
389 unsigned long state, void *data)
390{
391#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
392 struct netdev_notifier_info *dev_notif_info = data;
393 struct net_device *dev = dev_notif_info->dev;
394#else
395 struct net_device *dev = data;
396#endif
397 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
398 hdd_context_t *hdd_ctx;
399
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800400 ENTER_DEV(dev);
401
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800402 /* Make sure that this callback corresponds to our device. */
403 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
404 return NOTIFY_DONE;
405
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530406 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800407 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700408 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800409 return NOTIFY_DONE;
410 }
411
412 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700413 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800414 return NOTIFY_DONE;
415 }
416
417 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
418 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800419 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530420 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800421 return NOTIFY_DONE;
422 }
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530423 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800424 return NOTIFY_DONE;
425
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800426 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427 dev->name, state);
428
429 switch (state) {
430 case NETDEV_REGISTER:
431 break;
432
433 case NETDEV_UNREGISTER:
434 break;
435
436 case NETDEV_UP:
437 sme_ch_avoid_update_req(hdd_ctx->hHal);
438 break;
439
440 case NETDEV_DOWN:
441 break;
442
443 case NETDEV_CHANGE:
444 if (true == adapter->isLinkUpSvcNeeded)
445 complete(&adapter->linkup_event_var);
446 break;
447
448 case NETDEV_GOING_DOWN:
449 if (adapter->scan_info.mScanPending != false) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530450 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
451 adapter->sessionId, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452 } else {
hqueaa33ee2017-05-04 17:56:35 +0800453 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800454 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800455 }
456 break;
457
458 default:
459 break;
460 }
461
462 return NOTIFY_DONE;
463}
464
465/**
466 * hdd_netdev_notifier_call() - netdev notifier callback function
467 * @nb: pointer to notifier block
468 * @state: state
469 * @ndev: ndev pointer
470 *
471 * Return: 0 on success, error number otherwise.
472 */
473static int hdd_netdev_notifier_call(struct notifier_block *nb,
474 unsigned long state,
475 void *ndev)
476{
477 int ret;
478
479 cds_ssr_protect(__func__);
480 ret = __hdd_netdev_notifier_call(nb, state, ndev);
481 cds_ssr_unprotect(__func__);
482
483 return ret;
484}
485
486struct notifier_block hdd_netdev_notifier = {
487 .notifier_call = hdd_netdev_notifier_call,
488};
489
490/* variable to hold the insmod parameters */
491static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800492
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530493static int con_mode_ftm;
494
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800495/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530498/**
499 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
500 * @ch_width: NL channel width
501 *
502 * Converts the NL channel width to the driver's internal representation
503 *
504 * Return: Converted channel width. In case of non matching NL channel width,
505 * CH_WIDTH_MAX will be returned.
506 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800507enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530508{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800509 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700510
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800511 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530512 switch (ch_width) {
513 case NL80211_CHAN_WIDTH_20_NOHT:
514 case NL80211_CHAN_WIDTH_20:
515 return CH_WIDTH_20MHZ;
516 case NL80211_CHAN_WIDTH_40:
517 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530518 case NL80211_CHAN_WIDTH_80:
519 return CH_WIDTH_80MHZ;
520 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800521 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
522 return CH_WIDTH_80P80MHZ;
523 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
524 return CH_WIDTH_160MHZ;
525 else
526 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530527 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800528 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
529 return CH_WIDTH_160MHZ;
530 else
531 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530532 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800533 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530534 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800535 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530536 default:
537 hdd_err("Invalid channel width %d, setting to default",
538 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800539 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530540 }
541}
542
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530543/* wlan_hdd_find_opclass() - Find operating class for a channel
544 * @hal: handler to HAL
545 * @channel: channel id
546 * @bw_offset: bandwidth offset
547 *
548 * Function invokes sme api to find the operating class
549 *
550 * Return: operating class
551 */
552uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
553 uint8_t bw_offset)
554{
555 uint8_t opclass = 0;
556
557 sme_get_opclass(hal, channel, bw_offset, &opclass);
558 return opclass;
559}
560
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530562 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530563 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 * @bitmask: Bitmask of log levels to be enabled
565 *
566 * Called immediately after the cfg.ini is read in order to configure
567 * the desired trace levels.
568 *
569 * Return: None
570 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530571int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530573 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530574 int qdf_print_idx = -1;
575 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800576 /*
577 * if the bitmask is the default value, then a bitmask was not
578 * specified in cfg.ini, so leave the logging level alone (it
579 * will remain at the "compiled in" default value)
580 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700581 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530582 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530584 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530586 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530587 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530588 QDF_TRACE_LEVEL_NONE, 0);
589
590 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530591 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 /* now cycle through the bitmask until all "set" bits are serviced */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530593 level = QDF_TRACE_LEVEL_FATAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594 while (0 != bitmask) {
595 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530596 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530597 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530598 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530599 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800602 level++;
603 bitmask >>= 1;
604 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530605 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606}
607
608/**
609 * wlan_hdd_validate_context() - check the HDD context
610 * @hdd_ctx: HDD context pointer
611 *
612 * Return: 0 if the context is valid. Error code otherwise
613 */
614int wlan_hdd_validate_context(hdd_context_t *hdd_ctx)
615{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530617 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800618 return -ENODEV;
619 }
620
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800621 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800622 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530623 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800624 return -EAGAIN;
625 }
626
Rajeev Kumarfec3dbe2016-01-19 15:23:52 -0800627 if (cds_is_load_or_unload_in_progress()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800628 return -EAGAIN;
629 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530630
631 if (hdd_ctx->start_modules_in_progress ||
632 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800633 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530634 (void *)_RET_IP_);
635 return -EAGAIN;
636 }
637
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530638 if (cds_is_driver_in_bad_state()) {
639 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
640 (void *)_RET_IP_, cds_get_driver_state());
641 return -ENODEV;
642 }
643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800644 return 0;
645}
646
Dustin Brownf13b8c32017-05-19 17:23:08 -0700647int hdd_validate_adapter(hdd_adapter_t *adapter)
648{
649 if (!adapter) {
650 hdd_err("adapter is null");
651 return -EINVAL;
652 }
653
654 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
655 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
656 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
657 return -EINVAL;
658 }
659
660 if (!adapter->dev) {
661 hdd_err("adapter net_device is null");
662 return -EINVAL;
663 }
664
665 if (!(adapter->dev->flags & IFF_UP)) {
666 hdd_info("adapter net_device is not up");
667 return -EAGAIN;
668 }
669
670 if (adapter->sessionId == HDD_SESSION_ID_INVALID) {
671 hdd_info("adapter session is not open");
672 return -EAGAIN;
673 }
674
675 if (adapter->sessionId >= MAX_NUMBER_OF_ADAPTERS) {
676 hdd_err("bad adapter session Id: %u", adapter->sessionId);
677 return -EINVAL;
678 }
679
680 return 0;
681}
682
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800683/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530684 * wlan_hdd_validate_modules_state() - Check modules status
685 * @hdd_ctx: HDD context pointer
686 *
687 * Check's the driver module's state and returns true if the
688 * modules are enabled returns false if modules are closed.
689 *
690 * Return: True if modules are enabled or false.
691 */
692bool wlan_hdd_validate_modules_state(hdd_context_t *hdd_ctx)
693{
694 mutex_lock(&hdd_ctx->iface_change_lock);
695 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
696 mutex_unlock(&hdd_ctx->iface_change_lock);
697 hdd_notice("Modules not enabled, Present status: %d",
698 hdd_ctx->driver_status);
699 return false;
700 }
701 mutex_unlock(&hdd_ctx->iface_change_lock);
702 return true;
703}
704
705/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
707 * @hdd_adapter_t Hdd adapter.
708 *
709 * This function sets the IBSS power save config parameters to WMA
710 * which will send it to firmware if FW supports IBSS power save
711 * before vdev start.
712 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530713 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800714 * on failure.
715 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530716QDF_STATUS hdd_set_ibss_power_save_params(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717{
718 int ret;
719 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
720
721 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700722 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530723 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724 }
725
Naveen Rawat247a8682017-06-05 15:00:31 -0700726 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
728 hdd_ctx->config->ibssATIMWinSize,
729 VDEV_CMD);
730 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700731 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530732 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733 }
734
Naveen Rawat247a8682017-06-05 15:00:31 -0700735 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
737 hdd_ctx->config->isIbssPowerSaveAllowed,
738 VDEV_CMD);
739 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700740 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
741 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530742 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 }
744
Naveen Rawat247a8682017-06-05 15:00:31 -0700745 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
747 hdd_ctx->config->
748 isIbssPowerCollapseAllowed, VDEV_CMD);
749 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700750 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
751 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530752 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 }
754
Naveen Rawat247a8682017-06-05 15:00:31 -0700755 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
757 hdd_ctx->config->isIbssAwakeOnTxRx,
758 VDEV_CMD);
759 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700760 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530761 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 }
763
Naveen Rawat247a8682017-06-05 15:00:31 -0700764 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
766 hdd_ctx->config->ibssInactivityCount,
767 VDEV_CMD);
768 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700769 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530770 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771 }
772
Naveen Rawat247a8682017-06-05 15:00:31 -0700773 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
775 hdd_ctx->config->ibssTxSpEndInactivityTime,
776 VDEV_CMD);
777 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700778 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
779 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530780 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781 }
782
Naveen Rawat247a8682017-06-05 15:00:31 -0700783 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
785 hdd_ctx->config->ibssPsWarmupTime,
786 VDEV_CMD);
787 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700788 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
789 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530790 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 }
792
Naveen Rawat247a8682017-06-05 15:00:31 -0700793 ret = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
795 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
796 VDEV_CMD);
797 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700798 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
799 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530800 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801 }
802
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530803 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804}
805
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806#define INTF_MACADDR_MASK 0x7
807
808/**
809 * hdd_update_macaddr() - update mac address
810 * @config: hdd configuration
811 * @hw_macaddr: mac address
812 *
813 * Mac address for multiple virtual interface is found as following
814 * i) The mac address of the first interface is just the actual hw mac address.
815 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
816 * define the mac address for the remaining interfaces and locally
817 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
818 * supported virtual interfaces, right now this is 0x07 (meaning 8
819 * interface).
820 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
821 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
822 *
823 * Return: None
824 */
825void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530826 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800827{
828 int8_t i;
829 uint8_t macaddr_b3, tmp_br3;
830
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530831 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530832 QDF_MAC_ADDR_SIZE);
833 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530834 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530835 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836 macaddr_b3 = config->intfMacAddr[i].bytes[3];
837 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
838 INTF_MACADDR_MASK;
839 macaddr_b3 += tmp_br3;
840
841 /* XOR-ing bit-24 of the mac address. This will give enough
842 * mac address range before collision
843 */
844 macaddr_b3 ^= (1 << 7);
845
846 /* Set locally administered bit */
847 config->intfMacAddr[i].bytes[0] |= 0x02;
848 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800849 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 MAC_ADDRESS_STR, i,
851 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
852 }
853}
854
855static void hdd_update_tgt_services(hdd_context_t *hdd_ctx,
856 struct wma_tgt_services *cfg)
857{
858 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859
860 /* Set up UAPSD */
861 config->apUapsdEnabled &= cfg->uapsd;
862
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800863 /* 11AX mode support */
864 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
865 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
866 config->dot11Mode = eHDD_DOT11_MODE_11ac;
867
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868 /* 11AC mode support */
869 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
870 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
871 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872
873 /* ARP offload: override user setting if invalid */
874 config->fhostArpOffload &= cfg->arp_offload;
875
876#ifdef FEATURE_WLAN_SCAN_PNO
877 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800878 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 if (cfg->pno_offload)
880 config->PnoOffload = true;
881#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882#ifdef FEATURE_WLAN_TDLS
883 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +0530884 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
885 cfg->en_tdls_offchan;
886 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
887 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700888 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800889 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700890 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893#ifdef WLAN_FEATURE_ROAM_OFFLOAD
894 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
895#endif
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -0700896 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897
898}
899
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700900/**
901 * hdd_update_vdev_nss() - sets the vdev nss
902 * @hdd_ctx: HDD context
903 *
904 * Sets the Nss per vdev type based on INI
905 *
906 * Return: None
907 */
908static void hdd_update_vdev_nss(hdd_context_t *hdd_ctx)
909{
910 struct hdd_config *cfg_ini = hdd_ctx->config;
911 uint8_t max_supp_nss = 1;
912
Naveen Rawat10b1c152017-01-18 11:16:06 -0800913 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -0700914 max_supp_nss = 2;
915
916 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
917 cfg_ini->vdev_type_nss_2g, eCSR_BAND_24);
918
919 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
920 cfg_ini->vdev_type_nss_5g, eCSR_BAND_5G);
921}
922
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530923/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +0530924 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
925 * @hdd_ctx: HDD context
926 *
927 * Updates wiphy vhtcap fields
928 *
929 * Return: None
930 */
931static void hdd_update_wiphy_vhtcap(hdd_context_t *hdd_ctx)
932{
933 struct ieee80211_supported_band *band_5g =
934 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
935 uint32_t val;
936
937 if (!band_5g) {
938 hdd_debug("5GHz band disabled, skipping capability population");
939 return;
940 }
941
942 val = hdd_ctx->config->txBFCsnValue;
943 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
944
945 val = NUM_OF_SOUNDING_DIMENSIONS;
946 band_5g->vht_cap.cap |=
947 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
948
949 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
950 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
951}
952
953/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530954 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
955 * @hdd_ctx: HDD context
956 *
957 * Sets the DBS capability as per INI and firmware capability
958 *
959 * Return: None
960 */
961static void hdd_update_hw_dbs_capable(hdd_context_t *hdd_ctx)
962{
963 struct hdd_config *cfg_ini = hdd_ctx->config;
964 uint8_t hw_dbs_capable = 0;
965
966 if ((!cfg_ini->dual_mac_feature_disable)
Archana Ramachandran62886ce2017-03-24 14:46:32 -0700967 && policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +0530968 hw_dbs_capable = 1;
969
970 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
971}
972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973static void hdd_update_tgt_ht_cap(hdd_context_t *hdd_ctx,
974 struct wma_tgt_ht_cap *cfg)
975{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530976 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 uint32_t value, val32;
978 uint16_t val16;
979 struct hdd_config *pconfig = hdd_ctx->config;
980 tSirMacHTCapabilityInfo *phtCapInfo;
981 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
982 uint8_t enable_tx_stbc;
983
984 /* check and update RX STBC */
985 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
986 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
987
988 /* get the MPDU density */
989 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
990
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530991 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700992 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 value = 0;
994 }
995
996 /*
997 * MPDU density:
998 * override user's setting if value is larger
999 * than the one supported by target
1000 */
1001 if (value > cfg->mpdu_density) {
1002 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1003 cfg->mpdu_density);
1004
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301005 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001006 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 }
1008
1009 /* get the HT capability info */
1010 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301011 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001012 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 return;
1014 }
1015 val16 = (uint16_t) val32;
1016 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1017
1018 /* Set the LDPC capability */
1019 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1020
1021 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1022 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1023
1024 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1025 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1026
1027 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1028 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1029
1030 enable_tx_stbc = pconfig->enableTxSTBC;
1031
1032 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1033 pconfig->enable2x2 = 1;
1034 } else {
1035 pconfig->enable2x2 = 0;
1036 enable_tx_stbc = 0;
1037
1038 /* 1x1 */
1039 /* Update Rx Highest Long GI data Rate */
1040 if (sme_cfg_set_int(hdd_ctx->hHal,
1041 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001042 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301043 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001044 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 }
1046
1047 /* Update Tx Highest Long GI data Rate */
1048 if (sme_cfg_set_int
1049 (hdd_ctx->hHal,
1050 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001051 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301052 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001053 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 }
1055 }
1056 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1057 enable_tx_stbc = 0;
1058 phtCapInfo->txSTBC = enable_tx_stbc;
1059
1060 val32 = val16;
1061 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301062 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001063 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1065 value = SIZE_OF_SUPPORTED_MCS_SET;
1066 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301067 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001068 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001069
1070 if (pconfig->enable2x2) {
1071 for (value = 0; value < cfg->num_rf_chains; value++)
1072 mcs_set[value] =
1073 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1074
1075 status =
1076 sme_cfg_set_str(hdd_ctx->hHal,
1077 WNI_CFG_SUPPORTED_MCS_SET,
1078 mcs_set,
1079 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301080 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001081 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001082 }
1083 }
1084#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1085}
1086
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001087static void hdd_update_tgt_vht_cap(hdd_context_t *hdd_ctx,
1088 struct wma_tgt_vht_cap *cfg)
1089{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301090 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 uint32_t value = 0;
1092 struct hdd_config *pconfig = hdd_ctx->config;
1093 struct wiphy *wiphy = hdd_ctx->wiphy;
1094 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001095 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001096 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001097 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098
Dustin Brown5e06bd32016-10-04 12:49:10 -07001099 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001100 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001101 return;
1102 }
1103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104 /* Get the current MPDU length */
1105 status =
1106 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1107 &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 MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 value = 0;
1112 }
1113
1114 /*
1115 * VHT max MPDU length:
1116 * override if user configured value is too high
1117 * that the target cannot support
1118 */
1119 if (value > cfg->vht_max_mpdu) {
1120 status = sme_cfg_set_int(hdd_ctx->hHal,
1121 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1122 cfg->vht_max_mpdu);
1123
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001124 if (status == QDF_STATUS_E_FAILURE)
1125 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126 }
1127
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001128 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1129 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1130
1131 if (pconfig->enable2x2)
1132 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1133
1134 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1135 QDF_STATUS_E_FAILURE) {
1136 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1137 }
1138
1139 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1140 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1141 if (pconfig->enable2x2)
1142 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1143
1144 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1145 QDF_STATUS_E_FAILURE) {
1146 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1147 }
1148
1149 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1150 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1151 if (pconfig->enable2x2)
1152 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1153
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001154 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001155 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1156
1157 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1158 QDF_STATUS_E_FAILURE) {
1159 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1160 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001162 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 &value);
1164
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301165 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001166 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167 value = 0;
1168 }
1169
1170 /* Set the LDPC capability */
1171 if (value && !cfg->vht_rx_ldpc) {
1172 status = sme_cfg_set_int(hdd_ctx->hHal,
1173 WNI_CFG_VHT_LDPC_CODING_CAP,
1174 cfg->vht_rx_ldpc);
1175
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001176 if (status == QDF_STATUS_E_FAILURE)
1177 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 }
1179
1180 /* Get current GI 80 value */
1181 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1182 &value);
1183
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301184 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001185 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001186 value = 0;
1187 }
1188
1189 /* set the Guard interval 80MHz */
1190 if (value && !cfg->vht_short_gi_80) {
1191 status = sme_cfg_set_int(hdd_ctx->hHal,
1192 WNI_CFG_VHT_SHORT_GI_80MHZ,
1193 cfg->vht_short_gi_80);
1194
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001195 if (status == QDF_STATUS_E_FAILURE)
1196 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197 }
1198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 /* Get VHT TX STBC cap */
1200 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1201
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301202 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001203 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 value = 0;
1205 }
1206
1207 /* VHT TX STBC cap */
1208 if (value && !cfg->vht_tx_stbc) {
1209 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1210 cfg->vht_tx_stbc);
1211
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001212 if (status == QDF_STATUS_E_FAILURE)
1213 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 }
1215
1216 /* Get VHT RX STBC cap */
1217 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1218
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301219 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001220 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221 value = 0;
1222 }
1223
1224 /* VHT RX STBC cap */
1225 if (value && !cfg->vht_rx_stbc) {
1226 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1227 cfg->vht_rx_stbc);
1228
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001229 if (status == QDF_STATUS_E_FAILURE)
1230 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 }
1232
1233 /* Get VHT SU Beamformer cap */
1234 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1235 &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 SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 value = 0;
1240 }
1241
1242 /* set VHT SU Beamformer cap */
1243 if (value && !cfg->vht_su_bformer) {
1244 status = sme_cfg_set_int(hdd_ctx->hHal,
1245 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1246 cfg->vht_su_bformer);
1247
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001248 if (status == QDF_STATUS_E_FAILURE)
1249 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250 }
1251
1252 /* check and update SU BEAMFORMEE capabality */
1253 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1254 pconfig->enableTxBF = cfg->vht_su_bformee;
1255
1256 status = sme_cfg_set_int(hdd_ctx->hHal,
1257 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1258 pconfig->enableTxBF);
1259
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001260 if (status == QDF_STATUS_E_FAILURE)
1261 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262
1263 /* Get VHT MU Beamformer cap */
1264 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1265 &value);
1266
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301267 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001268 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 value = 0;
1270 }
1271
1272 /* set VHT MU Beamformer cap */
1273 if (value && !cfg->vht_mu_bformer) {
1274 status = sme_cfg_set_int(hdd_ctx->hHal,
1275 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1276 cfg->vht_mu_bformer);
1277
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001278 if (status == QDF_STATUS_E_FAILURE)
1279 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001280 }
1281
1282 /* Get VHT MU Beamformee cap */
1283 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1284 &value);
1285
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301286 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001287 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 value = 0;
1289 }
1290
1291 /* set VHT MU Beamformee cap */
1292 if (value && !cfg->vht_mu_bformee) {
1293 status = sme_cfg_set_int(hdd_ctx->hHal,
1294 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1295 cfg->vht_mu_bformee);
1296
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001297 if (status == QDF_STATUS_E_FAILURE)
1298 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 }
1300
1301 /* Get VHT MAX AMPDU Len exp */
1302 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1303 &value);
1304
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301305 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001306 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 value = 0;
1308 }
1309
1310 /*
1311 * VHT max AMPDU len exp:
1312 * override if user configured value is too high
1313 * that the target cannot support.
1314 * Even though Rome publish ampdu_len=7, it can
1315 * only support 4 because of some h/w bug.
1316 */
1317
1318 if (value > cfg->vht_max_ampdu_len_exp) {
1319 status = sme_cfg_set_int(hdd_ctx->hHal,
1320 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1321 cfg->vht_max_ampdu_len_exp);
1322
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001323 if (status == QDF_STATUS_E_FAILURE)
1324 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 }
1326
1327 /* Get VHT TXOP PS CAP */
1328 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1329
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301330 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001331 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001332 value = 0;
1333 }
1334
1335 /* set VHT TXOP PS cap */
1336 if (value && !cfg->vht_txop_ps) {
1337 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1338 cfg->vht_txop_ps);
1339
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001340 if (status == QDF_STATUS_E_FAILURE)
1341 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342 }
1343
1344 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1345 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1346 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1347 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1348 else
1349 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1350
1351
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001352 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1353 status = sme_cfg_set_int(hdd_ctx->hHal,
1354 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1355 VHT_CAP_160_AND_80P80_SUPP);
1356 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001357 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358 band_5g->vht_cap.cap |=
1359 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001360 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1361 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1362 status = sme_cfg_set_int(hdd_ctx->hHal,
1363 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1364 VHT_CAP_160_SUPP);
1365 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001366 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367 band_5g->vht_cap.cap |=
1368 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001369 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1370 }
1371 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1372 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301373 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001374 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301375 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001376 &value);
1377 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301378 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001379 value = 0;
1380 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301381 /* set the Guard interval 160MHz */
1382 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001383 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301384 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1385 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001386
1387 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301388 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001389 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390
1391 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC)
1392 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1393
1394 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1395 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1396 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1397 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1398
1399 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1400 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1401
1402 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1403 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1404 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1405 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1406 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1407 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1408
1409 band_5g->vht_cap.cap |=
1410 (cfg->vht_max_ampdu_len_exp <<
1411 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1412
1413 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1414 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1415 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1416 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1417 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1418 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1419 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1420 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1421
1422 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1423 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1424
1425}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001427/**
1428 * hdd_generate_macaddr_auto() - Auto-generate mac address
1429 * @hdd_ctx: Pointer to the HDD context
1430 *
1431 * Auto-generate mac address using device serial number.
1432 * Keep the first 3 bytes of OUI as before and replace
1433 * the last 3 bytes with the lower 3 bytes of serial number.
1434 *
1435 * Return: 0 for success
1436 * Non zero failure code for errors
1437 */
1438static int hdd_generate_macaddr_auto(hdd_context_t *hdd_ctx)
1439{
1440 unsigned int serialno = 0;
1441 struct qdf_mac_addr mac_addr = {
1442 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1443 };
1444
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001445 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001446 if (serialno == 0)
1447 return -EINVAL;
1448
1449 serialno &= 0x00ffffff;
1450
1451 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1452 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1453 mac_addr.bytes[5] = serialno & 0xff;
1454
1455 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1456 return 0;
1457}
1458
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301459/**
1460 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1461 * configuration to cfg_ini in HDD
1462 * @hdd_ctx: Pointer to hdd_ctx
1463 * @cfg: target configuration
1464 *
1465 * Return: None
1466 */
1467#ifdef FEATURE_WLAN_RA_FILTERING
1468static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1469 struct wma_tgt_cfg *cfg)
1470{
1471 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1472}
1473#else
1474static void hdd_update_ra_rate_limit(hdd_context_t *hdd_ctx,
1475 struct wma_tgt_cfg *cfg)
1476{
1477}
1478#endif
1479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480void hdd_update_tgt_cfg(void *context, void *param)
1481{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001482 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 hdd_context_t *hdd_ctx = (hdd_context_t *) context;
1484 struct wma_tgt_cfg *cfg = param;
1485 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001486 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301487 uint8_t antenna_mode;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301488
Yue Mae3e86ab2017-05-08 10:48:24 -07001489 /* Reuse same pdev for module start/stop or SSR */
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001490 if ((hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) ||
Yue Mae3e86ab2017-05-08 10:48:24 -07001491 !cds_is_driver_loading()) {
1492 hdd_err("Reuse pdev for module start/stop or SSR");
1493 /* Restore pdev to MAC/WMA contexts */
1494 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001495 } else {
1496 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1497 if (ret) {
1498 hdd_err("pdev creation fails!");
1499 QDF_BUG(0);
1500 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301501 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001502
Naveen Rawat64e477e2016-05-20 10:34:56 -07001503 if (cds_cfg) {
1504 if (hdd_ctx->config->enable_sub_20_channel_width !=
1505 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1506 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1507 cds_cfg->sub_20_channel_width =
1508 WLAN_SUB_20_CH_WIDTH_NONE;
1509 } else {
1510 cds_cfg->sub_20_channel_width =
1511 hdd_ctx->config->enable_sub_20_channel_width;
1512 }
1513 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514
1515 /* first store the INI band capability */
1516 temp_band_cap = hdd_ctx->config->nBandCapability;
1517
1518 hdd_ctx->config->nBandCapability = cfg->band_cap;
1519
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001520 /*
1521 * now overwrite the target band capability with INI
1522 * setting if INI setting is a subset
1523 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524
1525 if ((hdd_ctx->config->nBandCapability == eCSR_BAND_ALL) &&
1526 (temp_band_cap != eCSR_BAND_ALL))
1527 hdd_ctx->config->nBandCapability = temp_band_cap;
1528 else if ((hdd_ctx->config->nBandCapability != eCSR_BAND_ALL) &&
1529 (temp_band_cap != eCSR_BAND_ALL) &&
1530 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001531 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 }
1533
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301534 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001535 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1536 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1537 }
1538
1539 /* This can be extended to other configurations like ht, vht cap... */
1540
Anurag Chouhanc5548422016-02-24 18:33:27 +05301541 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001543 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001544 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001545 static struct qdf_mac_addr default_mac_addr = {
1546 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1547 };
1548 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1549 &default_mac_addr)) {
1550 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1551 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1552 MAC_ADDRESS_STR,
1553 MAC_ADDR_ARRAY(hdd_ctx->config->
1554 intfMacAddr[0].bytes));
1555 } else {
1556 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1557 MAC_ADDRESS_STR,
1558 MAC_ADDR_ARRAY(hdd_ctx->config->
1559 intfMacAddr[0].bytes));
1560 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001561 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 }
1563
1564 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001565 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001566
1567 hdd_ctx->max_intf_count = cfg->max_intf_count;
1568
Jeff Johnsonc875e242016-09-23 18:12:34 -07001569 hdd_lpass_target_config(hdd_ctx, cfg);
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07001570 hdd_green_ap_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1573 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1574
1575 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001578 if (cfg->services.en_11ax) {
1579 hdd_info("11AX: 11ax is enabled - update HDD config");
1580 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1581 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001582
1583 hdd_update_vdev_nss(hdd_ctx);
1584
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301585 hdd_update_hw_dbs_capable(hdd_ctx);
1586
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001587 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001588 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001589 hdd_debug("fine_time_meas_cap: 0x%x",
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001590 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001591
Nitesh Shahe50711f2017-04-26 16:30:45 +05301592 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1593 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1594 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001595 hdd_debug("Init current antenna mode: %d",
Archana Ramachandran393f3792015-11-13 17:13:21 -08001596 hdd_ctx->current_antenna_mode);
1597
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001598 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1599 hdd_ctx->config->bpf_packet_filter_enable);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301600 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301601
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301602 if ((hdd_ctx->config->txBFCsnValue >
1603 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1604 !cfg->tx_bfee_8ss_enabled)
1605 hdd_ctx->config->txBFCsnValue =
1606 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1607
1608 if (sme_cfg_set_int(hdd_ctx->hHal,
1609 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1610 hdd_ctx->config->txBFCsnValue) == QDF_STATUS_E_FAILURE)
1611 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1612
1613
1614 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
1615 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
1616 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301617
1618 /*
1619 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1620 */
1621 hdd_update_wiphy_vhtcap(hdd_ctx);
Arun Khandavallid454d422016-08-17 12:47:05 +05301622 /*
1623 * If BPF is enabled, maxWowFilters set to WMA_STA_WOW_DEFAULT_PTRN_MAX
1624 * because we need atleast WMA_STA_WOW_DEFAULT_PTRN_MAX free slots to
1625 * configure the STA mode wow pattern.
1626 */
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301627 if (hdd_ctx->bpf_enabled)
Arun Khandavallid454d422016-08-17 12:47:05 +05301628 hdd_ctx->config->maxWoWFilters = WMA_STA_WOW_DEFAULT_PTRN_MAX;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301629
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301630 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1631
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001632 /* Configure NAN datapath features */
1633 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001634 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635}
1636
Arif Hussaincd151632017-02-11 16:57:19 -08001637bool hdd_dfs_indicate_radar(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1640 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301641 QDF_STATUS status;
Manishekar Chandrasekaran11ecd552016-08-31 12:44:05 +05301642 hdd_ap_ctx_t *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643
Arif Hussaincd151632017-02-11 16:57:19 -08001644 if (!hdd_ctx || hdd_ctx->config->disableDFSChSwitch) {
1645 hdd_info("skip tx block hdd_ctx=%p, disableDFSChSwitch=%d",
1646 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301647 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001648 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649
Arif Hussaincd151632017-02-11 16:57:19 -08001650 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1651 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1652 adapter = adapterNode->pAdapter;
1653 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1654
1655 if ((QDF_SAP_MODE == adapter->device_mode ||
1656 QDF_P2P_GO_MODE == adapter->device_mode) &&
1657 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
1658 ap_ctx->operatingChannel))) {
1659 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
1660 true;
1661 hdd_info("tx blocked for session: %d",
1662 adapter->sessionId);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301663 }
Arif Hussaincd151632017-02-11 16:57:19 -08001664 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1665 adapterNode = pNext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301667
1668 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670
1671/**
1672 * hdd_is_valid_mac_address() - validate MAC address
1673 * @pMacAddr: Pointer to the input MAC address
1674 *
1675 * This function validates whether the given MAC address is valid or not
1676 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
1677 * where X is the hexa decimal digit character and separated by ':'
1678 * This algorithm works even if MAC address is not separated by ':'
1679 *
1680 * This code checks given input string mac contains exactly 12 hexadecimal
1681 * digits and a separator colon : appears in the input string only after
1682 * an even number of hex digits.
1683 *
1684 * Return: 1 for valid and 0 for invalid
1685 */
1686bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
1687{
1688 int xdigit = 0;
1689 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001690
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 while (*pMacAddr) {
1692 if (isxdigit(*pMacAddr)) {
1693 xdigit++;
1694 } else if (':' == *pMacAddr) {
1695 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
1696 break;
1697
1698 ++separator;
1699 } else {
1700 /* Invalid MAC found */
1701 return 0;
1702 }
1703 ++pMacAddr;
1704 }
1705 return xdigit == 12 && (separator == 5 || separator == 0);
1706}
1707
1708/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301709 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
1710 * @dev: Handle to struct net_device to be updated.
1711 *
1712 * Return: None
1713 */
1714static void hdd_mon_mode_ether_setup(struct net_device *dev)
1715{
1716 dev->header_ops = NULL;
1717 dev->type = ARPHRD_IEEE80211_RADIOTAP;
1718 dev->hard_header_len = ETH_HLEN;
1719 dev->mtu = ETH_DATA_LEN;
1720 dev->addr_len = ETH_ALEN;
1721 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
1722 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
1723 dev->priv_flags |= IFF_TX_SKB_SHARING;
1724
1725 memset(dev->broadcast, 0xFF, ETH_ALEN);
1726}
1727
1728/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001729 * __hdd__mon_open() - HDD Open function
1730 * @dev: Pointer to net_device structure
1731 *
1732 * This is called in response to ifconfig up
1733 *
1734 * Return: 0 for success; non-zero for failure
1735 */
1736static int __hdd_mon_open(struct net_device *dev)
1737{
1738 int ret;
1739
1740 ENTER_DEV(dev);
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05301741 hdd_mon_mode_ether_setup(dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001742 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07001743
1744 if (!ret)
1745 ret = hdd_enable_monitor_mode(dev);
1746
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001747 return ret;
1748}
1749
1750/**
1751 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
1752 * @dev: Pointer to net_device structure
1753 *
1754 * This is called in response to ifconfig up
1755 *
1756 * Return: 0 for success; non-zero for failure
1757 */
Jeff Johnson590e2012016-10-05 16:16:24 -07001758static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07001759{
1760 int ret;
1761
1762 cds_ssr_protect(__func__);
1763 ret = __hdd_mon_open(dev);
1764 cds_ssr_unprotect(__func__);
1765
1766 return ret;
1767}
1768
1769/**
Arun Khandavallifae92942016-08-01 13:31:08 +05301770 * hdd_start_adapter() - Wrapper function for device specific adapter
1771 * @adapter: pointer to HDD adapter
1772 *
1773 * This function is called to start the device specific adapter for
1774 * the mode passed in the adapter's device_mode.
1775 *
1776 * Return: 0 for success; non-zero for failure
1777 */
1778int hdd_start_adapter(hdd_adapter_t *adapter)
1779{
1780
1781 int ret;
1782 enum tQDF_ADAPTER_MODE device_mode = adapter->device_mode;
1783
1784 ENTER_DEV(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001785 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05301786
1787 switch (device_mode) {
1788 case QDF_P2P_CLIENT_MODE:
1789 case QDF_P2P_DEVICE_MODE:
1790 case QDF_OCB_MODE:
1791 case QDF_STA_MODE:
1792 case QDF_MONITOR_MODE:
1793 ret = hdd_start_station_adapter(adapter);
1794 if (ret)
1795 goto err_start_adapter;
1796 break;
1797 case QDF_P2P_GO_MODE:
1798 case QDF_SAP_MODE:
1799 ret = hdd_start_ap_adapter(adapter);
1800 if (ret)
1801 goto err_start_adapter;
1802 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05301803 case QDF_IBSS_MODE:
1804 /*
1805 * For IBSS interface is initialized as part of
1806 * hdd_init_station_mode()
1807 */
1808 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05301809 case QDF_FTM_MODE:
1810 ret = hdd_start_ftm_adapter(adapter);
1811 if (ret)
1812 goto err_start_adapter;
1813 break;
1814 default:
1815 hdd_err("Invalid session type %d", device_mode);
1816 QDF_ASSERT(0);
1817 goto err_start_adapter;
1818 }
1819 if (hdd_set_fw_params(adapter))
1820 hdd_err("Failed to set the FW params for the adapter!");
1821
1822 /*
1823 * Action frame registered in one adapter which will
1824 * applicable to all interfaces
1825 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05301826 ret = wlan_hdd_cfg80211_register_frames(adapter);
1827 if (ret < 0) {
1828 hdd_err("Failed to register frames - ret %d", ret);
1829 goto err_start_adapter;
1830 }
1831
Arun Khandavallifae92942016-08-01 13:31:08 +05301832 EXIT();
1833 return 0;
1834err_start_adapter:
1835 return -EINVAL;
1836}
1837
1838/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05301839 * hdd_enable_power_management() - API to Enable Power Management
1840 *
1841 * API invokes Bus Interface Layer power management functionality
1842 *
1843 * Return: None
1844 */
1845static void hdd_enable_power_management(void)
1846{
1847 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1848
1849 if (!hif_ctx) {
1850 hdd_err("Bus Interface Context is Invalid");
1851 return;
1852 }
1853
1854 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
1855}
1856
1857/**
1858 * hdd_disable_power_management() - API to disable Power Management
1859 *
1860 * API disable Bus Interface Layer Power management functionality
1861 *
1862 * Return: None
1863 */
1864static void hdd_disable_power_management(void)
1865{
1866 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
1867
1868 if (!hif_ctx) {
1869 hdd_err("Bus Interface Context is Invalid");
1870 return;
1871 }
1872
1873 hif_disable_power_management(hif_ctx);
1874}
1875
1876/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05301877 * hdd_update_hw_sw_info() - API to update the HW/SW information
1878 *
1879 * API to update the HW and SW information in the driver
1880 *
1881 * Return: None
1882 */
1883static void hdd_update_hw_sw_info(hdd_context_t *hdd_ctx)
1884{
1885 void *hif_sc;
1886
1887 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
1888 if (!hif_sc) {
1889 hdd_err("HIF context is NULL");
1890 return;
1891 }
1892
1893 /*
1894 * target hw version/revision would only be retrieved after firmware
1895 * download
1896 */
1897 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
1898 &hdd_ctx->target_hw_revision,
1899 &hdd_ctx->target_hw_name);
1900
1901 /* Get the wlan hw/fw version */
1902 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
1903
1904 return;
1905}
1906
1907/**
gbian62edd7e2017-03-07 13:12:13 +08001908 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
1909 * @hdd_ctx: Pointer to hdd context
1910 *
1911 * Return: none
1912 */
1913static void
1914hdd_update_cds_ac_specs_params(hdd_context_t *hdd_ctx)
1915{
1916 uint8_t num_entries = 0;
1917 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
1918 uint8_t *tx_sched_wrr_ac;
1919 int i;
1920 cds_context_type *cds_ctx;
1921
1922 if (NULL == hdd_ctx)
1923 return;
1924
1925 if (NULL == hdd_ctx->config) {
1926 /* Do nothing if hdd_ctx is invalid */
1927 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
1928 return;
1929 }
1930
1931 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1932
1933 if (!cds_ctx) {
1934 hdd_err("Invalid CDS Context");
1935 return;
1936 }
1937
1938 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
1939 switch (i) {
1940 case OL_TX_WMM_AC_BE:
1941 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
1942 break;
1943 case OL_TX_WMM_AC_BK:
1944 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
1945 break;
1946 case OL_TX_WMM_AC_VI:
1947 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
1948 break;
1949 case OL_TX_WMM_AC_VO:
1950 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
1951 break;
1952 default:
1953 tx_sched_wrr_ac = NULL;
1954 break;
1955 }
1956
1957 hdd_string_to_u8_array(tx_sched_wrr_ac,
1958 tx_sched_wrr_param,
1959 &num_entries,
1960 sizeof(tx_sched_wrr_param));
1961
1962 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
1963 cds_ctx->ac_specs[i].wrr_skip_weight =
1964 tx_sched_wrr_param[0];
1965 cds_ctx->ac_specs[i].credit_threshold =
1966 tx_sched_wrr_param[1];
1967 cds_ctx->ac_specs[i].send_limit =
1968 tx_sched_wrr_param[2];
1969 cds_ctx->ac_specs[i].credit_reserve =
1970 tx_sched_wrr_param[3];
1971 cds_ctx->ac_specs[i].discard_weight =
1972 tx_sched_wrr_param[4];
1973 }
1974
1975 num_entries = 0;
1976 }
1977}
1978
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07001979#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07001980static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
1981 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
1982{
1983 hdd_adapter_t *adapter = NULL;
1984 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1985
1986 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
1987 if (!adapter) {
1988 hdd_err("Adapter is NULL");
1989 return PM_MAX_NUM_OF_MODE;
1990 }
1991
1992 return policy_mgr_convert_device_mode_to_qdf_type(
1993 adapter->device_mode);
1994}
1995
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07001996static void hdd_register_policy_manager_callback(
1997 struct wlan_objmgr_psoc *psoc)
1998{
1999 struct policy_mgr_hdd_cbacks hdd_cbacks;
2000 hdd_cbacks.sap_restart_chan_switch_cb =
2001 sap_restart_chan_switch_cb;
2002 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2003 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002004 hdd_cbacks.get_mode_for_non_connected_vdev =
2005 wlan_hdd_get_mode_for_non_connected_vdev;
2006
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002007 if (QDF_STATUS_SUCCESS !=
2008 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2009 hdd_err("HDD callback registration with policy manager failed");
2010 }
2011}
2012#else
2013static void hdd_register_policy_manager_callback(
2014 struct wlan_objmgr_psoc *psoc)
2015{
2016}
2017#endif
2018
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002019#ifdef WLAN_FEATURE_NAN_CONVERGENCE
2020static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2021{
2022 struct nan_callbacks cb_obj = {0};
2023
2024 cb_obj.ndi_open = hdd_ndi_open;
2025 cb_obj.ndi_close = hdd_ndi_close;
2026 cb_obj.ndi_start = hdd_ndi_start;
2027 cb_obj.ndi_delete = hdd_ndi_delete;
2028 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2029 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2030
Naveen Rawat37f62c82017-03-26 22:24:43 -07002031 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2032 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002033 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002034
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002035 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2036}
2037#else
2038static void hdd_nan_register_callbacks(hdd_context_t *hdd_ctx)
2039{
2040}
2041#endif
2042
gbian62edd7e2017-03-07 13:12:13 +08002043/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302044 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2045 * @hdd_ctx: HDD context
2046 * @adapter: HDD adapter
2047 * @reinit: flag to indicate from SSR or normal path
2048 *
2049 * This function maintains the driver state machine it will be invoked from
2050 * startup, reinit and change interface. Depending on the driver state shall
2051 * perform the opening of the modules.
2052 *
2053 * Return: 0 for success; non-zero for failure
2054 */
2055int hdd_wlan_start_modules(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
2056 bool reinit)
2057{
2058 int ret;
2059 qdf_device_t qdf_dev;
2060 QDF_STATUS status;
2061 p_cds_contextType p_cds_context;
2062 bool unint = false;
2063 void *hif_ctx;
2064
2065 ENTER();
2066
2067 p_cds_context = cds_get_global_context();
2068 if (!p_cds_context) {
2069 hdd_err("Global Context is NULL");
2070 QDF_ASSERT(0);
2071 return -EINVAL;
2072 }
2073
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002074 hdd_debug("start modules called in state! :%d reinit: %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302075 hdd_ctx->driver_status, reinit);
2076
2077 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2078 if (!qdf_dev) {
2079 hdd_err("QDF Device Context is Invalid return");
2080 return -EINVAL;
2081 }
2082
2083 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302084 hdd_ctx->start_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05302085
2086 if (QDF_TIMER_STATE_RUNNING ==
2087 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
2088
2089 hdd_set_idle_ps_config(hdd_ctx, false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002090 hdd_debug("Interface change Timer running Stop timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05302091 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
2092 }
2093
2094 switch (hdd_ctx->driver_status) {
2095 case DRIVER_MODULES_UNINITIALIZED:
2096 unint = true;
2097 /* Fall through dont add break here */
2098 case DRIVER_MODULES_CLOSED:
2099 if (!reinit && !unint) {
2100 ret = pld_power_on(qdf_dev->dev);
2101 if (ret) {
2102 hdd_err("Failed to Powerup the device: %d", ret);
2103 goto release_lock;
2104 }
2105 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002106
2107 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2108 hdd_ctx->config->enable_fw_log);
2109
Arun Khandavallifae92942016-08-01 13:31:08 +05302110 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2111 qdf_dev->bus_type,
2112 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2113 HIF_ENABLE_TYPE_PROBE);
2114 if (ret) {
2115 hdd_err("Failed to open hif: %d", ret);
2116 goto power_down;
2117 }
2118
2119 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302120 if (!hif_ctx) {
2121 hdd_err("hif context is null!!");
2122 goto power_down;
2123 }
2124
Arun Khandavallifae92942016-08-01 13:31:08 +05302125 status = ol_cds_init(qdf_dev, hif_ctx);
2126 if (status != QDF_STATUS_SUCCESS) {
2127 hdd_err("No Memory to Create BMI Context :%d", status);
2128 goto hif_close;
2129 }
2130
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002131 ret = hdd_update_config(hdd_ctx);
2132 if (ret) {
2133 hdd_err("Failed to update configuration :%d", ret);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302134 goto ol_cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002135 }
2136
gbian62edd7e2017-03-07 13:12:13 +08002137 hdd_update_cds_ac_specs_params(hdd_ctx);
2138
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302139 status = cds_open(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302140 if (!QDF_IS_STATUS_SUCCESS(status)) {
2141 hdd_err("Failed to Open CDS: %d", status);
Abhishek Singhe9068f12017-03-31 14:14:52 +05302142 goto ol_cds_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302143 }
2144
Mukul Sharma9d797a02017-01-05 20:26:03 +05302145 /* initalize components configurations after psoc open */
2146 ret = hdd_update_components_config(hdd_ctx);
2147 if (ret) {
2148 hdd_err("Failed to update components configs :%d",
2149 ret);
2150 goto close;
2151 }
2152
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002153 /*
2154 * NAN compoenet requires certian operations like, open adapter,
2155 * close adapter, etc. to be initiated by HDD, for those
2156 * register HDD callbacks with UMAC's NAN componenet.
2157 */
2158 hdd_nan_register_callbacks(hdd_ctx);
2159
Arun Khandavallifae92942016-08-01 13:31:08 +05302160 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2161
2162 status = cds_pre_enable(hdd_ctx->pcds_context);
2163 if (!QDF_IS_STATUS_SUCCESS(status)) {
2164 hdd_err("Failed to pre-enable CDS: %d", status);
2165 goto close;
2166 }
2167
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002168 hdd_register_policy_manager_callback(
2169 hdd_ctx->hdd_psoc);
2170
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302171 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302172 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302173
Arun Khandavallifae92942016-08-01 13:31:08 +05302174 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2175 sme_register_ftm_msg_processor(hdd_ctx->hHal,
2176 hdd_ftm_mc_process_msg);
2177 break;
2178 }
2179 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002180 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302181 break;
2182 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302183
2184 if (reinit) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002185 if (hdd_ipa_uc_ssr_reinit(hdd_ctx)) {
2186 hdd_err("HDD IPA UC reinit failed");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002187 goto post_disable;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002188 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302189 }
2190
Arun Khandavallifae92942016-08-01 13:31:08 +05302191 /* Fall through dont add break here */
2192 case DRIVER_MODULES_OPENED:
2193 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002194 hdd_alert("adapter is Null");
2195 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302196 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302197 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2198 hdd_err("in ftm mode, no need to configure cds modules");
2199 break;
2200 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302201 if (hdd_configure_cds(hdd_ctx, adapter)) {
2202 hdd_err("Failed to Enable cds modules");
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002203 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302204 }
Komal Seelamf2136bb2016-09-28 18:30:44 +05302205 hdd_enable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05302206 hdd_info("Driver Modules Successfully Enabled");
2207 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2208 break;
2209 case DRIVER_MODULES_ENABLED:
2210 hdd_info("Driver modules already Enabled");
2211 break;
2212 default:
2213 hdd_err("WLAN start invoked in wrong state! :%d\n",
2214 hdd_ctx->driver_status);
2215 goto release_lock;
2216 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302217 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302218 mutex_unlock(&hdd_ctx->iface_change_lock);
2219 EXIT();
2220 return 0;
2221
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002222post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002223 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002224
Arun Khandavallifae92942016-08-01 13:31:08 +05302225close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002226 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302227 cds_close(hdd_ctx->hdd_psoc, p_cds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05302228
2229ol_cds_free:
2230 ol_cds_free();
2231
2232hif_close:
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05302233 hdd_hif_close(hdd_ctx, p_cds_context->pHIFContext);
Arun Khandavallifae92942016-08-01 13:31:08 +05302234power_down:
2235 if (!reinit && !unint)
2236 pld_power_off(qdf_dev->dev);
2237release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302238 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302239 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302240 EXIT();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002241
Arun Khandavallifae92942016-08-01 13:31:08 +05302242 return -EINVAL;
2243}
2244
Naveen Rawat910726a2017-03-06 11:42:51 -08002245#ifdef WIFI_POS_CONVERGED
2246static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2247{
2248 int ret = os_if_wifi_pos_register_nl();
2249
2250 if (ret)
2251 hdd_err("os_if_wifi_pos_register_nl failed");
2252
2253 return ret;
2254}
2255
2256static int hdd_deactivate_wifi_pos(void)
2257{
2258 int ret = os_if_wifi_pos_deregister_nl();
2259
2260 if (ret)
2261 hdd_err("os_if_wifi_pos_deregister_nl failed");
2262
2263 return ret;
2264}
2265
2266/**
2267 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2268 * @hdd_ctx: hdd context
2269 *
2270 * Return: status of operation
2271 */
2272static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2273{
2274 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2275 struct hdd_config *cfg = hdd_ctx->config;
2276
2277 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2278 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2279 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2280 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2281 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2282 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2283 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2284 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2285}
2286#else
2287static int hdd_activate_wifi_pos(hdd_context_t *hdd_ctx)
2288{
2289 return oem_activate_service(hdd_ctx);
2290}
2291
2292static int hdd_deactivate_wifi_pos(void)
2293{
2294 return 0;
2295}
2296
2297static void hdd_populate_wifi_pos_cfg(hdd_context_t *hdd_ctx)
2298{
2299}
2300#endif
2301
Arun Khandavallifae92942016-08-01 13:31:08 +05302302/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002303 * __hdd_open() - HDD Open function
2304 * @dev: Pointer to net_device structure
2305 *
2306 * This is called in response to ifconfig up
2307 *
2308 * Return: 0 for success; non-zero for failure
2309 */
2310static int __hdd_open(struct net_device *dev)
2311{
2312 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2313 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2314 int ret;
2315
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002316 ENTER_DEV(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302317 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Arun Khandavallifae92942016-08-01 13:31:08 +05302318 adapter->sessionId, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319
2320 ret = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302321 if (ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002322 return ret;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002324
Arun Khandavallifae92942016-08-01 13:31:08 +05302325 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2326 if (ret) {
2327 hdd_err("Failed to start WLAN modules return");
2328 return -ret;
2329 }
2330
2331
2332 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2333 ret = hdd_start_adapter(adapter);
2334 if (ret) {
2335 hdd_err("Failed to start adapter :%d",
2336 adapter->device_mode);
2337 return ret;
2338 }
2339 }
2340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2342 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002343 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002344 /* Enable TX queues only when we are connected */
2345 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302346 WLAN_START_ALL_NETIF_QUEUE,
2347 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002348 }
2349
Naveen Rawat286def52016-09-23 15:38:02 -07002350 /* Enable carrier and transmit queues for NDI */
2351 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002352 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002353 wlan_hdd_netif_queue_control(adapter,
2354 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2355 WLAN_CONTROL_PATH);
2356 }
2357
Naveen Rawat910726a2017-03-06 11:42:51 -08002358 hdd_populate_wifi_pos_cfg(hdd_ctx);
2359
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002360 return ret;
2361}
2362
Arun Khandavallifae92942016-08-01 13:31:08 +05302363
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002364/**
2365 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2366 * @dev: Pointer to net_device structure
2367 *
2368 * This is called in response to ifconfig up
2369 *
2370 * Return: 0 for success; non-zero for failure
2371 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002372static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002373{
2374 int ret;
2375
2376 cds_ssr_protect(__func__);
2377 ret = __hdd_open(dev);
2378 cds_ssr_unprotect(__func__);
2379
2380 return ret;
2381}
2382
2383/**
2384 * __hdd_stop() - HDD stop function
2385 * @dev: Pointer to net_device structure
2386 *
2387 * This is called in response to ifconfig down
2388 *
2389 * Return: 0 for success; non-zero for failure
2390 */
2391static int __hdd_stop(struct net_device *dev)
2392{
2393 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2394 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2395 int ret;
2396
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002397 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002398
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302399 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002400 adapter->sessionId, adapter->device_mode));
2401
2402 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302403 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002405
2406 /* Nothing to be done if the interface is not opened */
2407 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002408 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002409 return -ENODEV;
2410 }
2411
2412 /* Make sure the interface is marked as closed */
2413 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002414 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05302415 wlan_hdd_netif_queue_control(adapter,
2416 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2417 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418
2419 /*
Naveen Rawat286def52016-09-23 15:38:02 -07002420 * NAN data interface is different in some sense. The traffic on NDI is
2421 * bursty in nature and depends on the need to transfer. The service
2422 * layer may down the interface after the usage and up again when
2423 * required. In some sense, the NDI is expected to be available
2424 * (like SAP) iface until NDI delete request is issued by the service
2425 * layer. Skip BSS termination and adapter deletion for NAN Data
2426 * interface (NDI).
2427 */
2428 if (WLAN_HDD_IS_NDI(adapter))
2429 return 0;
2430
2431 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002432 * The interface is marked as down for outside world (aka kernel)
2433 * But the driver is pretty much alive inside. The driver needs to
2434 * tear down the existing connection on the netdev (session)
2435 * cleanup the data pipes and wait until the control plane is stabilized
2436 * for this interface. The call also needs to wait until the above
2437 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002438 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002439 * That is intentional to be able to scan if it is a STA/P2P interface
2440 */
Arun Khandavallifae92942016-08-01 13:31:08 +05302441 hdd_stop_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442
2443 /* DeInit the adapter. This ensures datapath cleanup as well */
2444 hdd_deinit_adapter(hdd_ctx, adapter, true);
2445
Arun Khandavallifae92942016-08-01 13:31:08 +05302446
2447 /*
2448 * Find if any iface is up. If any iface is up then can't put device to
2449 * sleep/power save mode
2450 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05302451 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002452 hdd_debug("Closing all modules from the hdd_stop");
Arun Khandavallifae92942016-08-01 13:31:08 +05302453 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05302454 hdd_ctx->config->iface_change_wait_time);
Arun Khandavallifae92942016-08-01 13:31:08 +05302455 }
2456
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002457 EXIT();
2458 return 0;
2459}
2460
2461/**
2462 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
2463 * @dev: pointer to net_device structure
2464 *
2465 * This is called in response to ifconfig down
2466 *
2467 * Return: 0 for success and error number for failure
2468 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002469static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002470{
2471 int ret;
2472
2473 cds_ssr_protect(__func__);
2474 ret = __hdd_stop(dev);
2475 cds_ssr_unprotect(__func__);
2476
2477 return ret;
2478}
2479
2480/**
2481 * __hdd_uninit() - HDD uninit function
2482 * @dev: Pointer to net_device structure
2483 *
2484 * This is called during the netdev unregister to uninitialize all data
2485 * associated with the device
2486 *
2487 * Return: None
2488 */
2489static void __hdd_uninit(struct net_device *dev)
2490{
2491 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2492
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002493 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002494
2495 do {
2496 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002497 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002498 break;
2499 }
2500
2501 if (NULL == adapter->pHddCtx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002502 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002503 break;
2504 }
2505
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002506 if (dev != adapter->dev)
2507 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002508
2509 hdd_deinit_adapter(adapter->pHddCtx, adapter, true);
2510
2511 /* after uninit our adapter structure will no longer be valid */
2512 adapter->dev = NULL;
2513 adapter->magic = 0;
2514 } while (0);
2515
2516 EXIT();
2517}
2518
2519/**
2520 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
2521 * @dev: pointer to net_device structure
2522 *
2523 * This is called during the netdev unregister to uninitialize all data
2524 * associated with the device
2525 *
2526 * Return: none
2527 */
2528static void hdd_uninit(struct net_device *dev)
2529{
2530 cds_ssr_protect(__func__);
2531 __hdd_uninit(dev);
2532 cds_ssr_unprotect(__func__);
2533}
2534
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002535static int hdd_open_cesium_nl_sock(void)
2536{
2537#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2538 struct netlink_kernel_cfg cfg = {
2539 .groups = WLAN_NLINK_MCAST_GRP_ID,
2540 .input = NULL
2541 };
2542#endif
2543 int ret = 0;
2544
2545#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
2546 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2547#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
2548 THIS_MODULE,
2549#endif
2550 &cfg);
2551#else
2552 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
2553 WLAN_NLINK_MCAST_GRP_ID,
2554 NULL, NULL, THIS_MODULE);
2555#endif
2556
2557 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07002558 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002559 ret = -ECONNREFUSED;
2560 }
2561
2562 return ret;
2563}
2564
2565static void hdd_close_cesium_nl_sock(void)
2566{
2567 if (NULL != cesium_nl_srv_sock) {
2568 netlink_kernel_release(cesium_nl_srv_sock);
2569 cesium_nl_srv_sock = NULL;
2570 }
2571}
2572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002573/**
2574 * __hdd_set_mac_address() - set the user specified mac address
2575 * @dev: Pointer to the net device.
2576 * @addr: Pointer to the sockaddr.
2577 *
2578 * This function sets the user specified mac address using
2579 * the command ifconfig wlanX hw ether <mac adress>.
2580 *
2581 * Return: 0 for success, non zero for failure
2582 */
2583static int __hdd_set_mac_address(struct net_device *dev, void *addr)
2584{
2585 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2586 hdd_context_t *hdd_ctx;
2587 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302588 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 int ret;
2590
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002591 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002592
2593 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2594 ret = wlan_hdd_validate_context(hdd_ctx);
2595 if (0 != ret)
2596 return ret;
2597
2598 memcpy(&adapter->macAddressCurrent, psta_mac_addr->sa_data, ETH_ALEN);
2599 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
2600
2601 EXIT();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05302602 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002603}
2604
2605/**
2606 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
2607 * function from SSR
2608 * @dev: pointer to net_device structure
2609 * @addr: Pointer to the sockaddr
2610 *
2611 * This function sets the user specified mac address using
2612 * the command ifconfig wlanX hw ether <mac adress>.
2613 *
2614 * Return: 0 for success.
2615 */
2616static int hdd_set_mac_address(struct net_device *dev, void *addr)
2617{
2618 int ret;
2619
2620 cds_ssr_protect(__func__);
2621 ret = __hdd_set_mac_address(dev, addr);
2622 cds_ssr_unprotect(__func__);
2623
2624 return ret;
2625}
2626
2627uint8_t *wlan_hdd_get_intf_addr(hdd_context_t *hdd_ctx)
2628{
2629 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002630
Anurag Chouhan6d760662016-02-20 16:05:43 +05302631 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002632 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
2633 break;
2634 }
2635
Anurag Chouhan6d760662016-02-20 16:05:43 +05302636 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637 return NULL;
2638
2639 hdd_ctx->config->intfAddrMask |= (1 << i);
2640 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
2641}
2642
2643void wlan_hdd_release_intf_addr(hdd_context_t *hdd_ctx, uint8_t *releaseAddr)
2644{
2645 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002646
Anurag Chouhan6d760662016-02-20 16:05:43 +05302647 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002648 if (!memcmp(releaseAddr,
2649 &hdd_ctx->config->intfMacAddr[i].bytes[0],
2650 6)) {
2651 hdd_ctx->config->intfAddrMask &= ~(1 << i);
2652 break;
2653 }
2654 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655}
2656
2657#ifdef WLAN_FEATURE_PACKET_FILTERING
2658/**
2659 * __hdd_set_multicast_list() - set the multicast address list
2660 * @dev: Pointer to the WLAN device.
2661 * @skb: Pointer to OS packet (sk_buff).
2662 *
2663 * This funciton sets the multicast address list.
2664 *
2665 * Return: None
2666 */
2667static void __hdd_set_multicast_list(struct net_device *dev)
2668{
2669 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 int i = 0, status;
2671 struct netdev_hw_addr *ha;
2672 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302673 struct pmo_mc_addr_list_params *mc_list_request = NULL;
2674 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2675 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002676
Jeff Johnson3c3994a2016-02-11 08:12:30 -08002677 ENTER_DEV(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05302678 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302679 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05302680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302682 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302683 goto out;
2684
2685 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
2686 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002687 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302688 goto out;
2689 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002690
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05302691 /* Delete already configured multicast address list */
2692 if (adapter->mc_addr_list.mc_cnt > 0) {
2693 hdd_info("clear previously configured MC address list");
2694 hdd_disable_and_flush_mc_addr_list(adapter,
2695 pmo_mc_list_change_notify);
2696 }
2697
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002698 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002699 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302700 hdd_disable_and_flush_mc_addr_list(adapter,
2701 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702 } else {
2703 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302704 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002705 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302706 pmo_ucfg_max_mc_addr_supported(psoc));
2707 hdd_disable_and_flush_mc_addr_list(adapter,
2708 pmo_mc_list_change_notify);
2709 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002712 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05302713 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714 if (i == mc_count)
2715 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302716 memset(&(mc_list_request->mc_addr[i].bytes),
2717 0, ETH_ALEN);
2718 memcpy(&(mc_list_request->mc_addr[i].bytes),
2719 ha->addr, ETH_ALEN);
2720 hdd_info("mlist[%d] = %pM", i,
2721 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 i++;
2723 }
2724 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302725
2726 mc_list_request->psoc = psoc;
2727 mc_list_request->vdev_id = adapter->sessionId;
2728 mc_list_request->count = mc_count;
2729 status = hdd_cache_mc_addr_list(mc_list_request);
2730 if (status == 0) {
2731 hdd_enable_mc_addr_filtering(adapter,
2732 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002733 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302734 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002735 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302736out:
2737 if (mc_list_request)
2738 qdf_mem_free(mc_list_request);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05302739 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740}
2741
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05302742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743/**
2744 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
2745 * @dev: pointer to net_device
2746 *
2747 * Return: none
2748 */
2749static void hdd_set_multicast_list(struct net_device *dev)
2750{
2751 cds_ssr_protect(__func__);
2752 __hdd_set_multicast_list(dev);
2753 cds_ssr_unprotect(__func__);
2754}
2755#endif
2756
2757/**
2758 * hdd_select_queue() - used by Linux OS to decide which queue to use first
2759 * @dev: Pointer to the WLAN device.
2760 * @skb: Pointer to OS packet (sk_buff).
2761 *
2762 * This function is registered with the Linux OS for network
2763 * core to decide which queue to use first.
2764 *
2765 * Return: ac, Queue Index/access category corresponding to UP in IP header
2766 */
2767static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
2768#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2769 , void *accel_priv
2770#endif
2771#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
2772 , select_queue_fallback_t fallback
2773#endif
2774)
2775{
2776 return hdd_wmm_select_queue(dev, skb);
2777}
2778
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002779static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780 .ndo_open = hdd_open,
2781 .ndo_stop = hdd_stop,
2782 .ndo_uninit = hdd_uninit,
2783 .ndo_start_xmit = hdd_hard_start_xmit,
2784 .ndo_tx_timeout = hdd_tx_timeout,
2785 .ndo_get_stats = hdd_get_stats,
2786 .ndo_do_ioctl = hdd_ioctl,
2787 .ndo_set_mac_address = hdd_set_mac_address,
2788 .ndo_select_queue = hdd_select_queue,
2789#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002790 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791#endif
2792};
2793
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002794/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002795static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002796 .ndo_open = hdd_mon_open,
2797 .ndo_stop = hdd_stop,
2798 .ndo_get_stats = hdd_get_stats,
2799};
2800
2801/**
2802 * hdd_set_station_ops() - update net_device ops for monitor mode
2803 * @pWlanDev: Handle to struct net_device to be updated.
2804 * Return: None
2805 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002806void hdd_set_station_ops(struct net_device *pWlanDev)
2807{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002808 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
2809 pWlanDev->netdev_ops = &wlan_mon_drv_ops;
2810 else
2811 pWlanDev->netdev_ops = &wlan_drv_ops;
2812}
2813
Komal Seelama89be8d2016-09-29 11:09:26 +05302814#ifdef FEATURE_RUNTIME_PM
Komal Seelam8634b772016-09-29 12:12:24 +05302815/**
2816 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
2817 * @hdd_ctx: HDD context
2818 *
2819 * Return: None
2820 */
2821static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx)
2822{
2823 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2824
Komal Seelamaa75f262016-09-29 12:32:13 +05302825 ctx->roc = qdf_runtime_lock_init("roc");
Komal Seelam81cb1662016-09-29 12:39:08 +05302826 ctx->dfs = qdf_runtime_lock_init("dfs");
Komal Seelam8634b772016-09-29 12:12:24 +05302827}
2828
2829/**
2830 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
2831 * @hdd_ctx: HDD Context
2832 *
2833 * Return: None
2834 */
2835static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx)
2836{
2837 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
2838
Komal Seelamaa75f262016-09-29 12:32:13 +05302839 qdf_runtime_lock_deinit(ctx->roc);
2840 ctx->roc = NULL;
Komal Seelam81cb1662016-09-29 12:39:08 +05302841 qdf_runtime_lock_deinit(ctx->dfs);
2842 ctx->dfs = NULL;
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05302843
2844 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
Komal Seelam8634b772016-09-29 12:12:24 +05302845}
2846
Komal Seelama89be8d2016-09-29 11:09:26 +05302847static void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter)
2848{
2849 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2850
2851 ctx->connect = qdf_runtime_lock_init("connect");
2852}
2853
2854static void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter)
2855{
2856 struct hdd_connect_pm_context *ctx = &adapter->connect_rpm_ctx;
2857
2858 qdf_runtime_lock_deinit(ctx->connect);
2859 ctx->connect = NULL;
2860}
2861#else /* FEATURE_RUNTIME_PM */
Komal Seelam8634b772016-09-29 12:12:24 +05302862static void hdd_runtime_suspend_context_init(hdd_context_t *hdd_ctx) {}
2863static void hdd_runtime_suspend_context_deinit(hdd_context_t *hdd_ctx) {}
Komal Seelama89be8d2016-09-29 11:09:26 +05302864static inline void hdd_adapter_runtime_suspend_init(hdd_adapter_t *adapter) {}
2865static inline void hdd_adapter_runtime_suspend_denit(hdd_adapter_t *adapter) {}
2866#endif /* FEATURE_RUNTIME_PM */
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002867/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08002868 * hdd_alloc_station_adapter() - allocate the station hdd adapter
2869 * @hdd_ctx: global hdd context
2870 * @macAddr: mac address to assign to the interface
2871 * @name: User-visible name of the interface
2872 *
2873 * hdd adapter pointer would point to the netdev->priv space, this function
2874 * would retrive the pointer, and setup the hdd adapter configuration.
2875 *
2876 * Return: the pointer to hdd adapter, otherwise NULL
2877 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878static hdd_adapter_t *hdd_alloc_station_adapter(hdd_context_t *hdd_ctx,
2879 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08002880 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881 const char *name)
2882{
2883 struct net_device *pWlanDev = NULL;
2884 hdd_adapter_t *adapter = NULL;
2885 /*
2886 * cfg80211 initialization and registration....
2887 */
Ryan Hsu07495ea2016-01-21 15:25:39 -08002888 pWlanDev = alloc_netdev_mq(sizeof(hdd_adapter_t), name,
2889#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
2890 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002892 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
2893 hdd_mon_mode_ether_setup : ether_setup),
2894 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895
2896 if (pWlanDev != NULL) {
2897
2898 /* Save the pointer to the net_device in the HDD adapter */
2899 adapter = (hdd_adapter_t *) netdev_priv(pWlanDev);
2900
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302901 qdf_mem_zero(adapter, sizeof(hdd_adapter_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
2903 adapter->dev = pWlanDev;
2904 adapter->pHddCtx = hdd_ctx;
2905 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Arun Khandavalli9ad88f02016-09-01 19:03:37 +05302906 adapter->sessionId = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907
2908 init_completion(&adapter->session_open_comp_var);
2909 init_completion(&adapter->session_close_comp_var);
2910 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05302911 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002912 init_completion(&adapter->linkup_event_var);
2913 init_completion(&adapter->cancel_rem_on_chan_var);
2914 init_completion(&adapter->rem_on_chan_ready_event);
2915 init_completion(&adapter->sta_authorized_event);
2916 init_completion(&adapter->offchannel_tx_event);
2917 init_completion(&adapter->tx_action_cnf_event);
2918#ifdef FEATURE_WLAN_TDLS
2919 init_completion(&adapter->tdls_add_station_comp);
2920 init_completion(&adapter->tdls_del_station_comp);
2921 init_completion(&adapter->tdls_mgmt_comp);
2922 init_completion(&adapter->tdls_link_establish_req_comp);
2923#endif
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08002924 init_completion(&adapter->ibss_peer_info_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002925 init_completion(&adapter->change_country_code);
2926
2927
2928 init_completion(&adapter->scan_info.abortscan_event_var);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05302929 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930
2931 adapter->offloads_configured = false;
2932 adapter->isLinkUpSvcNeeded = false;
2933 adapter->higherDtimTransition = true;
2934 /* Init the net_device structure */
2935 strlcpy(pWlanDev->name, name, IFNAMSIZ);
2936
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302937 qdf_mem_copy(pWlanDev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 sizeof(tSirMacAddr));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302939 qdf_mem_copy(adapter->macAddressCurrent.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940 sizeof(tSirMacAddr));
2941 pWlanDev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942
2943 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
2944 pWlanDev->features |=
2945 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
2946 pWlanDev->features |= NETIF_F_RXCSUM;
2947
Dhanashri Atre83d373d2015-07-28 16:45:59 -07002948 hdd_set_tso_flags(hdd_ctx, pWlanDev);
2949
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002950 hdd_set_station_ops(adapter->dev);
2951
2952 pWlanDev->destructor = free_netdev;
2953 pWlanDev->ieee80211_ptr = &adapter->wdev;
Mohit Khannaee9e80f2015-11-10 11:32:49 -08002954 pWlanDev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 adapter->wdev.wiphy = hdd_ctx->wiphy;
2956 adapter->wdev.netdev = pWlanDev;
2957 /* set pWlanDev's parent to underlying device */
2958 SET_NETDEV_DEV(pWlanDev, hdd_ctx->parent_dev);
2959 hdd_wmm_init(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05302960 hdd_adapter_runtime_suspend_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002961 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05302962 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002963 }
2964
2965 return adapter;
2966}
2967
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07002968static QDF_STATUS hdd_register_interface(hdd_adapter_t *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002969{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07002970 struct net_device *dev = adapter->dev;
2971 int ret;
2972
2973 ENTER();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002974
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08002975 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07002976 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
2977
2978 ret = dev_alloc_name(dev, dev->name);
2979 if (ret < 0) {
2980 hdd_err(
2981 "unable to get dev name: %s, err = 0x%x",
2982 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302983 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984 }
2985 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07002986
2987 ret = register_netdevice(dev);
2988 if (ret) {
2989 hdd_err("register_netdevice(%s) failed, err = 0x%x",
2990 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302991 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 }
2993 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07002994 ret = register_netdev(dev);
2995 if (ret) {
2996 hdd_err("register_netdev(%s) failed, err = 0x%x",
2997 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302998 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002999 }
3000 }
3001 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3002
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003003 EXIT();
3004
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303005 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006}
3007
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003008QDF_STATUS hdd_sme_close_session_callback(void *pContext)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003009{
3010 hdd_adapter_t *adapter = pContext;
3011
3012 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003013 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303014 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015 }
3016
3017 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003018 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303019 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020 }
3021
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003022 /*
3023 * For NAN Data interface, the close session results in the final
3024 * indication to the userspace
3025 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003026 if (adapter->device_mode == QDF_NDI_MODE)
3027 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 /*
3032 * We can be blocked while waiting for scheduled work to be
3033 * flushed, and the adapter structure can potentially be freed, in
3034 * which case the magic will have been reset. So make sure the
3035 * magic is still good, and hence the adapter structure is still
3036 * valid, before signaling completion
3037 */
3038 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
3039 complete(&adapter->session_close_comp_var);
3040
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303041 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003042}
3043
Krunal Soni8c37e322016-02-03 16:08:37 -08003044/**
3045 * hdd_check_and_init_tdls() - check and init TDLS operation for desired mode
3046 * @adapter: pointer to device adapter
Krunal Soni8c37e322016-02-03 16:08:37 -08003047 *
3048 * This routine will check the mode of adapter and if it is required then it
3049 * will initialize the TDLS operations
3050 *
3051 * Return: QDF_STATUS
3052 */
3053#ifdef FEATURE_WLAN_TDLS
Dustin Brownd28772b2017-03-17 14:16:07 -07003054static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003055{
Dustin Brownd28772b2017-03-17 14:16:07 -07003056 if (adapter->device_mode == QDF_IBSS_MODE)
3057 return QDF_STATUS_SUCCESS;
3058
3059 if (wlan_hdd_tdls_init(adapter)) {
3060 hdd_err("wlan_hdd_tdls_init failed");
3061 return QDF_STATUS_E_FAILURE;
Krunal Soni8c37e322016-02-03 16:08:37 -08003062 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003063 set_bit(TDLS_INIT_DONE, &adapter->event_flags);
3064
Krunal Soni8c37e322016-02-03 16:08:37 -08003065 return QDF_STATUS_SUCCESS;
3066}
3067#else
Dustin Brownd28772b2017-03-17 14:16:07 -07003068static QDF_STATUS hdd_check_and_init_tdls(hdd_adapter_t *adapter)
Krunal Soni8c37e322016-02-03 16:08:37 -08003069{
3070 return QDF_STATUS_SUCCESS;
3071}
3072#endif
3073
Dustin Brownd28772b2017-03-17 14:16:07 -07003074int hdd_vdev_ready(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075{
Dustin Brownd28772b2017-03-17 14:16:07 -07003076 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077
Dustin Brownd28772b2017-03-17 14:16:07 -07003078 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003079 if (QDF_IS_STATUS_ERROR(status))
3080 return qdf_status_to_os_return(status);
3081
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003082 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003083 if (QDF_IS_STATUS_ERROR(status))
3084 return qdf_status_to_os_return(status);
3085
3086 if (wma_capability_enhanced_mcast_filter())
3087 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3088 else
3089 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003090
3091 return qdf_status_to_os_return(status);
3092}
3093
3094int hdd_vdev_destroy(hdd_adapter_t *adapter)
3095{
3096 QDF_STATUS status;
3097 int errno;
3098 hdd_context_t *hdd_ctx;
3099 unsigned long rc;
3100
3101 hdd_info("destroying vdev %d", adapter->sessionId);
3102
3103 /* vdev created sanity check */
3104 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3105 hdd_err("vdev for Id %d does not exist", adapter->sessionId);
3106 return -EINVAL;
3107 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003108 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003109 /* do vdev logical destroy via objmgr */
3110 errno = hdd_objmgr_destroy_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003111 if (errno) {
3112 hdd_err("failed to destroy objmgr vdev: %d", errno);
3113 return errno;
3114 }
3115
Yue Maf9782842017-05-08 12:49:49 -07003116 /*
3117 * In SSR case, there is no need to destroy vdev in firmware since
3118 * it has already asserted. vdev can be released directly.
3119 */
3120 if (cds_is_driver_recovering())
3121 goto release_vdev;
3122
Dustin Brownd28772b2017-03-17 14:16:07 -07003123 /* close sme session (destroy vdev in firmware via legacy API) */
3124 INIT_COMPLETION(adapter->session_close_comp_var);
3125 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3126 status = sme_close_session(hdd_ctx->hHal, adapter->sessionId,
3127 hdd_sme_close_session_callback, adapter);
3128 if (QDF_IS_STATUS_ERROR(status)) {
3129 hdd_err("failed to close sme session: %d", status);
3130 return qdf_status_to_os_return(status);
3131 }
3132
3133 /* block on a completion variable until sme session is closed */
3134 rc = wait_for_completion_timeout(
3135 &adapter->session_close_comp_var,
3136 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3137 if (!rc) {
3138 hdd_err("timed out waiting for close sme session: %ld", rc);
3139 if (adapter->device_mode == QDF_NDI_MODE)
3140 hdd_ndp_session_end_handler(adapter);
3141 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3142 return -ETIMEDOUT;
3143 }
3144
Yue Maf9782842017-05-08 12:49:49 -07003145release_vdev:
Dustin Brown0d2eeae2017-03-24 15:21:32 -07003146 /* now that sme session is closed, allow physical vdev destroy */
3147 errno = hdd_objmgr_release_vdev(adapter);
3148 if (errno) {
3149 hdd_err("failed to release objmgr vdev: %d", errno);
3150 return errno;
3151 }
3152
Dustin Brownd28772b2017-03-17 14:16:07 -07003153 hdd_info("vdev destroyed successfully");
3154
3155 return 0;
3156}
3157
3158int hdd_vdev_create(hdd_adapter_t *adapter)
3159{
3160 QDF_STATUS status;
3161 int errno;
3162 hdd_context_t *hdd_ctx;
3163 uint32_t type;
3164 uint32_t sub_type;
3165 unsigned long rc;
3166
3167 hdd_info("creating new vdev");
3168
3169 /* determine vdev (sub)type */
3170 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303171 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003172 hdd_err("failed to get vdev type: %d", status);
3173 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003175
3176 /* do vdev create via objmgr */
3177 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003178 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003179 if (errno) {
3180 hdd_err("failed to create objmgr vdev: %d", errno);
3181 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003183
3184 /* Open a SME session (prepare vdev in firmware via legacy API) */
3185 INIT_COMPLETION(adapter->session_open_comp_var);
3186 status = sme_open_session(hdd_ctx->hHal, hdd_sme_roam_callback, adapter,
3187 (uint8_t *)&adapter->macAddressCurrent,
3188 adapter->sessionId, type, sub_type);
3189 if (QDF_IS_STATUS_ERROR(status)) {
3190 hdd_err("failed to open sme session: %d", status);
3191 errno = qdf_status_to_os_return(status);
3192 goto objmgr_vdev_destroy;
3193 }
3194
3195 /* block on a completion variable until sme session is opened */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003196 rc = wait_for_completion_timeout(
3197 &adapter->session_open_comp_var,
3198 msecs_to_jiffies(WLAN_WAIT_TIME_SESSIONOPENCLOSE));
3199 if (!rc) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003200 hdd_err("timed out waiting for open sme session: %ld", rc);
3201 errno = -ETIMEDOUT;
Abhishek Singh7e95dbc2017-07-06 17:57:50 +05303202 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3203 goto hdd_vdev_destroy;
Dustin Brownd28772b2017-03-17 14:16:07 -07003204 }
3205
3206 /* firmware ready for component communication, raise vdev_ready event */
3207 errno = hdd_vdev_ready(adapter);
3208 if (errno) {
3209 hdd_err("failed to dispatch vdev ready event: %d", errno);
3210 goto hdd_vdev_destroy;
3211 }
3212
3213 hdd_info("vdev %d created successfully", adapter->sessionId);
3214
3215 return 0;
3216
3217 /*
3218 * Due to legacy constraints, we need to destroy in the same order as
3219 * create. So, split error handling into 2 cases to accommodate.
3220 */
3221
3222objmgr_vdev_destroy:
Dustin Brown7d043f62017-03-27 12:07:36 -07003223 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003224
3225 return errno;
3226
3227hdd_vdev_destroy:
3228 QDF_BUG(!hdd_vdev_destroy(adapter));
3229
3230 return errno;
3231}
3232
3233QDF_STATUS hdd_init_station_mode(hdd_adapter_t *adapter)
3234{
3235 hdd_station_ctx_t *pHddStaCtx = &adapter->sessionCtx.station;
3236 hdd_context_t *hdd_ctx;
3237 QDF_STATUS status;
3238 int ret_val;
3239
3240 ret_val = hdd_vdev_create(adapter);
3241 if (ret_val) {
3242 hdd_err("failed to create vdev: %d", ret_val);
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05303243 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 }
3245
Dustin Brownd28772b2017-03-17 14:16:07 -07003246 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3247 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3248 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Naveen Rawata410c5a2016-09-19 14:22:33 -07003249 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
Dustin Brownd28772b2017-03-17 14:16:07 -07003250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 /* Register wireless extensions */
Dustin Brownd28772b2017-03-17 14:16:07 -07003252 status = hdd_register_wext(adapter->dev);
3253 if (QDF_IS_STATUS_ERROR(status)) {
3254 hdd_err("failed to register wireless extensions: %d", status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003255 goto error_register_wext;
3256 }
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003257 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303259 qdf_mem_set(pHddStaCtx->conn_info.staId,
3260 sizeof(pHddStaCtx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
3261
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003262 /* set fast roaming capability in sme session */
3263 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->sessionId,
3264 adapter->fast_roaming_allowed);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 /* Set the default operation channel */
3266 pHddStaCtx->conn_info.operationChannel =
3267 hdd_ctx->config->OperatingChannel;
3268
3269 /* Make the default Auth Type as OPEN */
3270 pHddStaCtx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
3271
3272 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303273 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003274 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 status, status);
3276 goto error_init_txrx;
3277 }
3278
3279 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3280
3281 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303282 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003283 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 status, status);
3285 goto error_wmm_init;
3286 }
3287
3288 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3289
Naveen Rawat247a8682017-06-05 15:00:31 -07003290 ret_val = sme_cli_set_command(adapter->sessionId,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291 WMI_PDEV_PARAM_BURST_ENABLE,
3292 hdd_ctx->config->enableSifsBurst,
3293 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003294 if (ret_val)
3295 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296
Dustin Brownd28772b2017-03-17 14:16:07 -07003297 status = hdd_check_and_init_tdls(adapter);
Krunal Soni8c37e322016-02-03 16:08:37 -08003298 if (status != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299 goto error_tdls_init;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300
Dhanashri Atre1a6a4ce2017-05-03 19:40:33 -07003301 adapter->dev->features |= NETIF_F_LRO;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303302 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304error_tdls_init:
3305 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3306 hdd_wmm_adapter_close(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307error_wmm_init:
3308 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3309 hdd_deinit_tx_rx(adapter);
3310error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07003311 hdd_unregister_wext(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07003313 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003315 return status;
3316}
3317
3318void hdd_cleanup_actionframe(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
3319{
3320 hdd_cfg80211_state_t *cfgState;
3321
3322 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3323
3324 if (NULL != cfgState->buf) {
3325 unsigned long rc;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003326
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003327 rc = wait_for_completion_timeout(
3328 &adapter->tx_action_cnf_event,
3329 msecs_to_jiffies(ACTION_FRAME_TX_TIMEOUT));
3330 if (!rc) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003331 hdd_err("HDD Wait for Action Confirmation Failed!!");
Masti, Narayanraddif8f6e7e2015-08-25 10:22:46 +05303332 /*
3333 * Inform tx status as FAILURE to upper layer and free
3334 * cfgState->buf
3335 */
3336 hdd_send_action_cnf(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337 }
3338 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339}
3340
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303341/**
3342 * hdd_station_adapter_deinit() - De-initialize the station adapter
3343 * @hdd_ctx: global hdd context
3344 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07003345 * @rtnl_held: Used to indicate whether or not the caller is holding
3346 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303347 *
3348 * This function De-initializes the STA/P2P/OCB adapter.
3349 *
3350 * Return: None.
3351 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003352static void hdd_station_adapter_deinit(hdd_context_t *hdd_ctx,
3353 hdd_adapter_t *adapter,
3354 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303355{
3356 ENTER_DEV(adapter->dev);
3357
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303358 if (adapter->dev) {
3359 if (rtnl_held)
3360 adapter->dev->wireless_handlers = NULL;
3361 else {
3362 rtnl_lock();
3363 adapter->dev->wireless_handlers = NULL;
3364 rtnl_unlock();
3365 }
3366 }
3367
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303368 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
3369 hdd_deinit_tx_rx(adapter);
3370 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3371 }
3372
3373 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3374 hdd_wmm_adapter_close(adapter);
3375 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3376 }
3377
3378 hdd_cleanup_actionframe(hdd_ctx, adapter);
3379 wlan_hdd_tdls_exit(adapter);
3380
3381 EXIT();
3382}
3383
3384/**
3385 * hdd_ap_adapter_deinit() - De-initialize the ap adapter
3386 * @hdd_ctx: global hdd context
3387 * @adapter: HDD adapter
3388 * @rtnl_held: the rtnl lock hold flag
3389 * This function De-initializes the AP/P2PGo adapter.
3390 *
3391 * Return: None.
3392 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003393static void hdd_ap_adapter_deinit(hdd_context_t *hdd_ctx,
3394 hdd_adapter_t *adapter,
3395 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303396{
3397 ENTER_DEV(adapter->dev);
3398
3399 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
3400 hdd_wmm_adapter_close(adapter);
3401 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
3402 }
Liangwei Dong8baf7c82016-10-11 01:26:59 -04003403 wlan_hdd_undo_acs(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303404
3405 hdd_cleanup_actionframe(hdd_ctx, adapter);
3406
3407 hdd_unregister_hostapd(adapter, rtnl_held);
3408
3409 EXIT();
3410}
3411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412void hdd_deinit_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3413 bool rtnl_held)
3414{
3415 ENTER();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003418 case QDF_STA_MODE:
3419 case QDF_P2P_CLIENT_MODE:
3420 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 {
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05303422 hdd_station_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423 break;
3424 }
3425
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003426 case QDF_SAP_MODE:
3427 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428 {
3429
Arun Khandavalli7e857c32016-06-26 12:07:16 +05303430 hdd_ap_adapter_deinit(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 break;
3432 }
3433
3434 default:
3435 break;
3436 }
3437
3438 EXIT();
3439}
3440
Jeff Johnson590e2012016-10-05 16:16:24 -07003441static void hdd_cleanup_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
3442 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443{
3444 struct net_device *pWlanDev = NULL;
3445
3446 if (adapter)
3447 pWlanDev = adapter->dev;
3448 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07003449 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 return;
3451 }
3452
Rajeev Kumardca5f812016-02-04 17:28:06 -08003453 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05303454
3455 if (adapter->scan_info.default_scan_ies) {
3456 qdf_mem_free(adapter->scan_info.default_scan_ies);
3457 adapter->scan_info.default_scan_ies = NULL;
3458 }
3459
Komal Seelama89be8d2016-09-29 11:09:26 +05303460 hdd_adapter_runtime_suspend_denit(adapter);
3461
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 /*
3463 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
3464 * the driver is almost closed and cannot handle either control
3465 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003466 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
3467 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 * is not right. Setting this flag helps hdd_stop() to recognize that
3469 * the interface is closed and restricts any operations on that
3470 */
3471 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3472
3473 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003474 if (rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 unregister_netdevice(pWlanDev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003476 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 unregister_netdev(pWlanDev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 /*
3479 * Note that the adapter is no longer valid at this point
3480 * since the memory has been reclaimed
3481 */
3482 }
3483}
3484
Jeff Johnson590e2012016-10-05 16:16:24 -07003485static QDF_STATUS hdd_check_for_existing_macaddr(hdd_context_t *hdd_ctx,
3486 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487{
3488 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
3489 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303490 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303493 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 adapter = adapterNode->pAdapter;
3495 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303496 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303498 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 }
3500 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
3501 adapterNode = pNext;
3502 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303503 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504}
Ryan Hsu07495ea2016-01-21 15:25:39 -08003505
Arun Khandavalli2358d522016-05-16 18:05:37 +05303506#ifdef CONFIG_FW_LOGS_BASED_ON_INI
3507/**
3508 * hdd_set_fw_log_params() - Set log parameters to FW
3509 * @hdd_ctx: HDD Context
3510 * @adapter: HDD Adapter
3511 *
3512 * This function set the FW Debug log level based on the INI.
3513 *
3514 * Return: None
3515 */
3516static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3517 hdd_adapter_t *adapter)
3518{
3519 uint8_t count = 0, numentries = 0,
3520 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
3521 uint32_t value = 0;
3522 int ret;
3523
Arun Khandavallifae92942016-08-01 13:31:08 +05303524 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
3525 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003526 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05303527 return;
3528 }
3529
Arun Khandavallifae92942016-08-01 13:31:08 +05303530 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05303531 hdd_ctx->fw_log_settings.dl_type =
3532 hdd_ctx->config->enableFwLogType;
Naveen Rawat247a8682017-06-05 15:00:31 -07003533 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303534 WMI_DBGLOG_TYPE,
3535 hdd_ctx->config->enableFwLogType,
3536 DBG_CMD);
3537 if (ret != 0)
3538 hdd_err("Failed to enable FW log type ret %d",
3539 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303540
3541 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05303542 hdd_ctx->config->enableFwLogLevel;
Naveen Rawat247a8682017-06-05 15:00:31 -07003543 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303544 WMI_DBGLOG_LOG_LEVEL,
3545 hdd_ctx->config->enableFwLogLevel,
3546 DBG_CMD);
3547 if (ret != 0)
3548 hdd_err("Failed to enable FW log level ret %d",
3549 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303550
3551 hdd_string_to_u8_array(
3552 hdd_ctx->config->enableFwModuleLogLevel,
3553 moduleloglevel,
3554 &numentries,
3555 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
3556
3557 while (count < numentries) {
3558 /*
3559 * FW module log level input string looks like
3560 * below:
3561 * gFwDebugModuleLoglevel=<FW Module ID>,
3562 * <Log Level>,...
3563 * For example:
3564 * gFwDebugModuleLoglevel=
3565 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
3566 * Above input string means :
3567 * For FW module ID 1 enable log level 0
3568 * For FW module ID 2 enable log level 1
3569 * For FW module ID 3 enable log level 2
3570 * For FW module ID 4 enable log level 3
3571 * For FW module ID 5 enable log level 4
3572 * For FW module ID 6 enable log level 5
3573 * For FW module ID 7 enable log level 6
3574 */
3575
Nishank Aggarwale239d962017-03-03 12:26:02 +05303576 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
3577 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
3578 hdd_err("Module id %d and dbglog level %d input length is more than max",
3579 moduleloglevel[count],
3580 moduleloglevel[count + 1]);
3581 return;
3582 }
3583
3584 value = moduleloglevel[count] << 16;
3585 value |= moduleloglevel[count + 1];
Naveen Rawat247a8682017-06-05 15:00:31 -07003586 ret = sme_cli_set_command(adapter->sessionId,
Arun Khandavallifae92942016-08-01 13:31:08 +05303587 WMI_DBGLOG_MOD_LOG_LEVEL,
3588 value, DBG_CMD);
3589 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05303590 hdd_err("Failed to enable FW module log level %d ret %d",
3591 value, ret);
3592
3593 count += 2;
3594 }
Arun Khandavallifae92942016-08-01 13:31:08 +05303595
Arun Khandavalli2358d522016-05-16 18:05:37 +05303596}
3597#else
3598static void hdd_set_fw_log_params(hdd_context_t *hdd_ctx,
3599 hdd_adapter_t *adapter)
3600{
3601}
3602
3603#endif
3604
3605/**
3606 * hdd_set_fw_params() - Set parameters to firmware
3607 * @adapter: HDD adapter
3608 *
3609 * This function Sets various parameters to fw once the
3610 * adapter is started.
3611 *
3612 * Return: 0 on success or errno on failure
3613 */
3614int hdd_set_fw_params(hdd_adapter_t *adapter)
3615{
3616 int ret;
3617 hdd_context_t *hdd_ctx;
3618
3619 ENTER_DEV(adapter->dev);
3620
3621 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3622 if (!hdd_ctx)
3623 return -EINVAL;
3624
Dustin Brown732ab9c2017-06-15 13:24:09 -07003625 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
3626 hdd_debug("FTM Mode is active; nothing to do");
3627 return 0;
3628 }
3629
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05303630 ret = sme_cli_set_command(adapter->sessionId,
3631 WMI_PDEV_PARAM_DTIM_SYNTH,
3632 hdd_ctx->config->enable_lprx, PDEV_CMD);
3633 if (ret) {
3634 hdd_err("Failed to set LPRx");
3635 goto error;
3636 }
3637
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05303638 if (adapter->device_mode == QDF_STA_MODE) {
3639 sme_set_smps_cfg(adapter->sessionId,
3640 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
3641 hdd_ctx->config->upper_brssi_thresh);
3642
3643 sme_set_smps_cfg(adapter->sessionId,
3644 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
3645 hdd_ctx->config->lower_brssi_thresh);
3646
3647 sme_set_smps_cfg(adapter->sessionId,
3648 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
3649 hdd_ctx->config->enable_dtim_1chrx);
3650 }
3651
Dustin Brown732ab9c2017-06-15 13:24:09 -07003652 if (hdd_ctx->config->enable2x2) {
3653 hdd_debug("configuring 2x2 mode fw params");
3654
Naveen Rawat247a8682017-06-05 15:00:31 -07003655 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003656 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
3657 hdd_ctx->config->enable_cck_tx_fir_override,
3658 PDEV_CMD);
3659 if (ret) {
3660 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
3661 ret);
3662 goto error;
3663 }
3664 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05303665#define HDD_DTIM_1CHAIN_RX_ID 0x5
3666#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07003667 hdd_debug("configuring 1x1 mode fw params");
3668
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003669 /*
3670 * Disable DTIM 1 chain Rx when in 1x1,
3671 * we are passing two value
3672 * as param_id << 29 | param_value.
3673 * Below param_value = 0(disable)
3674 */
Naveen Rawat247a8682017-06-05 15:00:31 -07003675 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003676 WMI_STA_SMPS_PARAM_CMDID,
3677 HDD_DTIM_1CHAIN_RX_ID <<
3678 HDD_SMPS_PARAM_VALUE_S,
3679 VDEV_CMD);
3680 if (ret) {
3681 hdd_err("DTIM 1 chain set failed %d", ret);
3682 goto error;
3683 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303684
Naveen Rawat247a8682017-06-05 15:00:31 -07003685 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003686 WMI_PDEV_PARAM_TX_CHAIN_MASK,
3687 hdd_ctx->config->txchainmask1x1,
3688 PDEV_CMD);
3689 if (ret) {
3690 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK set failed %d",
3691 ret);
3692 goto error;
3693 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303694
Naveen Rawat247a8682017-06-05 15:00:31 -07003695 ret = sme_cli_set_command(adapter->sessionId,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003696 WMI_PDEV_PARAM_RX_CHAIN_MASK,
3697 hdd_ctx->config->rxchainmask1x1,
3698 PDEV_CMD);
3699 if (ret) {
3700 hdd_err("WMI_PDEV_PARAM_RX_CHAIN_MASK set failed %d",
3701 ret);
3702 goto error;
3703 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303704#undef HDD_DTIM_1CHAIN_RX_ID
3705#undef HDD_SMPS_PARAM_VALUE_S
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07003706 }
3707
Naveen Rawat247a8682017-06-05 15:00:31 -07003708 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003709 WMI_PDEV_PARAM_HYST_EN,
3710 hdd_ctx->config->enableMemDeepSleep,
3711 PDEV_CMD);
3712 if (ret) {
3713 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
3714 goto error;
3715 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05303716
Naveen Rawat247a8682017-06-05 15:00:31 -07003717 ret = sme_cli_set_command(adapter->sessionId,
Dustin Brown732ab9c2017-06-15 13:24:09 -07003718 WMI_VDEV_PARAM_ENABLE_RTSCTS,
3719 hdd_ctx->config->rts_profile,
3720 VDEV_CMD);
3721 if (ret) {
3722 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
3723 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05303724 }
3725
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07003726 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
3727
3728 ret = wma_cli_set_command(adapter->sessionId,
3729 GEN_VDEV_PARAM_AMSDU,
3730 hdd_ctx->config->max_amsdu_num,
3731 GEN_CMD);
3732 if (ret != 0) {
3733 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
3734 goto error;
3735 }
3736
Arun Khandavalli2358d522016-05-16 18:05:37 +05303737 hdd_set_fw_log_params(hdd_ctx, adapter);
Arun Khandavalli2358d522016-05-16 18:05:37 +05303738 EXIT();
Dustin Brown732ab9c2017-06-15 13:24:09 -07003739
Arun Khandavalli2358d522016-05-16 18:05:37 +05303740 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05303741
Arun Khandavalli2358d522016-05-16 18:05:37 +05303742error:
3743 return -EINVAL;
3744}
3745
Ryan Hsu07495ea2016-01-21 15:25:39 -08003746/**
3747 * hdd_open_adapter() - open and setup the hdd adatper
3748 * @hdd_ctx: global hdd context
3749 * @session_type: type of the interface to be created
3750 * @iface_name: User-visible name of the interface
3751 * @macAddr: MAC address to assign to the interface
3752 * @name_assign_type: the name of assign type of the netdev
3753 * @rtnl_held: the rtnl lock hold flag
3754 *
3755 * This function open and setup the hdd adpater according to the device
3756 * type request, assign the name, the mac address assigned, and then prepared
3757 * the hdd related parameters, queue, lock and ready to start.
3758 *
3759 * Return: the pointer of hdd adapter, otherwise NULL.
3760 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761hdd_adapter_t *hdd_open_adapter(hdd_context_t *hdd_ctx, uint8_t session_type,
3762 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003763 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003764 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765{
3766 hdd_adapter_t *adapter = NULL;
3767 hdd_adapter_list_node_t *pHddAdapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303768 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769 hdd_cfg80211_state_t *cfgState;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771
3772 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
3773 /*
3774 * Max limit reached on the number of vdevs configured by the
3775 * host. Return error
3776 */
Arun Khandavallifae92942016-08-01 13:31:08 +05303777 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
3778 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 return NULL;
3780 }
3781
3782 if (macAddr == NULL) {
3783 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05303784 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 return NULL;
3786 }
3787 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303788 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303789 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
3790 " already exists",
3791 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 return NULL;
3793 }
3794
3795 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003796 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003797 /* Reset locally administered bit if the device mode is STA */
3798 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
3799 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003800 case QDF_P2P_CLIENT_MODE:
3801 case QDF_P2P_DEVICE_MODE:
3802 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07003803 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303804 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003805 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3806 name_assign_type,
3807 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808
3809 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05303810 hdd_err("failed to allocate adapter for session %d",
3811 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 return NULL;
3813 }
3814
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003815 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003817 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303819 else if (QDF_MONITOR_MODE == session_type)
3820 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821 else
3822 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3823
3824 adapter->device_mode = session_type;
3825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 /*
3828 * Workqueue which gets scheduled in IPv4 notification
3829 * callback
3830 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 INIT_WORK(&adapter->ipv4NotifierWorkQueue,
3832 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833
3834#ifdef WLAN_NS_OFFLOAD
3835 /*
3836 * Workqueue which gets scheduled in IPv6
3837 * notification callback.
3838 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 INIT_WORK(&adapter->ipv6NotifierWorkQueue,
3840 hdd_ipv6_notifier_work_queue);
3841#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303843 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303845 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 }
3847
3848 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003849 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303851 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3852 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05303853
Ravi Joshi1a292562017-05-18 16:28:54 -07003854 /* Initialize NAN Data Interface */
3855 if (QDF_NDI_MODE == session_type) {
3856 status = hdd_init_nan_data_mode(adapter);
3857 if (QDF_STATUS_SUCCESS != status)
3858 goto err_free_netdev;
3859 }
3860
3861 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003863 case QDF_P2P_GO_MODE:
3864 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08003865 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
3866 name_assign_type,
3867 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003868 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003869 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05303870 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871 return NULL;
3872 }
3873
3874 adapter->wdev.iftype =
3875 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08003876 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877 NL80211_IFTYPE_P2P_GO;
3878 adapter->device_mode = session_type;
3879
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003880 status = hdd_register_interface(adapter, rtnl_held);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303881 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3883 goto err_free_netdev;
3884 }
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003885 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303887 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3888 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303890 case QDF_FTM_MODE:
3891 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
3892 name_assign_type,
3893 "wlan0");
3894 if (NULL == adapter) {
3895 hdd_err("Failed to allocate adapter for FTM mode");
3896 return NULL;
3897 }
3898 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
3899 adapter->device_mode = session_type;
3900 status = hdd_register_interface(adapter, rtnl_held);
3901 if (QDF_STATUS_SUCCESS != status) {
3902 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
3903 goto err_free_netdev;
3904 }
3905 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003906 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303907 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303908 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3909 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05303910 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003912 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303913 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 return NULL;
3915 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916
hqueaa33ee2017-05-04 17:56:35 +08003917 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
3918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 cfgState = WLAN_HDD_GET_CFG_STATE_PTR(adapter);
3920 mutex_init(&cfgState->remain_on_chan_ctx_lock);
3921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303922 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 /* Add it to the hdd's session list. */
3924 pHddAdapterNode =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303925 qdf_mem_malloc(sizeof(hdd_adapter_list_node_t));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 if (NULL == pHddAdapterNode) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303927 status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 } else {
3929 pHddAdapterNode->pAdapter = adapter;
3930 status = hdd_add_adapter_back(hdd_ctx, pHddAdapterNode);
3931 }
3932 }
3933
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303934 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 if (NULL != adapter) {
3936 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
3937 adapter = NULL;
3938 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003939 if (NULL != pHddAdapterNode)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303940 qdf_mem_free(pHddAdapterNode);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003941
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 return NULL;
3943 }
3944
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303945 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08003946 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
3947 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 /* Adapter successfully added. Increment the vdev count */
3950 hdd_ctx->current_intf_count++;
3951
Jeff Johnson5880d792016-08-15 13:32:30 -07003952 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 hdd_ctx->current_intf_count);
3954
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08003955 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 }
3957
Rajeev Kumardca5f812016-02-04 17:28:06 -08003958 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07003959 hdd_err("Interface %s wow debug_fs init failed",
3960 netdev_name(adapter->dev));
3961
3962 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
3963 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964
3965 return adapter;
3966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967err_free_netdev:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 wlan_hdd_release_intf_addr(hdd_ctx, adapter->macAddressCurrent.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05303969 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970
3971 return NULL;
3972}
3973
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303974QDF_STATUS hdd_close_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003975 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976{
3977 hdd_adapter_list_node_t *adapterNode, *pCurrent, *pNext;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303978 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979
3980 status = hdd_get_front_adapter(hdd_ctx, &pCurrent);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303981 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnson5880d792016-08-15 13:32:30 -07003982 hdd_warn("adapter list empty %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 status);
3984 return status;
3985 }
3986
3987 while (pCurrent->pAdapter != adapter) {
3988 status = hdd_get_next_adapter(hdd_ctx, pCurrent, &pNext);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303989 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 break;
3991
3992 pCurrent = pNext;
3993 }
3994 adapterNode = pCurrent;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303995 if (QDF_STATUS_SUCCESS == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003996 hdd_debug("wait for bus bw work to flush");
Dustin Brown5ec6b552017-03-31 12:11:40 -07003997 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05303998 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -07003999
4000 /* cleanup adapter */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004001 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4002 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 hdd_cleanup_adapter(hdd_ctx, adapterNode->pAdapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 hdd_remove_adapter(hdd_ctx, adapterNode);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304005 qdf_mem_free(adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 adapterNode = NULL;
4007
Dustin Brown5ec6b552017-03-31 12:11:40 -07004008 /* conditionally restart the bw timer */
4009 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
4010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 /* Adapter removed. Decrement vdev count */
4012 if (hdd_ctx->current_intf_count != 0)
4013 hdd_ctx->current_intf_count--;
4014
4015 /* Fw will take care incase of concurrency */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304016 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304018
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304019 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020}
4021
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004022/**
4023 * hdd_close_all_adapters - Close all open adapters
4024 * @hdd_ctx: Hdd context
4025 * rtnl_held: True if RTNL lock held
4026 *
4027 * Close all open adapters.
4028 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304029 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004030 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304031QDF_STATUS hdd_close_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032{
4033 hdd_adapter_list_node_t *pHddAdapterNode;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304034 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035
4036 ENTER();
4037
4038 do {
4039 status = hdd_remove_front_adapter(hdd_ctx, &pHddAdapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304040 if (pHddAdapterNode && QDF_STATUS_SUCCESS == status) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304041 wlan_hdd_release_intf_addr(hdd_ctx,
4042 pHddAdapterNode->pAdapter->macAddressCurrent.bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 hdd_cleanup_adapter(hdd_ctx, pHddAdapterNode->pAdapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004044 rtnl_held);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304045 qdf_mem_free(pHddAdapterNode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304046 /* Adapter removed. Decrement vdev count */
4047 if (hdd_ctx->current_intf_count != 0)
4048 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304050 } while (NULL != pHddAdapterNode && QDF_STATUS_E_EMPTY != status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051
4052 EXIT();
4053
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304054 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055}
4056
4057void wlan_hdd_reset_prob_rspies(hdd_adapter_t *pHostapdAdapter)
4058{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304059 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 switch (pHostapdAdapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004063 case QDF_STA_MODE:
4064 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 {
4066 hdd_station_ctx_t *pHddStaCtx =
4067 WLAN_HDD_GET_STATION_CTX_PTR(pHostapdAdapter);
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004068 bssid = &pHddStaCtx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 break;
4070 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004071 case QDF_SAP_MODE:
4072 case QDF_P2P_GO_MODE:
4073 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 {
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004075 bssid = &pHostapdAdapter->macAddressCurrent;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 break;
4077 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004078 case QDF_FTM_MODE:
4079 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 default:
4081 /*
4082 * wlan_hdd_reset_prob_rspies should not have been called
4083 * for these kind of devices
4084 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004085 hdd_err("Unexpected request for the current device type %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 pHostapdAdapter->device_mode);
4087 return;
4088 }
4089
Anurag Chouhanc5548422016-02-24 18:33:27 +05304090 qdf_copy_macaddr(&updateIE.bssid, bssid);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091 updateIE.smeSessionId = pHostapdAdapter->sessionId;
4092 updateIE.ieBufferlength = 0;
4093 updateIE.pAdditionIEBuffer = NULL;
4094 updateIE.append = true;
4095 updateIE.notify = false;
4096 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(pHostapdAdapter),
4097 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304098 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004099 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 }
4101}
4102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304103QDF_STATUS hdd_stop_adapter(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 const bool bCloseSession)
4105{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304106 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107 hdd_wext_state_t *pWextState = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
4108 union iwreq_data wrqu;
4109 tSirUpdateIE updateIE;
4110 unsigned long rc;
Sachin Ahuja988fd102016-09-15 17:16:25 +05304111 hdd_scaninfo_t *scan_info = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112
4113 ENTER();
4114
Sachin Ahuja988fd102016-09-15 17:16:25 +05304115 scan_info = &adapter->scan_info;
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004116 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304117 wlan_hdd_netif_queue_control(adapter,
4118 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4119 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004121 case QDF_STA_MODE:
4122 case QDF_P2P_CLIENT_MODE:
4123 case QDF_IBSS_MODE:
4124 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004125 case QDF_NDI_MODE:
4126 if ((QDF_NDI_MODE == adapter->device_mode) ||
4127 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4129 hdd_is_connecting(
4130 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004131 INIT_COMPLETION(adapter->disconnect_comp_var);
4132 /*
4133 * For NDI do not use pWextState from sta_ctx, if needed
4134 * extract from ndi_ctx.
4135 */
4136 if (QDF_NDI_MODE == adapter->device_mode)
4137 qdf_ret_status = sme_roam_disconnect(
4138 hdd_ctx->hHal,
4139 adapter->sessionId,
4140 eCSR_DISCONNECT_REASON_NDI_DELETE);
4141 else if (pWextState->roamProfile.BSSType ==
4142 eCSR_BSS_TYPE_START_IBSS)
4143 qdf_ret_status = sme_roam_disconnect(
4144 hdd_ctx->hHal,
4145 adapter->sessionId,
4146 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004147 else if (QDF_STA_MODE == adapter->device_mode)
4148 qdf_ret_status =
4149 wlan_hdd_try_disconnect(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004151 qdf_ret_status = sme_roam_disconnect(
4152 hdd_ctx->hHal,
4153 adapter->sessionId,
4154 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004155 /* success implies disconnect command got
4156 * queued up successfully
4157 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004158 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4159 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 rc = wait_for_completion_timeout(
4161 &adapter->disconnect_comp_var,
4162 msecs_to_jiffies
4163 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004164 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004165 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004167 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4168 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 memset(&wrqu, '\0', sizeof(wrqu));
4170 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4171 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4172 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4173 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304174 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004175 if (scan_info != NULL && scan_info->mScanPending)
Mahesh A Saptasagarebb47fa2016-07-21 18:11:38 +05304176 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004177
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304178 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179
4180#ifdef WLAN_OPEN_SOURCE
4181 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
4182#endif
4183
4184 hdd_deregister_tx_flow_control(adapter);
4185
4186#ifdef WLAN_NS_OFFLOAD
4187#ifdef WLAN_OPEN_SOURCE
4188 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
4189#endif
4190#endif
4191
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304192 if (adapter->device_mode == QDF_STA_MODE)
4193 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4194 adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195 /*
4196 * It is possible that the caller of this function does not
4197 * wish to close the session
4198 */
Krunal Soni985b8132017-02-10 18:49:08 -08004199 if (true == bCloseSession) {
4200 if (0 != wlan_hdd_try_disconnect(adapter)) {
4201 hdd_err("Error: Can't disconnect adapter");
4202 return QDF_STATUS_E_FAILURE;
4203 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004204 hdd_vdev_destroy(adapter);
Krunal Soni985b8132017-02-10 18:49:08 -08004205 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 break;
4207
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004208 case QDF_SAP_MODE:
4209 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 /* Any softap specific cleanup here... */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004211 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
4213
4214 hdd_deregister_tx_flow_control(adapter);
4215
Kapil Guptac1224bf2017-06-22 21:22:40 +05304216 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217 mutex_lock(&hdd_ctx->sap_lock);
4218 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304219 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05304220 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
4222 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223 status = wlansap_stop_bss(
4224 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304226 if (QDF_IS_STATUS_SUCCESS(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227 hdd_hostapd_state_t *hostapd_state =
4228 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304229 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304230 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05304231 qdf_status =
4232 qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -08004233 qdf_stop_bss_event,
4234 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235
Anurag Chouhance0dc992016-02-16 18:18:03 +05304236 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004237 hdd_err("failure waiting for wlansap_stop_bss %d",
4238 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 }
4240 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004241 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004242 }
4243 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004244 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4245 adapter->device_mode,
4246 adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247
Anurag Chouhanc5548422016-02-24 18:33:27 +05304248 qdf_copy_macaddr(&updateIE.bssid,
Srinivas Girigowda8b983962015-11-18 22:14:34 -08004249 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004250 updateIE.smeSessionId = adapter->sessionId;
4251 updateIE.ieBufferlength = 0;
4252 updateIE.pAdditionIEBuffer = NULL;
4253 updateIE.append = false;
4254 updateIE.notify = false;
4255 /* Probe bcn reset */
4256 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4257 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304258 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004259 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 }
4261 /* Assoc resp reset */
4262 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
4263 &updateIE,
4264 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304265 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004266 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 }
4268 /* Reset WNI_CFG_PROBE_RSP Flags */
4269 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 }
Manikandan Mohan3dad1a42017-06-14 10:50:18 -07004271 qdf_mem_free(adapter->sessionCtx.ap.beacon);
4272 adapter->sessionCtx.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05304273 /*
4274 * If Do_Not_Break_Stream was enabled clear avoid channel list.
4275 */
4276 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
4277 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
4278
Peng Xu66162de2016-02-11 17:01:20 -08004279 if (true == bCloseSession)
Dustin Brown0d2eeae2017-03-24 15:21:32 -07004280 hdd_vdev_destroy(adapter);
Manikandan Mohan5df78272017-03-22 16:28:50 -07004281 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004283 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08004284 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004285 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07004286 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004287 break;
4288 default:
4289 break;
4290 }
4291
4292 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304293 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294}
4295
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05304296/**
4297 * hdd_deinit_all_adapters - deinit all adapters
4298 * @hdd_ctx: HDD context
4299 * @rtnl_held: True if RTNL lock held
4300 *
4301 */
4302void hdd_deinit_all_adapters(hdd_context_t *hdd_ctx, bool rtnl_held)
4303{
4304 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4305 QDF_STATUS status;
4306 hdd_adapter_t *adapter;
4307
4308 ENTER();
4309
4310 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4311
4312 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
4313 adapter = adapter_node->pAdapter;
4314 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
4315 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4316 adapter_node = next;
4317 }
4318
4319 EXIT();
4320}
4321
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304322QDF_STATUS hdd_stop_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323{
4324 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304325 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326 hdd_adapter_t *adapter;
4327
4328 ENTER();
4329
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304330 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4331
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4333
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304334 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 adapter = adapterNode->pAdapter;
4336 hdd_stop_adapter(hdd_ctx, adapter, true);
4337 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4338 adapterNode = pNext;
4339 }
4340
4341 EXIT();
4342
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304343 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004344}
4345
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304346QDF_STATUS hdd_reset_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347{
4348 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304349 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 hdd_adapter_t *adapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004351 hdd_station_ctx_t *pHddStaCtx;
4352 struct qdf_mac_addr peerMacAddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353
4354 ENTER();
4355
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05304356 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
4357
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4359
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304360 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361 adapter = adapterNode->pAdapter;
Yue Mad5b4b9f2017-05-26 16:23:40 -07004362 hdd_notice("Disabling queues for adapter type: %d",
4363 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304364
4365 if ((adapter->device_mode == QDF_STA_MODE) ||
Kabilan Kannan00d20412017-06-04 14:20:32 -07004366 (adapter->device_mode == QDF_P2P_CLIENT_MODE))
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304367 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07004368 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05304369
Arun Khandavallicc544b32017-01-30 19:52:16 +05304370 if (hdd_ctx->config->sap_internal_restart &&
4371 adapter->device_mode == QDF_SAP_MODE) {
4372 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304373 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05304374 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004375 if (test_bit(SOFTAP_BSS_STARTED,
4376 &adapter->event_flags)) {
4377 hdd_sap_indicate_disconnect_for_sta(adapter);
4378 hdd_cleanup_actionframe(hdd_ctx, adapter);
4379 hdd_sap_destroy_events(adapter);
4380 }
4381 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
4382 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05304383 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304384 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08004386 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004387
4388 adapter->sessionCtx.station.hdd_ReassocScenario = false;
4389
4390 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004391 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
4392 adapter->device_mode, adapter->sessionId);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4394 hdd_wmm_adapter_close(adapter);
4395 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4396 }
4397
Wu Gao3545e642017-07-14 19:24:41 +08004398 if (adapter->device_mode == QDF_SAP_MODE) {
4399 /*
4400 * If adapter is SAP, set session ID to invalid
4401 * since SAP session will be cleanup during SSR.
4402 */
Wu Gao36717432016-11-21 15:09:48 +08004403 wlansap_set_invalid_session(
4404 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4405
Wu Gao3545e642017-07-14 19:24:41 +08004406 wlansap_cleanup_cac_timer(
4407 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
4408 }
4409
Yue Mad5b4b9f2017-05-26 16:23:40 -07004410 /* Delete peers if any for STA and P2P client modes */
4411 if (adapter->device_mode == QDF_STA_MODE ||
4412 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4413 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
4414 qdf_copy_macaddr(&peerMacAddr,
4415 &pHddStaCtx->conn_info.bssId);
4416
4417 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
4418 peerMacAddr.bytes);
4419 }
4420
Yue Maf9782842017-05-08 12:49:49 -07004421 /* Destroy vdev which will be recreated during reinit. */
4422 hdd_vdev_destroy(adapter);
4423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4425 adapterNode = pNext;
4426 }
4427
4428 EXIT();
4429
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304430 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431}
4432
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304433bool hdd_check_for_opened_interfaces(hdd_context_t *hdd_ctx)
4434{
4435 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4436 QDF_STATUS status;
4437 bool close_modules = true;
4438
4439 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4440 while ((NULL != adapter_node) && (QDF_STATUS_SUCCESS == status)) {
4441 if (test_bit(DEVICE_IFACE_OPENED,
4442 &adapter_node->pAdapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004443 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05304444 close_modules = false;
4445 break;
4446 }
4447 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
4448 adapter_node = next;
4449 }
4450
4451 return close_modules;
4452}
4453
Arun Khandavallifae92942016-08-01 13:31:08 +05304454/**
4455 * hdd_is_interface_up()- Checkfor interface up before ssr
4456 * @hdd_ctx: HDD context
4457 *
4458 * check if there are any wlan interfaces before SSR accordingly start
4459 * the interface.
4460 *
4461 * Return: 0 if interface was opened else false
4462 */
4463static bool hdd_is_interface_up(hdd_adapter_t *adapter)
4464{
4465 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
4466 return true;
4467 else
4468 return false;
4469}
4470
Anurag Chouhanc4092922016-09-08 15:56:11 +05304471#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08004472 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304473struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4474 struct ieee80211_channel *channel,
4475 const u8 *bssid, const u8 *ssid,
4476 size_t ssid_len)
4477{
4478 return cfg80211_get_bss(wiphy, channel, bssid,
4479 ssid, ssid_len,
4480 WLAN_CAPABILITY_ESS,
4481 WLAN_CAPABILITY_ESS);
4482}
4483#else
4484struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
4485 struct ieee80211_channel *channel,
4486 const u8 *bssid, const u8 *ssid,
4487 size_t ssid_len)
4488{
4489 return cfg80211_get_bss(wiphy, channel, bssid,
4490 ssid, ssid_len,
4491 IEEE80211_BSS_TYPE_ESS,
4492 IEEE80211_PRIVACY_ANY);
4493}
4494#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304495
Abhishek Singha84d3952016-09-13 13:45:05 +05304496#if defined CFG80211_CONNECT_BSS
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304497#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
4498 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0))
4499/**
4500 * hdd_convert_timeout_reason() - Convert to kernel specific enum
4501 * @timeout_reason: reason for connect timeout
4502 *
4503 * This function is used to convert host timeout
4504 * reason enum to kernel specific enum.
4505 *
4506 * Return: nl timeout enum
4507 */
4508static enum nl80211_timeout_reason hdd_convert_timeout_reason(
4509 tSirResultCodes timeout_reason)
4510{
4511 switch (timeout_reason) {
4512 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
4513 return NL80211_TIMEOUT_SCAN;
4514 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
4515 return NL80211_TIMEOUT_AUTH;
4516 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
4517 return NL80211_TIMEOUT_ASSOC;
4518 default:
4519 return NL80211_TIMEOUT_UNSPECIFIED;
4520 }
4521}
4522
4523/**
4524 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
4525 * @dev: network device
4526 * @bssid: bssid to which we want to associate
4527 * @timeout_reason: reason for connect timeout
4528 *
4529 * This API is used to send connection timeout reason to supplicant
4530 *
4531 * Return: void
4532 */
4533static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4534 const u8 *bssid,
4535 tSirResultCodes timeout_reason)
4536{
4537 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004538
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304539 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4540
4541 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
4542 nl_timeout_reason);
4543}
4544
4545/**
4546 * __hdd_connect_bss() - API to send connection status to supplicant
4547 * @dev: network device
4548 * @bssid: bssid to which we want to associate
4549 * @req_ie: Request Information Element
4550 * @req_ie_len: len of the req IE
4551 * @resp_ie: Response IE
4552 * @resp_ie_len: len of ht response IE
4553 * @status: status
4554 * @gfp: Kernel Flag
4555 * @timeout_reason: reason for connect timeout
4556 *
4557 * Return: void
4558 */
4559static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4560 struct cfg80211_bss *bss, const u8 *req_ie,
4561 size_t req_ie_len, const u8 *resp_ie,
4562 size_t resp_ie_len, int status, gfp_t gfp,
4563 tSirResultCodes timeout_reason)
4564{
4565 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004566
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304567 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
4568
4569 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4570 resp_ie, resp_ie_len, status, gfp,
4571 nl_timeout_reason);
4572}
4573#else
4574#if defined CFG80211_CONNECT_TIMEOUT
4575static void hdd_cfg80211_connect_timeout(struct net_device *dev,
4576 const u8 *bssid,
4577 tSirResultCodes timeout_reason)
4578{
4579 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
4580}
4581#endif
4582
4583static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4584 struct cfg80211_bss *bss, const u8 *req_ie,
4585 size_t req_ie_len, const u8 *resp_ie,
4586 size_t resp_ie_len, int status, gfp_t gfp,
4587 tSirResultCodes timeout_reason)
4588{
4589 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
4590 resp_ie, resp_ie_len, status, gfp);
4591}
4592#endif
4593
Abhishek Singha84d3952016-09-13 13:45:05 +05304594/**
4595 * hdd_connect_bss() - API to send connection status to supplicant
4596 * @dev: network device
4597 * @bssid: bssid to which we want to associate
4598 * @req_ie: Request Information Element
4599 * @req_ie_len: len of the req IE
4600 * @resp_ie: Response IE
4601 * @resp_ie_len: len of ht response IE
4602 * @status: status
4603 * @gfp: Kernel Flag
4604 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304605 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05304606 *
4607 * The API is a wrapper to send connection status to supplicant
4608 *
4609 * Return: Void
4610 */
4611#if defined CFG80211_CONNECT_TIMEOUT
4612static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4613 struct cfg80211_bss *bss, const u8 *req_ie,
4614 size_t req_ie_len, const u8 *resp_ie,
4615 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304616 bool connect_timeout,
4617 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304618{
4619 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304620 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304621 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304622 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4623 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304624}
4625#else
4626static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
4627 struct cfg80211_bss *bss, const u8 *req_ie,
4628 size_t req_ie_len, const u8 *resp_ie,
4629 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304630 bool connect_timeout,
4631 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05304632{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304633 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
4634 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05304635}
4636#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05304637
4638/**
4639 * hdd_connect_result() - API to send connection status to supplicant
4640 * @dev: network device
4641 * @bssid: bssid to which we want to associate
4642 * @roam_info: information about connected bss
4643 * @req_ie: Request Information Element
4644 * @req_ie_len: len of the req IE
4645 * @resp_ie: Response IE
4646 * @resp_ie_len: len of ht response IE
4647 * @status: status
4648 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05304649 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304650 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05304651 *
4652 * The API is a wrapper to send connection status to supplicant
4653 * and allow runtime suspend
4654 *
4655 * Return: Void
4656 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304657void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4658 tCsrRoamInfo *roam_info, const u8 *req_ie,
4659 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304660 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304661 bool connect_timeout,
4662 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304663{
4664 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4665 struct cfg80211_bss *bss = NULL;
4666
4667 if (WLAN_STATUS_SUCCESS == status) {
4668 struct ieee80211_channel *chan;
4669 int freq;
4670 int chan_no = roam_info->pBssDesc->channelId;
4671
4672 if (chan_no <= 14)
4673 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004674 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304675 else
4676 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07004677 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304678
4679 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
4680 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
4681 roam_info->u.pConnectedProfile->SSID.ssId,
4682 roam_info->u.pConnectedProfile->SSID.length);
4683 }
Komal Seelama89be8d2016-09-29 11:09:26 +05304684
Abhishek Singha84d3952016-09-13 13:45:05 +05304685 hdd_connect_bss(dev, bssid, bss, req_ie,
4686 req_ie_len, resp_ie, resp_ie_len,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304687 status, gfp, connect_timeout, timeout_reason);
Komal Seelama89be8d2016-09-29 11:09:26 +05304688
4689 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004690 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304691}
4692#else
4693void hdd_connect_result(struct net_device *dev, const u8 *bssid,
4694 tCsrRoamInfo *roam_info, const u8 *req_ie,
4695 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05304696 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304697 bool connect_timeout,
4698 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05304699{
Komal Seelama89be8d2016-09-29 11:09:26 +05304700 hdd_adapter_t *padapter = (hdd_adapter_t *) netdev_priv(dev);
4701
Anurag Chouhanc4092922016-09-08 15:56:11 +05304702 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
4703 resp_ie, resp_ie_len, status, gfp);
Komal Seelama89be8d2016-09-29 11:09:26 +05304704 qdf_runtime_pm_allow_suspend(padapter->connect_rpm_ctx.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07004705 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05304706}
4707#endif
4708
4709
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304710QDF_STATUS hdd_start_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004711{
4712 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304713 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004714 hdd_adapter_t *adapter;
4715#ifndef MSM_PLATFORM
Anurag Chouhan6d760662016-02-20 16:05:43 +05304716 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717#endif
4718 eConnectionState connState;
4719
4720 ENTER();
4721
4722 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304723 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724 adapter = adapterNode->pAdapter;
4725
Arun Khandavallifae92942016-08-01 13:31:08 +05304726 if (!hdd_is_interface_up(adapter))
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304727 goto get_adapter;
Arun Khandavallifae92942016-08-01 13:31:08 +05304728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 hdd_wmm_init(adapter);
4730
Dustin Browna7e6a5c2017-07-07 12:52:24 -07004731 adapter->scan_info.mScanPending = false;
4732
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004734 case QDF_STA_MODE:
4735 case QDF_P2P_CLIENT_MODE:
4736 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737
4738 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
4739 ->conn_info.connState;
4740
4741 hdd_init_station_mode(adapter);
4742 /* Open the gates for HDD to receive Wext commands */
4743 adapter->isLinkUpSvcNeeded = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004745 /* Indicate disconnect event to supplicant
4746 * if associated previously
4747 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07004749 eConnectionState_IbssConnected == connState ||
4750 eConnectionState_NotConnected == connState ||
4751 eConnectionState_IbssDisconnected == connState ||
4752 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004754
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 memset(&wrqu, '\0', sizeof(wrqu));
4756 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4757 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4758 wireless_send_event(adapter->dev, SIOCGIWAP,
4759 &wrqu, NULL);
4760 adapter->sessionCtx.station.
4761 hdd_ReassocScenario = false;
4762
4763 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05304764 wlan_hdd_cfg80211_indicate_disconnect(
4765 adapter->dev, false,
4766 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004767 } else if (eConnectionState_Connecting == connState) {
4768 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004769 * Indicate connect failure to supplicant if we
4770 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05304772 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05304773 NULL, 0, NULL, 0,
4774 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004775 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004776 }
4777
4778 hdd_register_tx_flow_control(adapter,
4779 hdd_tx_resume_timer_expired_handler,
4780 hdd_tx_resume_cb);
4781
4782 break;
4783
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004784 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004785 if (hdd_ctx->config->sap_internal_restart)
Arun Khandavallicc544b32017-01-30 19:52:16 +05304786 hdd_init_ap_mode(adapter, true);
4787
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788 break;
4789
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004790 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004792 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
4794#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004795 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796 /* event supplicant to restart */
4797 cfg80211_del_sta(adapter->dev,
4798 (const u8 *)&bcastMac.bytes[0],
4799 GFP_KERNEL);
4800#endif
4801 break;
4802
4803 default:
4804 break;
4805 }
Hanumanth Reddy Pothulac1c4d2b2016-09-22 15:45:16 +05304806get_adapter:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004807 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4808 adapterNode = pNext;
4809 }
4810
4811 EXIT();
4812
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304813 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814}
4815
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304816QDF_STATUS hdd_get_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817 hdd_adapter_list_node_t **padapterNode)
4818{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304819 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004820
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004821 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304822 status = qdf_list_peek_front(&hdd_ctx->hddAdapters,
4823 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004824 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 return status;
4826}
4827
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304828QDF_STATUS hdd_get_next_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829 hdd_adapter_list_node_t *adapterNode,
4830 hdd_adapter_list_node_t **pNextAdapterNode)
4831{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304832 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004833
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004834 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304835 status = qdf_list_peek_next(&hdd_ctx->hddAdapters,
4836 (qdf_list_node_t *) adapterNode,
4837 (qdf_list_node_t **) pNextAdapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004838
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004839 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840 return status;
4841}
4842
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304843QDF_STATUS hdd_remove_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 hdd_adapter_list_node_t *adapterNode)
4845{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304846 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004847
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004848 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304849 status = qdf_list_remove_node(&hdd_ctx->hddAdapters,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 &adapterNode->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004851 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 return status;
4853}
4854
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304855QDF_STATUS hdd_remove_front_adapter(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004856 hdd_adapter_list_node_t **padapterNode)
4857{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304858 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004859
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004860 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304861 status = qdf_list_remove_front(&hdd_ctx->hddAdapters,
4862 (qdf_list_node_t **) padapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004863 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 return status;
4865}
4866
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304867QDF_STATUS hdd_add_adapter_back(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 hdd_adapter_list_node_t *adapterNode)
4869{
Anurag Chouhanffb21542016-02-17 14:33:03 +05304870 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004871
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004872 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304873 status = qdf_list_insert_back(&hdd_ctx->hddAdapters,
4874 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004875 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876 return status;
4877}
4878
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304879QDF_STATUS hdd_add_adapter_front(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 hdd_adapter_list_node_t *adapterNode)
4881{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304882 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004883
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004884 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Anurag Chouhanffb21542016-02-17 14:33:03 +05304885 status = qdf_list_insert_front(&hdd_ctx->hddAdapters,
4886 (qdf_list_node_t *) adapterNode);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08004887 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888 return status;
4889}
4890
4891hdd_adapter_t *hdd_get_adapter_by_macaddr(hdd_context_t *hdd_ctx,
4892 tSirMacAddr macAddr)
4893{
4894 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4895 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304896 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004897
4898 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
4899
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304900 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 adapter = adapterNode->pAdapter;
4902
4903 if (adapter
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304904 && !qdf_mem_cmp(adapter->macAddressCurrent.bytes,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004905 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004906 return adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004907
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4909 adapterNode = pNext;
4910 }
4911
4912 return NULL;
4913
4914}
4915
4916hdd_adapter_t *hdd_get_adapter_by_vdev(hdd_context_t *hdd_ctx,
4917 uint32_t vdev_id)
4918{
4919 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
4920 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304921 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304923 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004924
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304925 while ((NULL != adapterNode) && (QDF_STATUS_SUCCESS == qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004926 adapter = adapterNode->pAdapter;
4927
4928 if (adapter->sessionId == vdev_id)
4929 return adapter;
4930
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304931 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932 hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
4933 adapterNode = pNext;
4934 }
4935
Jeff Johnson5880d792016-08-15 13:32:30 -07004936 hdd_err("vdev_id %d does not exist with host", vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004937
4938 return NULL;
4939}
4940
Abhishek Singh7996eb72015-12-30 17:24:02 +05304941/**
4942 * hdd_get_adapter_by_sme_session_id() - Return adapter with
4943 * the sessionid
4944 * @hdd_ctx: hdd context.
4945 * @sme_session_id: sme session is for the adapter to get.
4946 *
4947 * This function is used to get the adapter with provided session id
4948 *
4949 * Return: adapter pointer if found
4950 *
4951 */
4952hdd_adapter_t *hdd_get_adapter_by_sme_session_id(hdd_context_t *hdd_ctx,
4953 uint32_t sme_session_id)
4954{
4955 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4956 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304957 QDF_STATUS qdf_status;
Abhishek Singh7996eb72015-12-30 17:24:02 +05304958
4959
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304960 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Abhishek Singh7996eb72015-12-30 17:24:02 +05304961
4962 while ((NULL != adapter_node) &&
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304963 (QDF_STATUS_SUCCESS == qdf_status)) {
Abhishek Singh7996eb72015-12-30 17:24:02 +05304964 adapter = adapter_node->pAdapter;
4965
4966 if (adapter &&
4967 adapter->sessionId == sme_session_id)
4968 return adapter;
4969
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304970 qdf_status =
Abhishek Singh7996eb72015-12-30 17:24:02 +05304971 hdd_get_next_adapter(hdd_ctx,
4972 adapter_node, &next);
4973 adapter_node = next;
4974 }
4975 return NULL;
4976}
4977
Naveen Rawat4edb6822017-04-12 10:09:17 -07004978hdd_adapter_t *hdd_get_adapter_by_iface_name(hdd_context_t *hdd_ctx,
4979 const char *iface_name)
4980{
4981 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
4982 hdd_adapter_t *adapter;
4983 QDF_STATUS qdf_status;
4984
4985 qdf_status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
4986
4987 while ((NULL != adapter_node) &&
4988 (QDF_STATUS_SUCCESS == qdf_status)) {
4989 adapter = adapter_node->pAdapter;
4990
4991 if (adapter &&
4992 !qdf_str_cmp(adapter->dev->name, iface_name))
4993 return adapter;
4994
4995 qdf_status =
4996 hdd_get_next_adapter(hdd_ctx,
4997 adapter_node, &next);
4998 adapter_node = next;
4999 }
5000 return NULL;
5001}
5002
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005003/**
5004 * hdd_get_adapter() - to get adapter matching the mode
5005 * @hdd_ctx: hdd context
5006 * @mode: adapter mode
5007 *
5008 * This routine will return the pointer to adapter matching
5009 * with the passed mode.
5010 *
5011 * Return: pointer to adapter or null
5012 */
5013hdd_adapter_t *hdd_get_adapter(hdd_context_t *hdd_ctx,
5014 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015{
5016 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
5017 hdd_adapter_t *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305018 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019
5020 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5021
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305022 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 adapter = adapterNode->pAdapter;
5024
5025 if (adapter && (mode == adapter->device_mode))
5026 return adapter;
5027
5028 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5029 adapterNode = pNext;
5030 }
5031
5032 return NULL;
5033
5034}
5035
5036/**
5037 * hdd_get_operating_channel() - return operating channel of the device mode
5038 * @hdd_ctx: Pointer to the HDD context.
5039 * @mode: Device mode for which operating channel is required.
5040 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005041 * QDF_STA_MODE,
5042 * QDF_P2P_CLIENT_MODE,
5043 * QDF_SAP_MODE,
5044 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 *
5046 * This API returns the operating channel of the requested device mode
5047 *
5048 * Return: channel number. "0" id the requested device is not found OR it is
5049 * not connected.
5050 */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005051uint8_t hdd_get_operating_channel(hdd_context_t *hdd_ctx,
5052 enum tQDF_ADAPTER_MODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053{
5054 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305055 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 hdd_adapter_t *adapter;
5057 uint8_t operatingChannel = 0;
5058
5059 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5060
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305061 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005062 adapter = adapterNode->pAdapter;
5063
5064 if (mode == adapter->device_mode) {
5065 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005066 case QDF_STA_MODE:
5067 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 if (hdd_conn_is_connected
5069 (WLAN_HDD_GET_STATION_CTX_PTR
5070 (adapter))) {
5071 operatingChannel =
5072 (WLAN_HDD_GET_STATION_CTX_PTR
5073 (adapter))->conn_info.
5074 operationChannel;
5075 }
5076 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005077 case QDF_SAP_MODE:
5078 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 /* softap connection info */
5080 if (test_bit
5081 (SOFTAP_BSS_STARTED,
5082 &adapter->event_flags))
5083 operatingChannel =
5084 (WLAN_HDD_GET_AP_CTX_PTR
5085 (adapter))->operatingChannel;
5086 break;
5087 default:
5088 break;
5089 }
5090
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005091 /* Found the device of interest. break the loop */
5092 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 }
5094
5095 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5096 adapterNode = pNext;
5097 }
5098 return operatingChannel;
5099}
5100
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305101static inline QDF_STATUS hdd_unregister_wext_all_adapters(hdd_context_t *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005102 hdd_ctx)
5103{
5104 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305105 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106 hdd_adapter_t *adapter;
5107
5108 ENTER();
5109
5110 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5111
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305112 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005114 if ((adapter->device_mode == QDF_STA_MODE) ||
5115 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5116 (adapter->device_mode == QDF_IBSS_MODE) ||
5117 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5118 (adapter->device_mode == QDF_SAP_MODE) ||
5119 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 wlan_hdd_cfg80211_deregister_frames(adapter);
5121 hdd_unregister_wext(adapter->dev);
5122 }
5123 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5124 adapterNode = pNext;
5125 }
5126
5127 EXIT();
5128
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305129 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130}
5131
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305132QDF_STATUS hdd_abort_mac_scan_all_adapters(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133{
5134 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305135 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005136 hdd_adapter_t *adapter;
5137
5138 ENTER();
5139
5140 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
5141
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305142 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005144 if ((adapter->device_mode == QDF_STA_MODE) ||
5145 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5146 (adapter->device_mode == QDF_IBSS_MODE) ||
5147 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5148 (adapter->device_mode == QDF_SAP_MODE) ||
5149 (adapter->device_mode == QDF_P2P_GO_MODE)) {
Abhishek Singh69ccb512017-04-25 11:58:16 +05305150 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
5151 adapter->sessionId, INVALID_SCAN_ID, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 }
5153 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
5154 adapterNode = pNext;
5155 }
5156
5157 EXIT();
5158
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305159 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160}
5161
Dustin Brownf27bce82016-11-03 12:52:27 -07005162/**
5163 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
5164 * adapters
5165 * @hdd_ctx: The HDD context containing the adapters to operate on
5166 *
5167 * return: QDF_STATUS_SUCCESS
5168 */
5169static QDF_STATUS hdd_abort_sched_scan_all_adapters(hdd_context_t *hdd_ctx)
5170{
5171 hdd_adapter_list_node_t *adapter_node = NULL, *next_node = NULL;
5172 QDF_STATUS status;
5173 hdd_adapter_t *adapter;
5174 int err;
5175
5176 ENTER();
5177
5178 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
5179
5180 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
5181 adapter = adapter_node->pAdapter;
5182 if ((adapter->device_mode == QDF_STA_MODE) ||
5183 (adapter->device_mode == QDF_P2P_CLIENT_MODE) ||
5184 (adapter->device_mode == QDF_IBSS_MODE) ||
5185 (adapter->device_mode == QDF_P2P_DEVICE_MODE) ||
5186 (adapter->device_mode == QDF_SAP_MODE) ||
5187 (adapter->device_mode == QDF_P2P_GO_MODE)) {
5188 err = wlan_hdd_sched_scan_stop(adapter->dev);
5189 if (err)
5190 hdd_err("Unable to stop scheduled scan");
5191 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005192 status = hdd_get_next_adapter(hdd_ctx, adapter_node,
5193 &next_node);
Dustin Brownf27bce82016-11-03 12:52:27 -07005194 adapter_node = next_node;
5195 }
5196
5197 EXIT();
5198
5199 return QDF_STATUS_SUCCESS;
5200}
5201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202#ifdef WLAN_NS_OFFLOAD
5203/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005204 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 * @hdd_ctx: Pointer to hdd context
5206 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005207 * Unregister for IPv6 address change notifications.
5208 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 * Return: None
5210 */
5211static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5212{
5213 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214}
5215
5216/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005217 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 * @hdd_ctx: Pointer to hdd context
5219 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005220 * Register for IPv6 address change notifications.
5221 *
5222 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005224static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225{
5226 int ret;
5227
5228 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
5229 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005230 if (ret) {
5231 hdd_err("Failed to register IPv6 notifier: %d", ret);
5232 goto out;
5233 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005235 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005236out:
5237 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005238}
5239#else
5240/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005241 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 * @hdd_ctx: Pointer to hdd context
5243 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005244 * Unregister for IPv6 address change notifications.
5245 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005246 * Return: None
5247 */
5248static void hdd_wlan_unregister_ip6_notifier(hdd_context_t *hdd_ctx)
5249{
5250}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005253 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 * @hdd_ctx: Pointer to hdd context
5255 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005256 * Register for IPv6 address change notifications.
5257 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 * Return: None
5259 */
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005260static int hdd_wlan_register_ip6_notifier(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005262 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263}
5264#endif
5265
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305266#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
5267/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005268 * hdd_logging_sock_activate_svc() - Activate logging
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305269 * @hdd_ctx: HDD context
5270 *
5271 * Activates the logging service
5272 *
5273 * Return: Zero in case of success, negative value otherwise
5274 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005275static int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305276{
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005277 int ret;
5278 struct hdd_config *config = hdd_ctx->config;
5279
5280 if (!config->wlanLoggingEnable)
5281 return 0;
5282
Srinivas Girigowda8187e792017-03-03 11:50:59 -08005283 ret = wlan_logging_sock_activate_svc(config->wlanLoggingToConsole,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005284 config->wlanLoggingNumBuf);
5285 if (ret)
5286 hdd_err("wlan_logging_sock_activate_svc failed: %d", ret);
5287 return ret;
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305288}
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005289
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305290/**
5291 * wlan_hdd_logging_sock_deactivate_svc() - Deactivate logging
5292 * @hdd_ctx: HDD context
5293 *
5294 * Deactivates the logging service
5295 *
5296 * Return: 0 on deactivating the logging service
5297 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005298static int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305299{
5300 if (hdd_ctx && hdd_ctx->config->wlanLoggingEnable)
5301 return wlan_logging_sock_deactivate_svc();
5302
5303 return 0;
5304}
5305#else
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005306static inline int hdd_logging_sock_activate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305307{
5308 return 0;
5309}
5310
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005311static inline int hdd_logging_sock_deactivate_svc(hdd_context_t *hdd_ctx)
Chandrasekaran, Manishekar3cc29cb2016-01-16 17:28:11 +05305312{
5313 return 0;
5314}
5315#endif
5316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005318 * hdd_register_notifiers - Register netdev notifiers.
5319 * @hdd_ctx: HDD context
5320 *
5321 * Register netdev notifiers like IPv4 and IPv6.
5322 *
5323 * Return: 0 on success and errno on failure
5324 */
5325static int hdd_register_notifiers(hdd_context_t *hdd_ctx)
5326{
5327 int ret;
5328
5329 ret = register_netdevice_notifier(&hdd_netdev_notifier);
5330 if (ret) {
5331 hdd_err("register_netdevice_notifier failed: %d", ret);
5332 goto out;
5333 }
5334
5335 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
5336 if (ret)
5337 goto unregister_notifier;
5338
5339 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
5340 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5341 if (ret) {
5342 hdd_err("Failed to register IPv4 notifier: %d", ret);
5343 goto unregister_ip6_notifier;
5344 }
5345
5346 return 0;
5347
5348unregister_ip6_notifier:
5349 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5350unregister_notifier:
5351 unregister_netdevice_notifier(&hdd_netdev_notifier);
5352out:
5353 return ret;
5354
5355}
5356
5357/**
5358 * hdd_unregister_notifiers - Unregister netdev notifiers.
5359 * @hdd_ctx: HDD context
5360 *
5361 * Unregister netdev notifiers like IPv4 and IPv6.
5362 *
5363 * Return: None.
5364 */
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305365void hdd_unregister_notifiers(hdd_context_t *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005366{
5367 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
5368
5369 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
5370
5371 unregister_netdevice_notifier(&hdd_netdev_notifier);
5372}
5373
5374/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005375 * hdd_exit_netlink_services - Exit netlink services
5376 * @hdd_ctx: HDD context
5377 *
5378 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
5379 * nl service.
5380 *
5381 * Return: None.
5382 */
5383static void hdd_exit_netlink_services(hdd_context_t *hdd_ctx)
5384{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005385 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08005386 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005387 ptt_sock_deactivate_svc();
5388
5389 nl_srv_exit();
5390}
5391
5392/**
5393 * hdd_init_netlink_services- Init netlink services
5394 * @hdd_ctx: HDD context
5395 *
5396 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
5397 * nl service.
5398 *
5399 * Return: 0 on success and errno on failure.
5400 */
5401static int hdd_init_netlink_services(hdd_context_t *hdd_ctx)
5402{
5403 int ret;
5404
Ryan Hsuceddceb2016-04-28 10:20:14 -07005405 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005406 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005407 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005408 goto out;
5409 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07005410 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005411
Naveen Rawat910726a2017-03-06 11:42:51 -08005412 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005413 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005414 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005415 goto err_nl_srv;
5416 }
5417
5418 ret = ptt_sock_activate_svc();
5419 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005420 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005421 goto err_nl_srv;
5422 }
5423
5424 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07005425 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005426 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005427
5428 ret = cnss_diag_activate_service();
5429 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005430 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005431 goto err_close_cesium;
5432 }
5433
5434 return 0;
5435
5436err_close_cesium:
5437 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005438 ptt_sock_deactivate_svc();
5439err_nl_srv:
5440 nl_srv_exit();
5441out:
5442 return ret;
5443}
5444
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005445/**
5446 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
5447 * @hdd_ctx: HDD context.
5448 *
5449 * Destroy RX wakelock.
5450 *
5451 * Return: None.
5452 */
5453static void hdd_rx_wake_lock_destroy(hdd_context_t *hdd_ctx)
5454{
5455 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
5456}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08005457
5458/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005459 * hdd_rx_wake_lock_create() - Create RX wakelock
5460 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005461 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005462 * Create RX wakelock.
5463 *
5464 * Return: None.
5465 */
5466static void hdd_rx_wake_lock_create(hdd_context_t *hdd_ctx)
5467{
5468 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
5469}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005470
5471/**
5472 * hdd_roc_context_init() - Init ROC context
5473 * @hdd_ctx: HDD context.
5474 *
5475 * Initialize ROC context.
5476 *
5477 * Return: 0 on success and errno on failure.
5478 */
5479static int hdd_roc_context_init(hdd_context_t *hdd_ctx)
5480{
5481 qdf_spinlock_create(&hdd_ctx->hdd_roc_req_q_lock);
5482 qdf_list_create(&hdd_ctx->hdd_roc_req_q, MAX_ROC_REQ_QUEUE_ENTRY);
5483
5484 INIT_DELAYED_WORK(&hdd_ctx->roc_req_work, wlan_hdd_roc_request_dequeue);
5485
5486 return 0;
5487}
5488
5489/**
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305490 * hdd_destroy_roc_req_q() - Free allocations in ROC Req Queue
5491 * @hdd_ctx: HDD context.
5492 *
5493 * Free memory allocations made in ROC Req Queue nodes.
5494 *
5495 * Return: None.
5496 */
5497static void hdd_destroy_roc_req_q(hdd_context_t *hdd_ctx)
5498{
5499 hdd_roc_req_t *hdd_roc_req;
5500 QDF_STATUS status;
5501
5502 qdf_spin_lock(&hdd_ctx->hdd_roc_req_q_lock);
5503
5504 while (!qdf_list_empty(&hdd_ctx->hdd_roc_req_q)) {
5505 status = qdf_list_remove_front(&hdd_ctx->hdd_roc_req_q,
5506 (qdf_list_node_t **) &hdd_roc_req);
5507
5508 if (QDF_STATUS_SUCCESS != status) {
Nachiket Kukaded45ab8c2017-05-08 16:12:02 +05305509 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5510 hdd_debug("unable to remove roc element from list");
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305511 QDF_ASSERT(0);
5512 return;
5513 }
5514
5515 if (hdd_roc_req->pRemainChanCtx)
5516 qdf_mem_free(hdd_roc_req->pRemainChanCtx);
5517
5518 qdf_mem_free(hdd_roc_req);
5519 }
5520
5521 qdf_spin_unlock(&hdd_ctx->hdd_roc_req_q_lock);
5522}
5523
5524/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005525 * hdd_roc_context_destroy() - Destroy ROC context
5526 * @hdd_ctx: HDD context.
5527 *
5528 * Destroy roc list and flush the pending roc work.
5529 *
5530 * Return: None.
5531 */
5532static void hdd_roc_context_destroy(hdd_context_t *hdd_ctx)
5533{
5534 flush_delayed_work(&hdd_ctx->roc_req_work);
Nachiket Kukade223ad8c2017-04-19 16:42:29 +05305535 hdd_destroy_roc_req_q(hdd_ctx);
Houston Hoffman2eac7c42016-12-12 12:22:52 -08005536 qdf_spinlock_destroy(&hdd_ctx->hdd_roc_req_q_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005537}
5538
5539/**
Houston Hoffman160db392016-10-10 17:37:51 -07005540 * hdd_context_deinit() - Deinitialize HDD context
5541 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005542 *
Houston Hoffman160db392016-10-10 17:37:51 -07005543 * Deinitialize HDD context along with all the feature specific contexts but
5544 * do not free hdd context itself. Caller of this API is supposed to free
5545 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005546 *
Houston Hoffman160db392016-10-10 17:37:51 -07005547 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005548 */
Houston Hoffman160db392016-10-10 17:37:51 -07005549static int hdd_context_deinit(hdd_context_t *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005550{
Houston Hoffman160db392016-10-10 17:37:51 -07005551 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005552
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005553 hdd_roc_context_destroy(hdd_ctx);
5554
5555 hdd_sap_context_destroy(hdd_ctx);
5556
5557 hdd_rx_wake_lock_destroy(hdd_ctx);
5558
5559 hdd_tdls_context_destroy(hdd_ctx);
5560
5561 hdd_scan_context_destroy(hdd_ctx);
5562
5563 qdf_list_destroy(&hdd_ctx->hddAdapters);
5564
Houston Hoffman160db392016-10-10 17:37:51 -07005565 return 0;
5566}
5567
5568/**
5569 * hdd_context_destroy() - Destroy HDD context
5570 * @hdd_ctx: HDD context to be destroyed.
5571 *
5572 * Free config and HDD context as well as destroy all the resources.
5573 *
5574 * Return: None
5575 */
5576static void hdd_context_destroy(hdd_context_t *hdd_ctx)
5577{
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05305578
5579 hdd_logging_sock_deactivate_svc(hdd_ctx);
Houston Hoffman160db392016-10-10 17:37:51 -07005580
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05305581 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
5582
Houston Hoffman160db392016-10-10 17:37:51 -07005583 hdd_context_deinit(hdd_ctx);
5584
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305585 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08005586 hdd_ctx->config = NULL;
5587
5588 wiphy_free(hdd_ctx->wiphy);
5589}
5590
5591/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305592 * wlan_destroy_bug_report_lock() - Destroy bug report lock
5593 *
5594 * This function is used to destroy bug report lock
5595 *
5596 * Return: None
5597 */
5598static void wlan_destroy_bug_report_lock(void)
5599{
5600 p_cds_contextType p_cds_context;
5601
5602 p_cds_context = cds_get_global_context();
5603 if (!p_cds_context) {
5604 hdd_err("cds context is NULL");
5605 return;
5606 }
5607
5608 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
5609}
5610
5611/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005612 * hdd_wlan_exit() - HDD WLAN exit function
5613 * @hdd_ctx: Pointer to the HDD Context
5614 *
5615 * This is the driver exit point (invoked during rmmod)
5616 *
5617 * Return: None
5618 */
Jeff Johnson590e2012016-10-05 16:16:24 -07005619static void hdd_wlan_exit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620{
5621 v_CONTEXT_t p_cds_context = hdd_ctx->pcds_context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305622 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05305624 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625
5626 ENTER();
5627
Arun Khandavallifae92942016-08-01 13:31:08 +05305628 if (QDF_TIMER_STATE_RUNNING ==
5629 qdf_mc_timer_get_current_state(&hdd_ctx->iface_change_timer)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005630 hdd_debug("Stop interface change timer");
Arun Khandavallifae92942016-08-01 13:31:08 +05305631 qdf_mc_timer_stop(&hdd_ctx->iface_change_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005632 }
5633
Arun Khandavallifae92942016-08-01 13:31:08 +05305634 if (!QDF_IS_STATUS_SUCCESS
5635 (qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer)))
5636 hdd_err("Cannot delete interface change timer");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07005637
Arun Khandavallifae92942016-08-01 13:31:08 +05305638
5639 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640
Nitesh Shah61c10d92016-10-19 19:29:15 +05305641 qdf_mc_timer_destroy(&hdd_ctx->tdls_source_timer);
5642
Prashanth Bhattaab004382016-10-11 16:08:11 -07005643 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644
5645#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05305646 if (QDF_TIMER_STATE_RUNNING ==
5647 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
5648 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649 }
5650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305651 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05305652 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005653 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654 }
Liangwei Dongaef84342016-10-21 05:28:00 -04005655 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5656 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5657 hdd_ctx->last_acs_channel_list = NULL;
5658 hdd_ctx->num_of_channels = 0;
5659 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661
Arun Khandavallifae92942016-08-01 13:31:08 +05305662 mutex_lock(&hdd_ctx->iface_change_lock);
5663 driver_status = hdd_ctx->driver_status;
5664 mutex_unlock(&hdd_ctx->iface_change_lock);
5665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666 /*
5667 * Powersave Offload Case
5668 * Disable Idle Power Save Mode
5669 */
5670 hdd_set_idle_ps_config(hdd_ctx, false);
5671
Arun Khandavallifae92942016-08-01 13:31:08 +05305672 if (driver_status != DRIVER_MODULES_CLOSED) {
5673 hdd_unregister_wext_all_adapters(hdd_ctx);
5674 /*
5675 * Cancel any outstanding scan requests. We are about to close
5676 * all of our adapters, but an adapter structure is what SME
5677 * passes back to our callback function. Hence if there
5678 * are any outstanding scan requests then there is a
5679 * race condition between when the adapter is closed and
5680 * when the callback is invoked. We try to resolve that
5681 * race condition here by canceling any outstanding scans
5682 * before we close the adapters.
5683 * Note that the scans may be cancelled in an asynchronous
5684 * manner, so ideally there needs to be some kind of
5685 * synchronization. Rather than introduce a new
5686 * synchronization here, we will utilize the fact that we are
5687 * about to Request Full Power, and since that is synchronized,
5688 * the expectation is that by the time Request Full Power has
5689 * completed, all scans will be cancelled
5690 */
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -07005691 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev);
Arun Khandavallifae92942016-08-01 13:31:08 +05305692 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07005693 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05305694 hdd_stop_all_adapters(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695 }
5696
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05305697 wlan_destroy_bug_report_lock();
5698
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699 /*
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305700 * Close the scheduler before calling cds_close to make sure
5701 * no thread is scheduled after the each module close is
5702 * is called i.e after all the data structures are freed.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305704 qdf_status = cds_sched_close(p_cds_context);
5705 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05305706 hdd_alert("Failed to close CDS Scheduler");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305707 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(qdf_status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07005710 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05305711
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05305712 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
5713 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
5714 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
5715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716 /*
5717 * Close CDS
5718 * This frees pMac(HAL) context. There should not be any call
5719 * that requires pMac access after this.
5720 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07005722 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08005723 hdd_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005725 hdd_close_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726
5727 hdd_ipa_cleanup(hdd_ctx);
5728
5729 /* Free up RoC request queue and flush workqueue */
5730 cds_flush_work(&hdd_ctx->roc_req_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005731
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05305732 wlansap_global_deinit();
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05305733 wlan_hdd_deinit_chan_info(hdd_ctx);
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305734 /*
5735 * If there is re_init failure wiphy would have already de-registered
5736 * check the wiphy status before un-registering again
5737 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05305738 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05305739 wiphy_unregister(wiphy);
5740 wlan_hdd_cfg80211_deinit(wiphy);
5741 hdd_lpass_notify_stop(hdd_ctx);
5742 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07005743
Arun Khandavallifae92942016-08-01 13:31:08 +05305744 hdd_exit_netlink_services(hdd_ctx);
5745 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05305746#ifdef FEATURE_WLAN_CH_AVOID
5747 mutex_destroy(&hdd_ctx->avoid_freq_lock);
5748#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05305749
5750 driver_status = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
5751 if (driver_status)
5752 hdd_err("Pdev delete failed");
5753
5754 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
5755 if (driver_status)
5756 hdd_err("Psoc delete failed");
Prashanth Bhatta527fd752016-04-28 12:35:23 -07005757 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758}
5759
5760void __hdd_wlan_exit(void)
5761{
5762 hdd_context_t *hdd_ctx;
5763
5764 ENTER();
5765
Anurag Chouhan6d760662016-02-20 16:05:43 +05305766 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005767 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005768 hdd_err("Invalid HDD Context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005769 EXIT();
5770 return;
5771 }
5772
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005773 memdump_deinit();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05305774 hdd_driver_memdump_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08005775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776 /* Do all the cleanup before deregistering the driver */
5777 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07005778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005779 EXIT();
5780}
5781
5782#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04005783/**
5784 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
5785 * @data: pointer to hdd_context_t
5786 *
5787 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
5788 * Then new ACS request will do a fresh scan without reusing the cached
5789 * scan information.
5790 *
5791 * Return: void
5792 */
Tang Yingying523322d2017-01-17 23:28:43 +08005793static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005794{
5795 hdd_context_t *hdd_ctx = (hdd_context_t *) data;
5796
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005797 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005798 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04005799 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
5800 qdf_mem_free(hdd_ctx->last_acs_channel_list);
5801 hdd_ctx->last_acs_channel_list = NULL;
5802 hdd_ctx->num_of_channels = 0;
5803 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804
5805 if (!hdd_ctx->hHal)
5806 return;
5807 sme_scan_flush_result(hdd_ctx->hHal);
5808}
5809#endif
5810
5811#ifdef QCA_HT_2040_COEX
5812/**
5813 * hdd_wlan_set_ht2040_mode() - notify FW with HT20/HT40 mode
5814 * @adapter: pointer to adapter
5815 * @staId: station id
5816 * @macAddrSTA: station MAC address
5817 * @channel_type: channel type
5818 *
5819 * This function notifies FW with HT20/HT40 mode
5820 *
5821 * Return: 0 if successful, error number otherwise
5822 */
5823int hdd_wlan_set_ht2040_mode(hdd_adapter_t *adapter, uint16_t staId,
Anurag Chouhan6d760662016-02-20 16:05:43 +05305824 struct qdf_mac_addr macAddrSTA, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005825{
5826 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305827 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005828 hdd_context_t *hdd_ctx = NULL;
5829
5830 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5831
5832 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305833 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005834 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305835
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005836 if (!hdd_ctx->hHal)
5837 return -EINVAL;
5838
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305839 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, staId, macAddrSTA,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005840 adapter->sessionId, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305841 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005842 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843 return -EINVAL;
5844 }
5845
5846 return 0;
5847}
5848#endif
5849
5850/**
5851 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
5852 * @state: state
5853 *
5854 * This function notifies FW with modem power status
5855 *
5856 * Return: 0 if successful, error number otherwise
5857 */
5858int hdd_wlan_notify_modem_power_state(int state)
5859{
5860 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305861 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005862 hdd_context_t *hdd_ctx;
5863
Anurag Chouhan6d760662016-02-20 16:05:43 +05305864 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005865 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305866 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005867 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05305868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869 if (!hdd_ctx->hHal)
5870 return -EINVAL;
5871
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305872 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
5873 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005874 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875 state);
5876 return -EINVAL;
5877 }
5878 return 0;
5879}
5880
5881/**
5882 *
5883 * hdd_post_cds_enable_config() - HDD post cds start config helper
5884 * @adapter - Pointer to the HDD
5885 *
5886 * Return: None
5887 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305888QDF_STATUS hdd_post_cds_enable_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005889{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305890 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891
5892 /*
5893 * Send ready indication to the HDD. This will kick off the MAC
5894 * into a 'running' state and should kick off an initial scan.
5895 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305896 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
5897 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07005898 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
5899 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901 }
5902
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305903 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904}
5905
5906/* wake lock APIs for HDD */
5907void hdd_prevent_suspend(uint32_t reason)
5908{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305909 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005910}
5911
5912void hdd_allow_suspend(uint32_t reason)
5913{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305914 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915}
5916
5917void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
5918{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05305919 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
5920 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005921}
5922
5923/**
5924 * hdd_exchange_version_and_caps() - exchange version and capability with target
5925 * @hdd_ctx: Pointer to HDD context
5926 *
5927 * This is the HDD function to exchange version and capability information
5928 * between Host and Target
5929 *
5930 * This function gets reported version of FW.
5931 * It also finds the version of target headers used to compile the host;
5932 * It compares the above two and prints a warning if they are different;
5933 * It gets the SW and HW version string;
5934 * Finally, it exchanges capabilities between host and target i.e. host
5935 * and target exchange a msg indicating the features they support through a
5936 * bitmap
5937 *
5938 * Return: None
5939 */
5940void hdd_exchange_version_and_caps(hdd_context_t *hdd_ctx)
5941{
5942
5943 tSirVersionType versionCompiled;
5944 tSirVersionType versionReported;
5945 tSirVersionString versionString;
5946 uint8_t fwFeatCapsMsgSupported = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305947 QDF_STATUS vstatus;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005948
5949 memset(&versionCompiled, 0, sizeof(versionCompiled));
5950 memset(&versionReported, 0, sizeof(versionReported));
5951
5952 /* retrieve and display WCNSS version information */
5953 do {
5954
5955 vstatus = sme_get_wcnss_wlan_compiled_version(hdd_ctx->hHal,
5956 &versionCompiled);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305957 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005958 hdd_err("unable to retrieve WCNSS WLAN compiled version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 break;
5960 }
5961
5962 vstatus = sme_get_wcnss_wlan_reported_version(hdd_ctx->hHal,
5963 &versionReported);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305964 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005965 hdd_err("unable to retrieve WCNSS WLAN reported version");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966 break;
5967 }
5968
5969 if ((versionCompiled.major != versionReported.major) ||
5970 (versionCompiled.minor != versionReported.minor) ||
5971 (versionCompiled.version != versionReported.version) ||
5972 (versionCompiled.revision != versionReported.revision)) {
5973 pr_err("%s: WCNSS WLAN Version %u.%u.%u.%u, "
5974 "Host expected %u.%u.%u.%u\n",
5975 WLAN_MODULE_NAME,
5976 (int)versionReported.major,
5977 (int)versionReported.minor,
5978 (int)versionReported.version,
5979 (int)versionReported.revision,
5980 (int)versionCompiled.major,
5981 (int)versionCompiled.minor,
5982 (int)versionCompiled.version,
5983 (int)versionCompiled.revision);
5984 } else {
5985 pr_info("%s: WCNSS WLAN version %u.%u.%u.%u\n",
5986 WLAN_MODULE_NAME,
5987 (int)versionReported.major,
5988 (int)versionReported.minor,
5989 (int)versionReported.version,
5990 (int)versionReported.revision);
5991 }
5992
5993 vstatus = sme_get_wcnss_software_version(hdd_ctx->hHal,
5994 versionString,
5995 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305996 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005997 hdd_err("unable to retrieve WCNSS software version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005998 break;
5999 }
6000
6001 pr_info("%s: WCNSS software version %s\n",
6002 WLAN_MODULE_NAME, versionString);
6003
6004 vstatus = sme_get_wcnss_hardware_version(hdd_ctx->hHal,
6005 versionString,
6006 sizeof(versionString));
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306007 if (!QDF_IS_STATUS_SUCCESS(vstatus)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006008 hdd_err("unable to retrieve WCNSS hardware version string");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009 break;
6010 }
6011
6012 pr_info("%s: WCNSS hardware version %s\n",
6013 WLAN_MODULE_NAME, versionString);
6014
6015 /*
6016 * 1.Check if FW version is greater than 0.1.1.0. Only then
6017 * send host-FW capability exchange message
6018 * 2.Host-FW capability exchange message is only present on
6019 * target 1.1 so send the message only if it the target is 1.1
6020 * minor numbers for different target branches:
6021 * 0 -> (1.0)Mainline Build
6022 * 1 -> (1.1)Mainline Build
6023 * 2->(1.04) Stability Build
6024 */
6025 if (((versionReported.major > 0) || (versionReported.minor > 1)
6026 || ((versionReported.minor >= 1)
6027 && (versionReported.version >= 1)))
6028 && ((versionReported.major == 1)
6029 && (versionReported.minor >= 1)))
6030 fwFeatCapsMsgSupported = 1;
6031
6032 if (fwFeatCapsMsgSupported) {
6033 /*
6034 * Indicate if IBSS heartbeat monitoring needs to be
6035 * offloaded
6036 */
6037 if (!hdd_ctx->config->enableIbssHeartBeatOffload) {
6038 sme_disable_feature_capablity
6039 (IBSS_HEARTBEAT_OFFLOAD);
6040 }
6041
6042 sme_feature_caps_exchange(hdd_ctx->hHal);
6043 }
6044
6045 } while (0);
6046
6047}
6048
6049/* Initialize channel list in sme based on the country code */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306050QDF_STATUS hdd_set_sme_chan_list(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006051{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006052
Amar Singhal6f8592b2017-04-26 14:31:58 -07006053 return sme_init_chan_list(hdd_ctx->hHal,
6054 hdd_ctx->reg.alpha2,
6055 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006056}
6057
6058/**
6059 * hdd_is_5g_supported() - check if hardware supports 5GHz
6060 * @hdd_ctx: Pointer to the hdd context
6061 *
6062 * HDD function to know if hardware supports 5GHz
6063 *
6064 * Return: true if hardware supports 5GHz
6065 */
6066bool hdd_is_5g_supported(hdd_context_t *hdd_ctx)
6067{
zdingf54169a2016-10-12 17:08:45 +08006068 if (!hdd_ctx || !hdd_ctx->config)
6069 return true;
6070
6071 if (hdd_ctx->config->nBandCapability != eCSR_BAND_24)
6072 return true;
6073 else
6074 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075}
6076
Amar Singhale4f28ee2015-10-21 14:36:56 -07006077static int hdd_wiphy_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078{
6079 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006080 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081
6082 wiphy = hdd_ctx->wiphy;
6083
6084 /*
6085 * The channel information in
6086 * wiphy needs to be initialized before wiphy registration
6087 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006088 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6089 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006090 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006091 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092 }
6093
6094#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6095 wiphy->wowlan = &wowlan_support_reg_init;
6096#else
6097 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6098 WIPHY_WOWLAN_MAGIC_PKT |
6099 WIPHY_WOWLAN_DISCONNECT |
6100 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6101 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6102 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6103 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6104 WIPHY_WOWLAN_RFKILL_RELEASE;
6105
6106 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6107 WOW_MAX_FILTERS_PER_LIST);
6108 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6109 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6110#endif
6111
6112 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006113 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306114 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006115 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306116 return ret_val;
6117 }
6118
Amar Singhal5cccafe2017-02-15 12:42:58 -08006119 if (!hdd_ctx->reg_offload)
6120 hdd_program_country_code(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006121
Amar Singhale4f28ee2015-10-21 14:36:56 -07006122 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006123}
6124
Ravi Joshie2331e82015-07-01 18:18:54 -07006125/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07006126 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07006127 * @hdd_ctx - handle to hdd context
6128 * @tx_packets - transmit packet count
6129 * @rx_packets - receive packet count
6130 *
6131 * The function controls the bus bandwidth and dynamic control of
6132 * tcp delayed ack configuration
6133 *
6134 * Returns: None
6135 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136#ifdef MSM_PLATFORM
Jeff Johnson590e2012016-10-05 16:16:24 -07006137static void hdd_pld_request_bus_bandwidth(hdd_context_t *hdd_ctx,
6138 const uint64_t tx_packets,
6139 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006140{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141 uint64_t total = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08006142 uint64_t temp_rx = 0;
6143 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006144 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08006145 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08006146 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006147 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006148 uint16_t index = 0;
6149 bool vote_level_change = false;
6150 bool rx_level_change = false;
6151 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006152
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153 if (total > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006154 next_vote_level = PLD_BUS_WIDTH_HIGH;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006155 else if (total > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006156 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Yue Mad6478e42015-10-20 18:49:24 -07006157 else if (total > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07006158 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07006159 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07006160 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006162 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006163 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
6164 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006165 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006166 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07006167 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05306168 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05306169 if (hdd_ctx->hbw_requested) {
6170 pld_remove_pm_qos(hdd_ctx->parent_dev);
6171 hdd_ctx->hbw_requested = false;
6172 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05306173 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006174 hdd_warn("low bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306175 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05306176 if (!hdd_ctx->hbw_requested) {
6177 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
6178 hdd_ctx->hbw_requested = true;
6179 }
6180
Nirav Shah3bbfa512016-05-12 16:43:49 +05306181 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006182 hdd_warn("high bandwidth set rx affinity fail");
Nirav Shah3bbfa512016-05-12 16:43:49 +05306183 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07006184 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 }
Mohit Khannae71e2262015-11-10 09:37:24 -08006186
6187 /* fine-tuning parameters for RX Flows */
6188 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
6189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08006191
Ravi Joshifed83572016-10-07 16:20:37 -07006192 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
6193 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
6194 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
6195 next_rx_level = WLAN_SVC_TP_HIGH;
6196 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07006197 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07006198 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08006199 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07006200 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 if (hdd_ctx->cur_rx_level != next_rx_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07006203 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 next_rx_level, temp_rx);
6205 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006206 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07006207 /* Send throughput indication only if it is enabled.
6208 * Disabling tcp_del_ack will revert the tcp stack behavior
6209 * to default delayed ack. Note that this will disable the
6210 * dynamic delayed ack mechanism across the system
6211 */
6212 if (hdd_ctx->config->enable_tcp_delack)
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306213 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6214 WLAN_SVC_WLAN_TP_IND,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 &next_rx_level,
6216 sizeof(next_rx_level));
6217 }
6218
Mohit Khannae71e2262015-11-10 09:37:24 -08006219 /* fine-tuning parameters for TX Flows */
6220 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
6221 hdd_ctx->prev_tx = tx_packets;
6222 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
6223 next_tx_level = WLAN_SVC_TP_HIGH;
6224 else
6225 next_tx_level = WLAN_SVC_TP_LOW;
6226
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006227 if (hdd_ctx->cur_tx_level != next_tx_level) {
Mohit Khannae71e2262015-11-10 09:37:24 -08006228 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
6229 next_tx_level, temp_tx);
6230 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006231 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05306232 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
6233 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08006234 &next_tx_level,
6235 sizeof(next_tx_level));
6236 }
6237
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006238 index = hdd_ctx->hdd_txrx_hist_idx;
6239
6240 if (vote_level_change || tx_level_change || rx_level_change) {
6241 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
6242 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
6243 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
6244 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
6245 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
6246 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
6247 hdd_ctx->hdd_txrx_hist_idx++;
6248 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
6249 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006250}
6251
6252#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306253static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254{
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306255 hdd_context_t *hdd_ctx = container_of(work, hdd_context_t,
6256 bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257 hdd_adapter_t *adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306258 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05306259 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
6260 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261 uint64_t total_tx = 0, total_rx = 0;
6262 hdd_adapter_list_node_t *adapterNode = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306263 QDF_STATUS status = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306264 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 bool connected = false;
6266 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
6267
Prashanth Bhattaab004382016-10-11 16:08:11 -07006268 if (wlan_hdd_validate_context(hdd_ctx))
6269 return;
6270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271 for (status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306272 NULL != adapterNode && QDF_STATUS_SUCCESS == status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273 status =
6274 hdd_get_next_adapter(hdd_ctx, adapterNode, &adapterNode)) {
6275
6276 if (adapterNode->pAdapter == NULL)
6277 continue;
6278 adapter = adapterNode->pAdapter;
Manjeet Singh01327cc2016-09-03 12:14:25 +05306279 /*
6280 * Validate magic so we don't end up accessing
6281 * an invalid adapter.
6282 */
6283 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
6284 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006286 if ((adapter->device_mode == QDF_STA_MODE ||
6287 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
6289 != eConnectionState_Associated) {
6290
6291 continue;
6292 }
6293
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006294 if ((adapter->device_mode == QDF_SAP_MODE ||
6295 adapter->device_mode == QDF_P2P_GO_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive == false) {
6297
6298 continue;
6299 }
6300
6301 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
6302 adapter->prev_tx_packets);
6303 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
6304 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306305
6306 if (adapter->device_mode == QDF_SAP_MODE ||
6307 adapter->device_mode == QDF_P2P_GO_MODE ||
6308 adapter->device_mode == QDF_IBSS_MODE) {
6309
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08006310 ret = cdp_get_intra_bss_fwd_pkts_count(
6311 cds_get_context(QDF_MODULE_ID_SOC),
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306312 adapter->sessionId,
6313 &fwd_tx_packets, &fwd_rx_packets);
6314 if (ret == A_OK) {
6315 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
6316 fwd_tx_packets,
6317 adapter->prev_fwd_tx_packets);
6318 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
6319 fwd_tx_packets,
6320 adapter->prev_fwd_rx_packets);
6321 }
6322 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323
6324 total_rx += adapter->stats.rx_packets;
6325 total_tx += adapter->stats.tx_packets;
6326
6327 spin_lock_bh(&hdd_ctx->bus_bw_lock);
6328 adapter->prev_tx_packets = adapter->stats.tx_packets;
6329 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306330 adapter->prev_fwd_tx_packets = fwd_tx_packets;
6331 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
6333 connected = true;
6334 }
6335
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05306336 /* add intra bss forwarded tx and rx packets */
6337 tx_packets += fwd_tx_packets_diff;
6338 rx_packets += fwd_rx_packets_diff;
6339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006340 hdd_ipa_uc_stat_query(hdd_ctx, &ipa_tx_packets, &ipa_rx_packets);
6341 tx_packets += (uint64_t)ipa_tx_packets;
6342 rx_packets += (uint64_t)ipa_rx_packets;
6343
6344 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006345 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 return;
6347 }
6348
Yuanyuan Liu13738502016-04-06 17:41:37 -07006349 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350
6351 hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
6352 hdd_ipa_uc_stat_request(adapter, 2);
6353
Dustin Brown2ed60362017-01-18 12:25:50 -08006354 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08006355 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08006356 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05306357 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08006358 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08006359 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360}
Prashanth Bhattaab004382016-10-11 16:08:11 -07006361
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306362/**
6363 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
6364 * @arg: Argument of timer function
6365 *
6366 * Schedule a workqueue in this function where all the processing is done.
6367 *
6368 * Return: None.
6369 */
6370static void __hdd_bus_bw_cbk(void *arg)
6371{
6372 hdd_context_t *hdd_ctx = (hdd_context_t *) arg;
6373
6374 if (wlan_hdd_validate_context(hdd_ctx))
6375 return;
6376
6377 schedule_work(&hdd_ctx->bus_bw_work);
6378}
6379
6380/**
6381 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
6382 * @arg: Argument of timer function
6383 *
6384 * Return: None.
6385 */
6386static void hdd_bus_bw_cbk(void *arg)
6387{
6388 cds_ssr_protect(__func__);
6389 __hdd_bus_bw_cbk(arg);
6390 cds_ssr_unprotect(__func__);
6391}
6392
Prashanth Bhattaab004382016-10-11 16:08:11 -07006393int hdd_bus_bandwidth_init(hdd_context_t *hdd_ctx)
6394{
6395 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306396 INIT_WORK(&hdd_ctx->bus_bw_work,
6397 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08006398 hdd_ctx->bus_bw_timer_running = false;
6399 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306400 qdf_timer_init(NULL,
6401 &hdd_ctx->bus_bw_timer,
6402 hdd_bus_bw_cbk, (void *)hdd_ctx,
6403 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006404
6405 return 0;
6406}
6407
6408void hdd_bus_bandwidth_destroy(hdd_context_t *hdd_ctx)
6409{
Dustin Brownfce08d12017-01-17 16:29:38 -08006410 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07006411 hdd_reset_tcp_delack(hdd_ctx);
6412
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006413 hdd_debug("wait for bus bw work to flush");
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05306414 cancel_work_sync(&hdd_ctx->bus_bw_work);
6415 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08006416 hdd_ctx->bus_bw_timer_running = false;
6417 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07006418}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419#endif
6420
6421/**
Nirav Shahed34b212016-04-25 10:59:16 +05306422 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
6423 * @hdd_ctx: hdd context
6424 *
6425 * Return: 0 for success or error code
6426 */
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07006427static int wlan_hdd_init_tx_rx_histogram(hdd_context_t *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05306428{
6429 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
6430 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
6431 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006432 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05306433 return -ENOMEM;
6434 }
6435 return 0;
6436}
6437
6438/**
6439 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
6440 * @hdd_ctx: hdd context
6441 *
6442 * Return: none
6443 */
6444void wlan_hdd_deinit_tx_rx_histogram(hdd_context_t *hdd_ctx)
6445{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306446 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
6447 return;
6448
6449 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
6450 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05306451}
6452
Nirav Shahda008342016-05-17 18:50:40 +05306453static uint8_t *convert_level_to_string(uint32_t level)
6454{
6455 switch (level) {
6456 /* initialize the wlan sub system */
6457 case WLAN_SVC_TP_NONE:
6458 return "NONE";
6459 case WLAN_SVC_TP_LOW:
6460 return "LOW";
6461 case WLAN_SVC_TP_MEDIUM:
6462 return "MED";
6463 case WLAN_SVC_TP_HIGH:
6464 return "HIGH";
6465 default:
6466 return "INVAL";
6467 }
6468}
6469
Nirav Shahed34b212016-04-25 10:59:16 +05306470
6471/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006472 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
6473 * @hdd_ctx: hdd context
6474 *
6475 * Return: none
6476 */
6477void wlan_hdd_display_tx_rx_histogram(hdd_context_t *hdd_ctx)
6478{
6479 int i;
6480
6481#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006482 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05306483 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006484 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006485 hdd_ctx->config->busBandwidthHighThreshold,
6486 hdd_ctx->config->busBandwidthMediumThreshold,
6487 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006488 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306489 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006490 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006491 hdd_ctx->config->tcpDelackThresholdHigh,
6492 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006493 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05306494 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495#endif
6496
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006497 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05306498 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
6499
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006500 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006501
6502 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006503 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006504 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006505 hdd_log(QDF_TRACE_LEVEL_ERROR,
Mohit Khannaafff9fb2016-11-16 20:22:03 -08006506 "[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
6507 i, hdd_ctx->hdd_txrx_hist[i].qtime,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006508 hdd_ctx->hdd_txrx_hist[i].interval_rx,
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006509 hdd_ctx->hdd_txrx_hist[i].interval_tx,
6510 convert_level_to_string(
6511 hdd_ctx->hdd_txrx_hist[i].
6512 next_vote_level),
6513 convert_level_to_string(
6514 hdd_ctx->hdd_txrx_hist[i].
6515 next_rx_level),
6516 convert_level_to_string(
6517 hdd_ctx->hdd_txrx_hist[i].
6518 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006519 }
Mohit Khannac68622e2017-01-31 21:07:12 -08006520
6521 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522}
6523
6524/**
6525 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
6526 * @hdd_ctx: hdd context
6527 *
6528 * Return: none
6529 */
6530void wlan_hdd_clear_tx_rx_histogram(hdd_context_t *hdd_ctx)
6531{
6532 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05306533 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
6534 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535}
6536
6537/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006538 * wlan_hdd_display_netif_queue_history() - display netif queue history
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539 * @pHddCtx: hdd context
6540 *
6541 * Return: none
6542 */
6543void wlan_hdd_display_netif_queue_history(hdd_context_t *hdd_ctx)
6544{
6545
6546 hdd_adapter_t *adapter = NULL;
6547 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306548 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549 int i;
Nirav Shahda008342016-05-17 18:50:40 +05306550 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551
6552 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306553 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006554 adapter = adapter_node->pAdapter;
6555
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006556 hdd_debug("Netif queue operation statistics:");
6557 hdd_debug("Session_id %d device mode %d",
Nirav Shah617cff92016-04-25 10:24:24 +05306558 adapter->sessionId, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006559 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05306560 curr_time = qdf_system_ticks();
6561 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05306562 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05306563 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05306564 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306565 unpause = adapter->total_unpause_time;
6566 } else {
Nirav Shahda008342016-05-17 18:50:40 +05306567 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05306568 pause = adapter->total_pause_time;
6569 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006570 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05306571 qdf_system_ticks_to_msecs(total),
6572 qdf_system_ticks_to_msecs(pause),
6573 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006574 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575
Nirav Shahda008342016-05-17 18:50:40 +05306576 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
6577 qdf_time_t pause_delta = 0;
6578
6579 if (adapter->pause_map & (1 << i))
6580 pause_delta = delta;
6581
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006582 /* using hdd_log to avoid printing function name */
6583 hdd_log(QDF_TRACE_LEVEL_ERROR,
6584 "%s: %d: %d: %ums",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585 hdd_reason_type_to_string(i),
6586 adapter->queue_oper_stats[i].pause_count,
Nirav Shahda008342016-05-17 18:50:40 +05306587 adapter->queue_oper_stats[i].unpause_count,
6588 qdf_system_ticks_to_msecs(
6589 adapter->queue_oper_stats[i].total_pause_time +
6590 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591 }
6592
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006593 hdd_debug("Netif queue operation history:");
6594 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05306595 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
6596
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006597 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598
6599 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07006600 /* using hdd_log to avoid printing function name */
6601 if (adapter->queue_oper_history[i].time == 0)
6602 continue;
6603 hdd_log(QDF_TRACE_LEVEL_ERROR,
6604 "%d: %u: %s: %s: %x",
Anurag Chouhan50220ce2016-02-18 20:11:33 +05306605 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006606 adapter->queue_oper_history[i].time),
6607 hdd_action_type_to_string(
6608 adapter->queue_oper_history[i].netif_action),
6609 hdd_reason_type_to_string(
6610 adapter->queue_oper_history[i].netif_reason),
6611 adapter->queue_oper_history[i].pause_map);
6612 }
6613
6614 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6615 adapter_node = next;
6616 }
6617
6618
6619}
6620
6621/**
6622 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
6623 * @hdd_ctx: hdd context
6624 *
6625 * Return: none
6626 */
6627void wlan_hdd_clear_netif_queue_history(hdd_context_t *hdd_ctx)
6628{
6629 hdd_adapter_t *adapter = NULL;
6630 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306631 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632
6633 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306634 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006635 adapter = adapter_node->pAdapter;
6636
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306637 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306639 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05306641 adapter->history_index = 0;
6642 adapter->start_time = adapter->last_time = qdf_system_ticks();
6643 adapter->total_pause_time = 0;
6644 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
6646 adapter_node = next;
6647 }
6648}
6649
6650/**
6651 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
6652 * @halHandle: Hal handle
6653 * @pContext: Pointer to the context
6654 * @sessionId: Session ID
6655 * @scanId: Scan ID
6656 * @status: Status
6657 *
6658 * This is the callback to be executed when 11d scan is completed to flush out
6659 * the scan results
6660 *
6661 * 11d scan is done during driver load and is a passive scan on all
6662 * channels supported by the device, 11d scans may find some APs on
6663 * frequencies which are forbidden to be used in the regulatory domain
6664 * the device is operating in. If these APs are notified to the supplicant
6665 * it may try to connect to these APs, thus flush out all the scan results
6666 * which are present in SME after 11d scan is done.
6667 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306668 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306670static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671 uint8_t sessionId, uint32_t scanId,
6672 eCsrScanStatus status)
6673{
6674 ENTER();
6675
6676 sme_scan_flush_result(halHandle);
6677
6678 EXIT();
6679
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306680 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006681}
6682
6683#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
6684/**
6685 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
6686 * @hdd_ctx: hdd global context
6687 *
6688 * Return: none
6689 */
6690static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6691{
6692 uint8_t i;
6693
6694 mutex_init(&hdd_ctx->op_ctx.op_lock);
6695 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
6696 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
6697 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
6698 }
6699}
6700#else
6701static void hdd_init_offloaded_packets_ctx(hdd_context_t *hdd_ctx)
6702{
6703}
6704#endif
6705
Yingying Tang95409972016-10-20 15:16:15 +08006706#ifdef WLAN_FEATURE_WOW_PULSE
6707/**
6708 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
6709 * @phddctx: hdd_context_t structure pointer
6710 * @enable: enable or disable this behaviour
6711 *
6712 * Return: int
6713 */
6714static int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6715{
6716 struct hdd_config *pcfg_ini = phddctx->config;
6717 struct wow_pulse_mode wow_pulse_set_info;
6718 QDF_STATUS status;
6719
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006720 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08006721
6722 if (false == phddctx->config->wow_pulse_support)
6723 return 0;
6724
6725 /* prepare the request to send to SME */
6726 if (enable == true) {
6727 wow_pulse_set_info.wow_pulse_enable = true;
6728 wow_pulse_set_info.wow_pulse_pin =
6729 pcfg_ini->wow_pulse_pin;
6730 wow_pulse_set_info.wow_pulse_interval_low =
6731 pcfg_ini->wow_pulse_interval_low;
6732 wow_pulse_set_info.wow_pulse_interval_high =
6733 pcfg_ini->wow_pulse_interval_high;
6734 } else {
6735 wow_pulse_set_info.wow_pulse_enable = false;
6736 wow_pulse_set_info.wow_pulse_pin = 0;
6737 wow_pulse_set_info.wow_pulse_interval_low = 0;
6738 wow_pulse_set_info.wow_pulse_interval_high = 0;
6739 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006740 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08006741 wow_pulse_set_info.wow_pulse_enable,
6742 wow_pulse_set_info.wow_pulse_pin,
6743 wow_pulse_set_info.wow_pulse_interval_low,
6744 wow_pulse_set_info.wow_pulse_interval_high);
6745
6746 status = sme_set_wow_pulse(&wow_pulse_set_info);
6747 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006748 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08006749 return -EIO;
6750 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006751 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08006752 return 0;
6753}
6754#else
6755static inline int wlan_hdd_set_wow_pulse(hdd_context_t *phddctx, bool enable)
6756{
6757 return 0;
6758}
6759#endif
6760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761#ifdef WLAN_FEATURE_FASTPATH
6762/**
6763 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
6764 * @hdd_cfg: hdd config
6765 * @context: lower layer context
6766 *
6767 * Return: none
6768 */
Arun Khandavallifae92942016-08-01 13:31:08 +05306769void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 void *context)
6771{
6772 if (hdd_cfg->fastpath_enable)
6773 hif_enable_fastpath(context);
6774}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006775#endif
6776
Yuanyuan Liu13738502016-04-06 17:41:37 -07006777#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778/**
6779 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006780 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006781 * @level: thermal level
6782 *
6783 * Change IPA data path to SW path when the thermal throttle level greater
6784 * than 0, and restore the original data path when throttle level is 0
6785 *
6786 * Return: none
6787 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006788static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789{
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08006790 hdd_context_t *hdd_ctx = context;
6791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006792 /* Change IPA to SW path when throttle level greater than 0 */
6793 if (level > THROTTLE_LEVEL_0)
6794 hdd_ipa_send_mcc_scc_msg(hdd_ctx, true);
6795 else
6796 /* restore original concurrency mode */
6797 hdd_ipa_send_mcc_scc_msg(hdd_ctx, hdd_ctx->mcc_mode);
6798}
6799
6800/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306801 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
6802 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05306803 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306805 * Get a safe channel to restart SAP. PCL already takes into account the
6806 * unsafe channels. So, the PCL is validated with the ACS range to provide
6807 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006808 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306809 * Return: Channel number to restart SAP in case of success. In case of any
6810 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306812static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
6813 hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306815 struct sir_pcl_list pcl;
6816 QDF_STATUS status;
6817 uint32_t i, j;
6818 tHalHandle *hal_handle;
6819 hdd_context_t *hdd_ctx;
6820 bool found = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306822 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6823 if (!hdd_ctx) {
6824 hdd_err("invalid HDD context");
6825 return INVALID_CHANNEL_ID;
6826 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05306828 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6829 if (!hal_handle) {
6830 hdd_err("invalid HAL handle");
6831 return INVALID_CHANNEL_ID;
6832 }
6833
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006834 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
6835 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306836 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list));
6837 if (QDF_IS_STATUS_ERROR(status)) {
6838 hdd_err("Get PCL failed");
6839 return INVALID_CHANNEL_ID;
6840 }
6841
6842 if (!pcl.pcl_len) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006843 hdd_err("pcl length is zero. this is not expected");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306844 return INVALID_CHANNEL_ID;
6845 }
6846
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006847 hdd_debug("start:%d end:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306848 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch,
6849 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch);
6850
6851 /* PCL already takes unsafe channel into account */
6852 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006853 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306854 if ((pcl.pcl_list[i] >=
6855 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6856 (pcl.pcl_list[i] <=
6857 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006858 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306859 return pcl.pcl_list[i];
6860 }
6861 }
6862
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006863 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306864
6865 /* Try for safe channel from all valid channel */
6866 pcl.pcl_len = MAX_NUM_CHAN;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006867 status = sme_get_cfg_valid_channels(pcl.pcl_list,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306868 &pcl.pcl_len);
6869 if (QDF_IS_STATUS_ERROR(status)) {
6870 hdd_err("error in getting valid channel list");
6871 return INVALID_CHANNEL_ID;
6872 }
6873
6874 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006875 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306876 found = false;
6877 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07006878 if (pcl.pcl_list[i] ==
6879 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006880 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306881 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 break;
6883 }
6884 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306885
6886 if (found)
6887 continue;
6888
6889 if ((pcl.pcl_list[i] >=
6890 adapter->sessionCtx.ap.sapConfig.acs_cfg.start_ch) &&
6891 (pcl.pcl_list[i] <=
6892 adapter->sessionCtx.ap.sapConfig.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006893 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306894 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895 }
6896 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306897
6898 return INVALID_CHANNEL_ID;
6899}
6900
6901/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006902 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306903 * @adapter: AP adapter
6904 * @channel: Channel
6905 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006906 * Moves the SAP interface by invoking the function which
6907 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306908 *
6909 * Return: None
6910 */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08006911void hdd_switch_sap_channel(hdd_adapter_t *adapter, uint8_t channel)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306912{
6913 hdd_ap_ctx_t *hdd_ap_ctx;
6914 tHalHandle *hal_handle;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006915 hdd_context_t *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306916
6917 if (!adapter) {
6918 hdd_err("invalid adapter");
6919 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306921
6922 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
6923
6924 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
6925 if (!hal_handle) {
6926 hdd_err("invalid HAL handle");
6927 return;
6928 }
6929
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006930 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6931
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306932 hdd_ap_ctx->sapConfig.channel = channel;
6933 hdd_ap_ctx->sapConfig.ch_params.ch_width =
6934 hdd_ap_ctx->sapConfig.ch_width_orig;
6935
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006936 hdd_debug("chan:%d width:%d",
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306937 channel, hdd_ap_ctx->sapConfig.ch_width_orig);
6938
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07006939 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
6940 hdd_ap_ctx->sapConfig.channel,
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05306941 hdd_ap_ctx->sapConfig.sec_ch,
6942 &hdd_ap_ctx->sapConfig.ch_params);
6943
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08006944 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
6945 adapter->sessionId, channel,
6946 hdd_ap_ctx->sapConfig.ch_width_orig);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947}
Kapil Gupta8878ad92017-02-13 11:56:04 +05306948
6949int hdd_update_acs_timer_reason(hdd_adapter_t *adapter, uint8_t reason)
6950{
6951 struct hdd_external_acs_timer_context *timer_context;
6952
6953 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
6954
6955 if (QDF_TIMER_STATE_RUNNING ==
6956 qdf_mc_timer_get_current_state(&adapter->sessionCtx.
6957 ap.vendor_acs_timer)) {
6958 qdf_mc_timer_stop(&adapter->sessionCtx.ap.vendor_acs_timer);
6959 }
6960 timer_context = (struct hdd_external_acs_timer_context *)
6961 adapter->sessionCtx.ap.vendor_acs_timer.user_data;
6962 timer_context->reason = reason;
6963 qdf_mc_timer_start(&adapter->sessionCtx.ap.vendor_acs_timer,
6964 WLAN_VENDOR_ACS_WAIT_TIME);
6965 /* Update config to application */
6966 hdd_cfg80211_update_acs_config(adapter, reason);
6967 hdd_notice("Updated ACS config to nl with reason %d", reason);
6968
6969 return 0;
6970}
6971
Agrawal Ashish467dde42016-09-08 18:44:22 +05306972/**
6973 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
6974 * @hdd_ctx: hdd context pointer
6975 *
6976 * hdd_unsafe_channel_restart_sap check all unsafe channel list
6977 * and if ACS is enabled, driver will ask userspace to restart the
6978 * sap. User space on LTE coex indication restart driver.
6979 *
6980 * Return - none
6981 */
6982void hdd_unsafe_channel_restart_sap(hdd_context_t *hdd_ctxt)
6983{
6984 QDF_STATUS status;
6985 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
6986 hdd_adapter_t *adapter_temp;
6987 uint32_t i;
6988 bool found = false;
6989 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990
Agrawal Ashish467dde42016-09-08 18:44:22 +05306991 status = hdd_get_front_adapter(hdd_ctxt, &adapter_node);
6992 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
6993 adapter_temp = adapter_node->pAdapter;
6994
6995 if (!adapter_temp) {
6996 hdd_err("adapter is NULL, moving to next one");
6997 goto next_adapater;
6998 }
6999
7000 if (!((adapter_temp->device_mode == QDF_SAP_MODE) &&
7001 (adapter_temp->sessionCtx.ap.sapConfig.acs_cfg.acs_mode))) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007002 hdd_debug("skip device mode:%d acs:%d",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307003 adapter_temp->device_mode,
7004 adapter_temp->sessionCtx.ap.sapConfig.
7005 acs_cfg.acs_mode);
7006 goto next_adapater;
7007 }
7008
7009 found = false;
7010 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007011 if (adapter_temp->sessionCtx.ap.operatingChannel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05307012 hdd_ctxt->unsafe_channel_list[i]) {
7013 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007014 hdd_debug("operating ch:%d is unsafe",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307015 adapter_temp->sessionCtx.ap.operatingChannel);
7016 break;
7017 }
7018 }
7019
7020 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007021 hdd_debug("ch:%d is safe. no need to change channel",
Agrawal Ashish467dde42016-09-08 18:44:22 +05307022 adapter_temp->sessionCtx.ap.operatingChannel);
7023 goto next_adapater;
7024 }
7025
Kapil Gupta8878ad92017-02-13 11:56:04 +05307026 if (hdd_ctxt->config->vendor_acs_support &&
7027 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
7028 hdd_update_acs_timer_reason(adapter_temp,
7029 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
7030 goto next_adapater;
7031 } else
7032 restart_chan =
7033 hdd_get_safe_channel_from_pcl_and_acs_range(
Agrawal Ashish467dde42016-09-08 18:44:22 +05307034 adapter_temp);
7035 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007036 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307037 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007038 /*
7039 * SAP restart due to unsafe channel. While
7040 * restarting the SAP, make sure to clear
7041 * acs_channel, channel to reset to
7042 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307043 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08007044 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05307045 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7046 adapter_temp->sessionCtx.ap.sapConfig.channel =
7047 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007048 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05307049 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
7050 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007051 hdd_switch_sap_channel(adapter_temp, restart_chan);
Agrawal Ashish467dde42016-09-08 18:44:22 +05307052 }
7053
7054next_adapater:
7055 status = hdd_get_next_adapter(hdd_ctxt, adapter_node, &next);
7056 adapter_node = next;
7057 }
7058}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060/**
7061 * hdd_ch_avoid_cb() - Avoid notified channels from FW handler
7062 * @adapter: HDD adapter pointer
7063 * @indParam: Channel avoid notification parameter
7064 *
7065 * Avoid channel notification from FW handler.
7066 * FW will send un-safe channel list to avoid over wrapping.
7067 * hostapd should not use notified channel
7068 *
7069 * Return: None
7070 */
Agrawal Ashish467dde42016-09-08 18:44:22 +05307071void hdd_ch_avoid_cb(void *hdd_context, void *indi_param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007072{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073 hdd_context_t *hdd_ctxt;
7074 tSirChAvoidIndType *ch_avoid_indi;
7075 uint8_t range_loop;
Amar Singhalb8d4f152016-02-10 10:21:43 -08007076 enum channel_enum channel_loop, start_channel_idx = INVALID_CHANNEL,
7077 end_channel_idx = INVALID_CHANNEL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007078 uint16_t start_channel;
7079 uint16_t end_channel;
7080 v_CONTEXT_t cds_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007081 tHddAvoidFreqList hdd_avoid_freq_list;
7082 uint32_t i;
7083
7084 /* Basic sanity */
7085 if (!hdd_context || !indi_param) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07007086 hdd_err("Invalid arguments");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007087 return;
7088 }
7089
7090 hdd_ctxt = (hdd_context_t *) hdd_context;
7091 ch_avoid_indi = (tSirChAvoidIndType *) indi_param;
7092 cds_context = hdd_ctxt->pcds_context;
7093
7094 /* Make unsafe channel list */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007095 hdd_debug("band count %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007096 ch_avoid_indi->avoid_range_count);
7097
7098 /* generate vendor specific event */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307099 qdf_mem_zero((void *)&hdd_avoid_freq_list, sizeof(tHddAvoidFreqList));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100 for (i = 0; i < ch_avoid_indi->avoid_range_count; i++) {
7101 hdd_avoid_freq_list.avoidFreqRange[i].startFreq =
7102 ch_avoid_indi->avoid_freq_range[i].start_freq;
7103 hdd_avoid_freq_list.avoidFreqRange[i].endFreq =
7104 ch_avoid_indi->avoid_freq_range[i].end_freq;
7105 }
7106 hdd_avoid_freq_list.avoidFreqRangeCount =
7107 ch_avoid_indi->avoid_range_count;
7108
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307109 mutex_lock(&hdd_ctxt->avoid_freq_lock);
7110 hdd_ctxt->coex_avoid_freq_list = hdd_avoid_freq_list;
7111 mutex_unlock(&hdd_ctxt->avoid_freq_lock);
7112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007113 /* clear existing unsafe channel cache */
7114 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307115 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007116 sizeof(hdd_ctxt->unsafe_channel_list));
7117
7118 for (range_loop = 0; range_loop < ch_avoid_indi->avoid_range_count;
7119 range_loop++) {
Amar Singhalb8d4f152016-02-10 10:21:43 -08007120 if (hdd_ctxt->unsafe_channel_count >= NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07007121 hdd_warn("LTE Coex unsafe channel list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122 break;
7123 }
7124
7125 start_channel = ieee80211_frequency_to_channel(
7126 ch_avoid_indi->avoid_freq_range[range_loop].start_freq);
7127 end_channel = ieee80211_frequency_to_channel(
7128 ch_avoid_indi->avoid_freq_range[range_loop].end_freq);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007129 hdd_debug("start %d : %d, end %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 ch_avoid_indi->avoid_freq_range[range_loop].start_freq,
7131 start_channel,
7132 ch_avoid_indi->avoid_freq_range[range_loop].end_freq,
7133 end_channel);
7134
7135 /* do not process frequency bands that are not mapped to
7136 * predefined channels
7137 */
7138 if (start_channel == 0 || end_channel == 0)
7139 continue;
7140
Amar Singhalb8d4f152016-02-10 10:21:43 -08007141 for (channel_loop = CHAN_ENUM_1; channel_loop <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007142 CHAN_ENUM_184; channel_loop++) {
7143 if (WLAN_REG_CH_TO_FREQ(channel_loop) >=
7144 ch_avoid_indi->avoid_freq_range[
7145 range_loop].start_freq) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146 start_channel_idx = channel_loop;
7147 break;
7148 }
7149 }
Amar Singhalb8d4f152016-02-10 10:21:43 -08007150 for (channel_loop = CHAN_ENUM_1; channel_loop <=
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007151 CHAN_ENUM_184; channel_loop++) {
7152 if (WLAN_REG_CH_TO_FREQ(channel_loop) >=
7153 ch_avoid_indi->avoid_freq_range[
7154 range_loop].end_freq) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155 end_channel_idx = channel_loop;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007156 if (WLAN_REG_CH_TO_FREQ(channel_loop) >
7157 ch_avoid_indi->avoid_freq_range[
7158 range_loop].end_freq)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007159 end_channel_idx--;
7160 break;
7161 }
7162 }
7163
Amar Singhalb8d4f152016-02-10 10:21:43 -08007164 if (start_channel_idx == INVALID_CHANNEL ||
7165 end_channel_idx == INVALID_CHANNEL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007166 continue;
7167
7168 for (channel_loop = start_channel_idx; channel_loop <=
7169 end_channel_idx; channel_loop++) {
7170 hdd_ctxt->unsafe_channel_list[
Amar Singhal7a1726a2015-10-14 16:28:11 -07007171 hdd_ctxt->unsafe_channel_count++] =
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007172 WLAN_REG_CH_NUM(channel_loop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007173 if (hdd_ctxt->unsafe_channel_count >=
Amar Singhalb8d4f152016-02-10 10:21:43 -08007174 NUM_CHANNELS) {
Jeff Johnson34c88b72016-08-15 14:27:11 -07007175 hdd_warn("LTECoex unsafe ch list full");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007176 break;
7177 }
7178 }
7179 }
7180
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007181 hdd_debug("number of unsafe channels is %d ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007182 hdd_ctxt->unsafe_channel_count);
7183
Yuanyuan Liu13738502016-04-06 17:41:37 -07007184 if (pld_set_wlan_unsafe_channel(hdd_ctxt->parent_dev,
7185 hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186 hdd_ctxt->unsafe_channel_count)) {
7187 hdd_err("Failed to set unsafe channel");
7188
7189 /* clear existing unsafe channel cache */
7190 hdd_ctxt->unsafe_channel_count = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307191 qdf_mem_zero(hdd_ctxt->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007192 sizeof(hdd_ctxt->unsafe_channel_list));
7193
7194 return;
7195 }
7196
7197 for (channel_loop = 0;
7198 channel_loop < hdd_ctxt->unsafe_channel_count; channel_loop++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007199 hdd_debug("channel %d is not safe ",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200 hdd_ctxt->unsafe_channel_list[channel_loop]);
7201 }
7202
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307203 mutex_lock(&hdd_ctxt->avoid_freq_lock);
7204 if (hdd_ctxt->dnbs_avoid_freq_list.avoidFreqRangeCount)
7205 if (wlan_hdd_merge_avoid_freqs(&hdd_avoid_freq_list,
7206 &hdd_ctxt->dnbs_avoid_freq_list)) {
7207 mutex_unlock(&hdd_ctxt->avoid_freq_lock);
7208 hdd_debug("unable to merge avoid freqs");
7209 return;
7210 }
7211 mutex_unlock(&hdd_ctxt->avoid_freq_lock);
Kondabattini, Ganeshcf7b60f2016-08-10 16:31:55 +05307212 /*
7213 * first update the unsafe channel list to the platform driver and
7214 * send the avoid freq event to the application
7215 */
Hanumanth Reddy Pothulaffc2d482017-07-04 11:32:44 +05307216 if (hdd_ctxt->config->restart_beaconing_on_chan_avoid_event) {
Hanumanth Reddy Pothula9c161dd2017-03-23 19:03:08 +05307217 wlan_hdd_send_avoid_freq_event(hdd_ctxt, &hdd_avoid_freq_list);
Kondabattini, Ganeshcf7b60f2016-08-10 16:31:55 +05307218
Hanumanth Reddy Pothula9c161dd2017-03-23 19:03:08 +05307219 if (!hdd_ctxt->unsafe_channel_count) {
7220 hdd_info("no unsafe channels - not restarting SAP");
7221 return;
7222 }
7223
7224 hdd_unsafe_channel_restart_sap(hdd_ctxt);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307225 }
Hanumanth Reddy Pothula9c161dd2017-03-23 19:03:08 +05307226
7227 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007228}
7229
7230/**
7231 * hdd_init_channel_avoidance() - Initialize channel avoidance
7232 * @hdd_ctx: HDD global context
7233 *
7234 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07007235 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007236 * down to the lower layers. Then subscribe to subsequent channel
7237 * avoidance events.
7238 *
7239 * Return: None
7240 */
7241static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7242{
7243 uint16_t unsafe_channel_count;
7244 int index;
7245
Yuanyuan Liu13738502016-04-06 17:41:37 -07007246 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
7247 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08007249 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007251 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252 hdd_ctx->unsafe_channel_count);
7253
Anurag Chouhan6d760662016-02-20 16:05:43 +05307254 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08007255 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256
7257 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007258 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007259 hdd_ctx->unsafe_channel_list[index]);
7260
7261 }
7262
7263 /* Plug in avoid channel notification callback */
7264 sme_add_ch_avoid_callback(hdd_ctx->hHal, hdd_ch_avoid_cb);
7265}
7266#else
7267static void hdd_init_channel_avoidance(hdd_context_t *hdd_ctx)
7268{
7269}
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007270static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271{
7272}
Yuanyuan Liu13738502016-04-06 17:41:37 -07007273#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007274
7275/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08007276 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
7277 * user space
7278 * @frame_ind: Management frame data to be informed.
7279 *
7280 * This function is used to indicate management frame to
7281 * user space
7282 *
7283 * Return: None
7284 *
7285 */
7286void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
7287{
7288 hdd_context_t *hdd_ctx = NULL;
7289 hdd_adapter_t *adapter = NULL;
7290 void *cds_context = NULL;
7291 int i;
7292
7293 /* Get the global VOSS context.*/
7294 cds_context = cds_get_global_context();
7295 if (!cds_context) {
7296 hdd_err("Global CDS context is Null");
7297 return;
7298 }
7299 /* Get the HDD context.*/
7300 hdd_ctx = (hdd_context_t *)cds_get_context(QDF_MODULE_ID_HDD);
7301
7302 if (0 != wlan_hdd_validate_context(hdd_ctx))
7303 return;
7304
7305 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
7306 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
7307 adapter =
7308 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
7309 if (adapter)
7310 break;
7311 }
7312 } else {
7313 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
7314 frame_ind->sessionId);
7315 }
7316
7317 if ((NULL != adapter) &&
7318 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
7319 __hdd_indicate_mgmt_frame(adapter,
7320 frame_ind->frame_len,
7321 frame_ind->frameBuf,
7322 frame_ind->frameType,
7323 frame_ind->rxChan,
7324 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08007325}
7326
Kapil Gupta8878ad92017-02-13 11:56:04 +05307327static void hdd_lte_coex_restart_sap(hdd_adapter_t *adapter,
7328 hdd_context_t *hdd_ctx)
7329{
7330 uint8_t restart_chan = 0;
7331
7332 restart_chan =
7333 hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
7334 if (!restart_chan) {
7335 hdd_alert("fail to restart SAP");
7336 } else {
7337 /* SAP restart due to unsafe channel. While restarting
7338 * the SAP, make sure to clear acs_channel, channel to
7339 * reset to 0. Otherwise these settings will override
7340 * the ACS while restart.
7341 */
7342 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
7343 adapter->sessionCtx.ap.sapConfig.channel =
7344 AUTO_CHANNEL_SELECT;
7345 hdd_info("sending coex indication");
7346 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7347 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007348 hdd_switch_sap_channel(adapter, restart_chan);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307349 }
7350}
7351
7352void hdd_acs_response_timeout_handler(void *context)
7353{
7354 struct hdd_external_acs_timer_context *timer_context =
7355 (struct hdd_external_acs_timer_context *)context;
7356 hdd_adapter_t *adapter;
7357 hdd_context_t *hdd_ctx;
7358 uint8_t reason;
7359
7360 ENTER();
7361 if (!timer_context) {
7362 hdd_err("invlaid timer context");
7363 return;
7364 }
7365 adapter = timer_context->adapter;
7366 reason = timer_context->reason;
7367
7368
7369 if ((!adapter) ||
7370 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
7371 hdd_err("invalid adapter or adapter has invalid magic");
7372 return;
7373 }
7374 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7375 if (wlan_hdd_validate_context(hdd_ctx))
7376 return;
7377
7378 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
7379 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7380 else
7381 return;
7382
7383 hdd_err("ACS timeout happened for %s reason %d",
7384 adapter->dev->name, reason);
7385 switch (reason) {
7386 /* SAP init case */
7387 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
7388 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
7389 false);
7390 wlan_hdd_cfg80211_start_acs(adapter);
7391 break;
7392 /* DFS detected on current channel */
7393 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
7394 wlan_sap_update_next_channel(
7395 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
7396 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
7397 adapter->sessionId);
7398 break;
7399 /* LTE coex event on current channel */
7400 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
7401 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
7402 break;
7403 default:
7404 hdd_info("invalid reason for timer invoke");
7405
7406 }
7407}
7408
Rajeev Kumard004abc2016-02-17 12:09:56 -08007409/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007410 * wlan_hdd_disable_all_dual_mac_features() - Disable dual mac features
7411 * @hdd_ctx: HDD context
7412 *
7413 * Disables all the dual mac features like DBS, Agile DFS etc.
7414 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307415 * Return: QDF_STATUS_SUCCESS on success
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007416 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307417static QDF_STATUS wlan_hdd_disable_all_dual_mac_features(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007418{
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007419 struct policy_mgr_dual_mac_config cfg = {0};
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307420 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007421
7422 if (!hdd_ctx) {
7423 hdd_err("HDD context is NULL");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307424 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007425 }
7426
7427 cfg.scan_config = 0;
7428 cfg.fw_mode_config = 0;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007429 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007430
7431 hdd_debug("Disabling all dual mac features...");
7432
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007433 status = sme_soc_set_dual_mac_config(cfg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307434 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
7436 return status;
7437 }
7438
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307439 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007440}
7441
7442/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007443 * hdd_override_ini_config - Override INI config
7444 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007445 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007446 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007447 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007448 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007449 */
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007450static void hdd_override_ini_config(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007451{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007452
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007453 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
7454 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007455 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007456 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007457 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007458 if (0 == enable_11d || 1 == enable_11d) {
7459 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007460 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007461 }
Leo Chang11545d62016-10-17 14:53:50 -07007462
7463 if (!hdd_ipa_is_present(hdd_ctx))
7464 hdd_ctx->config->IpaConfig = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007465}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007466
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007467/**
7468 * hdd_set_trace_level_for_each - Set trace level for each INI config
7469 * @hdd_ctx - HDD context
7470 *
7471 * Set trace level for each module based on INI config.
7472 *
7473 * Return: None
7474 */
7475static void hdd_set_trace_level_for_each(hdd_context_t *hdd_ctx)
7476{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307477 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
7478 hdd_ctx->config->qdf_trace_enable_wdi);
7479 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
7480 hdd_ctx->config->qdf_trace_enable_hdd);
7481 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
7482 hdd_ctx->config->qdf_trace_enable_sme);
7483 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
7484 hdd_ctx->config->qdf_trace_enable_pe);
7485 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
7486 hdd_ctx->config->qdf_trace_enable_wma);
7487 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
7488 hdd_ctx->config->qdf_trace_enable_sys);
7489 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
7490 hdd_ctx->config->qdf_trace_enable_qdf);
7491 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
7492 hdd_ctx->config->qdf_trace_enable_sap);
7493 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
7494 hdd_ctx->config->qdf_trace_enable_hdd_sap);
7495 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
7496 hdd_ctx->config->qdf_trace_enable_bmi);
7497 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
7498 hdd_ctx->config->qdf_trace_enable_cfg);
7499 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
7500 hdd_ctx->config->qdf_trace_enable_epping);
7501 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
7502 hdd_ctx->config->qdf_trace_enable_qdf_devices);
7503 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Bhargav Shah480a90f2015-06-24 15:10:14 +05307504 hdd_ctx->config->cfd_trace_enable_txrx);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307505 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
7506 hdd_ctx->config->qdf_trace_enable_htc);
7507 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
7508 hdd_ctx->config->qdf_trace_enable_hif);
7509 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
7510 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
7511 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
7512 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08007513 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
7514 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07007515 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
7516 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007517 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
7518 hdd_ctx->config->qdf_trace_enable_regulatory);
7519
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007521}
7522
7523/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007524 * hdd_context_init() - Initialize HDD context
7525 * @hdd_ctx: HDD context.
7526 *
7527 * Initialize HDD context along with all the feature specific contexts.
7528 *
7529 * return: 0 on success and errno on failure.
7530 */
7531static int hdd_context_init(hdd_context_t *hdd_ctx)
7532{
7533 int ret;
7534
7535 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
7536 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
7537
7538 hdd_init_ll_stats_ctx();
7539
7540 init_completion(&hdd_ctx->mc_sus_event_var);
7541 init_completion(&hdd_ctx->ready_to_suspend);
7542
7543 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307544 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007545 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307546
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007547 qdf_list_create(&hdd_ctx->hddAdapters, MAX_NUMBER_OF_ADAPTERS);
7548
7549 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
7550
7551 ret = hdd_scan_context_init(hdd_ctx);
7552 if (ret)
7553 goto list_destroy;
7554
Nitesh Shahd1266d72017-01-25 22:07:07 +05307555 hdd_tdls_context_init(hdd_ctx, false);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007556
7557 hdd_rx_wake_lock_create(hdd_ctx);
7558
7559 ret = hdd_sap_context_init(hdd_ctx);
7560 if (ret)
7561 goto scan_destroy;
7562
7563 ret = hdd_roc_context_init(hdd_ctx);
7564 if (ret)
7565 goto sap_destroy;
7566
7567 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
7568
7569 hdd_init_offloaded_packets_ctx(hdd_ctx);
7570
7571 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
7572 hdd_ctx->config);
7573 if (ret)
7574 goto roc_destroy;
7575
7576 return 0;
7577
7578roc_destroy:
7579 hdd_roc_context_destroy(hdd_ctx);
7580
7581sap_destroy:
7582 hdd_sap_context_destroy(hdd_ctx);
7583
7584scan_destroy:
7585 hdd_scan_context_destroy(hdd_ctx);
7586 hdd_rx_wake_lock_destroy(hdd_ctx);
7587 hdd_tdls_context_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007588list_destroy:
7589 qdf_list_destroy(&hdd_ctx->hddAdapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08007590
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007591 return ret;
7592}
7593
7594/**
7595 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05307596 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007597 *
7598 * Allocate and initialize HDD context. HDD context is allocated as part of
7599 * wiphy allocation and then context is initialized.
7600 *
7601 * Return: HDD context on success and ERR_PTR on failure
7602 */
Jeff Johnson590e2012016-10-05 16:16:24 -07007603static hdd_context_t *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007604{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307605 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007606 int ret = 0;
7607 hdd_context_t *hdd_ctx;
7608 v_CONTEXT_t p_cds_context;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307609 int qdf_print_idx = -1;
7610
7611 struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
7612 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
7613 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
7614 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
7615 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
7616 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
7617 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
7618 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
7619 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
7620 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
7621 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
7622 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
7623 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7624 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
7625 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
7626 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
7627 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
7628 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
7629 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
7630 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
7631 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiyaf928edf2017-02-06 14:43:24 +05307632 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
7633 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
7634 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
7635 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
7636 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
7637 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
Mukul Sharma4d7d6b02017-02-13 20:45:22 +05307638 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh9679dbf2017-02-15 11:35:41 +05307639 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
Tushnim Bhattacharyya6796d8d2017-03-17 11:06:03 -07007640 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
7641 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
Wu Gao9a704f42017-03-10 18:42:11 +08007642 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
Frank Liud4b2fa02017-03-29 11:46:48 +08007643 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07007644 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05307645 };
7646
7647 status = qdf_print_setup();
7648 if (status != QDF_STATUS_SUCCESS) {
7649 pr_err("QDF print control object setup failed\n");
7650 ret = -EINVAL;
7651 goto err_out;
7652 }
7653 /* Register the module here with QDF */
7654 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL,
7655 "MCL_WLAN");
7656
7657 /* if qdf_print_idx is negative */
7658 if (qdf_print_idx < 0) {
7659 pr_err("QDF print control can not be registered %d\n",
7660 qdf_print_idx);
7661 ret = -EINVAL;
7662 goto err_out;
7663 }
7664
7665 /* Store the qdf_pidx information into qdf module */
7666 qdf_set_pidx(qdf_print_idx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007667
7668 ENTER();
7669
7670 p_cds_context = cds_get_global_context();
7671 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007672 hdd_err("Failed to get CDS global context");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007673 ret = -EINVAL;
7674 goto err_out;
7675 }
7676
7677 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(hdd_context_t));
7678
7679 if (hdd_ctx == NULL) {
7680 ret = -ENOMEM;
7681 goto err_out;
7682 }
7683
7684 hdd_ctx->pcds_context = p_cds_context;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007685 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05307686 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007687
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307688 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007689 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007690 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007691 ret = -ENOMEM;
7692 goto err_free_hdd_context;
7693 }
7694
7695 /* Read and parse the qcom_cfg.ini file */
7696 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307697 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307698 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007699 WLAN_INI_FILE);
7700 ret = -EINVAL;
7701 goto err_free_config;
7702 }
7703
Dustin Brown7f939932017-05-18 15:02:17 -07007704 hdd_debug("setting timer multiplier: %u",
7705 hdd_ctx->config->timer_multiplier);
7706 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
7707
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007708
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05307709 if (hdd_ctx->config->fhostNSOffload)
7710 hdd_ctx->ns_offload_enable = true;
7711
Abhishek Singh5ea86532016-04-27 14:10:53 +05307712 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
7713
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007714 hdd_override_ini_config(hdd_ctx);
7715
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007716 ((cds_context_type *) (p_cds_context))->pHDDContext = (void *)hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007717
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007718 ret = hdd_context_init(hdd_ctx);
7719
7720 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007721 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007722
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007723 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05307724 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007725
Anurag Chouhan6d760662016-02-20 16:05:43 +05307726 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007727 goto skip_multicast_logging;
7728
7729 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
7730
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007731 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
7732 if (ret)
7733 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05307734
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007735 ret = hdd_logging_sock_activate_svc(hdd_ctx);
7736 if (ret)
Nirav Shahed34b212016-04-25 10:59:16 +05307737 goto err_free_histogram;
7738
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007739skip_multicast_logging:
7740 hdd_set_trace_level_for_each(hdd_ctx);
7741
7742 return hdd_ctx;
7743
Nirav Shahed34b212016-04-25 10:59:16 +05307744err_free_histogram:
7745 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7746
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07007747err_deinit_hdd_context:
7748 hdd_context_deinit(hdd_ctx);
7749
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007750err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307751 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007752
7753err_free_hdd_context:
7754 wiphy_free(hdd_ctx->wiphy);
7755
7756err_out:
7757 return ERR_PTR(ret);
7758}
7759
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007760#ifdef WLAN_OPEN_P2P_INTERFACE
7761/**
7762 * hdd_open_p2p_interface - Open P2P interface
7763 * @hdd_ctx: HDD context
7764 * @rtnl_held: True if RTNL lock held
7765 *
7766 * Open P2P interface during probe. This function called to open the P2P
7767 * interface at probe along with STA interface.
7768 *
7769 * Return: 0 on success and errno on failure
7770 */
7771static int hdd_open_p2p_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7772{
7773 hdd_adapter_t *adapter;
7774 uint8_t *p2p_dev_addr;
7775
7776 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
7777 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307778 qdf_mem_copy(hdd_ctx->p2pDeviceAddress.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007779 hdd_ctx->config->intfMacAddr[0].bytes,
7780 sizeof(tSirMacAddr));
7781
7782 /*
7783 * Generate the P2P Device Address. This consists of
7784 * the device's primary MAC address with the locally
7785 * administered bit set.
7786 */
7787 hdd_ctx->p2pDeviceAddress.bytes[0] |= 0x02;
7788 } else {
7789 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
7790 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007791 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007792 return -ENOSPC;
7793 }
7794
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307795 qdf_mem_copy(&hdd_ctx->p2pDeviceAddress.bytes[0], p2p_dev_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05307796 QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007797 }
7798
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007799 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007800 &hdd_ctx->p2pDeviceAddress.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08007801 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007802
7803 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007804 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007805 return -ENOSPC;
7806 }
7807
7808 return 0;
7809}
7810#else
Manishekar Chandrasekaranc81ba242016-07-18 17:44:44 +05307811static inline int hdd_open_p2p_interface(hdd_context_t *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007812 bool rtnl_held)
7813{
7814 return 0;
7815}
7816#endif
7817
Jeff Johnson957bc272017-02-02 08:54:48 -08007818static int hdd_open_ocb_interface(hdd_context_t *hdd_ctx, bool rtnl_held)
7819{
7820 hdd_adapter_t *adapter;
7821 int ret = 0;
7822
7823 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
7824 wlan_hdd_get_intf_addr(hdd_ctx),
7825 NET_NAME_UNKNOWN, rtnl_held);
7826 if (adapter == NULL) {
7827 hdd_err("Failed to open 802.11p interface");
7828 ret = -ENOSPC;
7829 }
7830
7831 return ret;
7832}
7833
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007834/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307835 * hdd_start_station_adapter()- Start the Station Adapter
7836 * @adapter: HDD adapter
7837 *
7838 * This function initializes the adapter for the station mode.
7839 *
7840 * Return: 0 on success or errno on failure.
7841 */
7842int hdd_start_station_adapter(hdd_adapter_t *adapter)
7843{
7844 QDF_STATUS status;
7845
7846 ENTER_DEV(adapter->dev);
7847
7848 status = hdd_init_station_mode(adapter);
7849
7850 if (QDF_STATUS_SUCCESS != status) {
7851 hdd_err("Error Initializing station mode: %d", status);
7852 return qdf_status_to_os_return(status);
7853 }
7854
Arun Khandavallifae92942016-08-01 13:31:08 +05307855 hdd_register_tx_flow_control(adapter,
7856 hdd_tx_resume_timer_expired_handler,
7857 hdd_tx_resume_cb);
7858
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307859 EXIT();
7860 return 0;
7861}
7862
7863/**
7864 * hdd_start_ap_adapter()- Start AP Adapter
7865 * @adapter: HDD adapter
7866 *
7867 * This function initializes the adapter for the AP mode.
7868 *
7869 * Return: 0 on success errno on failure.
7870 */
7871int hdd_start_ap_adapter(hdd_adapter_t *adapter)
7872{
7873 QDF_STATUS status;
7874
7875 ENTER();
7876
Arun Khandavallicc544b32017-01-30 19:52:16 +05307877 status = hdd_init_ap_mode(adapter, false);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307878
7879 if (QDF_STATUS_SUCCESS != status) {
7880 hdd_err("Error Initializing the AP mode: %d", status);
7881 return qdf_status_to_os_return(status);
7882 }
7883
Arun Khandavallifae92942016-08-01 13:31:08 +05307884 hdd_register_tx_flow_control(adapter,
7885 hdd_softap_tx_resume_timer_expired_handler,
7886 hdd_softap_tx_resume_cb);
7887
Arun Khandavalli7e857c32016-06-26 12:07:16 +05307888 EXIT();
7889 return 0;
7890}
7891
7892/**
7893 * hdd_start_ftm_adapter()- Start FTM adapter
7894 * @adapter: HDD adapter
7895 *
7896 * This function initializes the adapter for the FTM mode.
7897 *
7898 * Return: 0 on success or errno on failure.
7899 */
7900int hdd_start_ftm_adapter(hdd_adapter_t *adapter)
7901{
7902 QDF_STATUS qdf_status;
7903
7904 ENTER_DEV(adapter->dev);
7905
7906 qdf_status = hdd_init_tx_rx(adapter);
7907
7908 if (QDF_STATUS_SUCCESS != qdf_status) {
7909 hdd_err("Failed to start FTM adapter: %d", qdf_status);
7910 return qdf_status_to_os_return(qdf_status);
7911 }
7912
7913 return 0;
7914 EXIT();
7915}
7916
7917/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007918 * hdd_open_interfaces - Open all required interfaces
7919 * hdd_ctx: HDD context
7920 * rtnl_held: True if RTNL lock is held
7921 *
7922 * Open all the interfaces like STA, P2P and OCB based on the configuration.
7923 *
Jeff Johnson957bc272017-02-02 08:54:48 -08007924 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007925 */
Jeff Johnson957bc272017-02-02 08:54:48 -08007926static int hdd_open_interfaces(hdd_context_t *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007927{
Jeff Johnson957bc272017-02-02 08:54:48 -08007928 hdd_adapter_t *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007929 int ret;
7930
Jeff Johnson957bc272017-02-02 08:54:48 -08007931 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05307932 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08007933 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007934
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007935 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007936 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08007937 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007938
7939 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08007940 return -ENOSPC;
7941
Deepak Dhamdherea2785822016-11-17 01:17:45 -08007942 /* fast roaming is allowed only on first STA, i.e. wlan adapter */
7943 adapter->fast_roaming_allowed = true;
7944
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007945 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
7946 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08007947 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007948
7949 /* Open 802.11p Interface */
7950 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08007951 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
7952 if (ret)
7953 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007954 }
7955
Jeff Johnson957bc272017-02-02 08:54:48 -08007956 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007957
Jeff Johnson957bc272017-02-02 08:54:48 -08007958err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007959 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08007960 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08007961}
7962
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007963/**
7964 * hdd_update_country_code - Update country code
7965 * @hdd_ctx: HDD context
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007966 *
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007967 * Update country code based on module parameter country_code
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007968 *
7969 * Return: 0 on success and errno on failure
7970 */
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007971static int hdd_update_country_code(hdd_context_t *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007972{
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007973 if (!country_code)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007974 return 0;
7975
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07007976 return hdd_reg_set_country(hdd_ctx, country_code);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007977}
7978
Arun Khandavallic811dcc2016-06-26 07:37:21 +05307979#ifdef QCA_LL_TX_FLOW_CONTROL_V2
7980/**
7981 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
7982 * @cds_cfg: CDS Configuration
7983 * @hdd_ctx: Pointer to hdd context
7984 *
7985 * Return: none
7986 */
7987static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7988 *cds_cfg,
7989 hdd_context_t *hdd_ctx)
7990{
7991 cds_cfg->tx_flow_stop_queue_th =
7992 hdd_ctx->config->TxFlowStopQueueThreshold;
7993 cds_cfg->tx_flow_start_queue_offset =
7994 hdd_ctx->config->TxFlowStartQueueOffset;
7995}
7996#else
7997static inline void hdd_txrx_populate_cds_config(struct cds_config_info
7998 *cds_cfg,
7999 hdd_context_t *hdd_ctx)
8000{
8001}
8002#endif
8003
8004#ifdef FEATURE_WLAN_RA_FILTERING
8005/**
8006 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8007 * @cds_cfg: CDS Configuration
8008 * @hdd_ctx: Pointer to hdd context
8009 *
8010 * Return: none
8011 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308012static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308013 hdd_context_t *hdd_ctx)
8014{
8015 cds_cfg->ra_ratelimit_interval =
8016 hdd_ctx->config->RArateLimitInterval;
8017 cds_cfg->is_ra_ratelimit_enabled =
8018 hdd_ctx->config->IsRArateLimitEnabled;
8019}
8020#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308021static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308022 hdd_context_t *hdd_ctx)
8023{
8024}
8025#endif
8026
8027/**
8028 * hdd_update_cds_config() - API to update cds configuration parameters
8029 * @hdd_ctx: HDD Context
8030 *
8031 * Return: 0 for Success, errno on failure
8032 */
Jeff Johnson590e2012016-10-05 16:16:24 -07008033static int hdd_update_cds_config(hdd_context_t *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308034{
8035 struct cds_config_info *cds_cfg;
8036
8037 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
8038 if (!cds_cfg) {
8039 hdd_err("failed to allocate cds config");
8040 return -ENOMEM;
8041 }
8042
Srinivas Girigowda35b00312017-06-27 21:52:03 -07008043 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08008044 if (!hdd_ctx->config->nMaxPsPoll ||
8045 !hdd_ctx->config->enablePowersaveOffload) {
8046 cds_cfg->powersave_offload_enabled =
8047 hdd_ctx->config->enablePowersaveOffload;
8048 } else {
8049 if ((hdd_ctx->config->enablePowersaveOffload ==
8050 PS_QPOWER_NODEEPSLEEP) ||
8051 (hdd_ctx->config->enablePowersaveOffload ==
8052 PS_LEGACY_NODEEPSLEEP))
8053 cds_cfg->powersave_offload_enabled =
8054 PS_LEGACY_NODEEPSLEEP;
8055 else
8056 cds_cfg->powersave_offload_enabled =
8057 PS_LEGACY_DEEPSLEEP;
8058 hdd_info("Qpower disabled in cds config, %d",
8059 cds_cfg->powersave_offload_enabled);
8060 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308061 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
8062 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
8063 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
8064 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
8065 cds_cfg->max_wow_filters = hdd_ctx->config->maxWoWFilters;
8066
8067 /* Here ol_ini_info is used to store ini status of arp offload
8068 * ns offload and others. Currently 1st bit is used for arp
8069 * off load and 2nd bit for ns offload currently, rest bits are unused
8070 */
8071 if (hdd_ctx->config->fhostArpOffload)
8072 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x1;
8073 if (hdd_ctx->config->fhostNSOffload)
8074 cds_cfg->ol_ini_info = cds_cfg->ol_ini_info | 0x2;
8075
8076 /*
8077 * Copy the DFS Phyerr Filtering Offload status.
8078 * This parameter reflects the value of the
8079 * dfs_phyerr_filter_offload flag as set in the ini.
8080 */
8081 cds_cfg->dfs_phyerr_filter_offload =
8082 hdd_ctx->config->fDfsPhyerrFilterOffload;
8083 if (hdd_ctx->config->ssdp)
8084 cds_cfg->ssdp = hdd_ctx->config->ssdp;
8085
8086 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
8087 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
8088
8089 cds_cfg->ap_maxoffload_reorderbuffs =
8090 hdd_ctx->config->apMaxOffloadReorderBuffs;
8091
8092 cds_cfg->ap_disable_intrabss_fwd =
8093 hdd_ctx->config->apDisableIntraBssFwd;
8094
8095 cds_cfg->dfs_pri_multiplier =
8096 hdd_ctx->config->dfsRadarPriMultiplier;
8097 cds_cfg->reorder_offload =
8098 hdd_ctx->config->reorderOffloadSupport;
8099
8100 /* IPA micro controller data path offload resource config item */
8101 cds_cfg->uc_offload_enabled = hdd_ipa_uc_is_enabled(hdd_ctx);
Yun Parkde380782016-08-17 16:26:54 -07008102 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
8103 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008104 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008105 hdd_ctx->config->IpaUcTxBufCount);
8106 hdd_ctx->config->IpaUcTxBufCount =
8107 rounddown_pow_of_two(
8108 hdd_ctx->config->IpaUcTxBufCount);
8109 if (!hdd_ctx->config->IpaUcTxBufCount) {
8110 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308111 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008112 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008113 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008114 hdd_ctx->config->IpaUcTxBufCount);
8115 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308116 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
8117 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07008118 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
8119 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008120 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07008121 hdd_ctx->config->IpaUcRxIndRingCount);
8122 hdd_ctx->config->IpaUcRxIndRingCount =
8123 rounddown_pow_of_two(
8124 hdd_ctx->config->IpaUcRxIndRingCount);
8125 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
8126 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308127 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07008128 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008129 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07008130 hdd_ctx->config->IpaUcRxIndRingCount);
8131 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308132 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07008133 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308134 cds_cfg->uc_tx_partition_base =
8135 hdd_ctx->config->IpaUcTxPartitionBase;
8136 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
8137
8138 cds_cfg->ip_tcp_udp_checksum_offload =
8139 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Nirav Shahbd36b062016-07-18 11:12:59 +05308140 cds_cfg->enable_rxthread = hdd_ctx->enableRxThread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308141 cds_cfg->ce_classify_enabled =
8142 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07008143 cds_cfg->bpf_packet_filter_enable =
8144 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308145 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
8146 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
8147 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07008148 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07008149 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Naveen Rawat91df30a2016-10-12 21:26:18 -07008150 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07008151 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05308152 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
8153 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05308154 cds_cfg->auto_power_save_fail_mode =
8155 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308156
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05308157 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
8158
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308159 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
8160 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
8161 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07008162 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308163 cds_init_ini_config(cds_cfg);
8164 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05308165
8166exit:
8167 qdf_mem_free(cds_cfg);
8168 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308169}
8170
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008171/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008172 * hdd_update_user_config() - API to update user configuration
8173 * parameters to obj mgr which are used by multiple components
8174 * @hdd_ctx: HDD Context
8175 *
8176 * Return: 0 for Success, errno on failure
8177 */
8178static int hdd_update_user_config(hdd_context_t *hdd_ctx)
8179{
8180 struct wlan_objmgr_psoc_user_config *user_config;
8181
8182 user_config = qdf_mem_malloc(sizeof(*user_config));
8183 if (user_config == NULL) {
8184 hdd_alert("Failed to alloc memory for user_config!");
8185 return -ENOMEM;
8186 }
8187
8188 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
8189 user_config->dual_mac_feature_disable =
8190 hdd_ctx->config->dual_mac_feature_disable;
8191 user_config->indoor_channel_support =
8192 hdd_ctx->config->indoor_channel_support;
8193 user_config->is_11d_support_enabled =
8194 hdd_ctx->config->Is11dSupportEnabled;
8195 user_config->is_11h_support_enabled =
8196 hdd_ctx->config->Is11hSupportEnabled;
8197 user_config->optimize_chan_avoid_event =
8198 hdd_ctx->config->goptimize_chan_avoid_event;
8199 user_config->skip_dfs_chnl_in_p2p_search =
8200 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07008201 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08008202 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
8203
8204 qdf_mem_free(user_config);
8205 return 0;
8206}
8207
8208/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008209 * hdd_init_thermal_info - Initialize thermal level
8210 * @hdd_ctx: HDD context
8211 *
8212 * Initialize thermal level at SME layer and set the thermal level callback
8213 * which would be called when a configured thermal threshold is hit.
8214 *
8215 * Return: 0 on success and errno on failure
8216 */
8217static int hdd_init_thermal_info(hdd_context_t *hdd_ctx)
8218{
8219 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308220 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008221
8222 thermal_param.smeThermalMgmtEnabled =
8223 hdd_ctx->config->thermalMitigationEnable;
8224 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
8225
Poddar, Siddarth83905022016-04-16 17:56:08 -07008226 thermal_param.sme_throttle_duty_cycle_tbl[0] =
8227 hdd_ctx->config->throttle_dutycycle_level0;
8228 thermal_param.sme_throttle_duty_cycle_tbl[1] =
8229 hdd_ctx->config->throttle_dutycycle_level1;
8230 thermal_param.sme_throttle_duty_cycle_tbl[2] =
8231 hdd_ctx->config->throttle_dutycycle_level2;
8232 thermal_param.sme_throttle_duty_cycle_tbl[3] =
8233 hdd_ctx->config->throttle_dutycycle_level3;
8234
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008235 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
8236 hdd_ctx->config->thermalTempMinLevel0;
8237 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
8238 hdd_ctx->config->thermalTempMaxLevel0;
8239 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
8240 hdd_ctx->config->thermalTempMinLevel1;
8241 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
8242 hdd_ctx->config->thermalTempMaxLevel1;
8243 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
8244 hdd_ctx->config->thermalTempMinLevel2;
8245 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
8246 hdd_ctx->config->thermalTempMaxLevel2;
8247 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
8248 hdd_ctx->config->thermalTempMinLevel3;
8249 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
8250 hdd_ctx->config->thermalTempMaxLevel3;
8251
8252 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
8253
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308254 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05308255 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008256
8257 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
8258 hdd_set_thermal_level_cb);
8259
8260 return 0;
8261
8262}
8263
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008264#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
8265/**
8266 * hdd_hold_rtnl_lock - Hold RTNL lock
8267 *
8268 * Hold RTNL lock
8269 *
8270 * Return: True if held and false otherwise
8271 */
8272static inline bool hdd_hold_rtnl_lock(void)
8273{
8274 rtnl_lock();
8275 return true;
8276}
8277
8278/**
8279 * hdd_release_rtnl_lock - Release RTNL lock
8280 *
8281 * Release RTNL lock
8282 *
8283 * Return: None
8284 */
8285static inline void hdd_release_rtnl_lock(void)
8286{
8287 rtnl_unlock();
8288}
8289#else
8290static inline bool hdd_hold_rtnl_lock(void) { return false; }
8291static inline void hdd_release_rtnl_lock(void) { }
8292#endif
8293
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008294#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008295
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308296/* MAX iwpriv command support */
8297#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308298#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308299#define MAX_PKTLOG_SIZE 16
8300
8301/**
8302 * hdd_pktlog_set_buff_size() - set pktlog buffer size
8303 * @hdd_ctx: hdd context
8304 * @set_value2: pktlog buffer size value
8305 *
8306 *
8307 * Return: 0 for success or error.
8308 */
8309static int hdd_pktlog_set_buff_size(hdd_context_t *hdd_ctx, int set_value2)
8310{
8311 struct sir_wifi_start_log start_log = { 0 };
8312 QDF_STATUS status;
8313
8314 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8315 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8316 start_log.ini_triggered = cds_is_packet_log_enabled();
8317 start_log.user_triggered = 1;
8318 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308319 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308320
8321 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8322 if (!QDF_IS_STATUS_SUCCESS(status)) {
8323 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8324 EXIT();
8325 return -EINVAL;
8326 }
8327
8328 return 0;
8329}
8330
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008331/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308332 * hdd_pktlog_clear_buff() - clear pktlog buffer
8333 * @hdd_ctx: hdd context
8334 *
8335 * Return: 0 for success or error.
8336 */
8337static int hdd_pktlog_clear_buff(hdd_context_t *hdd_ctx)
8338{
8339 struct sir_wifi_start_log start_log;
8340 QDF_STATUS status;
8341
8342 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8343 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
8344 start_log.ini_triggered = cds_is_packet_log_enabled();
8345 start_log.user_triggered = 1;
8346 start_log.size = 0;
8347 start_log.is_pktlog_buff_clear = true;
8348
8349 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8350 if (!QDF_IS_STATUS_SUCCESS(status)) {
8351 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8352 EXIT();
8353 return -EINVAL;
8354 }
8355
8356 return 0;
8357}
8358
8359
8360/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008361 * hdd_process_pktlog_command() - process pktlog command
8362 * @hdd_ctx: hdd context
8363 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308364 * @set_value2: pktlog buffer size value
8365 *
8366 * This function process pktlog command.
8367 * set_value2 only matters when set_value is 3 (set buff size)
8368 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008369 *
8370 * Return: 0 for success or error.
8371 */
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308372int hdd_process_pktlog_command(hdd_context_t *hdd_ctx, uint32_t set_value,
8373 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008374{
8375 int ret;
8376 bool enable;
8377 uint8_t user_triggered = 0;
8378
8379 ret = wlan_hdd_validate_context(hdd_ctx);
8380 if (0 != ret)
8381 return ret;
8382
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008383 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008384
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308385 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008386 hdd_err("invalid pktlog value %d", set_value);
8387 return -EINVAL;
8388 }
8389
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308390 if (set_value == PKTLOG_SET_BUFF_SIZE) {
8391 if (set_value2 <= 0) {
8392 hdd_err("invalid pktlog size %d", set_value2);
8393 return -EINVAL;
8394 } else if (set_value2 > MAX_PKTLOG_SIZE) {
8395 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
8396 return -EINVAL;
8397 }
8398 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308399 } else if (set_value == PKTLOG_CLEAR_BUFF) {
8400 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308401 }
8402
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008403 /*
8404 * set_value = 0 then disable packetlog
8405 * set_value = 1 enable packetlog forcefully
8406 * set_vlaue = 2 then disable packetlog if disabled through ini or
8407 * enable packetlog with AUTO type.
8408 */
8409 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
8410 true : false;
8411
8412 if (1 == set_value) {
8413 enable = true;
8414 user_triggered = 1;
8415 }
8416
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308417 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008418}
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008419/**
8420 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
8421 * @hdd_ctx: HDD context
8422 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308423 * @user_triggered: triggered through iwpriv
8424 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008425 *
8426 * Return: 0 on success; error number otherwise
8427 */
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008428int hdd_pktlog_enable_disable(hdd_context_t *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308429 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008430{
8431 struct sir_wifi_start_log start_log;
8432 QDF_STATUS status;
8433
8434 start_log.ring_id = RING_ID_PER_PACKET_STATS;
8435 start_log.verbose_level =
8436 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08008437 start_log.ini_triggered = cds_is_packet_log_enabled();
8438 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05308439 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05308440 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05308441 /*
8442 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
8443 * commands. Host uses this flag to decide whether to send pktlog
8444 * disable command to fw without sending pktlog enable command
8445 * previously. For eg, If vendor sends pktlog disable command without
8446 * sending pktlog enable command, then host discards the packet
8447 * but for iwpriv command, host will send it to fw.
8448 */
8449 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08008450 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
8451 if (!QDF_IS_STATUS_SUCCESS(status)) {
8452 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
8453 EXIT();
8454 return -EINVAL;
8455 }
8456
8457 return 0;
8458}
8459#endif /* REMOVE_PKT_LOG */
8460
Komal Seelam92fff912016-03-24 11:51:41 +05308461/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008462 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
8463 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05308464 * @dev: Device Pointer
8465 * @num: Number of Valid Mac address
8466 *
8467 * Return: Pointer to MAC address buffer
8468 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008469static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
8470 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05308471{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008472 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05308473}
Komal Seelam92fff912016-03-24 11:51:41 +05308474
8475/**
8476 * hdd_populate_random_mac_addr() - API to populate random mac addresses
8477 * @hdd_ctx: HDD Context
8478 * @num: Number of random mac addresses needed
8479 *
8480 * Generate random addresses using bit manipulation on the base mac address
8481 *
8482 * Return: None
8483 */
Nachiket Kukadee4d86442017-06-23 16:57:00 +05308484void hdd_populate_random_mac_addr(hdd_context_t *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05308485{
8486 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
8487 uint32_t iter;
8488 struct hdd_config *ini = hdd_ctx->config;
8489 uint8_t *buf = NULL;
8490 uint8_t macaddr_b3, tmp_br3;
8491 uint8_t *src = ini->intfMacAddr[0].bytes;
8492
8493 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
8494 buf = ini->intfMacAddr[iter].bytes;
8495 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
8496 macaddr_b3 = buf[3];
8497 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
8498 INTF_MACADDR_MASK;
8499 macaddr_b3 += tmp_br3;
8500 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
8501 buf[0] |= 0x02;
8502 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008503 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308504 }
8505}
8506
8507/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008508 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05308509 * @hdd_ctx: HDD Context
8510 *
8511 * API to get mac addresses from platform driver and update the driver
8512 * structures and configure FW with the base mac address.
8513 * Return: int
8514 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008515static int hdd_platform_wlan_mac(hdd_context_t *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05308516{
8517 uint32_t no_of_mac_addr, iter;
8518 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
8519 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
8520 uint8_t *addr, *buf;
8521 struct device *dev = hdd_ctx->parent_dev;
8522 struct hdd_config *ini = hdd_ctx->config;
8523 tSirMacAddr mac_addr;
8524 QDF_STATUS status;
8525
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008526 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05308527
8528 if (no_of_mac_addr == 0 || !addr) {
8529 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
8530 return -EINVAL;
8531 }
8532
8533 if (no_of_mac_addr > max_mac_addr)
8534 no_of_mac_addr = max_mac_addr;
8535
8536 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
8537
8538 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
8539 buf = ini->intfMacAddr[iter].bytes;
8540 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008541 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05308542 }
8543
8544 status = sme_set_custom_mac_addr(mac_addr);
8545
8546 if (!QDF_IS_STATUS_SUCCESS(status))
8547 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008548
Komal Seelam92fff912016-03-24 11:51:41 +05308549 if (no_of_mac_addr < max_mac_addr)
8550 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
8551 no_of_mac_addr);
8552 return 0;
8553}
8554
8555/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008556 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
8557 * @hdd_ctx: HDD Context
8558 *
8559 * Update MAC address to FW. If MAC address passed by FW is invalid, host
8560 * will generate its own MAC and update it to FW.
8561 *
8562 * Return: 0 for success
8563 * Non-zero error code for failure
8564 */
8565static int hdd_update_mac_addr_to_fw(hdd_context_t *hdd_ctx)
8566{
8567 tSirMacAddr customMacAddr;
8568 QDF_STATUS status;
8569
8570 qdf_mem_copy(&customMacAddr,
8571 &hdd_ctx->config->intfMacAddr[0].bytes[0],
8572 sizeof(tSirMacAddr));
8573 status = sme_set_custom_mac_addr(customMacAddr);
8574 if (!QDF_IS_STATUS_SUCCESS(status))
8575 return -EAGAIN;
8576 return 0;
8577}
8578
8579/**
Komal Seelam92fff912016-03-24 11:51:41 +05308580 * hdd_initialize_mac_address() - API to get wlan mac addresses
8581 * @hdd_ctx: HDD Context
8582 *
8583 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
8584 * is provisioned with mac addresses, driver uses it, else it will use
8585 * wlan_mac.bin to update HW MAC addresses.
8586 *
8587 * Return: None
8588 */
8589static void hdd_initialize_mac_address(hdd_context_t *hdd_ctx)
8590{
8591 QDF_STATUS status;
8592 int ret;
8593
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08008594 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05308595 if (ret == 0)
8596 return;
8597
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008598 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
8599 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05308600
8601 status = hdd_update_mac_config(hdd_ctx);
8602
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008603 if (QDF_IS_STATUS_SUCCESS(status))
8604 return;
8605
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07008606 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
8607 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008608
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008609 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008610 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08008611 if (ret != 0) {
8612 hdd_err("MAC address out-of-sync, ret:%d", ret);
8613 QDF_ASSERT(ret);
8614 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07008615 }
Komal Seelam92fff912016-03-24 11:51:41 +05308616}
8617
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008618static int hdd_set_smart_chainmask_enabled(hdd_context_t *hdd_ctx)
8619{
8620 int vdev_id = 0;
8621 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
8622 int value = hdd_ctx->config->smart_chainmask_enabled;
8623 int vpdev = PDEV_CMD;
8624 int ret;
8625
Naveen Rawat247a8682017-06-05 15:00:31 -07008626 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008627 if (ret)
8628 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
8629
8630 return ret;
8631}
8632
8633static int hdd_set_alternative_chainmask_enabled(hdd_context_t *hdd_ctx)
8634{
8635 int vdev_id = 0;
8636 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
8637 int value = hdd_ctx->config->alternative_chainmask_enabled;
8638 int vpdev = PDEV_CMD;
8639 int ret;
8640
Naveen Rawat247a8682017-06-05 15:00:31 -07008641 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008642 if (ret)
8643 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
8644 ret);
8645
8646 return ret;
8647}
8648
Jeff Johnson12a744b2017-04-04 08:19:37 -07008649static int hdd_set_ani_enabled(hdd_context_t *hdd_ctx)
8650{
8651 int vdev_id = 0;
8652 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
8653 int value = hdd_ctx->config->ani_enabled;
8654 int vpdev = PDEV_CMD;
8655 int ret;
8656
Naveen Rawat247a8682017-06-05 15:00:31 -07008657 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07008658 if (ret)
8659 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
8660
8661 return ret;
8662}
8663
Jeff Johnson89c66ff2016-04-22 15:21:37 -07008664/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07008665 * hdd_pre_enable_configure() - Configurations prior to cds_enable
8666 * @hdd_ctx: HDD context
8667 *
8668 * Pre configurations to be done at lower layer before calling cds enable.
8669 *
8670 * Return: 0 on success and errno on failure.
8671 */
8672static int hdd_pre_enable_configure(hdd_context_t *hdd_ctx)
8673{
8674 int ret;
8675 QDF_STATUS status;
8676 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07008677 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008678
Leo Changfdb45c32016-10-28 11:09:23 -07008679 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008680 /*
8681 * Set 802.11p config
8682 * TODO-OCB: This has been temporarily added here to ensure this
8683 * parameter is set in CSR when we init the channel list. This should
8684 * be removed once the 5.9 GHz channels are added to the regulatory
8685 * domain.
8686 */
8687 hdd_set_dot11p_config(hdd_ctx);
8688
8689 /*
8690 * Note that the cds_pre_enable() sequence triggers the cfg download.
8691 * The cfg download must occur before we update the SME config
8692 * since the SME config operation must access the cfg database
8693 */
8694 status = hdd_set_sme_config(hdd_ctx);
8695
8696 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008697 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008698 ret = qdf_status_to_os_return(status);
8699 goto out;
8700 }
8701
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07008702 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
8703 if (QDF_STATUS_SUCCESS != status) {
8704 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
8705 ret = qdf_status_to_os_return(status);
8706 goto out;
8707 }
8708
Naveen Rawat247a8682017-06-05 15:00:31 -07008709 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07008710 hdd_ctx->config->tx_chain_mask_1ss,
8711 PDEV_CMD);
8712 if (0 != ret) {
8713 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
8714 goto out;
8715 }
8716
Jeff Johnsona89e25d2017-02-24 12:25:07 -08008717 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
8718 if (ret)
8719 goto out;
8720
8721 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
8722 if (ret)
8723 goto out;
8724
Jeff Johnson12a744b2017-04-04 08:19:37 -07008725 ret = hdd_set_ani_enabled(hdd_ctx);
8726 if (ret)
8727 goto out;
8728
Naveen Rawat247a8682017-06-05 15:00:31 -07008729 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08008730 hdd_ctx->config->arp_ac_category,
8731 PDEV_CMD);
8732 if (0 != ret) {
8733 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
8734 hdd_ctx->config->arp_ac_category, ret);
8735 goto out;
8736 }
8737
8738
Prashanth Bhatta07998752016-04-28 12:35:33 -07008739 status = hdd_set_sme_chan_list(hdd_ctx);
8740 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008741 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07008742 ret = qdf_status_to_os_return(status);
8743 goto out;
8744 }
8745
8746 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07008747 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008748 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07008749 ret = -EINVAL;
8750 goto out;
8751 }
8752
Prashanth Bhatta07998752016-04-28 12:35:33 -07008753 /*
8754 * Set the MAC Address Currently this is used by HAL to add self sta.
8755 * Remove this once self sta is added as part of session open.
8756 */
8757 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
8758 hdd_ctx->config->intfMacAddr[0].bytes,
8759 sizeof(hdd_ctx->config->intfMacAddr[0]));
8760
8761 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
8762 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
8763 hal_status, hal_status);
8764 ret = -EINVAL;
8765 goto out;
8766 }
8767
8768 hdd_init_channel_avoidance(hdd_ctx);
8769
8770out:
8771 return ret;
8772}
8773
8774/**
Peng Xu8fdaa492016-06-22 10:20:47 -07008775 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
8776 * @context_ptr - hdd context pointer
8777 * @event_ptr - event structure pointer
8778 *
8779 * This is the p2p listen offload stop event handler, it sends vendor
8780 * event back to supplicant to notify the stop reason.
8781 *
8782 * Return: None
8783 */
8784static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
8785 void *event_ptr)
8786{
8787 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
8788 struct sir_p2p_lo_event *evt = event_ptr;
8789 struct sk_buff *vendor_event;
8790
8791 ENTER();
8792
8793 if (hdd_ctx == NULL) {
8794 hdd_err("Invalid HDD context pointer");
8795 return;
8796 }
8797
8798 vendor_event =
8799 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
8800 NULL, sizeof(uint32_t) + NLMSG_HDRLEN,
8801 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
8802 GFP_KERNEL);
8803
8804 if (!vendor_event) {
8805 hdd_err("cfg80211_vendor_event_alloc failed");
8806 return;
8807 }
8808
8809 if (nla_put_u32(vendor_event,
8810 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
8811 evt->reason_code)) {
8812 hdd_err("nla put failed");
8813 kfree_skb(vendor_event);
8814 return;
8815 }
8816
8817 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
8818}
8819
8820/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05308821 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
8822 * @hdd_ctx: HDD context
8823 *
8824 * This function sends the adaptive dwell time config configuration to the
8825 * firmware via WMA
8826 *
8827 * Return: 0 - success, < 0 - failure
8828 */
8829static int hdd_adaptive_dwelltime_init(hdd_context_t *hdd_ctx)
8830{
8831 QDF_STATUS status;
8832 struct adaptive_dwelltime_params dwelltime_params;
8833
8834 dwelltime_params.is_enabled =
8835 hdd_ctx->config->adaptive_dwell_mode_enabled;
8836 dwelltime_params.dwelltime_mode =
8837 hdd_ctx->config->global_adapt_dwelltime_mode;
8838 dwelltime_params.lpf_weight =
8839 hdd_ctx->config->adapt_dwell_lpf_weight;
8840 dwelltime_params.passive_mon_intval =
8841 hdd_ctx->config->adapt_dwell_passive_mon_intval;
8842 dwelltime_params.wifi_act_threshold =
8843 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
8844
8845 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
8846 &dwelltime_params);
8847
8848 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
8849 if (!QDF_IS_STATUS_SUCCESS(status)) {
8850 hdd_err("Failed to send Adaptive Dwelltime configuration!");
8851 return -EAGAIN;
8852 }
8853 return 0;
8854}
8855
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308856int hdd_dbs_scan_selection_init(hdd_context_t *hdd_ctx)
8857{
8858 QDF_STATUS status;
8859 struct wmi_dbs_scan_sel_params dbs_scan_params;
8860 uint32_t i = 0;
8861 uint8_t count = 0, numentries = 0;
8862 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
8863 * CDS_DBS_SCAN_CLIENTS_MAX];
8864
8865 /* check if DBS is enabled or supported */
8866 if ((hdd_ctx->config->dual_mac_feature_disable)
8867 || (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc)))
8868 return -EINVAL;
8869
8870 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
8871 dbs_scan_config, &numentries,
8872 (CDS_DBS_SCAN_PARAM_PER_CLIENT
8873 * CDS_DBS_SCAN_CLIENTS_MAX));
8874
8875 hdd_info("numentries %hu", numentries);
8876 if (!numentries) {
8877 hdd_info("Donot send scan_selection_config");
8878 return 0;
8879 }
8880
8881 /* hdd_set_fw_log_params */
8882 dbs_scan_params.num_clients = 0;
8883 while (count < (numentries - 2)) {
8884 dbs_scan_params.module_id[i] = dbs_scan_config[count];
8885 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
8886 dbs_scan_params.num_non_dbs_scans[i] =
8887 dbs_scan_config[count + 2];
8888 dbs_scan_params.num_clients++;
8889 hdd_debug("module:%d NDS:%d NNDS:%d",
8890 dbs_scan_params.module_id[i],
8891 dbs_scan_params.num_dbs_scans[i],
8892 dbs_scan_params.num_non_dbs_scans[i]);
8893 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
8894 i++;
8895 }
8896
8897 dbs_scan_params.pdev_id = 0;
8898
8899 hdd_debug("clients:%d pdev:%d",
8900 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
8901
8902 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
8903 &dbs_scan_params);
8904 hdd_debug("Sending DBS Scan Selection Configuration to fw");
8905 if (!QDF_IS_STATUS_SUCCESS(status)) {
8906 hdd_err("Failed to send DBS Scan selection configuration!");
8907 return -EAGAIN;
8908 }
8909 return 0;
8910}
8911
Arun Khandavallid4349a92016-07-25 11:10:43 +05308912#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8913/**
8914 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
8915 * @hdd_ctx: HDD context
8916 *
8917 * Set auto shutdown callback to get indications from firmware to indicate
8918 * userspace to shutdown WLAN after a configured amount of inactivity.
8919 *
8920 * Return: 0 on success and errno on failure.
8921 */
8922static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8923{
8924 QDF_STATUS status;
8925
8926 if (!hdd_ctx->config->WlanAutoShutdown)
8927 return 0;
8928
8929 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
8930 wlan_hdd_auto_shutdown_cb);
8931 if (status != QDF_STATUS_SUCCESS)
8932 hdd_err("Auto shutdown feature could not be enabled: %d",
8933 status);
8934
8935 return qdf_status_to_os_return(status);
8936}
8937#else
8938static int hdd_set_auto_shutdown_cb(hdd_context_t *hdd_ctx)
8939{
8940 return 0;
8941}
8942#endif
8943
8944/**
8945 * hdd_features_init() - Init features
8946 * @hdd_ctx: HDD context
8947 * @adapter: Primary adapter context
8948 *
8949 * Initialize features and their feature context after WLAN firmware is up.
8950 *
8951 * Return: 0 on success and errno on failure.
8952 */
8953static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
8954{
8955 tSirTxPowerLimit hddtxlimit;
8956 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05308957 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05308958 int ret;
8959
8960 ENTER();
8961
Kiran Kumar Lokereb1d412e2017-04-23 17:19:43 -07008962 ret = hdd_update_country_code(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308963 if (ret) {
8964 hdd_err("Failed to update country code: %d", ret);
8965 goto out;
8966 }
8967
8968 /* FW capabilities received, Set the Dot11 mode */
8969 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07008970 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
8971 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05308972
Arun Khandavallid4349a92016-07-25 11:10:43 +05308973
8974 if (hdd_ctx->config->fIsImpsEnabled)
8975 hdd_set_idle_ps_config(hdd_ctx, true);
8976 else
8977 hdd_set_idle_ps_config(hdd_ctx, false);
8978
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308979 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008980 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05308981
Arun Khandavallid4349a92016-07-25 11:10:43 +05308982 if (hdd_lro_init(hdd_ctx))
8983 hdd_err("Unable to initialize LRO in fw");
8984
8985 if (hdd_adaptive_dwelltime_init(hdd_ctx))
8986 hdd_err("Unable to send adaptive dwelltime setting to FW");
8987
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05308988 if (hdd_dbs_scan_selection_init(hdd_ctx))
8989 hdd_err("Unable to send DBS scan selection setting to FW");
8990
Arun Khandavallid4349a92016-07-25 11:10:43 +05308991 ret = hdd_init_thermal_info(hdd_ctx);
8992 if (ret) {
8993 hdd_err("Error while initializing thermal information");
8994 goto deregister_frames;
8995 }
8996
Poddar, Siddarth66a46592017-02-22 11:44:44 +05308997 if (cds_is_packet_log_enabled())
8998 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
8999
Arun Khandavallid4349a92016-07-25 11:10:43 +05309000 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9001 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9002 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9003 if (!QDF_IS_STATUS_SUCCESS(status))
9004 hdd_err("Error setting txlimit in sme: %d", status);
9005
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009006 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309007
Arun Khandavallid4349a92016-07-25 11:10:43 +05309008 ret = hdd_register_cb(hdd_ctx);
9009 if (ret) {
9010 hdd_err("Failed to register HDD callbacks!");
9011 goto deregister_frames;
9012 }
9013
9014 if (hdd_ctx->config->dual_mac_feature_disable) {
9015 status = wlan_hdd_disable_all_dual_mac_features(hdd_ctx);
9016 if (status != QDF_STATUS_SUCCESS) {
9017 hdd_err("Failed to disable dual mac features");
9018 goto deregister_cb;
9019 }
9020 }
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +05309021 if (hdd_ctx->config->goptimize_chan_avoid_event) {
9022 status = sme_enable_disable_chanavoidind_event(
9023 hdd_ctx->hHal, 0);
9024 if (!QDF_IS_STATUS_SUCCESS(status)) {
9025 hdd_err("Failed to disable Chan Avoidance Indication");
9026 goto deregister_cb;
9027 }
9028 }
Arun Khandavallid4349a92016-07-25 11:10:43 +05309029
Manjeet Singha9cae432017-02-28 11:58:22 +05309030 if (hdd_ctx->config->enable_5g_band_pref) {
9031 band_pref_params.rssi_boost_threshold_5g =
9032 hdd_ctx->config->rssi_boost_threshold_5g;
9033 band_pref_params.rssi_boost_factor_5g =
9034 hdd_ctx->config->rssi_boost_factor_5g;
9035 band_pref_params.max_rssi_boost_5g =
9036 hdd_ctx->config->max_rssi_boost_5g;
9037 band_pref_params.rssi_penalize_threshold_5g =
9038 hdd_ctx->config->rssi_penalize_threshold_5g;
9039 band_pref_params.rssi_penalize_factor_5g =
9040 hdd_ctx->config->rssi_penalize_factor_5g;
9041 band_pref_params.max_rssi_penalize_5g =
9042 hdd_ctx->config->max_rssi_penalize_5g;
9043 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
9044 }
9045
Arun Khandavallid4349a92016-07-25 11:10:43 +05309046 /* register P2P Listen Offload event callback */
9047 if (wma_is_p2p_lo_capable())
9048 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
9049 wlan_hdd_p2p_lo_event_callback);
9050
9051 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
9052
9053 if (ret)
9054 goto deregister_cb;
9055
9056 EXIT();
9057 return 0;
9058
9059deregister_cb:
9060 hdd_deregister_cb(hdd_ctx);
9061deregister_frames:
9062 wlan_hdd_cfg80211_deregister_frames(adapter);
9063out:
9064 return -EINVAL;
9065
9066}
9067
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009068/**
9069 * hdd_features_deinit() - Deinit features
9070 * @hdd_ctx: HDD context
9071 *
9072 * De-Initialize features and their feature context.
9073 *
9074 * Return: none.
9075 */
9076static void hdd_features_deinit(hdd_context_t *hdd_ctx)
9077{
9078 wlan_hdd_tsf_deinit(hdd_ctx);
9079}
9080
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309081#ifdef NAPIER_SCAN
9082/**
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309083 * hdd_post_cds_enable_config() - HDD post cds start config helper
9084 * @adapter - Pointer to the HDD
9085 *
9086 * Return: None
9087 */
9088static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
9089{
9090 QDF_STATUS status;
9091
9092 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
9093 wlan_cfg80211_inform_bss_frame,
9094 SCAN_CB_TYPE_INFORM_BCN);
9095 if (!QDF_IS_STATUS_SUCCESS(status)) {
9096 hdd_err("failed with status code %08d [x%08x]",
9097 status, status);
9098 return status;
9099 }
9100
9101 return QDF_STATUS_SUCCESS;
9102}
9103#else
9104static inline QDF_STATUS hdd_register_bcn_cb(hdd_context_t *hdd_ctx)
9105{
9106 return QDF_STATUS_SUCCESS;
9107}
9108
9109#endif
Arun Khandavallid4349a92016-07-25 11:10:43 +05309110
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309111/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309112 * hdd_configure_cds() - Configure cds modules
9113 * @hdd_ctx: HDD context
9114 * @adapter: Primary adapter context
9115 *
9116 * Enable Cds modules after WLAN firmware is up.
9117 *
9118 * Return: 0 on success and errno on failure.
9119 */
9120int hdd_configure_cds(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
9121{
9122 int ret;
9123 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05309124
9125 ret = hdd_pre_enable_configure(hdd_ctx);
9126 if (ret) {
9127 hdd_err("Failed to pre-configure cds");
9128 goto out;
9129 }
9130
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009131 /* Always get latest IPA resources allocated from cds_open and configure
9132 * IPA module before configuring them to FW. Sequence required as crash
9133 * observed otherwise.
9134 */
Manikandan Mohan2e803a02017-02-14 14:57:53 -08009135 if (hdd_ipa_uc_ol_init(hdd_ctx)) {
9136 hdd_err("Failed to setup pipes");
9137 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08009138 }
9139
Arun Khandavallifae92942016-08-01 13:31:08 +05309140 /*
9141 * Start CDS which starts up the SME/MAC/HAL modules and everything
9142 * else
9143 */
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309144 status = cds_enable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309145
9146 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009147 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +05309148 goto out;
9149 }
9150
9151 status = hdd_post_cds_enable_config(hdd_ctx);
9152 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009153 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009154 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309155 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +05309156 status = hdd_register_bcn_cb(hdd_ctx);
9157 if (!QDF_IS_STATUS_SUCCESS(status)) {
9158 hdd_alert("hdd_post_cds_enable_config failed");
9159 goto cds_disable;
9160 }
Arun Khandavallifae92942016-08-01 13:31:08 +05309161
9162 ret = hdd_features_init(hdd_ctx, adapter);
9163 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009164 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05309165
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +05309166 if (hdd_enable_egap(hdd_ctx))
9167 hdd_debug("enhance green ap is not enabled");
9168
Arun Khandavallifae92942016-08-01 13:31:08 +05309169 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009170
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009171cds_disable:
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309172 cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -07009173
Arun Khandavallifae92942016-08-01 13:31:08 +05309174out:
9175 return -EINVAL;
9176}
9177
9178/**
9179 * hdd_deconfigure_cds() -De-Configure cds
9180 * @hdd_ctx: HDD context
9181 *
9182 * Deconfigure Cds modules before WLAN firmware is down.
9183 *
9184 * Return: 0 on success and errno on failure.
9185 */
Jeff Johnson590e2012016-10-05 16:16:24 -07009186static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +05309187{
9188 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -07009189 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309190
9191 ENTER();
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009192
9193 /* De-init features */
9194 hdd_features_deinit(hdd_ctx);
9195
Arun Khandavallifae92942016-08-01 13:31:08 +05309196 /* De-register the SME callbacks */
9197 hdd_deregister_cb(hdd_ctx);
9198
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309199 qdf_status = cds_disable(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309200 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9201 hdd_err("Failed to Disable the CDS Modules! :%d",
9202 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -07009203 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309204 }
9205
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05309206 if (hdd_ipa_uc_ol_deinit(hdd_ctx)) {
9207 hdd_err("Failed to disconnect pipes");
9208 ret = -EINVAL;
9209 }
9210
Arun Khandavallifae92942016-08-01 13:31:08 +05309211 EXIT();
Houston Hoffman6640cf32016-10-10 16:44:29 -07009212 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309213}
9214
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009215#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
9216static void hdd_deregister_policy_manager_callback(
9217 struct wlan_objmgr_psoc *psoc)
9218{
9219 if (QDF_STATUS_SUCCESS !=
9220 policy_mgr_deregister_hdd_cb(psoc)) {
9221 hdd_err("HDD callback deregister with policy manager failed");
9222 }
9223}
9224#else
9225static void hdd_deregister_policy_manager_callback(
9226 struct wlan_objmgr_psoc *psoc)
9227{
9228}
9229#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309230
9231/**
9232 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
9233 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009234 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +05309235 *
9236 * This function maintains the driver state machine it will be invoked from
9237 * exit, shutdown and con_mode change handler. Depending on the driver state
9238 * shall perform the stopping/closing of the modules.
9239 *
9240 * Return: 0 for success; non-zero for failure
9241 */
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009242int hdd_wlan_stop_modules(hdd_context_t *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +05309243{
9244 void *hif_ctx;
9245 qdf_device_t qdf_ctx;
9246 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309247 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -07009248 bool is_idle_stop = !cds_is_driver_unloading() &&
9249 !cds_is_driver_recovering();
9250 int active_threads;
Arun Khandavallifae92942016-08-01 13:31:08 +05309251
9252 ENTER();
9253
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07009254 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
9255
Arun Khandavallifae92942016-08-01 13:31:08 +05309256 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
9257 if (!qdf_ctx) {
9258 hdd_err("QDF device context NULL");
9259 return -EINVAL;
9260 }
9261
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309262 mutex_lock(&hdd_ctx->iface_change_lock);
9263 hdd_ctx->stop_modules_in_progress = true;
Arun Khandavallifae92942016-08-01 13:31:08 +05309264
Dustin Brown70111822017-03-30 15:31:40 -07009265 active_threads = cds_return_external_threads_count();
9266 if (active_threads > 0 || hdd_ctx->isWiphySuspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -07009267 hdd_warn("External threads %d wiphy suspend %d",
Dustin Brown70111822017-03-30 15:31:40 -07009268 active_threads, hdd_ctx->isWiphySuspended);
9269
9270 cds_print_external_threads();
9271
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009272 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -07009273 mutex_unlock(&hdd_ctx->iface_change_lock);
9274 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009275 hdd_ctx->config->iface_change_wait_time);
9276 hdd_ctx->stop_modules_in_progress = false;
Dustin Brown70111822017-03-30 15:31:40 -07009277 return 0;
9278 }
Rajeev Kumar86177c22017-03-16 19:44:39 -07009279 }
9280
Arun Khandavallifae92942016-08-01 13:31:08 +05309281 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
9282
9283 switch (hdd_ctx->driver_status) {
9284 case DRIVER_MODULES_UNINITIALIZED:
9285 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309286 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309287 case DRIVER_MODULES_CLOSED:
9288 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309289 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309290 case DRIVER_MODULES_ENABLED:
Komal Seelamf2136bb2016-09-28 18:30:44 +05309291 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +05309292 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009293 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +05309294 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309295 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309296 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009297 hdd_debug("successfully Disabled the CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309298 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
9299 break;
9300 case DRIVER_MODULES_OPENED:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009301 hdd_debug("Closing CDS modules!");
Arun Khandavallifae92942016-08-01 13:31:08 +05309302 break;
9303 default:
9304 hdd_err("Trying to stop wlan in a wrong state: %d",
9305 hdd_ctx->driver_status);
9306 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309307 ret = -EINVAL;
9308 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +05309309 }
9310
Rajeev Kumarbe021242017-02-16 16:12:23 -08009311 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +05309312 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
9313 hdd_err("Failed to process post CDS disable Modules! :%d",
9314 qdf_status);
9315 ret = -EINVAL;
9316 QDF_ASSERT(0);
9317 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05309318 qdf_status = cds_close(hdd_ctx->hdd_psoc, hdd_ctx->pcds_context);
Arun Khandavallifae92942016-08-01 13:31:08 +05309319 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009320 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +05309321 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309322 QDF_ASSERT(0);
9323 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -07009324
Arun Khandavallifae92942016-08-01 13:31:08 +05309325 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
9326 if (!hif_ctx) {
9327 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309328 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05309329 }
9330
Sravan Kumar Kairam64574952017-06-22 11:48:18 +05309331 hdd_runtime_suspend_context_deinit(hdd_ctx);
9332
Sravan Kumar Kairam27296782017-04-21 22:04:18 +05309333 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309334
9335 ol_cds_free();
9336
Dustin Brown70111822017-03-30 15:31:40 -07009337 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309338 ret = pld_power_off(qdf_ctx->dev);
9339 if (ret)
9340 hdd_err("CNSS power down failed put device into Low power mode:%d",
9341 ret);
9342 }
9343 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07009344 /*
9345 * Reset total mac phy during module stop such that during
9346 * next module start same psoc is used to populate new service
9347 * ready data
9348 */
9349 hdd_ctx->hdd_psoc->total_mac_phy = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05309350
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309351done:
9352 hdd_ctx->stop_modules_in_progress = false;
9353 mutex_unlock(&hdd_ctx->iface_change_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +05309354 EXIT();
9355
Arun Khandavallia172c3e2016-08-26 17:33:13 +05309356 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05309357
9358}
9359
9360/**
9361 * hdd_iface_change_callback() - Function invoked when stop modules expires
9362 * @priv: pointer to hdd context
9363 *
9364 * This function is invoked when the timer waiting for the interface change
9365 * expires, it shall cut-down the power to wlan and stop all the modules.
9366 *
9367 * Return: void
9368 */
9369static void hdd_iface_change_callback(void *priv)
9370{
9371 hdd_context_t *hdd_ctx = (hdd_context_t *) priv;
9372 int ret;
9373 int status = wlan_hdd_validate_context(hdd_ctx);
9374
9375 if (status)
9376 return;
9377
9378 ENTER();
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009379 hdd_debug("Interface change timer expired close the modules!");
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009380 ret = hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309381 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009382 hdd_err("Failed to stop modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05309383 EXIT();
9384}
9385
9386/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309387 * hdd_state_info_dump() - prints state information of hdd layer
9388 * @buf: buffer pointer
9389 * @size: size of buffer to be filled
9390 *
9391 * This function is used to dump state information of hdd layer
9392 *
9393 * Return: None
9394 */
9395static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
9396{
9397 hdd_context_t *hdd_ctx;
9398 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
9399 QDF_STATUS status;
9400 hdd_station_ctx_t *hdd_sta_ctx;
9401 hdd_adapter_t *adapter;
9402 uint16_t len = 0;
9403 char *buf = *buf_ptr;
9404
9405 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9406 if (!hdd_ctx) {
9407 hdd_err("Failed to get hdd context ");
9408 return;
9409 }
9410
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009411 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309412
9413 len += scnprintf(buf + len, *size - len,
9414 "\n isWiphySuspended %d", hdd_ctx->isWiphySuspended);
9415 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -08009416 "\n is_scheduler_suspended %d",
9417 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309418
9419 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
9420
9421 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
9422 adapter = adapter_node->pAdapter;
9423 if (adapter->dev)
9424 len += scnprintf(buf + len, *size - len,
9425 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +08009426 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309427 "\n device_mode: %d", adapter->device_mode);
9428 switch (adapter->device_mode) {
9429 case QDF_STA_MODE:
9430 case QDF_P2P_CLIENT_MODE:
9431 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
9432 len += scnprintf(buf + len, *size - len,
9433 "\n connState: %d",
9434 hdd_sta_ctx->conn_info.connState);
9435 break;
9436
9437 default:
9438 break;
9439 }
9440 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
9441 adapter_node = next;
9442 }
9443
9444 *size -= len;
9445 *buf_ptr += len;
9446}
9447
9448/**
9449 * hdd_register_debug_callback() - registration function for hdd layer
9450 * to print hdd state information
9451 *
9452 * Return: None
9453 */
9454static void hdd_register_debug_callback(void)
9455{
9456 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
9457}
9458
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309459/*
9460 * wlan_init_bug_report_lock() - Initialize bug report lock
9461 *
9462 * This function is used to create bug report lock
9463 *
9464 * Return: None
9465 */
9466static void wlan_init_bug_report_lock(void)
9467{
9468 p_cds_contextType p_cds_context;
9469
9470 p_cds_context = cds_get_global_context();
9471 if (!p_cds_context) {
9472 hdd_err("cds context is NULL");
9473 return;
9474 }
9475
9476 qdf_spinlock_create(&p_cds_context->bug_report_lock);
9477}
9478
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309479/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009480 * hdd_wlan_startup() - HDD init function
9481 * @dev: Pointer to the underlying device
9482 *
9483 * This is the driver startup code executed once a WLAN device has been detected
9484 *
9485 * Return: 0 for success, < 0 for failure
9486 */
Arun Khandavallifae92942016-08-01 13:31:08 +05309487int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009488{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309489 QDF_STATUS status;
Jeff Johnson957bc272017-02-02 08:54:48 -08009490 hdd_context_t *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009491 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009492 bool rtnl_held;
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309493 int set_value;
Naveen Rawat247a8682017-06-05 15:00:31 -07009494 uint32_t num_abg_tx_chains = 0;
9495 uint32_t num_11b_tx_chains = 0;
9496 uint32_t num_11ag_tx_chains = 0;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009497
9498 ENTER();
9499
Arun Khandavallifae92942016-08-01 13:31:08 +05309500 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009501
9502 if (IS_ERR(hdd_ctx))
9503 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009504
Abhishek Singhe9068f12017-03-31 14:14:52 +05309505 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
9506 DEFAULT_PSOC_ID);
9507 if (ret) {
9508 hdd_err("Psoc creation fails!");
9509 QDF_BUG(0);
9510 goto err_hdd_free_context;
9511 }
9512
Arun Khandavallifae92942016-08-01 13:31:08 +05309513 qdf_mc_timer_init(&hdd_ctx->iface_change_timer, QDF_TIMER_TYPE_SW,
9514 hdd_iface_change_callback, (void *)hdd_ctx);
9515
9516 mutex_init(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05309517#ifdef FEATURE_WLAN_CH_AVOID
9518 mutex_init(&hdd_ctx->avoid_freq_lock);
9519#endif
Arun Khandavallifae92942016-08-01 13:31:08 +05309520
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009521 ret = hdd_init_netlink_services(hdd_ctx);
9522 if (ret)
Dustin Brown20912462017-06-07 13:48:25 -07009523 goto err_hdd_free_psoc;
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009524
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009525 hdd_request_manager_init();
Jeff Johnsona7e5eed2016-09-28 15:19:13 -07009526 hdd_green_ap_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05309527
Jeff Johnson957bc272017-02-02 08:54:48 -08009528 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309529 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009530 hdd_err("Failed to start modules: %d", ret);
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009531 goto err_exit_nl_srv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009532 }
9533
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05309534 wlan_init_bug_report_lock();
9535
Yingying Tang80e15f32016-09-27 18:23:01 +08009536 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009537
Yingying Tang95409972016-10-20 15:16:15 +08009538 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009539 hdd_debug("Failed to set wow pulse");
Yingying Tang95409972016-10-20 15:16:15 +08009540
Anurag Chouhan6d760662016-02-20 16:05:43 +05309541 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009542
9543 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009544 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +05309545 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009546 }
9547
Prashanth Bhatta07998752016-04-28 12:35:33 -07009548 ret = hdd_wiphy_init(hdd_ctx);
9549 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009550 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05309551 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009552 }
9553
Nirav Shahcc1f1ae2016-04-26 11:41:29 +05309554 if (hdd_ctx->config->enable_dp_trace)
9555 qdf_dp_trace_init();
9556
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309557 if (hdd_ipa_init(hdd_ctx) == QDF_STATUS_E_FAILURE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009558 goto err_wiphy_unregister;
9559
Kapil Gupta4f0c0c12017-02-07 15:21:15 +05309560 wlan_hdd_init_chan_info(hdd_ctx);
9561
Yuanyuan Liuc98370e2016-10-13 11:22:13 -07009562 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -08009563
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009564 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009565
Jeff Johnson957bc272017-02-02 08:54:48 -08009566 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
9567 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009568 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -08009569 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009570 }
9571
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009572 hdd_release_rtnl_lock();
9573 rtnl_held = false;
9574
Yingying Tang3ba3dbc2016-09-27 16:36:58 +08009575 wlan_hdd_update_11n_mode(hdd_ctx->config);
9576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009577#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05309578 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +05309579 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009580 hdd_skip_acs_scan_timer_handler,
9581 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309582 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -07009583 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -04009584 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009585#endif
9586
Nitesh Shah61c10d92016-10-19 19:29:15 +05309587 qdf_mc_timer_init(&hdd_ctx->tdls_source_timer,
9588 QDF_TIMER_TYPE_SW,
9589 wlan_hdd_change_tdls_mode,
9590 hdd_ctx);
9591
Prashanth Bhattaab004382016-10-11 16:08:11 -07009592 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009593
Jeff Johnson9afc5012016-09-23 13:56:27 -07009594 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009595
Nirav Shahbd36b062016-07-18 11:12:59 +05309596 if (hdd_ctx->rps)
9597 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -07009598
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009599 ret = hdd_register_notifiers(hdd_ctx);
9600 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009601 goto err_close_adapters;
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05309602
9603 status = wlansap_global_init();
9604 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson957bc272017-02-02 08:54:48 -08009605 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07009606
Komal Seelam8634b772016-09-29 12:12:24 +05309607 hdd_runtime_suspend_context_init(hdd_ctx);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009608 memdump_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +05309609 hdd_driver_memdump_init();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -08009610
Arun Khandavallifae92942016-08-01 13:31:08 +05309611 if (hdd_ctx->config->fIsImpsEnabled)
9612 hdd_set_idle_ps_config(hdd_ctx, true);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309613
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309614 if (hdd_ctx->config->sifs_burst_duration) {
9615 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
9616 hdd_ctx->config->sifs_burst_duration;
9617
9618 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
Naveen Rawat247a8682017-06-05 15:00:31 -07009619 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
Manjeet Singhe7ecb7c2016-09-03 12:34:53 +05309620 set_value, PDEV_CMD);
9621 }
9622
Paul Zhang42dade02017-05-12 19:20:37 +08009623 if (hdd_ctx->config->is_force_1x1)
Naveen Rawat247a8682017-06-05 15:00:31 -07009624 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
Paul Zhang42dade02017-05-12 19:20:37 +08009625 1, PDEV_CMD);
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309626 /* set chip power save failure detected callback */
9627 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
9628 hdd_chip_pwr_save_fail_detected_cb);
Paul Zhang42dade02017-05-12 19:20:37 +08009629
lifeng959a04c2017-05-10 14:21:28 +08009630 if (hdd_ctx->config->max_mpdus_inampdu) {
9631 set_value = hdd_ctx->config->max_mpdus_inampdu;
Naveen Rawat247a8682017-06-05 15:00:31 -07009632 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
lifeng959a04c2017-05-10 14:21:28 +08009633 set_value, PDEV_CMD);
9634 }
9635
9636 if (hdd_ctx->config->enable_rts_sifsbursting) {
9637 set_value = hdd_ctx->config->enable_rts_sifsbursting;
Naveen Rawat247a8682017-06-05 15:00:31 -07009638 sme_cli_set_command(0,
lifeng959a04c2017-05-10 14:21:28 +08009639 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
9640 set_value, PDEV_CMD);
9641 }
9642
Naveen Rawat247a8682017-06-05 15:00:31 -07009643 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
9644 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
9645 if (!hdd_ctx->config->enable2x2) {
9646 if (num_11b_tx_chains > 1)
9647 num_11b_tx_chains = 1;
9648 if (num_11ag_tx_chains > 1)
9649 num_11ag_tx_chains = 1;
9650 }
9651 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
9652 num_11b_tx_chains);
9653 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
9654 num_11ag_tx_chains);
9655 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
9656 num_abg_tx_chains, PDEV_CMD);
9657
Arunk Khandavalliba3d5582017-07-11 19:48:32 +05309658 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam())
9659 qdf_mc_timer_start(&hdd_ctx->iface_change_timer,
Hanumanth Reddy Pothula42e714a2016-12-21 19:33:57 +05309660 hdd_ctx->config->iface_change_wait_time);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +05309661
Sachin Ahujadddd2632017-03-07 19:07:24 +05309662 hdd_start_complete(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009663 goto success;
9664
Jeff Johnson957bc272017-02-02 08:54:48 -08009665err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -08009666 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009667
Jeff Johnson46bde382017-02-01 15:31:16 -08009668err_release_rtnl_lock:
Arun Khandavallid4349a92016-07-25 11:10:43 +05309669 if (rtnl_held)
9670 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009671
Anurag Chouhance6a4052016-09-14 18:20:42 +05309672 hdd_ipa_cleanup(hdd_ctx);
Yun Park6a46ad82016-01-04 16:48:19 -08009673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009674err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009675 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009676
Arun Khandavallifae92942016-08-01 13:31:08 +05309677err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07009678 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05309679
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05309680err_exit_nl_srv:
Arunk Khandavallifbc1ef02017-03-14 21:25:05 +05309681 if (DRIVER_MODULES_CLOSED == hdd_ctx->driver_status) {
9682 status = cds_sched_close(hdd_ctx->pcds_context);
9683 if (!QDF_IS_STATUS_SUCCESS(status)) {
9684 hdd_err("Failed to close CDS Scheduler");
9685 QDF_ASSERT(QDF_IS_STATUS_SUCCESS(status));
9686 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009687 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009688
Houston Hoffman47a4a052016-11-14 23:22:44 -08009689 hdd_green_ap_deinit(hdd_ctx);
Jeff Johnsonce0032c2017-01-20 07:18:27 -08009690 hdd_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -07009691 hdd_exit_netlink_services(hdd_ctx);
9692
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309693 cds_deinit_ini_config();
Dustin Brown20912462017-06-07 13:48:25 -07009694
9695err_hdd_free_psoc:
9696 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9697
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009698err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +05309699 if (cds_is_fw_down())
9700 hdd_err("Not setting the complete event as fw is down");
9701 else
9702 hdd_start_complete(ret);
9703
Arun Khandavallifae92942016-08-01 13:31:08 +05309704 qdf_mc_timer_destroy(&hdd_ctx->iface_change_timer);
9705 mutex_destroy(&hdd_ctx->iface_change_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009706 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009707 return -EIO;
9708
9709success:
9710 EXIT();
9711 return 0;
9712}
9713
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009714/**
Arun Khandavallifae92942016-08-01 13:31:08 +05309715 * hdd_wlan_update_target_info() - update target type info
9716 * @hdd_ctx: HDD context
9717 * @context: hif context
9718 *
9719 * Update target info received from firmware in hdd context
9720 * Return:None
9721 */
9722
9723void hdd_wlan_update_target_info(hdd_context_t *hdd_ctx, void *context)
9724{
9725 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
9726
9727 if (!tgt_info) {
9728 hdd_err("Target info is Null");
9729 return;
9730 }
9731
9732 hdd_ctx->target_type = tgt_info->target_type;
9733}
9734
9735/**
9736 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309737 * @hdd_ctx: HDD context
9738 *
9739 * Register the HDD callbacks to CDS/SME.
9740 *
9741 * Return: 0 for success or Error code for failure
9742 */
9743int hdd_register_cb(hdd_context_t *hdd_ctx)
9744{
9745 QDF_STATUS status;
9746 int ret = 0;
9747
9748 ENTER();
9749
9750 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
9751
9752 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
9753 hdd_send_oem_data_rsp_msg);
9754
9755 status = sme_fw_mem_dump_register_cb(hdd_ctx->hHal,
9756 wlan_hdd_cfg80211_fw_mem_dump_cb);
9757 if (!QDF_IS_STATUS_SUCCESS(status)) {
9758 hdd_err("Failed to register memdump callback");
9759 ret = -EINVAL;
9760 return ret;
9761 }
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +05309762 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
9763 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309764 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
9765 sme_nan_register_callback(hdd_ctx->hHal,
9766 wlan_hdd_cfg80211_nan_callback);
9767 sme_stats_ext_register_callback(hdd_ctx->hHal,
9768 wlan_hdd_cfg80211_stats_ext_callback);
9769
9770 sme_ext_scan_register_callback(hdd_ctx->hHal,
9771 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +08009772 sme_stats_ext2_register_callback(hdd_ctx->hHal,
9773 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309774
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309775 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
9776 hdd_rssi_threshold_breached);
9777
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309778 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
9779 wlan_hdd_cfg80211_link_layer_stats_callback);
9780
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05309781 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
9782
Zhang Qianca38fb12016-12-23 11:10:48 +08009783 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
9784 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
9785
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05309786 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
9787 hdd_lost_link_info_cb);
9788 /* print error and not block the startup process */
9789 if (!QDF_IS_STATUS_SUCCESS(status))
9790 hdd_err("set lost link info callback failed");
9791
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309792 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
9793
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08009794 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009795 hdd_set_connection_in_progress,
9796 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +05309797
9798 status = sme_congestion_register_callback(hdd_ctx->hHal,
9799 hdd_update_cca_info_cb);
9800 if (!QDF_IS_STATUS_SUCCESS(status))
9801 hdd_err("set congestion callback failed");
9802
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +05309803 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
9804 hdd_bt_activity_cb);
9805 if (!QDF_IS_STATUS_SUCCESS(status))
9806 hdd_err("set bt activity info callback failed");
9807
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309808 EXIT();
9809
9810 return ret;
9811}
9812
9813/**
9814 * hdd_deregister_cb() - De-Register HDD callbacks.
9815 * @hdd_ctx: HDD context
9816 *
9817 * De-Register the HDD callbacks to CDS/SME.
9818 *
9819 * Return: void
9820 */
9821void hdd_deregister_cb(hdd_context_t *hdd_ctx)
9822{
9823 QDF_STATUS status;
9824
9825 ENTER();
9826
9827 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
9828 if (!QDF_IS_STATUS_SUCCESS(status))
9829 hdd_err("De-register of dcc stats callback failed: %d",
9830 status);
9831
9832 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309833 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
9834
Arun Khandavalli4b55da72016-07-19 19:55:01 +05309835 sme_stats_ext_register_callback(hdd_ctx->hHal,
9836 wlan_hdd_cfg80211_stats_ext_callback);
9837
9838 sme_nan_deregister_callback(hdd_ctx->hHal);
9839 status = sme_reset_tsfcb(hdd_ctx->hHal);
9840 if (!QDF_IS_STATUS_SUCCESS(status))
9841 hdd_err("Failed to de-register tsfcb the callback:%d",
9842 status);
9843 status = sme_fw_mem_dump_unregister_cb(hdd_ctx->hHal);
9844 if (!QDF_IS_STATUS_SUCCESS(status))
9845 hdd_err("Failed to de-register the fw mem dump callback: %d",
9846 status);
9847
9848 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
9849 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
9850
9851 EXIT();
9852}
9853
9854/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009855 * hdd_softap_sta_deauth() - handle deauth req from HDD
9856 * @adapter: Pointer to the HDD
9857 * @enable: bool value
9858 *
9859 * This to take counter measure to handle deauth req from HDD
9860 *
9861 * Return: None
9862 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309863QDF_STATUS hdd_softap_sta_deauth(hdd_adapter_t *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009864 struct tagCsrDelStaParams *pDelStaParams)
9865{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309866 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009867
9868 ENTER();
9869
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009870 hdd_debug("hdd_softap_sta_deauth:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009871 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9872
9873 /* Ignore request to deauth bcmc station */
9874 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309875 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009876
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309877 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009878 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9879 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009880
9881 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309882 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009883}
9884
9885/**
9886 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
9887 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309888 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009889 *
9890 * This to take counter measure to handle deauth req from HDD
9891 *
9892 * Return: None
9893 */
9894void hdd_softap_sta_disassoc(hdd_adapter_t *adapter,
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309895 struct tagCsrDelStaParams *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009896{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009897 ENTER();
9898
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009899 hdd_debug("hdd_softap_sta_disassoc:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009900 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9901
9902 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309903 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009904 return;
9905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009906 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +05309907 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009908}
9909
9910void hdd_softap_tkip_mic_fail_counter_measure(hdd_adapter_t *adapter,
9911 bool enable)
9912{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009913 ENTER();
9914
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009915 hdd_debug("hdd_softap_tkip_mic_fail_counter_measure:(%p, false)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009916 (WLAN_HDD_GET_CTX(adapter))->pcds_context);
9917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009918 wlansap_set_counter_measure(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9919 (bool) enable);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009920}
9921
9922/**
9923 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
9924 * @hdd_ctx: HDD Context
9925 *
9926 * API to find if there is any STA or P2P-Client is connected
9927 *
9928 * Return: true if connected; false otherwise
9929 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309930QDF_STATUS hdd_issta_p2p_clientconnected(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009931{
9932 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
9933}
9934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009935/**
9936 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
9937 * @adapter: HDD adapter pointer
9938 *
9939 * This function loop through each adapter and disable roaming on each STA
9940 * device mode except the input adapter.
9941 *
9942 * Note: On the input adapter roaming is not enabled yet hence no need to
9943 * disable.
9944 *
9945 * Return: None
9946 */
9947void wlan_hdd_disable_roaming(hdd_adapter_t *adapter)
9948{
9949 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9950 hdd_adapter_t *adapterIdx = NULL;
9951 hdd_adapter_list_node_t *adapterNode = NULL;
9952 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309953 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009954
9955 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08009956 hdd_ctx->config->isRoamOffloadScanEnabled &&
9957 QDF_STA_MODE == adapter->device_mode &&
9958 policy_mgr_is_sta_active_connection_exists(
9959 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009960 hdd_debug("Connect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009961 adapter->sessionId);
9962 /*
9963 * Loop through adapter and disable roaming for each STA device
9964 * mode except the input adapter.
9965 */
9966 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
9967
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309968 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009969 adapterIdx = adapterNode->pAdapter;
9970
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009971 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009972 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009973 hdd_debug("Disable Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009974 adapterIdx->sessionId);
9975 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
9976 (adapterIdx),
9977 adapterIdx->sessionId, 0);
9978 }
9979
9980 status = hdd_get_next_adapter(hdd_ctx,
9981 adapterNode,
9982 &pNext);
9983 adapterNode = pNext;
9984 }
9985 }
9986}
9987
9988/**
9989 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
9990 * @adapter: HDD adapter pointer
9991 *
9992 * This function loop through each adapter and enable roaming on each STA
9993 * device mode except the input adapter.
9994 * Note: On the input adapter no need to enable roaming because link got
9995 * disconnected on this.
9996 *
9997 * Return: None
9998 */
9999void wlan_hdd_enable_roaming(hdd_adapter_t *adapter)
10000{
10001 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
10002 hdd_adapter_t *adapterIdx = NULL;
10003 hdd_adapter_list_node_t *adapterNode = NULL;
10004 hdd_adapter_list_node_t *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010005 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010006
10007 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010008 hdd_ctx->config->isRoamOffloadScanEnabled &&
10009 QDF_STA_MODE == adapter->device_mode &&
10010 policy_mgr_is_sta_active_connection_exists(
10011 hdd_ctx->hdd_psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010012 hdd_debug("Disconnect received on STA sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010013 adapter->sessionId);
10014 /*
10015 * Loop through adapter and enable roaming for each STA device
10016 * mode except the input adapter.
10017 */
10018 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10019
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010020 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010021 adapterIdx = adapterNode->pAdapter;
10022
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010023 if (QDF_STA_MODE == adapterIdx->device_mode
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010024 && adapter->sessionId != adapterIdx->sessionId) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010025 hdd_debug("Enabling Roaming on sessionId(%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010026 adapterIdx->sessionId);
10027 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
10028 (adapterIdx),
10029 adapterIdx->sessionId,
10030 REASON_CONNECT);
10031 }
10032
10033 status = hdd_get_next_adapter(hdd_ctx,
10034 adapterNode,
10035 &pNext);
10036 adapterNode = pNext;
10037 }
10038 }
10039}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010040
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010041/**
10042 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
10043 * @skb: sk buffer pointer
10044 *
10045 * Sends the bcast message to SVC multicast group with generic nl socket
10046 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
10047 *
10048 * Return: None
10049 */
10050static void nl_srv_bcast_svc(struct sk_buff *skb)
10051{
10052#ifdef CNSS_GENL
10053 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
10054#else
10055 nl_srv_bcast(skb);
10056#endif
10057}
10058
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010059void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010060{
10061 struct sk_buff *skb;
10062 struct nlmsghdr *nlh;
10063 tAniMsgHdr *ani_hdr;
10064 void *nl_data = NULL;
10065 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010066 struct radio_index_tlv *radio_info;
10067 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010068
10069 if (in_interrupt() || irqs_disabled() || in_atomic())
10070 flags = GFP_ATOMIC;
10071
10072 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
10073
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010074 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010075 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010076
10077 nlh = (struct nlmsghdr *)skb->data;
10078 nlh->nlmsg_pid = 0; /* from kernel */
10079 nlh->nlmsg_flags = 0;
10080 nlh->nlmsg_seq = 0;
10081 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
10082
10083 ani_hdr = NLMSG_DATA(nlh);
10084 ani_hdr->type = type;
10085
10086 switch (type) {
10087 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053010088 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010089 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010090 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010091 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010092 ani_hdr->length = 0;
10093 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010094 break;
10095 case WLAN_SVC_WLAN_STATUS_IND:
10096 case WLAN_SVC_WLAN_VERSION_IND:
10097 case WLAN_SVC_DFS_CAC_START_IND:
10098 case WLAN_SVC_DFS_CAC_END_IND:
10099 case WLAN_SVC_DFS_RADAR_DETECT_IND:
10100 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
10101 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080010102 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053010103 case WLAN_SVC_RPS_ENABLE_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010104 ani_hdr->length = len;
10105 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
10106 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
10107 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010108 break;
10109
10110 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070010111 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010112 type);
10113 kfree_skb(skb);
10114 return;
10115 }
10116
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010117 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080010118 * Add radio index at the end of the svc event in TLV format
10119 * to maintain the backward compatibility with userspace
10120 * applications.
10121 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010122
10123 tlv_len = 0;
10124
10125 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
10126 < WLAN_NL_MAX_PAYLOAD) {
10127 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
10128 sizeof(*ani_hdr) + len);
10129 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
10130 radio_info->length = (unsigned short) sizeof(radio_info->radio);
10131 radio_info->radio = radio;
10132 tlv_len = sizeof(*radio_info);
Srinivas Girigowdac06543c2017-03-09 15:10:03 -080010133 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010134 "Added radio index tlv - radio index %d",
10135 radio_info->radio);
10136 }
10137
10138 nlh->nlmsg_len += tlv_len;
10139 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
10140
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053010141 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010142}
10143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010144#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10145void wlan_hdd_auto_shutdown_cb(void)
10146{
hque52fdd62017-06-05 11:27:44 +080010147 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010148
10149 if (!hdd_ctx)
10150 return;
10151
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010152 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010153 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
10154 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010155}
10156
10157void wlan_hdd_auto_shutdown_enable(hdd_context_t *hdd_ctx, bool enable)
10158{
10159 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010160 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010161 hdd_adapter_t *adapter;
10162 bool ap_connected = false, sta_connected = false;
10163 tHalHandle hal_handle;
10164
10165 hal_handle = hdd_ctx->hHal;
10166 if (hal_handle == NULL)
10167 return;
10168
10169 if (hdd_ctx->config->WlanAutoShutdown == 0)
10170 return;
10171
10172 if (enable == false) {
10173 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010174 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010175 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010176 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053010177 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070010178 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010179 return;
10180 }
10181
10182 /* To enable shutdown timer check conncurrency */
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010183 if (policy_mgr_concurrent_open_sessions_running(
10184 hdd_ctx->hdd_psoc)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010185 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
10186
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010187 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010188 adapter = adapterNode->pAdapter;
10189 if (adapter
10190 && adapter->device_mode ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010191 QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010192 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10193 conn_info.connState ==
10194 eConnectionState_Associated) {
10195 sta_connected = true;
10196 break;
10197 }
10198 }
10199 if (adapter
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010200 && adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010201 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
10202 bApActive == true) {
10203 ap_connected = true;
10204 break;
10205 }
10206 }
10207 status = hdd_get_next_adapter(hdd_ctx,
10208 adapterNode,
10209 &pNext);
10210 adapterNode = pNext;
10211 }
10212 }
10213
10214 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010215 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010216 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010217 }
Jeff Johnson68755312017-02-10 11:46:55 -080010218
10219 if (sme_set_auto_shutdown_timer(hal_handle,
10220 hdd_ctx->config->WlanAutoShutdown)
10221 != QDF_STATUS_SUCCESS)
10222 hdd_err("Failed to start wlan auto shutdown timer");
10223 else
10224 hdd_notice("Auto Shutdown timer for %d seconds enabled",
10225 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010226}
10227#endif
10228
10229hdd_adapter_t *hdd_get_con_sap_adapter(hdd_adapter_t *this_sap_adapter,
10230 bool check_start_bss)
10231{
10232 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
10233 hdd_adapter_t *adapter, *con_sap_adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010234 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010235 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
10236
10237 con_sap_adapter = NULL;
10238
10239 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010240 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010241 adapter = adapterNode->pAdapter;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010242 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
10243 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010244 adapter != this_sap_adapter) {
10245 if (check_start_bss) {
10246 if (test_bit(SOFTAP_BSS_STARTED,
10247 &adapter->event_flags)) {
10248 con_sap_adapter = adapter;
10249 break;
10250 }
10251 } else {
10252 con_sap_adapter = adapter;
10253 break;
10254 }
10255 }
10256 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
10257 adapterNode = pNext;
10258 }
10259
10260 return con_sap_adapter;
10261}
10262
10263#ifdef MSM_PLATFORM
Dustin Brown5ec6b552017-03-31 12:11:40 -070010264static inline bool hdd_adapter_is_sta(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010265{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010266 return adapter->device_mode == QDF_STA_MODE ||
10267 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010268}
10269
Dustin Brown5ec6b552017-03-31 12:11:40 -070010270static inline bool hdd_adapter_is_ap(hdd_adapter_t *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010271{
Dustin Brown5ec6b552017-03-31 12:11:40 -070010272 return adapter->device_mode == QDF_SAP_MODE ||
10273 adapter->device_mode == QDF_P2P_GO_MODE;
10274}
10275
10276static bool hdd_any_adapter_is_assoc(hdd_context_t *hdd_ctx)
10277{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010278 QDF_STATUS status;
Dustin Brown5ec6b552017-03-31 12:11:40 -070010279 hdd_adapter_list_node_t *node;
10280
10281 status = hdd_get_front_adapter(hdd_ctx, &node);
10282 while (QDF_IS_STATUS_SUCCESS(status) && node) {
10283 hdd_adapter_t *adapter = node->pAdapter;
10284
10285 if (adapter &&
10286 hdd_adapter_is_sta(adapter) &&
10287 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
10288 conn_info.connState == eConnectionState_Associated) {
10289 return true;
10290 }
10291
10292 if (adapter &&
10293 hdd_adapter_is_ap(adapter) &&
10294 WLAN_HDD_GET_AP_CTX_PTR(adapter)->bApActive) {
10295 return true;
10296 }
10297
10298 status = hdd_get_next_adapter(hdd_ctx, node, &node);
10299 }
10300
10301 return false;
10302}
10303
10304static bool hdd_bus_bw_compute_timer_is_running(hdd_context_t *hdd_ctx)
10305{
10306 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010307
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010308 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070010309 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053010310 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010311
Dustin Brown5ec6b552017-03-31 12:11:40 -070010312 return is_running;
10313}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010314
Dustin Brown5ec6b552017-03-31 12:11:40 -070010315static void __hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10316{
10317 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10318 hdd_ctx->bus_bw_timer_running = true;
10319 qdf_timer_start(&hdd_ctx->bus_bw_timer,
10320 hdd_ctx->config->busBandwidthComputeInterval);
10321 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10322}
10323
10324void hdd_bus_bw_compute_timer_start(hdd_context_t *hdd_ctx)
10325{
10326 ENTER();
10327
10328 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10329 hdd_debug("Bandwidth compute timer already started");
10330 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010331 }
10332
Dustin Brown5ec6b552017-03-31 12:11:40 -070010333 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10334
10335 EXIT();
10336}
10337
10338void hdd_bus_bw_compute_timer_try_start(hdd_context_t *hdd_ctx)
10339{
10340 ENTER();
10341
10342 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10343 hdd_debug("Bandwidth compute timer already started");
10344 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070010345 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070010346
10347 if (hdd_any_adapter_is_assoc(hdd_ctx))
10348 __hdd_bus_bw_compute_timer_start(hdd_ctx);
10349
10350 EXIT();
10351}
10352
10353static void __hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10354{
10355 hdd_ipa_set_perf_level(hdd_ctx, 0, 0);
10356
10357 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
10358 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
10359 hdd_ctx->bus_bw_timer_running = false;
10360 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
10361
10362 hdd_reset_tcp_delack(hdd_ctx);
10363}
10364
10365void hdd_bus_bw_compute_timer_stop(hdd_context_t *hdd_ctx)
10366{
10367 ENTER();
10368
10369 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10370 hdd_debug("Bandwidth compute timer already stopped");
10371 return;
10372 }
10373
10374 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10375
10376 EXIT();
10377}
10378
10379void hdd_bus_bw_compute_timer_try_stop(hdd_context_t *hdd_ctx)
10380{
10381 ENTER();
10382
10383 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
10384 hdd_debug("Bandwidth compute timer already stopped");
10385 return;
10386 }
10387
10388 if (!hdd_any_adapter_is_assoc(hdd_ctx))
10389 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
10390
10391 EXIT();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010392}
10393#endif
10394
10395/**
10396 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
10397 * and sta's operating channel.
10398 * @sta_adapter: Describe the first argument to foobar.
10399 * @ap_adapter: Describe the second argument to foobar.
10400 * @roam_profile: Roam profile of AP to which STA wants to connect.
10401 * @concurrent_chnl_same: If both SAP and STA channels are same then
10402 * set this flag to true else false.
10403 *
10404 * This function checks the sap's operating channel and sta's operating channel.
10405 * if both are same then it will return false else it will restart the sap in
10406 * sta's channel and return true.
10407 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010408 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010409 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010410QDF_STATUS wlan_hdd_check_custom_con_channel_rules(hdd_adapter_t *sta_adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010411 hdd_adapter_t *ap_adapter,
10412 tCsrRoamProfile *roam_profile,
10413 tScanResultHandle *scan_cache,
10414 bool *concurrent_chnl_same)
10415{
10416 hdd_ap_ctx_t *hdd_ap_ctx;
10417 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010418 QDF_STATUS status;
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010419 enum tQDF_ADAPTER_MODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010420 *concurrent_chnl_same = true;
10421
10422 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10423 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070010424 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010425 scan_cache,
10426 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010427 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010428 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010429 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
10430 if (hdd_ap_ctx->operatingChannel != channel_id) {
10431 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010432 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010433 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010434 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010435 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
10436 if (hdd_ap_ctx->operatingChannel != channel_id) {
10437 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010438 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010439 }
10440 }
10441 } else {
10442 /*
10443 * Lets handle worst case scenario here, Scan cache lookup is
10444 * failed so we have to stop the SAP to avoid any channel
10445 * discrepancy between SAP's channel and STA's channel.
10446 * Return the status as failure so caller function could know
10447 * that scan look up is failed.
10448 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070010449 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010450 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010451 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010452 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010453}
10454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010455/**
10456 * wlan_hdd_stop_sap() - This function stops bss of SAP.
10457 * @ap_adapter: SAP adapter
10458 *
10459 * This function will process the stopping of sap adapter.
10460 *
10461 * Return: None
10462 */
10463void wlan_hdd_stop_sap(hdd_adapter_t *ap_adapter)
10464{
10465 hdd_ap_ctx_t *hdd_ap_ctx;
10466 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010467 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010468 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010469
10470 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010471 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010472 return;
10473 }
10474
10475 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10476 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010477 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010478 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053010479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010480 mutex_lock(&hdd_ctx->sap_lock);
10481 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080010482 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010483 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
10484 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010485 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010486 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010487 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010488 sapContext)) {
Anurag Chouhance0dc992016-02-16 18:18:03 +053010489 qdf_status = qdf_wait_single_event(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080010490 qdf_stop_bss_event,
10491 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010492 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010493 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070010494 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010495 return;
10496 }
10497 }
10498 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010499 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
10500 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010501 ap_adapter->sessionId);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010502 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010503 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010504 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010505 }
10506 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010507}
10508
10509/**
10510 * wlan_hdd_start_sap() - this function starts bss of SAP.
10511 * @ap_adapter: SAP adapter
10512 *
10513 * This function will process the starting of sap adapter.
10514 *
10515 * Return: None
10516 */
Arun Khandavallicc544b32017-01-30 19:52:16 +053010517void wlan_hdd_start_sap(hdd_adapter_t *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010518{
10519 hdd_ap_ctx_t *hdd_ap_ctx;
10520 hdd_hostapd_state_t *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053010521 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010522 hdd_context_t *hdd_ctx;
10523 tsap_Config_t *sap_config;
10524
10525 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010526 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010527 return;
10528 }
10529
Krunal Soni9b04c9b2016-03-10 13:08:05 -080010530 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070010531 hdd_err("SoftAp role has not been enabled");
10532 return;
10533 }
10534
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010535 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
10536 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
10537 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
10538 sap_config = &ap_adapter->sessionCtx.ap.sapConfig;
10539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010540 mutex_lock(&hdd_ctx->sap_lock);
10541 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
10542 goto end;
10543
10544 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010545 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010546 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
10547 goto end;
10548 }
10549
Wei Song2f76f642016-11-18 16:32:53 +080010550 qdf_event_reset(&hostapd_state->qdf_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010551 if (wlansap_start_bss(hdd_ap_ctx->sapContext, hdd_hostapd_sap_event_cb,
10552 &hdd_ap_ctx->sapConfig,
10553 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010554 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010555 goto end;
10556
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010557 hdd_debug("Waiting for SAP to start");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010558 qdf_status = qdf_wait_single_event(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080010559 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053010560 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070010561 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010562 goto end;
10563 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070010564 hdd_info("SAP Start Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010565 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Krunal Sonib37bb352016-12-20 14:12:21 -080010566 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010567 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
10568 ap_adapter->device_mode,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010569 ap_adapter->sessionId);
10570 hostapd_state->bCommit = true;
10571
10572end:
10573 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070010574 /* SAP context and beacon cleanup will happen during driver unload
10575 * in hdd_stop_adapter
10576 */
10577 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
10578
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010579}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010580
10581/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010582 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
10583 * mac scan config
10584 * @status: Status of set antenna mode
10585 *
10586 * Callback on setting the dual mac configuration
10587 *
10588 * Return: None
10589 */
10590void wlan_hdd_soc_set_antenna_mode_cb(
10591 enum set_antenna_mode_status status)
10592{
10593 hdd_context_t *hdd_ctx;
10594
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010595 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080010596
10597 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10598 if (0 != wlan_hdd_validate_context(hdd_ctx))
10599 return;
10600
10601 /* Signal the completion of set dual mac config */
10602 complete(&hdd_ctx->set_antenna_mode_cmpl);
10603}
10604
10605/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010606 * hdd_get_fw_version() - Get FW version
10607 * @hdd_ctx: pointer to HDD context.
10608 * @major_spid: FW version - major spid.
10609 * @minor_spid: FW version - minor spid
10610 * @ssid: FW version - ssid
10611 * @crmid: FW version - crmid
10612 *
10613 * This function is called to get the firmware build version stored
10614 * as part of the HDD context
10615 *
10616 * Return: None
10617 */
10618void hdd_get_fw_version(hdd_context_t *hdd_ctx,
10619 uint32_t *major_spid, uint32_t *minor_spid,
10620 uint32_t *siid, uint32_t *crmid)
10621{
10622 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
10623 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
10624 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
10625 *crmid = hdd_ctx->target_fw_version & 0x7fff;
10626}
10627
10628#ifdef QCA_CONFIG_SMP
10629/**
10630 * wlan_hdd_get_cpu() - get cpu_index
10631 *
10632 * Return: cpu_index
10633 */
10634int wlan_hdd_get_cpu(void)
10635{
10636 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010637
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010638 put_cpu();
10639 return cpu_index;
10640}
10641#endif
10642
10643/**
10644 * hdd_get_fwpath() - get framework path
10645 *
10646 * This function is used to get the string written by
10647 * userspace to start the wlan driver
10648 *
10649 * Return: string
10650 */
10651const char *hdd_get_fwpath(void)
10652{
10653 return fwpath.string;
10654}
10655
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010656/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010657 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010658 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010659 * This function initilizes CDS global context with the help of cds_init. This
10660 * has to be the first function called after probe to get a valid global
10661 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010662 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010663 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010664 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010665int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010666{
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010667 v_CONTEXT_t p_cds_context = NULL;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010668 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010669
Houston Hoffman9e06e542016-12-12 12:06:26 -080010670 p_cds_context = cds_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010671#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10672 wlan_logging_sock_init_svc();
10673#endif
10674
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010675 if (p_cds_context == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010676 hdd_err("Failed to allocate CDS context");
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010677 ret = -ENOMEM;
10678 goto err_out;
10679 }
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010680
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010681 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010682 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010683
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010684err_out:
10685 return ret;
10686}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010687
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010688/**
10689 * hdd_deinit() - Deinitialize Driver
10690 *
10691 * This function frees CDS global context with the help of cds_deinit. This
10692 * has to be the last function call in remove callback to free the global
10693 * context.
10694 */
10695void hdd_deinit(void)
10696{
Dustin Brownedce4a52017-05-10 11:59:15 -070010697 hdd_deinit_wowl();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010698 cds_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010699
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010700#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
10701 wlan_logging_sock_deinit_svc();
10702#endif
10703}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010704
Yue Ma6e7b1a02017-04-03 14:17:46 -070010705#ifdef QCA_WIFI_NAPIER_EMULATION
10706#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
10707#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010708#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070010709#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010710
Sachin Ahujadddd2632017-03-07 19:07:24 +053010711static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
10712 struct file *file)
10713{
10714 return 0;
10715}
10716
10717static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
10718 const char __user *user_buf,
10719 size_t count,
10720 loff_t *f_pos)
10721{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010722 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053010723 static const char wlan_off_str[] = "OFF";
10724 static const char wlan_on_str[] = "ON";
10725 int ret;
10726 unsigned long rc;
10727
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010728 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010729 pr_err("Failed to read buffer\n");
10730 return -EINVAL;
10731 }
10732
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010733 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010734 pr_debug("Wifi turning off from UI\n");
10735 goto exit;
10736 }
10737
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053010738 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053010739 pr_err("Invalid value received from framework");
10740 goto exit;
10741 }
10742
10743 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053010744 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010745 rc = wait_for_completion_timeout(&wlan_start_comp,
10746 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
10747 if (!rc) {
10748 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
10749 ret = -EINVAL;
10750 hdd_start_complete(ret);
10751 return ret;
10752 }
10753
10754 hdd_start_complete(0);
10755 }
10756
10757exit:
10758 return count;
10759}
10760
10761
10762const struct file_operations wlan_hdd_state_fops = {
10763 .owner = THIS_MODULE,
10764 .open = wlan_hdd_state_ctrl_param_open,
10765 .write = wlan_hdd_state_ctrl_param_write,
10766};
10767
10768static int wlan_hdd_state_ctrl_param_create(void)
10769{
10770 unsigned int wlan_hdd_state_major = 0;
10771 int ret;
10772 struct device *dev;
10773
10774 device = MKDEV(wlan_hdd_state_major, 0);
10775
10776 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
10777 if (ret) {
10778 pr_err("Failed to register qcwlanstate");
10779 goto dev_alloc_err;
10780 }
10781 wlan_hdd_state_major = MAJOR(device);
10782
10783 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
10784 if (IS_ERR(class)) {
10785 pr_err("wlan_hdd_state class_create error");
10786 goto class_err;
10787 }
10788
10789 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
10790 if (IS_ERR(dev)) {
10791 pr_err("wlan_hdd_statedevice_create error");
10792 goto err_class_destroy;
10793 }
10794
10795 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
10796 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
10797 if (ret) {
10798 pr_err("Failed to add cdev error");
10799 goto cdev_add_err;
10800 }
10801
10802 pr_info("wlan_hdd_state %s major(%d) initialized",
10803 WLAN_MODULE_NAME, wlan_hdd_state_major);
10804
10805 return 0;
10806
10807cdev_add_err:
10808 device_destroy(class, device);
10809err_class_destroy:
10810 class_destroy(class);
10811class_err:
10812 unregister_chrdev_region(device, dev_num);
10813dev_alloc_err:
10814 return -ENODEV;
10815}
10816
10817static void wlan_hdd_state_ctrl_param_destroy(void)
10818{
10819 cdev_del(&wlan_hdd_state_cdev);
10820 device_destroy(class, device);
10821 class_destroy(class);
10822 unregister_chrdev_region(device, dev_num);
10823
10824 pr_info("Device node unregistered");
10825}
10826
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010827/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053010828 * component_init - API to init cld component's
10829 *
10830 * Return: None
10831 */
10832static void component_init(void)
10833{
10834 pmo_init();
10835}
10836
10837/**
10838 * component_deinit - API to deinit cld component's
10839 *
10840 * Return: None
10841 */
10842static void component_deinit(void)
10843{
10844 pmo_deinit();
10845}
10846
10847/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010848 * __hdd_module_init - Module init helper
10849 *
10850 * Module init helper function used by both module and static driver.
10851 *
10852 * Return: 0 for success, errno on failure
10853 */
10854static int __hdd_module_init(void)
10855{
10856 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010857
Dustin Brownab482ac2017-06-09 17:00:44 -070010858 pr_err("%s: Loading driver v%s (%s)%s\n",
10859 WLAN_MODULE_NAME,
10860 QWLAN_VERSIONSTR,
Naveen Rawat93836252017-06-20 16:30:59 -070010861 g_wlan_driver_timestamp,
Dustin Brownab482ac2017-06-09 17:00:44 -070010862 TIMER_MANAGER_STR MEMORY_DEBUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010863
Sachin Ahujadddd2632017-03-07 19:07:24 +053010864 ret = wlan_hdd_state_ctrl_param_create();
10865 if (ret) {
10866 pr_err("wlan_hdd_state_create:%x\n", ret);
10867 goto err_dev_state;
10868 }
10869
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010870 pld_init();
10871
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010872 ret = hdd_init();
10873 if (ret) {
10874 pr_err("hdd_init failed %x\n", ret);
10875 goto err_hdd_init;
10876 }
10877
Rajeev Kumar97767a02016-11-30 11:20:40 -080010878 dispatcher_init();
10879
Mukul Sharmad75a6672017-06-22 15:40:53 +053010880 /* Ensure to call post objmgr init */
10881 component_init();
10882
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010883 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010884
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010885 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010886
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010887 ret = wlan_hdd_register_driver();
10888 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070010889 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
10890 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010891 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010892 }
10893
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053010894 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010895
10896 return 0;
10897out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010898 qdf_wake_lock_destroy(&wlan_wake_lock);
Rajeev Kumar97767a02016-11-30 11:20:40 -080010899 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010900 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080010901
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010902err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010903 pld_deinit();
Sachin Ahujadddd2632017-03-07 19:07:24 +053010904 wlan_hdd_state_ctrl_param_destroy();
10905err_dev_state:
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010906 return ret;
10907}
10908
10909/**
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010910 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
10911 *
10912 * Block the unloading of the driver until the cds recovery is completed
10913 *
10914 * Return: None
10915 */
10916static void hdd_wait_for_recovery_completion(void)
10917{
10918 int retry = 0;
10919
10920 /* Wait for recovery to complete */
10921 while (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010922 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010923 msleep(1000);
10924 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010925 hdd_err("SSR never completed, error");
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010926 QDF_BUG(0);
10927 }
10928 }
10929}
10930
10931/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010932 * __hdd_module_exit - Module exit helper
10933 *
10934 * Module exit helper function used by both module and static driver.
10935 */
10936static void __hdd_module_exit(void)
10937{
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010938 int qdf_print_idx = -1;
10939
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010940 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
10941 QWLAN_VERSIONSTR);
10942
bings6028ee82017-03-29 07:51:40 +080010943 cds_set_unload_in_progress(true);
10944
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053010945 hdd_wait_for_recovery_completion();
10946
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010947 wlan_hdd_unregister_driver();
10948
Anurag Chouhana37b5b72016-02-21 14:53:42 +053010949 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080010950
Mukul Sharmad75a6672017-06-22 15:40:53 +053010951 /* Ensure to call prior to objmgr deinit */
10952 component_deinit();
10953
Rajeev Kumar97767a02016-11-30 11:20:40 -080010954 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053010955 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070010956 pld_deinit();
10957
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053010958 qdf_print_idx = qdf_get_pidx();
10959 qdf_print_ctrl_cleanup(qdf_print_idx);
Sachin Ahujadddd2632017-03-07 19:07:24 +053010960 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010961}
10962
Arun Khandavallifae92942016-08-01 13:31:08 +053010963#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010964/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010965 * wlan_boot_cb() - Wlan boot callback
10966 * @kobj: object whose directory we're creating the link in.
10967 * @attr: attribute the user is interacting with
10968 * @buff: the buffer containing the user data
10969 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010970 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010971 * This callback is invoked when the fs is ready to start the
10972 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010973 *
Arun Khandavallifae92942016-08-01 13:31:08 +053010974 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010975 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010976static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010977 struct kobj_attribute *attr,
10978 const char *buf,
10979 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010980{
Arun Khandavallifae92942016-08-01 13:31:08 +053010981
Arun Khandavallifae92942016-08-01 13:31:08 +053010982 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010983 pr_err("%s: wlan driver already initialized\n", __func__);
10984 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053010985 }
10986
Arun Khandavallifae92942016-08-01 13:31:08 +053010987 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010988 pr_err("%s: wlan driver initialization failed\n", __func__);
10989 return -EIO;
10990 }
10991
10992 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053010993
10994 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080010995}
Arun Khandavallifae92942016-08-01 13:31:08 +053010996
10997/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070010998 * hdd_sysfs_cleanup() - cleanup sysfs
10999 *
11000 * Return: None
11001 *
11002 */
11003static void hdd_sysfs_cleanup(void)
11004{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011005 /* remove from group */
11006 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
11007 sysfs_remove_group(wlan_loader->boot_wlan_obj,
11008 wlan_loader->attr_group);
11009
11010 /* unlink the object from parent */
11011 kobject_del(wlan_loader->boot_wlan_obj);
11012
11013 /* free the object */
11014 kobject_put(wlan_loader->boot_wlan_obj);
11015
11016 kfree(wlan_loader->attr_group);
11017 kfree(wlan_loader);
11018
11019 wlan_loader = NULL;
11020}
11021
11022/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011023 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
11024 * ready
11025 *
11026 * This is creates the syfs entry boot_wlan. Which shall be invoked
11027 * when the filesystem is ready.
11028 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011029 * QDF API cannot be used here since this function is called even before
11030 * initializing WLAN driver.
11031 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011032 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053011033 */
11034static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011035{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011036 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011037
11038 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011039 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011040 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053011041
11042 wlan_loader->boot_wlan_obj = NULL;
11043 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
11044 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011045 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053011046 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053011047
11048 wlan_loader->loaded_state = 0;
11049 wlan_loader->attr_group->attrs = attrs;
11050
11051 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
11052 kernel_kobj);
11053 if (!wlan_loader->boot_wlan_obj) {
11054 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053011055 goto error_return;
11056 }
11057
11058 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
11059 wlan_loader->attr_group);
11060 if (ret) {
11061 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
11062 goto error_return;
11063 }
11064
11065 return 0;
11066
11067error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011068 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053011069
11070 return ret;
11071}
11072
11073/**
11074 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
11075 *
11076 * Return: 0 on success or errno on failure
11077 */
11078static int wlan_deinit_sysfs(void)
11079{
Arun Khandavallifae92942016-08-01 13:31:08 +053011080 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011081 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053011082 return -EINVAL;
11083 }
11084
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011085 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011086 return 0;
11087}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011088
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070011089#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053011090
11091#ifdef MODULE
11092/**
11093 * __hdd_module_init - Module init helper
11094 *
11095 * Module init helper function used by both module and static driver.
11096 *
11097 * Return: 0 for success, errno on failure
11098 */
11099static int hdd_module_init(void)
11100{
Arun Khandavallifae92942016-08-01 13:31:08 +053011101 if (__hdd_module_init()) {
11102 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070011103 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011104 }
11105
Dustin Brownab482ac2017-06-09 17:00:44 -070011106 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011107}
11108#else
11109static int __init hdd_module_init(void)
11110{
11111 int ret = -EINVAL;
11112
11113 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070011114 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053011115 pr_err("Failed to create sysfs entry for loading wlan");
11116
11117 return ret;
11118}
11119#endif
11120
11121
11122#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011123/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011124 * hdd_module_exit() - Exit function
11125 *
11126 * This is the driver exit point (invoked when module is unloaded using rmmod)
11127 *
11128 * Return: None
11129 */
11130static void __exit hdd_module_exit(void)
11131{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011132 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011133}
Arun Khandavallifae92942016-08-01 13:31:08 +053011134#else
11135static void __exit hdd_module_exit(void)
11136{
11137 __hdd_module_exit();
11138 wlan_deinit_sysfs();
11139}
11140#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011141
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011142static int fwpath_changed_handler(const char *kmessage, struct kernel_param *kp)
11143{
11144 return param_set_copystring(kmessage, kp);
11145}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011146
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011147/**
11148 * is_con_mode_valid() check con mode is valid or not
11149 * @mode: global con mode
11150 *
11151 * Return: TRUE on success FALSE on failure
11152 */
11153static bool is_con_mode_valid(enum tQDF_GLOBAL_CON_MODE mode)
11154{
11155 switch (mode) {
11156 case QDF_GLOBAL_MONITOR_MODE:
11157 case QDF_GLOBAL_FTM_MODE:
11158 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011159 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011160 return true;
11161 default:
11162 return false;
11163 }
11164}
11165
11166/**
11167 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
11168 * @mode: global con mode
11169 *
11170 * Return: adapter mode
11171 */
11172static enum tQDF_ADAPTER_MODE hdd_get_adpter_mode(
11173 enum tQDF_GLOBAL_CON_MODE mode)
11174{
11175
11176 switch (mode) {
11177 case QDF_GLOBAL_MISSION_MODE:
11178 return QDF_STA_MODE;
11179 case QDF_GLOBAL_MONITOR_MODE:
11180 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011181 case QDF_GLOBAL_EPPING_MODE:
11182 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011183 case QDF_GLOBAL_FTM_MODE:
11184 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011185 case QDF_GLOBAL_QVIT_MODE:
11186 return QDF_QVIT_MODE;
11187 default:
11188 return QDF_MAX_NO_OF_MODE;
11189 }
11190}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011191
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011192static void hdd_cleanup_present_mode(hdd_context_t *hdd_ctx,
11193 enum tQDF_GLOBAL_CON_MODE curr_mode)
11194{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011195 int driver_status;
11196
11197 driver_status = hdd_ctx->driver_status;
11198
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011199 switch (curr_mode) {
11200 case QDF_GLOBAL_MISSION_MODE:
11201 case QDF_GLOBAL_MONITOR_MODE:
11202 case QDF_GLOBAL_FTM_MODE:
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053011203 if (driver_status != DRIVER_MODULES_CLOSED) {
11204 hdd_abort_mac_scan_all_adapters(hdd_ctx);
11205 hdd_stop_all_adapters(hdd_ctx);
11206 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011207 hdd_deinit_all_adapters(hdd_ctx, false);
11208 hdd_close_all_adapters(hdd_ctx, false);
11209 break;
11210 case QDF_GLOBAL_EPPING_MODE:
11211 epping_disable();
11212 epping_close();
11213 break;
11214 default:
11215 return;
11216 }
11217}
11218
11219static int hdd_register_req_mode(hdd_context_t *hdd_ctx,
11220 enum tQDF_GLOBAL_CON_MODE mode)
11221{
11222 hdd_adapter_t *adapter;
11223 int ret = 0;
11224 bool rtnl_held;
11225 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11226 QDF_STATUS status;
11227
11228 if (!qdf_dev) {
11229 hdd_err("qdf device context is Null return!");
11230 return -EINVAL;
11231 }
11232
11233 rtnl_held = hdd_hold_rtnl_lock();
11234 switch (mode) {
11235 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080011236 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11237 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011238 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011239 break;
11240 case QDF_GLOBAL_FTM_MODE:
11241 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11242 wlan_hdd_get_intf_addr(hdd_ctx),
11243 NET_NAME_UNKNOWN, rtnl_held);
11244 if (adapter == NULL)
11245 ret = -EINVAL;
11246 break;
11247 case QDF_GLOBAL_MONITOR_MODE:
11248 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11249 wlan_hdd_get_intf_addr(hdd_ctx),
11250 NET_NAME_UNKNOWN, rtnl_held);
11251 if (adapter == NULL)
11252 ret = -EINVAL;
11253 break;
11254 case QDF_GLOBAL_EPPING_MODE:
11255 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011256 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011257 hdd_err("Failed to open in eeping mode: %d", status);
11258 ret = -EINVAL;
11259 break;
11260 }
11261 ret = epping_enable(qdf_dev->dev);
11262 if (ret) {
11263 hdd_err("Failed to enable in epping mode : %d", ret);
11264 epping_close();
11265 }
11266 break;
11267 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011268 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011269 ret = -ENOTSUPP;
11270 break;
11271 }
11272 hdd_release_rtnl_lock();
11273 rtnl_held = false;
11274 return ret;
11275}
11276
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011277/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011278 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011279 * @kmessage: con mode name on which driver to be bring up
11280 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011281 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011282 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011283 * This function is invoked when user updates con mode using sys entry,
11284 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011285 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011286 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011287 */
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011288static int __con_mode_handler(const char *kmessage, struct kernel_param *kp,
11289 hdd_context_t *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011290{
11291 int ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011292 hdd_adapter_t *adapter;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011293 enum tQDF_GLOBAL_CON_MODE curr_mode;
11294 enum tQDF_ADAPTER_MODE adapter_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011295
Dustin Brownab6029b2017-05-24 13:04:19 -070011296 hdd_info("con_mode handler: %s", kmessage);
11297
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053011298 ret = wlan_hdd_validate_context(hdd_ctx);
11299 if (ret)
11300 return ret;
11301
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011302 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011303
11304 ret = param_set_int(kmessage, kp);
Arun Khandavallifae92942016-08-01 13:31:08 +053011305
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011306 if (!(is_con_mode_valid(con_mode))) {
11307 hdd_err("invlaid con_mode %d", con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011308 ret = -EINVAL;
11309 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011310 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011311
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011312 curr_mode = hdd_get_conparam();
11313 if (curr_mode == con_mode) {
11314 hdd_err("curr mode: %d is same as user triggered mode %d",
11315 curr_mode, con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011316 ret = 0;
11317 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011318 }
11319
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011320 /* Cleanup present mode before switching to new mode */
11321 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +053011322
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011323 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011324 if (ret) {
11325 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011326 goto reset_flags;
11327 }
11328
11329 hdd_set_conparam(con_mode);
11330
11331 /* Register for new con_mode & then kick_start modules again */
11332 ret = hdd_register_req_mode(hdd_ctx, con_mode);
11333 if (ret) {
11334 hdd_err("Failed to register for new mode");
11335 goto reset_flags;
11336 }
11337
11338 adapter_mode = hdd_get_adpter_mode(con_mode);
11339 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
11340 hdd_err("invalid adapter");
11341 ret = -EINVAL;
11342 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011343 }
11344
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053011345 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053011346 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011347 hdd_err("Failed to get adapter:%d", adapter_mode);
11348 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011349 }
11350
11351 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
11352 if (ret) {
11353 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011354 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053011355 }
11356
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011357 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
11358 con_mode == QDF_GLOBAL_FTM_MODE) {
11359 if (hdd_start_adapter(adapter)) {
11360 hdd_err("Failed to start %s adapter", kmessage);
11361 ret = -EINVAL;
11362 goto reset_flags;
11363 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011364 }
11365
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053011366 hdd_info("Mode successfully changed to %s", kmessage);
11367 ret = 0;
11368
11369reset_flags:
11370 cds_set_load_in_progress(false);
11371 return ret;
11372}
11373
11374
11375static int con_mode_handler(const char *kmessage, struct kernel_param *kp)
11376{
11377 int ret;
11378 hdd_context_t *hdd_ctx;
11379
11380 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11381 ret = wlan_hdd_validate_context(hdd_ctx);
11382 if (ret)
11383 return ret;
11384
11385 cds_ssr_protect(__func__);
11386 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
11387 cds_ssr_unprotect(__func__);
11388
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011389 return ret;
11390}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011391
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053011392static int con_mode_handler_ftm(const char *kmessage,
11393 struct kernel_param *kp)
11394{
11395 int ret;
11396
11397 ret = param_set_int(kmessage, kp);
11398
11399 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
11400 pr_err("Only FTM mode supported!");
11401 return -ENOTSUPP;
11402 }
11403
11404 hdd_set_conparam(con_mode_ftm);
11405 con_mode = con_mode_ftm;
11406
11407 return ret;
11408}
11409
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011410/**
11411 * hdd_get_conparam() - driver exit point
11412 *
11413 * This is the driver exit point (invoked when module is unloaded using rmmod)
11414 *
Anurag Chouhan6d760662016-02-20 16:05:43 +053011415 * Return: enum tQDF_GLOBAL_CON_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011416 */
Anurag Chouhan6d760662016-02-20 16:05:43 +053011417enum tQDF_GLOBAL_CON_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011418{
Anurag Chouhan6d760662016-02-20 16:05:43 +053011419 return (enum tQDF_GLOBAL_CON_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011420}
11421
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011422void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011423{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080011424 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011425}
11426
Komal Seelamc11bb222016-01-27 18:57:10 +053011427/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053011428 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
11429 * @hdd_ctx: HDD context
11430 *
11431 * Cleans up the pre cac interface, if it exists
11432 *
11433 * Return: None
11434 */
11435void hdd_clean_up_pre_cac_interface(hdd_context_t *hdd_ctx)
11436{
11437 uint8_t session_id;
11438 QDF_STATUS status;
11439 struct hdd_adapter_s *precac_adapter;
11440
11441 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
11442 if (QDF_IS_STATUS_ERROR(status)) {
11443 hdd_err("failed to get pre cac vdev id");
11444 return;
11445 }
11446
11447 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
11448 if (!precac_adapter) {
11449 hdd_err("invalid pre cac adapater");
11450 return;
11451 }
11452
11453 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
11454 wlan_hdd_sap_pre_cac_failure,
11455 (void *)precac_adapter);
11456 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
11457
11458}
11459
11460/**
Komal Seelamec702b02016-02-24 18:42:16 +053011461 * hdd_update_ol_config - API to update ol configuration parameters
11462 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053011463 *
Komal Seelamc11bb222016-01-27 18:57:10 +053011464 * Return: void
11465 */
Komal Seelamec702b02016-02-24 18:42:16 +053011466static void hdd_update_ol_config(hdd_context_t *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053011467{
Komal Seelamec702b02016-02-24 18:42:16 +053011468 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011469 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053011470
Komal Seelamec702b02016-02-24 18:42:16 +053011471 if (!ol_ctx)
11472 return;
11473
11474 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
11475 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
11476 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
11477 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070011478 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053011479
11480 ol_init_ini_config(ol_ctx, &cfg);
11481}
11482
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011483#ifdef FEATURE_RUNTIME_PM
11484/**
11485 * hdd_populate_runtime_cfg() - populate runtime configuration
11486 * @hdd_ctx: hdd context
11487 * @cfg: pointer to the configuration memory being populated
11488 *
11489 * Return: void
11490 */
11491static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11492 struct hif_config_info *cfg)
11493{
11494 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
11495 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
11496}
11497#else
11498static void hdd_populate_runtime_cfg(hdd_context_t *hdd_ctx,
11499 struct hif_config_info *cfg)
11500{
11501}
11502#endif
11503
Komal Seelamec702b02016-02-24 18:42:16 +053011504/**
11505 * hdd_update_hif_config - API to update HIF configuration parameters
11506 * @hdd_ctx: HDD Context
11507 *
11508 * Return: void
11509 */
11510static void hdd_update_hif_config(hdd_context_t *hdd_ctx)
11511{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053011512 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053011513 struct hif_config_info cfg;
11514
11515 if (!scn)
11516 return;
11517
11518 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070011519 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053011520 hif_init_ini_config(scn, &cfg);
11521}
11522
11523/**
11524 * hdd_update_config() - Initialize driver per module ini parameters
11525 * @hdd_ctx: HDD Context
11526 *
11527 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011528 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053011529 */
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011530int hdd_update_config(hdd_context_t *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053011531{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011532 int ret;
11533
Komal Seelamec702b02016-02-24 18:42:16 +053011534 hdd_update_ol_config(hdd_ctx);
11535 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011536 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
11537 ret = hdd_update_cds_config_ftm(hdd_ctx);
11538 else
11539 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080011540 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053011541
11542 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053011543}
11544
Mukul Sharma9d797a02017-01-05 20:26:03 +053011545#ifdef FEATURE_WLAN_RA_FILTERING
11546/**
11547 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
11548 * @psoc_cfg: pmo psoc Configuration
11549 * @hdd_ctx: Pointer to hdd context
11550 *
11551 * Return: none
11552 */
11553static inline void hdd_ra_populate_pmo_config(
11554 struct pmo_psoc_cfg *psoc_cfg,
11555 hdd_context_t *hdd_ctx)
11556{
11557 psoc_cfg->ra_ratelimit_interval =
11558 hdd_ctx->config->RArateLimitInterval;
11559 psoc_cfg->ra_ratelimit_enable =
11560 hdd_ctx->config->IsRArateLimitEnabled;
11561}
11562#else
11563static inline void hdd_ra_populate_pmo_config(
11564 struct cds_config_info *cds_cfg,
11565 hdd_context_t *hdd_ctx)
11566{
11567}
11568#endif
11569/**
11570 * hdd_update_pmo_config - API to update pmo configuration parameters
11571 * @hdd_ctx: HDD context
11572 *
11573 * Return: void
11574 */
11575static int hdd_update_pmo_config(hdd_context_t *hdd_ctx)
11576{
11577 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11578 struct pmo_psoc_cfg psoc_cfg;
11579 QDF_STATUS status;
11580
11581 /*
11582 * Value of hdd_ctx->wowEnable can be,
11583 * 0 - Disable both magic pattern match and pattern byte match.
11584 * 1 - Enable magic pattern match on all interfaces.
11585 * 2 - Enable pattern byte match on all interfaces.
11586 * 3 - Enable both magic patter and pattern byte match on
11587 * all interfaces.
11588 */
11589 psoc_cfg.magic_ptrn_enable =
11590 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
11591 psoc_cfg.ptrn_match_enable_all_vdev =
11592 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
11593 psoc_cfg.bpf_enable =
11594 hdd_ctx->config->bpf_packet_filter_enable;
11595 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070011596 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011597 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
11598 if (hdd_ctx->config->fhostNSOffload)
11599 psoc_cfg.ns_offload_enable_dynamic = true;
11600 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
11601 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
11602 psoc_cfg.active_mode_offload =
11603 hdd_ctx->config->active_mode_offload;
11604 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
11605 psoc_cfg.max_wow_filters = hdd_ctx->config->maxWoWFilters;
Mukul Sharma9223f232017-03-08 18:42:27 +053011606 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
11607 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
11608 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
11609 psoc_cfg.power_save_mode =
11610 hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053011611 psoc_cfg.auto_power_save_fail_mode =
11612 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053011613
11614 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053011615 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
11616 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011617 status = pmo_ucfg_update_psoc_config(psoc, &psoc_cfg);
11618 if (status != QDF_STATUS_SUCCESS) {
11619 hdd_err("failed pmo psoc configuration");
11620 return -EINVAL;
11621 }
11622
11623 return 0;
11624}
11625
Abhishek Singh257a9482017-03-06 16:52:39 +053011626#ifdef NAPIER_SCAN
Abhishek Singhb20db962017-03-03 21:28:46 +053011627
11628#ifdef FEATURE_WLAN_SCAN_PNO
11629static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11630 struct hdd_config *cfg)
11631{
11632 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
11633 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
11634 pno_cfg->stationary_thresh = cfg->stationary_thresh;
11635 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
11636 pno_cfg->channel_prediction_full_scan =
11637 cfg->channel_prediction_full_scan;
11638}
11639#else
11640static inline void
11641hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
11642 struct hdd_config *cfg)
11643{
11644 return;
11645}
11646#endif
11647
Abhishek Singh257a9482017-03-06 16:52:39 +053011648/**
11649 * hdd_update_scan_config - API to update scan configuration parameters
11650 * @hdd_ctx: HDD context
11651 *
11652 * Return: 0 if success else err
11653 */
11654static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11655{
11656 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11657 struct scan_user_cfg scan_cfg;
11658 struct hdd_config *cfg = hdd_ctx->config;
11659 QDF_STATUS status;
11660
11661 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
11662 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
11663 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
11664 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
11665 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
11666 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
11667 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053011668 /* convert to ms */
11669 scan_cfg.scan_cache_aging_time =
11670 cfg->scanAgingTimeout * 1000;
11671 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
11672 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
11673 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
11674 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053011675 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053011676 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Abhishek Singh257a9482017-03-06 16:52:39 +053011677
Abhishek Singhb20db962017-03-03 21:28:46 +053011678 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
11679
Abhishek Singh257a9482017-03-06 16:52:39 +053011680 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
11681 if (status != QDF_STATUS_SUCCESS) {
11682 hdd_err("failed pmo psoc configuration");
11683 return -EINVAL;
11684 }
11685
11686 return 0;
11687}
11688#else
11689static int hdd_update_scan_config(hdd_context_t *hdd_ctx)
11690{
11691 return 0;
11692}
11693#endif
11694
Frank Liud4b2fa02017-03-29 11:46:48 +080011695#ifdef CONVERGED_TDLS_ENABLE
11696static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11697{
11698 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
11699 struct tdls_start_params tdls_cfg;
11700 struct tdls_user_config *config = &tdls_cfg.config;
11701 struct hdd_config *cfg = hdd_ctx->config;
11702 QDF_STATUS status;
11703
11704 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
11705 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
11706 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
11707 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
11708 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
11709 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
11710 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
11711 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
11712 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
11713 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
11714 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
11715 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
11716 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
11717 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
11718 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
11719 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
11720 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
11721 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
11722 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
11723 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
11724 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
11725 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
11726 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
11727 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
11728 (cfg->fEnableTDLSImplicitTrigger ?
11729 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
11730 (cfg->fTDLSExternalControl ?
11731 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
11732
11733 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
11734 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
11735 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
11736 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011737 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011738 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
Frank Liud4b2fa02017-03-29 11:46:48 +080011739 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
11740 tdls_cfg.tdls_evt_cb_data = psoc;
11741 tdls_cfg.tdls_tl_peer_data = hdd_ctx;
11742 tdls_cfg.tdls_reg_tl_peer = hdd_tdls_register_tdls_peer;
11743 tdls_cfg.tdls_dereg_tl_peer = hdd_tdls_deregister_tdl_peer;
Kabilan Kannanf56f9d52017-04-05 03:31:34 -070011744 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
11745 tdls_cfg.tdls_wmm_cb_data = psoc;
11746 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
11747 tdls_cfg.tdls_rx_cb_data = psoc;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011748 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Frank Liud4b2fa02017-03-29 11:46:48 +080011749
11750 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
11751 if (status != QDF_STATUS_SUCCESS) {
11752 hdd_err("failed pmo psoc configuration");
11753 return -EINVAL;
11754 }
11755
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011756 hdd_ctx->tdls_umac_comp_active = true;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011757 /* disable napier specific tdls data path */
11758 hdd_ctx->tdls_nap_active = false;
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011759
Frank Liud4b2fa02017-03-29 11:46:48 +080011760 return 0;
11761}
11762#else
11763static int hdd_update_tdls_config(hdd_context_t *hdd_ctx)
11764{
Kabilan Kannan1c1c4022017-04-06 22:49:26 -070011765 hdd_ctx->tdls_umac_comp_active = false;
Kabilan Kannan256e3182017-05-02 16:02:37 -070011766 /* disable napier specific tdls data path */
11767 hdd_ctx->tdls_nap_active = false;
Frank Liud4b2fa02017-03-29 11:46:48 +080011768 return 0;
11769}
11770#endif
11771
Mukul Sharma9d797a02017-01-05 20:26:03 +053011772int hdd_update_components_config(hdd_context_t *hdd_ctx)
11773{
11774 int ret;
11775
11776 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053011777 if (ret)
11778 return ret;
11779 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080011780 if (ret)
11781 return ret;
11782 ret = hdd_update_tdls_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053011783
11784 return ret;
11785}
11786
Agrawal Ashish65634612016-08-18 13:24:32 +053011787/**
11788 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
11789 * @mode : cfg80211 DFS mode
11790 *
11791 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
11792 */
11793enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
11794{
11795 switch (mode) {
11796 case DFS_MODE_ENABLE:
11797 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011798 case DFS_MODE_DISABLE:
11799 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011800 case DFS_MODE_DEPRIORITIZE:
11801 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011802 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011803 hdd_debug("ACS dfs mode is NONE");
11804 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053011805 }
11806}
11807
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011808/**
11809 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
11810 * @hddctx: pointer to hdd context
11811 * @set_value: enable/disable
11812 *
11813 * When Host sends vendor command enable, FW will send *ONE* CA ind to
11814 * Host(even though it is duplicate). When Host send vendor command
11815 * disable,FW doesn't perform any action. Whenever any change in
11816 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
11817 *
11818 * return - 0 on success, appropriate error values on failure.
11819 */
11820int hdd_enable_disable_ca_event(hdd_context_t *hddctx, uint8_t set_value)
11821{
11822 QDF_STATUS status;
11823
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011824 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011825 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011826
11827 if (!hddctx->config->goptimize_chan_avoid_event) {
11828 hdd_warn("goptimize_chan_avoid_event ini param disabled");
11829 return -EINVAL;
11830 }
11831
11832 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
11833 if (!QDF_IS_STATUS_SUCCESS(status)) {
11834 hdd_err("Failed to send chan avoid command to SME");
11835 return -EINVAL;
11836 }
11837 return 0;
11838}
Agrawal Ashish65634612016-08-18 13:24:32 +053011839
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011840/**
11841 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
11842 * @value: value to set
11843 *
11844 * This function will set the passed value to roaming in progress flag.
11845 *
11846 * Return: None
11847 */
11848void hdd_set_roaming_in_progress(bool value)
11849{
11850 hdd_context_t *hdd_ctx;
11851
11852 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11853 if (!hdd_ctx) {
11854 hdd_err("HDD context is NULL");
11855 return;
11856 }
11857
11858 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011859 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011860}
11861
11862/**
11863 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011864 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011865 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011866 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011867 */
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011868bool hdd_is_roaming_in_progress(hdd_adapter_t *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011869{
11870 hdd_context_t *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011871 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011872
11873 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11874 if (!hdd_ctx) {
11875 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011876 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011877 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011878 hdd_debug("dev mode = %d, roaming_in_progress = %d",
11879 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080011880 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
11881 hdd_ctx->roaming_in_progress);
11882
11883 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080011884}
11885
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011886/**
11887 * hdd_is_connection_in_progress() - check if connection is in
11888 * progress
11889 * @session_id: session id
11890 * @reason: scan reject reason
11891 *
11892 * Go through each adapter and check if Connection is in progress
11893 *
11894 * Return: true if connection is in progress else false
11895 */
11896bool hdd_is_connection_in_progress(uint8_t *session_id,
11897 enum scan_reject_states *reason)
11898{
11899 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
11900 hdd_station_ctx_t *hdd_sta_ctx = NULL;
11901 hdd_adapter_t *adapter = NULL;
11902 QDF_STATUS status = 0;
11903 uint8_t sta_id = 0;
11904 uint8_t *sta_mac = NULL;
11905 hdd_context_t *hdd_ctx;
11906
11907 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11908 if (!hdd_ctx) {
11909 hdd_err("HDD context is NULL");
11910 return false;
11911 }
11912
11913 if (true == hdd_ctx->btCoexModeSet) {
11914 hdd_info("BTCoex Mode operation in progress");
11915 return true;
11916 }
11917 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
11918 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
11919 adapter = adapter_node->pAdapter;
11920 if (!adapter)
11921 goto end;
11922
11923 hdd_info("Adapter with device mode %s(%d) exists",
11924 hdd_device_mode_to_string(adapter->device_mode),
11925 adapter->device_mode);
11926 if (((QDF_STA_MODE == adapter->device_mode)
11927 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
11928 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
11929 && (eConnectionState_Connecting ==
11930 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
11931 conn_info.connState)) {
11932 hdd_err("%p(%d) Connection is in progress",
11933 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11934 adapter->sessionId);
11935 if (session_id && reason) {
11936 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011937 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011938 }
11939 return true;
11940 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070011941 /*
11942 * sme_neighbor_middle_of_roaming is for LFR2
11943 * hdd_is_roaming_in_progress is for LFR3
11944 */
11945 if (((QDF_STA_MODE == adapter->device_mode) &&
11946 sme_neighbor_middle_of_roaming(
11947 WLAN_HDD_GET_HAL_CTX(adapter),
11948 adapter->sessionId)) ||
11949 hdd_is_roaming_in_progress(adapter)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011950 hdd_err("%p(%d) Reassociation in progress",
11951 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
11952 adapter->sessionId);
11953 if (session_id && reason) {
11954 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011955 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011956 }
11957 return true;
11958 }
11959 if ((QDF_STA_MODE == adapter->device_mode) ||
11960 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
11961 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
11962 hdd_sta_ctx =
11963 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11964 if ((eConnectionState_Associated ==
11965 hdd_sta_ctx->conn_info.connState)
11966 && (false ==
11967 hdd_sta_ctx->conn_info.uIsAuthenticated)) {
11968 sta_mac = (uint8_t *)
11969 &(adapter->macAddressCurrent.bytes[0]);
11970 hdd_err("client " MAC_ADDRESS_STR
11971 " is in middle of WPS/EAPOL exchange.",
11972 MAC_ADDR_ARRAY(sta_mac));
11973 if (session_id && reason) {
11974 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011975 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011976 }
11977 return true;
11978 }
11979 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
11980 (QDF_P2P_GO_MODE == adapter->device_mode)) {
11981 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
11982 sta_id++) {
11983 if (!((adapter->aStaInfo[sta_id].isUsed)
11984 && (OL_TXRX_PEER_STATE_CONN ==
11985 adapter->aStaInfo[sta_id].tlSTAState)))
11986 continue;
11987
11988 sta_mac = (uint8_t *)
11989 &(adapter->aStaInfo[sta_id].
11990 macAddrSTA.bytes[0]);
11991 hdd_err("client " MAC_ADDRESS_STR
11992 " of SAP/GO is in middle of WPS/EAPOL exchange",
11993 MAC_ADDR_ARRAY(sta_mac));
11994 if (session_id && reason) {
11995 *session_id = adapter->sessionId;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011996 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080011997 }
11998 return true;
11999 }
12000 if (hdd_ctx->connection_in_progress) {
12001 hdd_err("AP/GO: connection is in progress");
12002 return true;
12003 }
12004 }
12005end:
12006 status = hdd_get_next_adapter(hdd_ctx, adapter_node, &next);
12007 adapter_node = next;
12008 }
12009 return false;
12010}
12011
12012/**
12013 * hdd_restart_sap() - to restart SAP in driver internally
12014 * @ap_adapter: Pointer to SAP hdd_adapter_t structure
12015 *
12016 * Return: None
12017 */
12018void hdd_restart_sap(hdd_adapter_t *ap_adapter)
12019{
12020 hdd_ap_ctx_t *hdd_ap_ctx;
12021 hdd_hostapd_state_t *hostapd_state;
12022 QDF_STATUS qdf_status;
12023 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12024 tsap_Config_t *sap_config;
12025 void *sap_ctx;
12026
12027 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12028 sap_config = &hdd_ap_ctx->sapConfig;
12029 sap_ctx = hdd_ap_ctx->sapContext;
12030
12031 mutex_lock(&hdd_ctx->sap_lock);
12032 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
12033 wlan_hdd_del_station(ap_adapter);
12034 hdd_cleanup_actionframe(hdd_ctx, ap_adapter);
12035 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
12036 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
12037 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
12038 qdf_status =
12039 qdf_wait_single_event(&hostapd_state->
12040 qdf_stop_bss_event,
12041 SME_CMD_TIMEOUT_VALUE);
12042
12043 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12044 cds_err("SAP Stop Failed");
12045 goto end;
12046 }
12047 }
12048 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012049 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012050 ap_adapter->device_mode, ap_adapter->sessionId);
12051 cds_err("SAP Stop Success");
12052
12053 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
12054 cds_err("SAP Not able to set AP IEs");
12055 wlansap_reset_sap_config_add_ie(sap_config,
12056 eUPDATE_IE_ALL);
12057 goto end;
12058 }
12059
12060 qdf_event_reset(&hostapd_state->qdf_event);
12061 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
12062 sap_config,
12063 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
12064 cds_err("SAP Start Bss fail");
12065 wlansap_reset_sap_config_add_ie(sap_config,
12066 eUPDATE_IE_ALL);
12067 goto end;
12068 }
12069
12070 cds_info("Waiting for SAP to start");
12071 qdf_status =
12072 qdf_wait_single_event(&hostapd_state->qdf_event,
12073 SME_CMD_TIMEOUT_VALUE);
12074 wlansap_reset_sap_config_add_ie(sap_config,
12075 eUPDATE_IE_ALL);
12076 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
12077 cds_err("SAP Start failed");
12078 goto end;
12079 }
12080 cds_err("SAP Start Success");
12081 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
12082 if (hostapd_state->bssState == BSS_START)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012083 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12084 ap_adapter->device_mode,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012085 ap_adapter->sessionId);
12086 hostapd_state->bCommit = true;
12087 }
12088end:
12089 mutex_unlock(&hdd_ctx->sap_lock);
12090 return;
12091}
12092
12093/**
12094 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
12095 * with non dfs acs
12096 *
12097 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
12098 *
12099 * Return: None
12100 */
12101void hdd_check_and_restart_sap_with_non_dfs_acs(void)
12102{
12103 hdd_adapter_t *ap_adapter;
12104 hdd_context_t *hdd_ctx;
12105 cds_context_type *cds_ctx;
12106
12107 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12108 if (!hdd_ctx) {
12109 cds_err("HDD context is NULL");
12110 return;
12111 }
12112
12113 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
12114 if (!cds_ctx) {
12115 cds_err("Invalid CDS Context");
12116 return;
12117 }
12118
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012119 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
12120 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012121 cds_info("Concurrency mode is not SAP");
12122 return;
12123 }
12124
12125 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070012126 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
12127 &ap_adapter->event_flags) &&
12128 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
12129 ap_adapter->sessionCtx.ap.operatingChannel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012130
12131 cds_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
12132 ap_adapter->sessionCtx.ap.sapConfig.channel =
12133 AUTO_CHANNEL_SELECT;
12134 ap_adapter->sessionCtx.ap.sapConfig.
12135 acs_cfg.acs_mode = true;
12136
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012137 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080012138 }
12139}
12140
12141/**
12142 * hdd_set_connection_in_progress() - to set the connection in
12143 * progress flag
12144 * @value: value to set
12145 *
12146 * This function will set the passed value to connection in progress flag.
12147 * If value is previously being set to true then no need to set it again.
12148 *
12149 * Return: true if value is being set correctly and false otherwise.
12150 */
12151bool hdd_set_connection_in_progress(bool value)
12152{
12153 bool status = true;
12154 hdd_context_t *hdd_ctx;
12155
12156 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12157 if (!hdd_ctx) {
12158 cds_err("HDD context is NULL");
12159 return false;
12160 }
12161
12162 qdf_spin_lock(&hdd_ctx->connection_status_lock);
12163 /*
12164 * if the value is set to true previously and if someone is
12165 * trying to make it true again then it could be some race
12166 * condition being triggered. Avoid this situation by returning
12167 * false
12168 */
12169 if (hdd_ctx->connection_in_progress && value)
12170 status = false;
12171 else
12172 hdd_ctx->connection_in_progress = value;
12173 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
12174 return status;
12175}
12176
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012177int wlan_hdd_send_p2p_quota(hdd_adapter_t *adapter, int set_value)
12178{
12179 if (!adapter) {
12180 hdd_err("Invalid adapter");
12181 return -EINVAL;
12182 }
12183 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012184 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012185 WMA_VDEV_MCC_SET_TIME_QUOTA,
12186 set_value, VDEV_CMD);
12187 return 0;
12188
12189}
12190
12191int wlan_hdd_send_mcc_latency(hdd_adapter_t *adapter, int set_value)
12192{
12193 if (!adapter) {
12194 hdd_err("Invalid adapter");
12195 return -EINVAL;
12196 }
12197
12198 hdd_info("Send MCC latency WMA: %d", set_value);
Naveen Rawat247a8682017-06-05 15:00:31 -070012199 sme_cli_set_command(adapter->sessionId,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070012200 WMA_VDEV_MCC_SET_TIME_LATENCY,
12201 set_value, VDEV_CMD);
12202 return 0;
12203}
12204
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070012205hdd_adapter_t *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
12206 *psoc, uint8_t vdev_id)
12207{
12208 hdd_adapter_t *adapter = NULL;
12209 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12210
12211 /*
12212 * Currently PSOC is not being used. But this logic will
12213 * change once we have the converged implementation of
12214 * HDD context per PSOC in place. This would break if
12215 * multiple vdev objects reuse the vdev id.
12216 */
12217 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
12218 if (!adapter)
12219 hdd_err("Get adapter by vdev id failed");
12220
12221 return adapter;
12222}
12223
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053012224int hdd_get_rssi_snr_by_bssid(hdd_adapter_t *adapter, const uint8_t *bssid,
12225 int8_t *rssi, int8_t *snr)
12226{
12227 QDF_STATUS status;
12228 hdd_wext_state_t *wext_state = WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
12229 tCsrRoamProfile *profile = &wext_state->roamProfile;
12230
12231 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
12232 profile, bssid, rssi, snr);
12233 if (QDF_STATUS_SUCCESS != status) {
12234 hdd_warn("sme_get_rssi_snr_by_bssid failed");
12235 return -EINVAL;
12236 }
12237
12238 return 0;
12239}
12240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012241/* Register the module init/exit functions */
12242module_init(hdd_module_init);
12243module_exit(hdd_module_exit);
12244
12245MODULE_LICENSE("Dual BSD/GPL");
12246MODULE_AUTHOR("Qualcomm Atheros, Inc.");
12247MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
12248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012249module_param_call(con_mode, con_mode_handler, param_get_int, &con_mode,
12250 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012251
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012252module_param_call(con_mode_ftm, con_mode_handler_ftm, param_get_int,
12253 &con_mode_ftm, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12254
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012255module_param_call(fwpath, fwpath_changed_handler, param_get_string, &fwpath,
12256 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
12257
12258module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
12259
12260module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
12261
12262module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);